DEV Community

Cover image for HTML Tags Explained: The Building Blocks of Web Pages
Abdelhakim Baalla
Abdelhakim Baalla

Posted on • Edited on

1

HTML Tags Explained: The Building Blocks of Web Pages

Introduction

Have you ever wondered how websites display text, images, and other content in an organized way? The secret lies in HTML tags—the fundamental building blocks of every web page you visit. Whether you're aspiring to become a web developer or just curious about how websites work, understanding HTML tags is your first step into the exciting world of web development.

In this guide, we'll explore what HTML tags are, how they work, and the most essential tags you need to know to start building your own web pages. No prior coding experience required—just bring your curiosity!

What Are HTML Tags?

HTML (HyperText Markup Language) is the standard language used to create web pages. Think of HTML as the skeleton that gives structure to web content. Within this language, tags are the commands that tell browsers how to display content.

Anatomy of an HTML Tag

HTML tags typically come in pairs and follow this format:

<tagname>Content goes here</tagname>
Enter fullscreen mode Exit fullscreen mode

Let's break this down:

  • The opening tag: <tagname>
  • The content: Whatever goes between the tags
  • The closing tag: </tagname> (notice the forward slash)

Some tags, called "self-closing" or "empty" tags, don't need a closing tag:

<tagname />
Enter fullscreen mode Exit fullscreen mode

How Browsers Interpret Tags

When you visit a website, your browser reads the HTML tags and renders the content accordingly. The tags themselves aren't displayed—they just tell the browser what to do with the content they surround.

Essential HTML Structure Tags

Every HTML document follows a specific structure. Here's the basic template:

<!DOCTYPE html>
<html>
<head>
    <title>Your Page Title</title>
</head>
<body>
    <!-- Your content goes here -->
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Let's understand each of these structure tags:

<!DOCTYPE html>

This declaration tells the browser which version of HTML the page is using (in this case, HTML5). It's not technically a tag, but it's required at the beginning of every HTML document.

<html></html>

This tag is the root element that contains all other HTML elements on the page.

<head></head>

The head section contains meta-information about the document, such as the title, character set, styles, scripts, and other important but invisible elements.

<title></title>

This tag defines the title of your web page—the text that appears on browser tabs.

<body></body>

The body tag contains all the visible content of your web page, including text, images, links, and more.

Text Formatting Tags

Now let's explore the tags that help you format text on your web pages:

Headings

HTML offers six levels of headings, from <h1> (most important) to <h6> (least important):

<h1>This is a main heading</h1>
<h2>This is a subheading</h2>
<h3>This is a smaller subheading</h3>
<h4>Even smaller...</h4>
<h5>Getting quite small...</h5>
<h6>Smallest heading</h6>
Enter fullscreen mode Exit fullscreen mode

Paragraphs

The <p> tag defines a paragraph:

<p>This is a paragraph of text. It can contain multiple sentences and will be displayed as a block element with space before and after it.</p>
Enter fullscreen mode Exit fullscreen mode

Text Styling

While CSS is the preferred way to style text, HTML provides some basic text formatting tags:

<strong>This text is bold</strong>
<em>This text is emphasized (usually italic)</em>
<u>This text is underlined</u>
<mark>This text is highlighted</mark>
<del>This text is strikethrough</del>
<small>This text is smaller</small>
Enter fullscreen mode Exit fullscreen mode

List Tags

Lists help organize information in a structured way. HTML supports three types of lists:

Unordered Lists

Use <ul> for bullet-point lists:

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

Ordered Lists

Use <ol> for numbered lists:

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

Definition Lists

Use <dl> for term-definition pairs:

<dl>
    <dt>HTML</dt>
    <dd>HyperText Markup Language - the standard language for creating web pages</dd>
    <dt>CSS</dt>
    <dd>Cascading Style Sheets - used to style HTML elements</dd>
</dl>
Enter fullscreen mode Exit fullscreen mode

Link and Image Tags

These tags help you add interactivity and visual elements to your pages.

Links

The <a> (anchor) tag creates hyperlinks:

<a href="https://www.example.com">Visit Example.com</a>
Enter fullscreen mode Exit fullscreen mode

You can link to sections within the same page using IDs:

<a href="#section1">Jump to Section 1</a>

<!-- Later in the document -->
<h2 id="section1">Section 1</h2>
Enter fullscreen mode Exit fullscreen mode

Images

The <img> tag displays images:

<img src="image.jpg" alt="Description of the image" width="300" height="200">
Enter fullscreen mode Exit fullscreen mode

The alt attribute is crucial for accessibility, providing a text description for screen readers or when images fail to load.

Table Tags

Tables help organize data in rows and columns:

<table>
    <thead>
        <tr>
            <th>Name</th>
            <th>Age</th>
            <th>Country</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>John</td>
            <td>25</td>
            <td>USA</td>
        </tr>
        <tr>
            <td>Maria</td>
            <td>30</td>
            <td>Spain</td>
        </tr>
    </tbody>
</table>
Enter fullscreen mode Exit fullscreen mode

Key table tags:

  • <table>: Defines a table
  • <thead>: Groups header content
  • <tbody>: Groups body content
  • <tr>: Defines a table row
  • <th>: Defines a header cell
  • <td>: Defines a standard cell

Form Tags

Forms allow users to input data and interact with your website:

<form action="/submit-form" method="post">
    <label for="name">Name:</label>
    <input type="text" id="name" name="name" required>

    <label for="email">Email:</label>
    <input type="email" id="email" name="email" required>

    <label for="message">Message:</label>
    <textarea id="message" name="message" rows="4"></textarea>

    <button type="submit">Send Message</button>
</form>
Enter fullscreen mode Exit fullscreen mode

Common form elements:

  • <form>: Container for form elements
  • <input>: Creates various input fields (text, email, password, checkbox, etc.)
  • <textarea>: Creates multi-line text input
  • <select> and <option>: Creates dropdown menus
  • <button>: Creates clickable buttons
  • <label>: Associates text with form controls for better accessibility

Semantic HTML Tags

Semantic tags give meaning to your HTML structure, making it more accessible and SEO-friendly:

<header>
    <nav>
        <ul>
            <li><a href="#home">Home</a></li>
            <li><a href="#about">About</a></li>
            <li><a href="#contact">Contact</a></li>
        </ul>
    </nav>
</header>

<main>
    <section id="home">
        <h2>Welcome to our website</h2>
        <p>This is the main content area.</p>
    </section>

    <article>
        <h2>Blog Post Title</h2>
        <p>This is a blog post content.</p>
    </article>

    <aside>
        <h3>Related Links</h3>
        <ul>
            <li><a href="#">Another article</a></li>
            <li><a href="#">Resources</a></li>
        </ul>
    </aside>
</main>

<footer>
    <p>Copyright &copy; 2025</p>
</footer>
Enter fullscreen mode Exit fullscreen mode

Key semantic tags:

  • <header>: Page or section header
  • <nav>: Navigation links
  • <main>: Main content area
  • <section>: Thematic grouping of content
  • <article>: Self-contained content
  • <aside>: Related but separate content
  • <footer>: Page or section footer

Common HTML Attributes

Attributes provide additional information about HTML elements:

<a href="https://www.example.com" target="_blank" title="Visit Example.com">Example</a>
Enter fullscreen mode Exit fullscreen mode

Common attributes:

  • id: Unique identifier for an element
  • class: Used to classify elements for styling
  • style: Adds inline CSS styles
  • src: Specifies source for media elements
  • href: Specifies link destination
  • alt: Alternative text for images
  • title: Additional information (shown as tooltip)
  • target: Specifies where to open linked documents

Best Practices for Using HTML Tags

Follow these tips to write clean, efficient, and accessible HTML:

  1. Always use lowercase tags: HTML is not case-sensitive, but lowercase is the convention.
  2. Close all tags properly: Make sure every opening tag has a corresponding closing tag (except for self-closing tags).
  3. Use semantic tags: They improve accessibility and SEO.
  4. Keep your code indented: It makes your code more readable.
  5. Use meaningful values for attributes: Especially for id, class, and alt.
  6. Validate your HTML: Use tools like the W3C Markup Validation Service.

Putting It All Together: A Simple Webpage Example

Here's a complete example that uses many of the tags we've covered:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My First HTML Page</title>
</head>
<body>
    <header>
        <h1>Welcome to My Website</h1>
        <nav>
            <ul>
                <li><a href="#about">About</a></li>
                <li><a href="#services">Services</a></li>
                <li><a href="#contact">Contact</a></li>
            </ul>
        </nav>
    </header>

    <main>
        <section id="about">
            <h2>About Me</h2>
            <p>Hello! I'm learning HTML and building my first webpage.</p>
            <img src="profile.jpg" alt="My profile picture" width="200">
        </section>

        <section id="services">
            <h2>My Services</h2>
            <ul>
                <li>Web Design</li>
                <li>Content Creation</li>
                <li>SEO Optimization</li>
            </ul>
        </section>

        <section id="contact">
            <h2>Contact Me</h2>
            <form>
                <label for="name">Name:</label>
                <input type="text" id="name" name="name"><br>

                <label for="email">Email:</label>
                <input type="email" id="email" name="email"><br>

                <label for="message">Message:</label><br>
                <textarea id="message" name="message" rows="4" cols="30"></textarea><br>

                <button type="submit">Send</button>
            </form>
        </section>
    </main>

    <footer>
        <p>&copy; 2025 My Website. All rights reserved.</p>
    </footer>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Conclusion

Congratulations! You now understand the basics of HTML tags and how they work together to create web pages. This knowledge is the foundation for all web development, and with practice, you'll soon be building more complex and beautiful websites.

Remember, the best way to learn is by doing. Try creating your own simple web pages using the tags we've covered. Start small, experiment, and gradually incorporate more complex elements as you grow more comfortable.

The web development community is vast and supportive, so don't hesitate to seek help when you need it. There are countless resources, forums, and communities dedicated to helping beginners like you succeed.

Ready to Take the Next Step?

Now that you understand HTML tags, consider learning CSS to style your HTML elements and JavaScript to add interactivity to your web pages. These three technologies—HTML, CSS, and JavaScript—form the core of front-end web development.

Follow Me

If you found this guide helpful, please consider following me for more web development content:

Do you have questions about HTML or web development? Feel free to reach out! I'd love to hear from you and help you on your coding journey.

Top comments (0)

👋 Kindness is contagious

If this article connected with you, consider tapping ❤️ or leaving a brief comment to share your thoughts!

Okay