HTML 5 classnames and IDs

后端 未结 2 1615
星月不相逢
星月不相逢 2020-12-12 00:01

I know that in HTML4 classes and id cannot start with numbers.

I am coding in HTML 5/php and alot of my ids and classes have just numbers in them that point to a pri

相关标签:
2条回答
  • 2020-12-12 00:26

    I’ve researched this thoroughly and wrote about my findings: The id attribute got more classy in HTML5. From that article:

    HTML5 gets rid of the additional restrictions on the id attribute. The only requirements left — apart from being unique in the document — are that the value must contain at least one character (can’t be empty), and that it can’t contain any space characters.

    To target a classname or ID that starts with a digit in CSS or in JavaScript using the Selectors API, you should escape them. For example, to target the element with id="404", you can’t just use #404 — you’d have to escape it as follows:

    #\34 04 {
      background: pink;
    }
    
    0 讨论(0)
  • 2020-12-12 00:29

    The official html5 specs are here: id-attribute in html5.

    (Here you go for html4)

    So in html5 the only restriction is minimum 1 char and no whitespaces.

    0 讨论(0)
提交回复
热议问题