What are the allowed tags inside a ``?
A <li>
in HTML can nest flow content, which includes most tags like <div>
, <span>
, headers (<h1>
-<h6>
), paragraphs (<p>
), and embedded content (<img>
, <video>
). It cannot, however, include interactive content, such as <button>
or form elements (<input>
, <textarea>
). This flexibility permits sophisticated structures inside a list item.
Example:
Defining flow content
Flow content anchors most HTML tags; your comprehension of it is critical for the structurally and semantically sound usage of <li>
elements. Though most frequently used HTML tags are deemed flow content, they must be appropriately used inside <li>
to maintain accessibility and SEO strength.
Block versus inline
Both block and inline elements find a home inside <li>
. However, recognise their presentation traits - block elements typically break to new lines and take up the full width, while inline elements settle within surrounding content. Think of the <li>
as a flexible boat that adapts to the content it carries.
Special content cases
Apply conscious thought when including tables and nested lists—they need clear purpose and tidy composition. Meanwhile, elements typically used at the document-level such as <header>
, <footer>
, and <main>
should be avoided to shun semantic ambiguity.
The holy grail of nesting
To circumvent total chaos, respect the Golden Rule of Semantics: only nest elements that logically belong together and maintain a sensible hierarchy, supporting both user experience and compliance with HTML standards.
Assessing your content
Standards assurance is a hefty task, but W3C's Markup Validation Service perfects the process. Use different content samples to validate your <li>
composition, and align it with web standards.
Enhancing accessibility
As the complexity of <li>
content mounts, accessibility considerations become paramount. Use ARIA roles and properties judiciously to make sure assistive technologies can interpret and navigate through your lists correctly. Soundly built <li>
tags help create a universally accessible and inclusive web.
Was this article helpful?