html id/class first symbol digit, is valid?

This question already has an answer here:

  • What are valid values for the id attribute in HTML? 21 answers

  • 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; } #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.

    链接地址: http://www.djcxy.com/p/15448.html

    上一篇: div与ID =“(名称)”我可以使用这个或不?

    下一篇: html id / class第一个符号数字,是否有效?