0

I'm generating IDs for elements in a page, and would like to make sure I don't stumble across some invalid 'id' value. While the W3 standard seems to say that anything goes, you never know about all browsers, etc, so I'm asking here.


I'm talking about id as in <div id='myid' />.

2
  • 1
    Please provide more detail about the doctypes you are targetting. Commented Jun 24, 2011 at 18:48
  • html 4, html 5, xhtml 1.0 and 1.1 Commented Jun 24, 2011 at 20:03

1 Answer 1

1

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

From: http://www.w3.org/TR/html4/types.html

Sign up to request clarification or add additional context in comments.

1 Comment

I wouldn't recommend the use of "." and ":" though. It's very likely they'll get interpreted as class and pseudo-class selectors.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.