What are valid values for the id attribute in HTML?

Ask a question
1

When creating theid attributes for HTML elements, what rules are there for the value?

Coin iconoffer bounty
add comment

1 Answer

2

For HTML5, an id has to contain at least 1 character and may not contain any spaces.

In XHTML, ids are case-sensitive.

Periods, colons and hashtags have a special meaning in CSS selectors, so if you use those in ids, you’d have to escape them with a backslash in a CSS selector, or a double backslash in a CSS selector string passed to jQuery.

add comment

Your Answer