HTML: Allowed Characters in id Attribute

By Xah Lee. Date: . Last updated: .


HTML5 allows any character except any type of space character. And, it must not be empty string. For example, you can have:

<p id="34">something</p>

<p id="♥">something</p>

<p id="#yes">something</p>

HTML 4.x

id attribute value must:

Note: you can start it with a Unicode letter, such as “α”, and the W3C validator will pass it as valid (as of 2012-03-29). [see Using Unicode in HTML Attributes]



The value must be unique amongst all the IDs in the element's home subtree and must contain at least one character. The value must not contain any space characters.



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 (".").


HTML 4.01:

In certain cases, authors may specify the value of an attribute without any quotation marks. The attribute value may only contain letters (a-z and A-Z), digits (0-9), hyphens (ASCII decimal 45), periods (ASCII decimal 46), underscores (ASCII decimal 95), and colons (ASCII decimal 58). We recommend using quotation marks even when it is possible to eliminate them.

Attribute names are always case-insensitive.

Attribute values are generally case-insensitive. The definition of each attribute in the reference manual indicates whether its value is case-insensitive.


Allowed Characters and Case Sensitivity