DEV Community

Cover image for Day 3 of HTML
Raizo-03
Raizo-03

Posted on

Day 3 of HTML

Today I explored HTML lists, which are essential for organizing content in a structured way. Here's everything I learned about creating and customizing lists:

πŸ“‹ Types of Lists in HTML

HTML provides several types of lists to organize information:

  1. Ordered Lists (<ol>) - numbered lists
  2. Unordered Lists (<ul>) - bulleted lists
  3. Description Lists (<dl>) - term and definition pairs

πŸ”’ Ordered Lists (<ol>)

Ordered lists display items with numbers, letters, or roman numerals by default starting from 1.

Basic Ordered List:

<ol>
  <li>First item</li>
  <li>Second item</li>
  <li>Third item</li>
</ol>
Enter fullscreen mode Exit fullscreen mode

Output:

  1. First item
  2. Second item
  3. Third item

Ordered List Attributes:

type Attribute:

  • type="1" - numbers (default)
  • type="A" - uppercase letters
  • type="a" - lowercase letters
  • type="I" - uppercase Roman numerals
  • type="i" - lowercase Roman numerals
<ol type="A">
  <li>Apple</li>
  <li>Banana</li>
  <li>Cherry</li>
</ol>
Enter fullscreen mode Exit fullscreen mode

Output:
A. Apple
B. Banana
C. Cherry

start Attribute:

Changes the starting number of the list:

<ol start="5">
  <li>Fifth item</li>
  <li>Sixth item</li>
  <li>Seventh item</li>
</ol>
Enter fullscreen mode Exit fullscreen mode

Output:

  1. Fifth item
  2. Sixth item
  3. Seventh item

reversed Attribute:

Creates a countdown list:

<ol reversed>
  <li>Third place</li>
  <li>Second place</li>
  <li>First place</li>
</ol>
Enter fullscreen mode Exit fullscreen mode

πŸ”Έ Unordered Lists (<ul>)

Unordered lists display items with bullet points and don't follow any numerical order.

Basic Unordered List:

<ul>
  <li>Coffee</li>
  <li>Tea</li>
  <li>Juice</li>
</ul>
Enter fullscreen mode Exit fullscreen mode

Output:
β€’ Coffee
β€’ Tea
β€’ Juice

Unordered List type Attribute (CSS is preferred):

  • type="disc" - filled circle (default)
  • type="circle" - empty circle
  • type="square" - filled square
<ul type="square">
  <li>HTML</li>
  <li>CSS</li>
  <li>JavaScript</li>
</ul>
Enter fullscreen mode Exit fullscreen mode

πŸ“ List Item Element (<li>)

The <li> tag defines individual list items and must be enclosed within <ol>, <ul>, or <menu> tags.

List Item value Attribute:

Only works in ordered lists - sets a specific number for that item:

<ol>
  <li>Step 1</li>
  <li>Step 2</li>
  <li value="10">Step 10</li>
  <li>Step 11</li>
</ol>
Enter fullscreen mode Exit fullscreen mode

Output:

  1. Step 1
  2. Step 2
  3. Step 10
  4. Step 11

πŸ”— Nested Lists

You can create lists within lists for hierarchical organization:

<ul>
  <li>Frontend Technologies
    <ol>
      <li>HTML</li>
      <li>CSS</li>
      <li>JavaScript</li>
    </ol>
  </li>
  <li>Backend Technologies
    <ul>
      <li>Node.js</li>
      <li>Python</li>
      <li>PHP</li>
    </ul>
  </li>
</ul>
Enter fullscreen mode Exit fullscreen mode

πŸ“– Description Lists (<dl>)

Description lists contain term-definition pairs using <dt> (term) and <dd> (definition):

<dl>
  <dt>HTML</dt>
  <dd>HyperText Markup Language - the standard markup language for web pages</dd>

  <dt>CSS</dt>
  <dd>Cascading Style Sheets - used for styling HTML elements</dd>

  <dt>JavaScript</dt>
  <dd>A programming language that enables interactive web pages</dd>
</dl>
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ Practical Examples

Navigation Menu:

<ul>
  <li><a href="#home">Home</a></li>
  <li><a href="#about">About</a></li>
  <li><a href="#services">Services</a></li>
  <li><a href="#contact">Contact</a></li>
</ul>
Enter fullscreen mode Exit fullscreen mode

Step-by-Step Instructions:

<ol>
  <li>Open your code editor</li>
  <li>Create a new HTML file</li>
  <li>Add the basic HTML structure</li>
  <li>Save the file with .html extension</li>
  <li>Open in your web browser</li>
</ol>
Enter fullscreen mode Exit fullscreen mode

Shopping List with Categories:

<ul>
  <li>Fruits
    <ul>
      <li>Apples</li>
      <li>Oranges</li>
      <li>Bananas</li>
    </ul>
  </li>
  <li>Vegetables
    <ul>
      <li>Carrots</li>
      <li>Broccoli</li>
      <li>Spinach</li>
    </ul>
  </li>
</ul>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)