HTML
  • Tag - Quackit Tutorials
  • HTML <li> Tag

    The HTML <li> tag represents a list item in ordered and unordered lists.

    The <li> tag is placed inside either a <ol> tag or a <ul> to represent each individual item within that list. It can also be used with the <menu> tag for HTML 5.1 and HTML Living Standard documents.

    Syntax

    The <li> tag is written as <li></li> with the list item inserted between the start and end tags. The element must be placed inside either a <ol> tag or a <ul> tag to provide each individual list item within those elements.

    The <li> tag can also be used inside the <menu> element (only when the element is in the toolbar state), however, that element is not supported by the W3C HTML5 specification - it is currently only supported by the HTML 5.1 specification and the WHATWG HTML Living Standard.

    Like this:

    <ul> <li>List item...</li> <li>List item...</li> <li>List item...</li> </ul>

    Examples

    Unordered List

    Here's an example of using the <li> inside the <ul> tag to create an unordered list.

    <ul> <li>Cats</li> <li>Dogs</li> <li>Birds</li> </ul>

    Ordered List

    Here's an example of using the <li> inside the <ol> tag to create an ordered list.

    <ol> <li>Cats</li> <li>Dogs</li> <li>Birds</li> </ol>

    The value Attribute

    You can use the value attribute to specify a number for a list item. Any subesquent list items increment their value from that initial value (unless you override it with a new value).

    Note that you can only use the value attribute when using the <ol> element.

    Also note that the ordinal value of the value attribute must be a valid integer.

    <ol> <li value="11">Cats</li> <li>Dogs</li> <li>Birds</li> </ol>

    Applying Styles

    You can use the CSS list-style, list-style-image, list-style-position, and list-style-type properties to change the styles of the <li> elements.

    Although you can apply these properties directly to the <li> element, they are usually applied to the parent element (which is then cascaded down to the <li> element).

    Here are some examples.

    Roman Numerals

    This example uses the list-style-type property to specify roman numerals.

    <!DOCTYPE html> <title>Example</title> <style> ol { list-style-type: lower-roman; } </style> <ol> <li>Cats</li> <li>Dogs</li> <li>Birds</li> </ol>

    Square Bullets

    This example uses the list-style-type property to specify square bullets for each list item within an unordered list.

    <!DOCTYPE html> <title>Example</title> <style> ul { list-style-type: square; } </style> <ul> <li>Cats</li> <li>Dogs</li> <li>Birds</li> </ul>

    Images

    You can replace the bullet points with an image using the list-style-image property.

    <!DOCTYPE html> <title>Example</title> <style> ul { list-style-image: url(/pix/printer_icon.gif)} </style> <p>Remember to print the following:</p> <ul> <li>Cats</li> <li>Dogs</li> <li>Birds</li> </ul>

    Position of List Item

    This example uses the list-style-position property to specify the position of the list items.

    <!DOCTYPE html> <title>Example</title> <style> ol.inside { list-style-position: inside; } </style> <p>Normal:</p> <ol> <li>Cats</li> <li>Dogs</li> <li>Birds</li> </ol> <p>With <code>list-style-position: inside;</code> applied:</p> <ol class="inside"> <li>Cats</li> <li>Dogs</li> <li>Birds</li> </ol>

    The list-style Property

    The list-style property is a shortcut property. It allows you to apply multiple properties to your list items.

    Example:

    <!DOCTYPE html> <title>Example</title> <style> ol { list-style: lower-greek inside; } </style> <ol> <li>Cats</li> <li>Dogs</li> <li>Birds</li> </ol>

    Attributes

    Attributes can be added to an HTML element to provide more information about how the element should appear or behave.

    The <li> element accepts the following attributes.

    AttributeDescription
    valueSpecifies the value of the list item. The value must be a number. Can only be used if the list is an ordered list (i.e. <ol>).

    Global Attributes

    The following attributes are standard across all HTML elements. Therefore, you can use these attributes with the <li> tag , as well as with all other HTML tags.

    • accesskey
    • autocapitalize
    • class
    • contenteditable
    • data-*
    • dir
    • draggable
    • hidden
    • id
    • inputmode
    • is
    • itemid
    • itemprop
    • itemref
    • itemscope
    • itemtype
    • lang
    • part
    • slot
    • spellcheck
    • style
    • tabindex
    • title
    • translate

    For a full explanation of these attributes, see HTML 5 global attributes.

    Event Handlers

    Event handler content attributes enable you to invoke a script from within your HTML. The script is invoked when a certain "event" occurs. Each event handler content attribute deals with a different event.

    • onabort
    • onauxclick
    • onblur
    • oncancel
    • oncanplay
    • oncanplaythrough
    • onchange
    • onclick
    • onclose
    • oncontextmenu
    • oncopy
    • oncuechange
    • oncut
    • ondblclick
    • ondrag
    • ondragend
    • ondragenter
    • ondragexit
    • ondragleave
    • ondragover
    • ondragstart
    • ondrop
    • ondurationchange
    • onemptied
    • onended
    • onerror
    • onfocus
    • onformdata
    • oninput
    • oninvalid
    • onkeydown
    • onkeypress
    • onkeyup
    • onlanguagechange
    • onload
    • onloadeddata
    • onloadedmetadata
    • onloadstart
    • onmousedown
    • onmouseenter
    • onmouseleave
    • onmousemove
    • onmouseout
    • onmouseover
    • onmouseup
    • onpaste
    • onpause
    • onplay
    • onplaying
    • onprogress
    • onratechange
    • onreset
    • onresize
    • onscroll
    • onsecuritypolicyviolation
    • onseeked
    • onseeking
    • onselect
    • onslotchange
    • onstalled
    • onsubmit
    • onsuspend
    • ontimeupdate
    • ontoggle
    • onvolumechange
    • onwaiting
    • onwheel

    Most event handler content attributes can be used on all HTML elements, but some event handlers have specific rules around when they can be used and which elements they are applicable to.

    For more detail, see HTML event handler content attributes.

    Tag » What Is Li In Html