The <ul> tag initiates an unordered list, while each item within the list is designated with the <li> tag.
By default, the list items are represented with small black circles as bullets.
Example
<ul> <li>Coffee</li> <li>Tea</li> <li>Milk</li> </ul> |
The CSS list-style-type property is employed to specify the appearance of the marker for list items.
It can take on any of the subsequent values:
Value |
Description |
disc |
Configures the list of item marker to a bullet, which is the default setting. |
circle |
Specifies the marker for list items to be a circle. |
square |
Designates the marker for list items to be a square |
none |
The list items will lack markers. |
<ul style=”list-style-type:disc;”> <li>Coffee</li> <li>Tea</li> <li>Milk</li> </ul> |
<ul style=”list-style-type:circle;”> <li>Coffee</li> <li>Tea</li> <li>Milk</li> </ul> |
<ul style=”list-style-type:square;”> <li>Coffee</li> <li>Tea</li> <li>Milk</li> </ul> |
<ul style=”list-style-type:none;”> <li>Coffee</li> <li>Tea</li> <li>Milk</li> </ul> |
Lists can be structured hierarchically, with one list contained within another (a list inside another list).
Example
<ul> <li>Coffee</li> <li>Tea <ul> <li>Black tea</li> <li>Green tea</li> </ul> </li> <li>Milk</li> </ul> |
Remember: Within a list item (<li>), you can include another list, as well as other HTML elements such as images, links, and more. |
HTML lists offer versatility in styling through CSS.
A common approach involves styling a list horizontally, often utilized to craft navigation menus.
Example
<!DOCTYPE html> <html> <head> <style> ul { list-style-type: none; margin: 0; padding: 0; overflow: hidden; background-color: #333333; } li { li a { li a:hover { </head> <body> <ul> <li><a href=”#home”>Home</a></li> <li><a href=”#news”>News</a></li> <li><a href=”#contact”>Contact</a></li> <li><a href=”#about”>About</a></li> </ul> </body> </html> |