In HTML, what characters are valid as the first character in an id
or class
attribute?
For example, is <div id="4bla"></div>
valid or must they start with only letters?
In HTML, what characters are valid as the first character in an id
or class
attribute?
For example, is <div id="4bla"></div>
valid or must they start with only letters?
HTML5:
As of HTML5, it is indeed valid to start an ID with a digit.
In HTML5, even this is valid:
<p id="#">Foo.
<p id="##">Bar.
<p id="♥">Baz.
<p id="©">Inga.
<p id="{}">Lorem.
As is your example:
<div id="4bla"></div>
Note: It may be valid in HTML5, however it is not valid in CSS.
That means <div id="4bla"></div>
is valid, but #4bla { background-color:red; }
isn't.
Start ID's with characters instead for maximum compatibility.
HTML4:
It is invalid if you're still using HTML4:
"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 (".")."
No, its not XHTML valid. You can use the XHTML-Validator to check your HTML code.
But even if its not XHTML-Valid it should work in almost every browser.