The <li> Tag
It should be quite obvious to you by now that the <li> tag defines an item in a list. It's
the universal tag for list items in ordered (<ol>) and unordered (<ul>) lists, as we discussed earlier,
and for directories (<dir>) and
menus (<menu>), which we
discuss in detail later in this chapter.
Because the end of a list element can always be inferred by the
surrounding document structure, most authors omit the ending </li> tags for their HTML list elements.
That makes sense because it becomes easier to add, delete, and move
elements around within a list. However, XHTML requires the end tag, so
it's best to get used to including it in your documents.
Although universal in meaning, there are some differences and
restrictions to the use of the <li> tag for each list type. In
unordered and ordered lists, nearly anything can follow the <li> tag, including other lists and
multiple paragraphs. Typically, if it handles indentation at all, the
browser successively indents nested list items, and the content in those
items is justified to the innermost indented margin.
Directory and menu lists are another matter. They are lists of short items, like a single ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access