Are custom elements valid HTML5?

后端 未结 12 1437
执念已碎
执念已碎 2020-11-22 09:27

I\'ve been unable to find a definitive answer to whether custom tags are valid in HTML5, like this:

Hello!

12条回答
  •  春和景丽
    2020-11-22 09:47

    data-* attributes are valid in HTML5 and even in HTML4 all web browsers used to respect them. Adding new tags is technically okay, but is not recommended just because:

    1. It may conflict with something added in the future, and
    2. Makes the HTML document invalid unless dynamically added via JavaScript.

    I use custom tags only in places that Google does not care, for ecample in a game engine iframe, i made a tag that contained , and - but through JavaScript only. And it was fully valid, according to the validator. It even works in Internet explorer with its styling! ;]

提交回复
热议问题