HTML <li> Element

Publish in HTML Tutorial el 24/05/2025 16:33

The <li> (List Item) element is used to represent an item in a list. It must be contained within a parent element: either an <ol> (ordered list), <ul> (unordered list), or <menu> (menu list). The <li> element is fundamental for creating structured content in HTML documents.


Basic Syntax

Here's how the basic syntax of an <li> element looks:

When rendered, this will appear as:

  • First item
  • Second item
  • Third item


Attributes

The <li> element supports several attributes:

  • value (for <ol> only): Sets the number of the list item
  • type (deprecated): Was used to set the numbering/bullet type


Examples

Example 1: Basic Unordered List

A simple unordered list with default bullet points:

Play Code


Example 2: Ordered List with Value Attribute

An ordered list where we manually set the numbering using the value attribute:

Play Code


Example 3: Nested Lists

Lists can be nested inside other list items to create hierarchical structures:

Play Code


Example 4: Dynamic List with JavaScript

Creating a list dynamically using JavaScript:

Play Code


Example 5: Interactive List with JavaScript

A list with interactive items that respond to clicks:

Play Code


Tips and Tricks

  • You can style list items individually using CSS classes or IDs
  • To remove default bullets in unordered lists, use list-style-type: none in CSS
  • List items can contain any HTML elements, not just text
  • For semantic correctness, always wrap <li> elements in a proper parent (<ul>, <ol>, or <menu>)
  • Use CSS counters for advanced numbering schemes in ordered lists


Browser Support

The <li> element is supported by all browsers and has been part of HTML since the earliest versions.

También te puede interesar

HTML <style> Element
HTML <style> Element

The <style> HTML element contains style information for a document, or part of a document. ...

HTML <strong> Element
HTML <strong> Element

The <strong> element is used to indicate that its content has strong importance, seriousnes...

HTML <span> Element
HTML <span> Element

The <span> element is an inline container used to mark up a part of a text or document. Unl...

HTML <source> Element
HTML <source> Element

The <source> element is used to specify multiple media resources for media elements like &l...

HTML <small> Element
HTML <small> Element

The <small> element is used to represent side-comments and small print, typically for discl...

HTML <section> Element
HTML <section> Element

HTML <section> Element: The Complete Guide The <section> element is a semantic HTML ...