Altcademy - a Forbes magazine logo Best Coding Bootcamp 2023

How to add bullet points in HTML

Understanding HTML Elements

Before we dive into the specifics of adding bullet points in HTML, it's important to understand the basics of HTML elements. In simple terms, HTML (HyperText Markup Language) is the coding language that structures the content on the web. It uses different 'elements', encapsulated within angled brackets '<>' to organize and format the webpage.

A common analogy to understand HTML elements is to think of them as different parts of a house. Just as a house has rooms, doors, windows, each with a specific function, an HTML webpage consists of elements like headings, paragraphs, links, and lists, each serving a particular purpose.

The Magic of List Elements

Now, let's focus on the specific elements that allow us to create bullet points, these are the list elements. There are three types of list elements in HTML:

  1. <ul>: Stands for Unordered List. This is the one we use to create bullet points.
  2. <ol>: Stands for Ordered List. This is used when we want to number our list items.
  3. <dl>: Stands for Description List. This is somewhat different and is used to display a list of terms with their descriptions.

Think of these list elements as different types of containers that hold items (list items). The <ul> element can be compared to a bucket, where the order of items doesn't matter. On the other hand, <ol> is like a numbered queue where order matters.

Creating Bullet Points with <ul> and <li>

To create bullet points in HTML, we will be using the <ul> (Unordered List) element in combination with the <li> (List Item) element. The <ul> element acts as the container for the list, while the <li> elements are the actual items or bullet points within the list.

Here's a simple example:

<ul>
    <li>First item</li>
    <li>Second item</li>
    <li>Third item</li>
</ul>

This piece of code will generate a list with three bullet points: 'First item', 'Second item', and 'Third item'.

Nesting Lists for Sub-points

In some cases, you may want to include sub-points under your main bullet points. This can be done by 'nesting' another <ul> element within an <li> element.

Nesting in HTML is like placing a box within a box. The outer box is the parent element and the box inside is the child element.

Here's how you can do it:

<ul>
    <li>Main point
        <ul>
            <li>Sub-point 1</li>
            <li>Sub-point 2</li>
        </ul>
    </li>
    <li>Another main point</li>
</ul>

This code will create a bullet point 'Main point' with two sub-points 'Sub-point 1' and 'Sub-point 2'. 'Another main point' will be another bullet point at the same level as 'Main point'.

Customizing Bullet Points with CSS

HTML also allows you to customize the appearance of your bullet points using CSS (Cascading Style Sheets). CSS is like the paint and decoration for the 'house' we mentioned earlier. It defines how HTML elements are displayed.

For instance, you can change the bullet point style from the default disc to a square using the list-style-type property:

<ul style="list-style-type:square;">
    <li>First item</li>
    <li>Second item</li>
    <li>Third item</li>
</ul>

This code will display the list items with square bullet points instead of the usual round ones.

In conclusion, adding bullet points in HTML is a simple and effective way to structure your content, making it reader-friendly. With a solid understanding of list elements and a bit of CSS, you can create and customize lists to suit the needs of your webpage. Happy coding!