How does AngularJS get away with using custom HTML5 element tags and attributes?

前端 未结 4 663
故里飘歌
故里飘歌 2020-12-08 13:03

Most browsers seem to allow you to create any element tag you like, and add any attribute name you like to elements. For example:


<         


        
4条回答
  •  -上瘾入骨i
    2020-12-08 14:06

    It won't validate but it will render.

    HTML5 is designed to be very forgiving (contrary to XHTML). This is in part so that "older" HTML5 browsers can allow new elements (as well as badly formatted HTML) which that version doesn't support yet without breaking the page.

    This can of course be "exploited" to introduce custom tags.

    That being said - you can also do this with HTML4.

    As mentioned in comments: you also have the ability to prefix any attributes in an ordinary tag with data- and it will validate.

提交回复
热议问题