Is it OK to use unknown HTML tags?

前端 未结 12 1214
梦如初夏
梦如初夏 2020-11-30 04:54

Correct me if I\'m mistaken, but AFAIK, unknown HTML tags in markup (i.e. tags not defined in the HTML spec, like say, ) will eventually be treate

相关标签:
12条回答
  • 2020-11-30 05:06

    What's wrong with the judicious use of < !-- your stuff here -- >. It worked for scripts back around the time of the Cretaceous–Paleogene boundary. Dinosaurs ceased to be a problem around that time, that is apart from the flying, feathered variety.

    0 讨论(0)
  • 2020-11-30 05:07

    Generally not recommendable, e.g. IE wont apply css-styles to unknown tags.

    All other browsers render unknown tags as inline-Elements (which causes problems with nesting).

    I recommend you the following article: http://diveintohtml5.info/ There is a section about unknown tags.

    0 讨论(0)
  • 2020-11-30 05:20

    It's bad practice and you should not do it. The browser renders it as div as fallback solution in most cases but it's not valid html and therefore never will pass a validity test.

    0 讨论(0)
  • 2020-11-30 05:21

    Rule #1 of browser interoperability is: don't have errors. No matter how many browsers you test in, there are always browsers you can't test, for instance because they don't exist yet.
    Also, unknown elements will be treated as <span>, not <div> by most browsers currently.

    If it's really source readability(*) you're after, you should look into XML+XSLT.
    That way, you can use all the tag names you want, and make them behave in any way you like and you don't have to worry that <media> will be a real element in some future version of HTML.

    One good real world example is the element <picture>. If a website ever used <picture> and relied on the notion that this element would have no styles or special content by itself, they are in trouble now!

    (*) With XML+XSLT, the readability will be in the XML part, not the XSLT part, obviously.

    0 讨论(0)
  • 2020-11-30 05:22

    In my case I use a lot of them into my Webkit-powered game GUI system, and everything works.

    0 讨论(0)
  • 2020-11-30 05:24

    W3C says:

    HTML5 supports unknown tags as inline elements, but it recommends CSS styling for it.

    Here is the source: https://www.w3schools.com/html/html5_browsers.asp

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