HTML Lists are basically used to enlist items in a web page. They are also used to enlist navigation items in websites. List items can contain any HTML element inside them. There are three types of lists in HTML namely:
An unordered list is placed inside the <ul> tag. Each list item is placed inside the <li> tag. The unordered list items will be marked with bullets (small black circles) by default.
<ul> <li>HTML</li> <li>CSS </li> <li>Javascript</li> </ul>
You can use type attribute to change the list item marker. CSS property list-style-type or list-style can also be used to style them along with style attribute or using CSS.
Attribute Value | Description |
---|---|
disc | Set bullet as the list item marker |
circle | Set circle as the list item marker |
square | Set square as the list item marker |
none | Hide the list item marker |
<ul type="disc"> <li>HTML</li> <li>CSS </li> <li>Javascript</li> </ul>
<ul type="circle"> <li>HTML</li> <li>CSS </li> <li>Javascript</li> </ul>
<ul type="square"> <li>HTML</li> <li>CSS </li> <li>Javascript</li> </ul>
<ul type="none"> <li>HTML</li> <li>CSS </li> <li>Javascript</li> </ul>
An ordered list starts with the <ol> tag. Each list item starts with the <li> tag. The list items will be marked with numbers by default.
<ol> <li>HTML</li> <li>CSS </li> <li>Javascript</li> </ol>
You can use type attribute to change the list item marker. CSS property list-style-type or list-style can also be used to style them along with style attribute or using CSS.
Attribute Value | Description |
---|---|
1 | Set The list items will be ordered in sequence with numbers (default) |
A | Set The list items will be ordered in sequence with uppercase alphabets |
a | Set The list items will be ordered in sequence with lowercase alphabets |
I | Set The list items will be ordered in sequence with uppercase roman numbers |
i | Set The list items will be ordered in sequence with lowercase roman numbers |
<ol type="1"> <li>HTML</li> <li>CSS </li> <li>Javascript</li> </ol>
<ol type="A"> <li>HTML</li> <li>CSS </li> <li>Javascript</li> </ol>
<ol type="a"> <li>HTML</li> <li>CSS </li> <li>Javascript</li> </ol>
<ol type="I"> <li>HTML</li> <li>CSS </li> <li>Javascript</li> </ol>
<ol type="i"> <li>HTML</li> <li>CSS </li> <li>Javascript</li> </ol>
A description list is a list of terms followed by a description of each term. The <dl> tag defines the description list while the <dt> tag defines the term (name) and the <dd> tag describes each term.
<dl> <dt>HTML</dt> <dd>Hypertext Markup Language</dd> <dt>CSS</dt> <dd>Cascading Style Sheet</dd> </dl>
HTML lists can be added inside another HTML list which is termed as nested HTML list.
<ul> <li>HTML <ul> <li>Headings</li> <li>Paragraphs</li> <li>Text Formatting</li> <li>Links</li> <li>Images</li> <li>Lists</li> </ul> </li> <li>CSS</li> <li>Javascript</li> </ul>
An ordered list starts counting from the initial value on the sequence. You can use start attribute to force the counting from any value in the numerical sequence. Note: This only works for numerically ordered lists.
Leave a comment