DEV Community

Cover image for Day 3/365 Days Full Stack Challenge: Organizing Information - Creating Lists in HTML
CodeWithDhanian
CodeWithDhanian

Posted on

Day 3/365 Days Full Stack Challenge: Organizing Information - Creating Lists in HTML

Day 3: Organizing Information - Creating Lists in HTML

Welcome back,

It's Day 3, and you're building momentum. I'm Dhanian, and I'm here to guide you. So far, your web page can display structured text and link to other places. But how do you present a list of ingredients, a series of steps, or a collection of features neatly? You use HTML lists.

Today, we're learning how to organize content into clear, easy-to-read lists. This is a powerful tool for improving the readability and structure of your content. HTML provides two main types of lists: unordered and ordered.

Let's get organized.

1. Unordered Lists (<ul>): The Bulleted List

What it is: An unordered list is used to group a collection of items where the order does not matter. Think of a shopping list or a list of features—it doesn't matter which one you read first.

What it does: The browser automatically renders each item in an unordered list with a bullet point (a small dot) by default. The <ul> tag defines the entire list, and each individual item within it is defined by a list item tag, <li>.

When to use it: Perfect for listing features, ingredients, pack contents, or any other group of related items that have no required sequence.

Code Snippet & Example:

<body>
  <h2>Grocery List</h2>
  <ul>
    <li>Milk</li>
    <li>Eggs</li>
    <li>Bread</li>
    <li>Apples</li>
  </ul>
</body>
Enter fullscreen mode Exit fullscreen mode

Explanation: The <ul> tag opens and closes the entire list. Each item is wrapped in its own <li> (list item) tag. The browser handles the indentation and adds the bullet points for you.

2. Ordered Lists (<ol>): The Numbered List

What it is: An ordered list is used when the sequence of the items is important. The order provides meaning, such as in a recipe's instructions or a step-by-step guide.

What it does: The browser automatically numbers each item in the list sequentially (1, 2, 3...). Like the unordered list, the <ol> tag defines the list, and <li> tags define each item.

When to use it: Ideal for instructions, rankings, directions, or any process that must be followed in a specific order.

Code Snippet & Example:

<body>
  <h2>How to Brew Tea</h2>
  <ol>
    <li>Boil fresh water in a kettle.</li>
    <li>Place a tea bag into your mug.</li>
    <li>Pour the hot water over the tea bag.</li>
    <li>Let it steep for 3-5 minutes.</li>
    <li>Remove the tea bag and enjoy.</li>
  </ol>
</body>
Enter fullscreen mode Exit fullscreen mode

Explanation: The <ol> tag tells the browser to create a numbered list. Notice how the items are automatically numbered. If you were to add a new step in the middle, the browser would automatically renumber all the following items.

Taking it Further: Nested Lists

The real power of lists is revealed when you combine them. You can place an entire new list inside a list item (<li>) to create a sub-list or a nested hierarchy. This is incredibly useful for complex information like outlines, table of contents, or multi-level menus.

You can mix and match ordered and unordered lists within each other.

Code Snippet & Example:

<body>
  <h2>Table of Contents for a Book</h2>
  <ol>
    <li>Introduction</li>
    <li>Web Development Fundamentals
      <ul>
        <li>HTML Basics</li> <!-- This is a sub-point of Chapter 2 -->
        <li>CSS Styling</li>
        <li>JavaScript Interactions</li>
      </ul>
    </li> <!-- Notice the </li> closes after the nested <ul> -->
    <li>Building Your First Website
      <ol>
        <li>Planning the Site</li> <!-- A numbered sub-list -->
        <li>Creating the HTML Structure</li>
        <li>Styling with CSS</li>
      </ol>
    </li>
    <li>Conclusion</li>
  </ol>
</body>
Enter fullscreen mode Exit fullscreen mode

Explanation: Here, Chapter 2 has an unordered list of key topics, and Chapter 3 has an ordered list of steps. The key is to properly nest the tags. The nested <ul> or <ol> must be placed *inside the <li> tag of the parent list item, before the parent's closing </li>.*


Putting It All Together: A Practical Example

Let's create a complete HTML page that uses everything we've learned so far, with a focus on today's lesson about lists.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Day 3: My Recipe Page</title>
</head>
<body>

    <h1>Dhanian's Simple Pasta Recipe</h1>
    <p>This is a quick and easy recipe for a classic tomato pasta sauce. Perfect for a weeknight dinner!</p>

    <h2>Ingredients</h2>
    <p>Here's what you'll need (makes 2 servings):</p>
    <!-- Unordered list for ingredients (order doesn't matter) -->
    <ul>
        <li>200g of your favorite pasta</li>
        <li>1 can (400g) of crushed tomatoes</li>
        <li>1 small onion</li>
        <li>2 cloves of garlic</li>
        <li>1 tbsp olive oil</li>
        <li>Fresh basil</li>
        <li>Salt and pepper to taste</li>
    </ul>

    <h2>Instructions</h2>
    <!-- Ordered list for steps (order is crucial!) -->
    <ol>
        <li>Bring a large pot of salted water to a boil.</li>
        <li>Add pasta and cook according to package directions.</li>
        <li>While the pasta cooks, finely chop the onion and garlic.</li>
        <li>In a pan, heat olive oil over medium heat. Add onion and garlic and cook until soft and fragrant.</li>
        <li>Pour in the crushed tomatoes, add salt and pepper. Simmer for 10 minutes.</li>
        <li>Drain the cooked pasta, reserving a cup of pasta water.</li>
        <li>Add the drained pasta to the sauce pan. Toss to combine, adding a splash of pasta water if the sauce is too thick.</li>
        <li>Stir in fresh basil leaves before serving.</li>
    </ol>

    <h2>Serving Suggestions</h2>
    <!-- Another unordered list -->
    <ul>
        <li>Top with grated Parmesan cheese.</li>
        <li>Serve with a side salad and crusty bread.
            <ul>
                <li>For the salad, try mixed greens with a lemon vinaigrette.</li> <!-- A nested list! -->
            </ul>
        </li>
    </ul>

    <p>Find more recipes on <a href="https://www.allrecipes.com" target="_blank">AllRecipes</a>.</p>

</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Your Day 3 Challenge:

  1. Create a new file called lists.html.
  2. Build your own page using the example above as a guide. Choose a topic that naturally uses lists, such as:
    • A page about your favorite music artists and their albums.
    • Instructions for a hobby or task you know well.
    • A list of your career goals and the steps to achieve them.
  3. Must include:
    • At least one unordered list (<ul>).
    • At least one ordered list (<ol>).
    • At least one nested list (a list inside a list item).
    • Use headings (<h1>, <h2>, etc.) and paragraphs (<p>) to structure your content.
    • Include at least one link.
  4. Save the file and open it in your browser. Admire your beautifully organized content!

You've just learned how to bring order and clarity to information. This skill is invaluable for creating professional, user-friendly websites.

Keep up the fantastic work. See you on Day 4.


Are you finding these daily lessons helpful? Imagine having a complete roadmap. My ebook, "The Complete Full-Stack Developer Handbook," is designed to be your companion throughout this entire year-long journey, offering deeper dives, projects, and a structured learning path.

https://codewithdhanian.gumroad.com/l/gzjvj

— Dhanian

Top comments (0)