Are custom elements valid HTML5?

后端 未结 12 1449
执念已碎
执念已碎 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 10:02

    To give an updated answer reflecting modern pages.

    Custom tags are valid if either,

    1) They contain a dash

    
    

    2) They are embedded XML

    Hello!
    

    This assumes you are using the HTML5 doctype

    Considering these simple restrictions it now makes sense to do your best to keep your HTML markup valid (please stop closing tags like and


    , it's silly and incorrect unless you use an XHTML doctype, which you probably have no need for).

    Given that HTML5 clearly defines the parsing rules a compliant browser will be able to handle any tag that you throw at it even if it isn't strictly valid.

提交回复
热议问题