HTML HTML Foundation & Core Concepts HTML Tags, Elements, and Attributes

01So, What Exactly Is an HTML Tag?

If you’ve been confused about HTML tags, HTML elements, and HTML attributes, you’re not alone. Even people who have been coding for a while mix these up. So let’s fix that once and for all, in plain English.

An HTML tag is just a label wrapped in angle brackets. It tells the browser: “Hey, this piece of content has a specific purpose.”

Tags look like this:

<p>
<h1>
<a>
<img>

That’s it. An HTML tag is simply a keyword inside < and >. Nothing magical. Just a label.

Most tags come in pairs: an opening tag and a closing tag. The closing tag has a forward slash before the keyword.

<p>This is a paragraph.</p>
<h1>This is a heading.</h1>
<strong>This is bold text.</strong>

Opening tag + content + closing tag. That pattern is the backbone of HTML syntax, and once you see it, you’ll spot it everywhere.


02Tags vs. Elements: There Is a Difference

This is where most beginners get tripped up. The terms “tag” and “element” are often used interchangeably, but technically they mean different things.

Tags vs Elements: Side by Side

A Tag

<p>

Just the label itself. The opening or closing marker alone.

An Element

<p>Hello World</p>

The opening tag + the content + the closing tag, all together.

Think of a tag as the bread slices, and the element as the entire sandwich.

So when someone says “use the <p> tag,” they mean the tag. When they say “the paragraph element,” they mean the full thing: opening tag, the text inside, and closing tag combined.

This distinction becomes clearer when you look at the list of HTML elements in context. Each element is a complete unit that the browser reads and renders.


03What Is an HTML Element Made Of?

Every HTML element has up to three parts:

Anatomy of an HTML Element

<a href="/">

Opening Tag

Go Home

Content

</a>

Closing Tag

The full element: <a href="/">Go Home</a>

Notice something in that example? href="/" is sitting inside the opening tag. That is an HTML attribute. We’ll get to those in a moment.


04HTML Syntax: The Rules You Must Know

HTML syntax is the set of rules that defines how you write HTML correctly. It’s not complicated, but skipping these rules causes browsers to misread your page.

Here are the core HTML syntax rules:

<!-- Rule 1: Tags are lowercase -->
<p>Correct</p>
<P>Still works but outdated</P>

<!-- Rule 2: Closing tags have a forward slash -->
<p>Always close your tags</p>

<!-- Rule 3: Nest elements properly (inner closes before outer) -->
<p><strong>Correct nesting</strong></p>

<!-- Rule 4: Attribute values go in quotes -->
<a href="https://example.com">Click here</a>

<!-- Rule 5: Self-closing tags don't need a closing tag -->
<img src="photo.jpg" alt="A photo">
<br>
<hr>

Proper HTML syntax keeps your code clean, readable, and browser-friendly. Browsers are forgiving with broken HTML, but that forgiveness can cause layout bugs that are hard to trace. Writing clean syntax from the start is always worth it.

Nesting HTML Elements the Right Way

Nesting means putting one element inside another. HTML syntax requires that you close inner elements before closing outer ones.

Nesting: Correct vs Incorrect

✓ Correct

<p>
  <strong>Bold</strong>
  text here.
</p>

✗ Wrong

<p>
  <strong>Bold
</p>
  </strong>

05HTML Tag Types: Not All Tags Are the Same

Now let’s talk about the different HTML tag types. Understanding this helps you pick the right tag for the right job.

1. Paired Tags (Opening + Closing)

These are the most common HTML tag types. They wrap around content and have both an opening and closing version.

<h1>I am a heading</h1>
<p>I am a paragraph.</p>
<div>I am a container.</div>
<ul>
  <li>I am a list item.</li>
  <li>Another item.</li>
</ul>
<a href="/">I am a link.</a>

2. Self-Closing Tags (Void Elements)

Some HTML tag types don’t wrap around content because they have nothing to wrap. They stand alone. These are called void elements or self-closing tags.

<img src="cat.jpg" alt="A cute cat">
<br>
<hr>
<input type="text">
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">

In HTML5, you don’t need a trailing slash for self-closing tags. <br> and <br /> both work, but <br> is the modern standard.

HTML Tag Types at a Glance

Paired Tags

Wrap around content. Need both an opening and closing tag.

<p>
<div>
<h1>
<a>
<ul>
<section>

Self-Closing Tags

Stand alone. No content inside. No closing tag needed.

<img>
<br>
<hr>
<input>
<meta>
<link>

06A Practical List of HTML Tags You’ll Use Every Day

Here is a solid list of HTML tags broken down by category. You don’t need to memorize every single one right now. Just get familiar with what exists.

Text and Heading Tags

<!-- Headings: h1 is the biggest, h6 is the smallest -->
<h1>Main Page Heading</h1>
<h2>Section Heading</h2>
<h3>Sub-section Heading</h3>
<h4>Smaller Sub-heading</h4>
<h5>Even Smaller</h5>
<h6>Smallest Heading</h6>

<!-- Paragraphs and text -->
<p>A regular paragraph of text.</p>
<strong>Bold and important text.</strong>
<em>Emphasized (italic) text.</em>
<small>Smaller, fine print text.</small>
<mark>Highlighted text.</mark>
<code>Inline code snippet.</code>
<blockquote>A quoted block of text.</blockquote>

Structure and Layout Tags

<div>A generic block container</div>
<span>A generic inline container</span>

<!-- Semantic structural tags (HTML5) -->
<header>Top of the page or section</header>
<nav>Navigation links</nav>
<main>Main content of the page</main>
<section>A thematic section</section>
<article>A self-contained piece of content</article>
<aside>Related sidebar content</aside>
<footer>Bottom of the page or section</footer>

Link and Media Tags

<!-- Links -->
<a href="https://example.com">Click this link</a>

<!-- Images (self-closing) -->
<img src="dog.jpg" alt="A happy dog">

<!-- Video -->
<video src="clip.mp4" controls></video>

<!-- Audio -->
<audio src="song.mp3" controls></audio>

List Tags

<!-- Unordered (bullet) list -->
<ul>
  <li>Apples</li>
  <li>Oranges</li>
  <li>Bananas</li>
</ul>

<!-- Ordered (numbered) list -->
<ol>
  <li>Wake up</li>
  <li>Write HTML</li>
  <li>Feel great</li>
</ol>

<!-- Description list -->
<dl>
  <dt>HTML</dt>
  <dd>HyperText Markup Language</dd>
</dl>

Form Tags

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

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

  <textarea name="message" rows="4"></textarea>

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

Table Tags

<table>
  <thead>
    <tr>
      <th>Name</th>
      <th>Age</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Sara</td>
      <td>24</td>
    </tr>
    <tr>
      <td>Ali</td>
      <td>31</td>
    </tr>
  </tbody>
</table>

07What Are HTML Attributes? (The Superpowers of Elements)

Now for the fun part. HTML attributes are extra pieces of information you add to an opening tag. They customize or configure how an element behaves.

Attributes always live inside the opening tag. They follow this pattern:

HTML Attribute Syntax

<
tagname
attribute
=
"value"
>
Attribute Name
Equals Sign
Attribute Value (in quotes)

Here’s a simple example. The <a> tag creates a link. But without the href attribute, it’s just text. The attribute is what gives it a destination:

<!-- Without attribute: just styled text, no link -->
<a>Click me</a>

<!-- With attribute: now it's an actual working link -->
<a href="https://example.com">Click me</a>

Attributes are what turn basic HTML elements into powerful, functional pieces of a webpage. That’s why I call them superpowers.

One Element Can Have Multiple Attributes

You can stack multiple attributes on a single element. Just separate them with a space inside the opening tag:

<a href="https://example.com" target="_blank" title="Visit Example">Open in New Tab</a>

<img src="banner.jpg" alt="A colorful banner" width="800" height="200">

<input type="email" id="email" name="email" placeholder="Enter your email" required>

Notice required at the end of the input? That’s a boolean attribute. It has no value. Its presence alone is enough to activate the behavior.


08The Full List of HTML Attributes (The Most Important Ones)

Here is the list of HTML attributes you’ll use across almost every project. These are grouped by what they do.

Universal Attributes (Work on Almost Every Element)

Global / Universal HTML Attributes

Attribute What It Does Example
id Unique identifier for one element id="header"
class Group elements for CSS/JS targeting class="btn primary"
style Inline CSS directly on element style="color:red"
title Tooltip text on hover title="More info"
lang Sets the language of the element lang="en"
hidden Hides the element from view hidden

Link Attributes (<a>)

<!-- href: where the link goes -->
<a href="https://example.com">Visit Example</a>

<!-- target: how it opens (_blank opens a new tab) -->
<a href="https://example.com" target="_blank">Open New Tab</a>

<!-- rel: relationship (noopener is a security best practice) -->
<a href="https://example.com" target="_blank" rel="noopener noreferrer">Safe Link</a>

<!-- download: makes the browser download the file -->
<a href="resume.pdf" download>Download Resume</a>

Image Attributes (<img>)

<!-- src: image file path -->
<!-- alt: text description (important for accessibility and SEO) -->
<img src="profile.jpg" alt="Profile photo of Sara">

<!-- width and height: size in pixels -->
<img src="logo.png" alt="Company logo" width="200" height="80">

<!-- loading: lazy loading for performance -->
<img src="big-image.jpg" alt="A large photo" loading="lazy">

Form and Input Attributes

<!-- type: what kind of input -->
<input type="text">
<input type="email">
<input type="password">
<input type="checkbox">
<input type="radio">
<input type="number">
<input type="date">

<!-- placeholder: hint text inside the input -->
<input type="text" placeholder="Enter your name">

<!-- required: makes the field mandatory -->
<input type="email" required>

<!-- disabled: greys out the input -->
<input type="text" disabled>

<!-- value: pre-fills the input -->
<input type="text" value="John Doe">

<!-- min, max, step: number range control -->
<input type="number" min="1" max="100" step="5">

Data Attributes (Custom Attributes)

HTML lets you create your own custom attributes using the data-* prefix. These are incredibly useful when you need to store extra data on an element for JavaScript to read.

<!-- You can make up any name after "data-" -->
<button data-user-id="42" data-action="delete">Delete User</button>

<div data-product="shoes" data-price="59.99" data-in-stock="true">
  Air Max 90
</div>

<!-- JavaScript reads them like this -->
<script>
  const btn = document.querySelector('button');
  console.log(btn.dataset.userId); // "42"
  console.log(btn.dataset.action); // "delete"
</script>

09The List of HTML Elements: Organized by Purpose

The list of HTML elements is large, but you only need a core set to build real websites. Let’s look at that core set, organized by what they do.

Core HTML Elements by Category

Document Structure

<html>
<head>
<body>
<title>
<meta>
<link>
<script>

Layout & Sections

<header>
<nav>
<main>
<section>
<article>
<aside>
<footer>
<div>

Text Content

<h1>-<h6>
<p>
<strong>
<em>
<span>
<br>
<mark>
<blockquote>

Forms & Inputs

<form>
<input>
<button>
<label>
<textarea>
<select>
<option>

10Block-Level vs Inline Elements: A Key Distinction

When going through the list of HTML elements, you’ll notice they behave in two distinct ways. This is one of the most important things to understand.

Block vs Inline Elements: Visual Demo

BLOCK-LEVEL ELEMENTS (each takes full width, new line)

<div> I take the full width of my parent
<p> I also take full width. New line.
<h2> Same here. Another line.

INLINE ELEMENTS (sit side-by-side, only take needed width)

This is normal text.
<strong> Bold
and
<em> italic
and
<span> a span
all sit in a line together.

Block-level elements like <div>, <p>, <h1>, and <section> always start on a new line and stretch to fill the full available width.

Inline elements like <span>, <strong>, <em>, and <a> sit within the flow of text. They only take up as much space as their content needs.


11Putting It All Together: Tags, Elements, and Attributes Working as One

Here is a real-world example of a complete webpage section that uses proper HTML syntax, multiple HTML tag types, and a range of attributes from the list of HTML attributes:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>My First Real Page</title>
</head>
<body>

  <header>
    <nav>
      <a href="/" title="Home">Home</a>
      <a href="/about">About</a>
      <a href="/contact">Contact</a>
    </nav>
  </header>

  <main>
    <article>
      <h1>Welcome to My Website</h1>
      <p>
        This is a <strong>real paragraph</strong> with
        <em>some emphasis</em> and a
        <a href="https://example.com" target="_blank" rel="noopener">link</a>.
      </p>

      <img src="hero.jpg" alt="A welcoming hero image" width="800" height="400" loading="lazy">

      <ul>
        <li>HTML gives structure</li>
        <li>CSS adds styling</li>
        <li>JavaScript adds behavior</li>
      </ul>

      <form action="/subscribe" method="post">
        <label for="email">Subscribe:</label>
        <input type="email" id="email" name="email" placeholder="[email protected]" required>
        <button type="submit">Subscribe</button>
      </form>

    </article>
  </main>

  <footer>
    <p>&copy; 2026 My Website</p>
  </footer>

</body>
</html>

Look at how naturally everything fits. Tags wrap content, elements work together, and attributes power the details. That’s HTML doing its job.


12Common Mistakes Beginners Make (And How to Avoid Them)

Mistakes to Avoid

Forgetting to close paired tags

✗ Wrong

<p>Hello World

✓ Correct

<p>Hello World</p>

Attribute values without quotes

✗ Wrong

<img src=photo.jpg>

✓ Correct

<img src="photo.jpg">

Putting attributes in the closing tag

✗ Wrong

</a href="/">

✓ Correct

<a href="/">...</a>

Skipping the alt attribute on images

✗ Bad practice

<img src="cat.jpg">

✓ Correct

<img src="cat.jpg" alt="A cat">


13Quick Reference Cheat Sheet: HTML Tags, Elements, and Attributes

Here’s your at-a-glance summary. Bookmark this section.

Cheat Sheet: HTML Tags, Elements & Attributes

What is a Tag?

A label in angle brackets. <p> and </p> are both tags.

What is an Element?

The full unit: <p>Content</p>. Opening tag + content + closing tag.

What is an Attribute?

Extra info inside the opening tag. <a href="/" target="_blank">. Always name="value".

HTML Tag Types

Paired tags (open + close) and self-closing tags (void elements like <img>, <br>, <input>).

HTML Syntax Rules

Use lowercase tags. Close all paired tags. Use quotes around attribute values. Nest elements properly (inner closes first).


14You Now Understand HTML Tags, Elements, and Attributes

These three concepts, tags, elements, and attributes, are the foundation of everything you’ll build with HTML. Once you know how they fit together, the entire list of HTML tags and the list of HTML elements stop being intimidating. They become tools you reach for with confidence.

You understand that a tag is the label, an element is the full unit, and an attribute is the configuration living inside the opening tag. You know the two main HTML tag types (paired and self-closing), and you know why HTML syntax rules matter.

The next step is practice. Take a tag from the list of HTML elements, throw some attributes on it, and build something. There’s no better way to make this knowledge stick.

HTML Tags, Elements, and Attributes

Choose a difficulty to load your challenge

Loading challenge…

Ready to Practice?

Select a difficulty level above to load your challenge.

Easy

1
Live Preview
Great Work!