Contents

Lists

Lists are a great way to organize information and make it easy to follow. HTML gives you different types of lists, like ordered lists for numbered items, unordered lists with bullets, and description lists for terms and definitions. Let’s dive into how to use them, nest them, and style them with CSS to create more structured content.

ordered and unordered list

Ordered Lists ( < ol >)

An ordered list is used when the order matters, like steps in a process or a ranked list. The items are usually numbered by default.

Basic Example:
				
					<ol>
  <li>First item</li>
  <li>Second item</li>
  <li>Third item</li>
</ol>


				
			

This will show up as:

  1. First item
  2. Second item
  3. Third item
 
Customizing Ordered Lists

You can change the numbering style using the type attribute:

  • type="1": Numbers (1, 2, 3…)
  • type="A": Uppercase letters (A, B, C…)
  • type="a": Lowercase letters (a, b, c…)
  • type="I": Roman numerals (I, II, III…)
  • type="i": Lowercase Roman numerals (i, ii, iii…)

 

Example:

				
					<ol type="A">
  <li>First item</li>
  <li>Second item</li>
  <li>Third item</li>
</ol>

				
			

This will render as:

A. First item
B. Second item
C. Third item

Unordered Lists (< ul > )

An unordered list is great for items that don’t need to be in any particular order, like shopping lists or random ideas. The items are usually marked with bullet points.

Basic Example:

				
					<ul>
  <li>Apple</li>
  <li>Banana</li>
  <li>Cherry</li>
</ul>


				
			

This will show up as:

  • Apple
  • Banana
  • Cherry
 
Changing Bullet Styles

You can change the bullet style using the type attribute or with CSS:

  • type="disc": Solid bullet (●)
  • type="circle": Hollow circle (○)
  • type="square": Solid square (■)

Example:

				
					<ul type="circle">
  <li>Apple</li>
  <li>Banana</li>
  <li>Cherry</li>
</ul>

				
			

This will render as:

○ Apple
○ Banana
○ Cherry

Description Lists ( < dl >, < dt >, < dd >,)

A description list is for pairing terms with their descriptions, like a glossary or a list of definitions.

Basic Example:
				
					<dl>
  <dt>HTML</dt>
  <dd>A markup language for creating web pages.</dd>

  <dt>CSS</dt>
  <dd>A style sheet language used for describing the look of a webpage.</dd>
</dl>

				
			

This will display as:

HTML
A markup language for creating web pages.

CSS
A style sheet language used for describing the look of a webpage.

Nesting Lists

You can nest lists inside one another to create a hierarchy. For example, you might want to list categories, and then list items within those categories.

Example:
				
					<ol>
  <li>Fruits
    <ul>
      <li>Apple</li>
      <li>Banana</li>
      <li>Cherry</li>
    </ul>
  </li>
  <li>Vegetables
    <ul>
      <li>Carrot</li>
      <li>Broccoli</li>
      <li>Spinach</li>
    </ul>
  </li>
</ol>

				
			

This will display as:

  1. Fruits
    • Apple
    • Banana
    • Cherry
  2. Vegetables
    • Carrot
    • Broccoli
    • Spinach

Styling Lists

You can use CSS to change how lists look, from adjusting bullet types to removing them altogether.

Styling Unordered Lists with CSS

To change bullet types, you can use list-style-type in CSS.

Example:

				
					<ul class="custom-list">
  <li>Apple</li>
  <li>Banana</li>
  <li>Cherry</li>
</ul>

<style>
  .custom-list {
    list-style-type: square;
  }
</style>

				
			

This will show square bullets:

■ Apple
■ Banana
■ Cherry

Hiding List Markers

If you want to remove bullets or numbers, you can use list-style-type: none.

Example:

				
					<ul class="no-bullets">
  <li>Apple</li>
  <li>Banana</li>
  <li>Cherry</li>
</ul>

<style>
  .no-bullets {
    list-style-type: none;
    padding: 0;
  }
</style>

				
			

This will display the list without any bullets:

      Apple

     Banana

     Cherry

Adjusting List Spacing

To add space between items, you can use margin or padding with CSS.

Example:

 
				
					<ul class="spaced-list">
  <li>Apple</li>
  <li>Banana</li>
  <li>Cherry</li>
</ul>

<style>
  .spaced-list li {
    margin-bottom: 10px;
  }
</style>


				
			

This will add some space between the items, making the list more readable.

Summary

HTML lists are a handy way to present content in an organized way. Ordered lists (<ol>) work well for items that need to be in sequence, while unordered lists (<ul>) are perfect for things like bullet points. Description lists (<dl>) are great for pairing terms with definitions. You can nest lists for more complex layouts, and CSS lets you tweak the look and feel of your lists. Mastering these list types will help you better organize content on your web pages.