What are the allowed tags inside a <li>?
I have been searching for the list of tags that are available inside a <li>
but couldn't find any reference.
Is it possible that any standards-compliant HTML 4+ block element is allowed in them?
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.
It's a block level element so pretty much anything goes. Trouble only comes when you're putting block level elements inside inline ones.
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.
上一篇: 使用制表符而不是空格时保持最大行长度?
下一篇: <li>中的允许标签是什么?