What are the allowed tags inside a <li>?

拈花ヽ惹草 提交于 2019-12-17 04:01:41

问题


I have been searching for the list of tags that are available inside a <li>, but I couldn't find any reference.

Is it possible that any standards-compliant HTML 4+ block element is allowed in them?


回答1:


TL;DR: an <li> can contain any element that is valid in <body>.

In the HTML 4.01 spec for lists you’ll find the relevant extract of the DTD:

<!ELEMENT LI - O (%flow;)* -- list item -->

This specifies that an <li> may contain flow content, which is the collection of all block and inline elements.

The HTML5 spec for an <li> is the same in that it also allows any flow content.




回答2:


It's a block level element so pretty much anything goes. Trouble only comes when you're putting block level elements inside inline ones.




回答3:


Yup, pretty much. You can have lists inside lists (either inside the <li> or just loose inside the <ol>/<ul> the inner list must be inside an <li>), block elements and inline elements.

To me it wouldn't make much sense to put a <table> inside an <li>, but even that's still valid.




回答4:


You can use the W3C's Markup Validation Service to test against your cases to know whether or not your markup is valid.

This validator checks the markup validity of Web documents in HTML, XHTML, SMIL, MathML, etc.



来源:https://stackoverflow.com/questions/4967976/what-are-the-allowed-tags-inside-a-li

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!