What are valid values for the id attribute in HTML?

HTMLWeb DevelopmentFront End Technology

The valid values for id attributes are different in HTML4 and HTML5.


HTML does not allow space characters. The string should not be empty. It must contain atleast one character.

<p id="test">This is demo text.</p>
<p id="#test"> This is demo text.</p>

Refer for more.


ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

Refer for more.

Updated on 19-Feb-2020 11:28:37