Does the <li> tag always have to be nested within the <ul> tag?

Question

Does the <li> tag always have to be nested within the <ul> tag?

Answer

The <li> element can be a direct child of either the <ul> or the <ol> elements but it should never exist outside of either of these parent elements.

29 Likes

the

  • tag will be placed inside the
      tag because the
    • tag mean listed items and that helps you organize your unlisted items.
    • help organize all of the items after the unlisted items.
  • 2 Likes

    what is an <ol> element?

    2 Likes

    SInce ‘ul’ is unorganised list, ‘ol’ must be organised list IMO.

    4 Likes

    ul stands for “Unordered List” and ol stands for " Ordered Lists" except that each list item is numbered.
    while li element will show the lists like this:

    • List item 1
    • List item 2
    • List item 3

    A ol element will show the lists like this:

    1. List item 1
    2. List item 2
    3. List item 3
    25 Likes

    The Living Standard also includes the <menu></menu> element, which also has LI as direct children.

    By default they are numbered from 1 to n, but we can also specify letters, lower or upper case, or Roman numerals, also upper or lower case. We can also specify the starting character.

    https://html.spec.whatwg.org/multipage/grouping-content.html#the-ol-element

    Scroll down that page to find UL, LI, and MENU.

    8 Likes

    I notice that I can leave aside the end tag for list items () and everything seems to work fine. Is it really necessary to type an end tag for list items?

    1 Like

    Best practices recommend including both tags; however, W3C has gone along with omitting the endtag. This also applies to paragraphs. Let the situation dictate, and keep it localized and well contained.

    2 Likes