Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

"The id attribute got more classy in HTML5" is written at some pages. If I use class attribute instead of id, does it conform to HTML5? Thanks for your help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
316 views
Welcome To Ask or Share your Answers For Others

1 Answer

The attributes still have two different purposes:

  • class can contain multiple classes and multiple elements can have the same classes
  • id contains a single ID and that ID can only be used for one element.

The statement you quoted exists because some restrictions on how an ID must look like have been lifted in HTML5 - classes never had those restrictions.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...