HTML
  • value Attribute

  • The value attribute of the <li> element is used to set the value of the list item. Since the value is a number, it would be set only for the ol element in HTML i.e. the ordered list.

    Following is the syntax −

    <li value="num">

    Above, num is the value of the list item in an ordered list. 

    Let us now see an example to implement the value attribute of the <li> element −

    Example

     Live Demo

    <!DOCTYPE html>
    <html>
    <body>
    <h1>Subjects</h1>
    <p>Following are the subjects −</p>
    <ol>
       <li>Maths</li>
       <li>Science</li>
       <li>English</li>
       <li>French</li>
    </ol>
    <p>Remaining subjects −</p>
    <ol>
       <li value="5">Coffee</li>
       <li>Accounts</li>
       <li>Programming</li>
       <li>Networking</li>
    </ol>
    </body>
    </html>

    Output

    In the above example, we have set two unordered lists −

    <p>Following are the subjects −</p>
    <ol>
       <li>Maths</li>
       <li>Science</li>
       <li>English</li>
       <li>French</li>
    </ol>
    <p>Remaining subjects −</p>
    
    <ol>
       <li value="5">Coffee</li>
       <li>Accounts</li>
       <li>Programming</li>
       <li>Networking</li>
    </ol>

    One of them is not beginning from the default 1. We have set a different value using the value attribute −

    <ol>
       <li value="5">Coffee</li>
       <li>Accounts</li>
       <li>Programming</li>
       <li>Networking</li>
    </ol>

    Updated on: 30-Jul-2019

    154 Views

    Kickstart Your Career

    Get certified by completing the course

    Get Started
    Advertisements