Learn the fundamentals of HTML tags and elements. Understand opening tags, closing tags, void elements, block vs inline elements, and commonly used HTML tags with practical examples.

Every website you've ever visited is built with HTML. It's the foundation – the skeleton that gives structure to web pages.
But what exactly are HTML tags and elements? And why do developers keep using these terms interchangeably (even though they're different)?
Let's break it down.
HTML stands for HyperText Markup Language. It's not a programming language – it's a markup language that tells browsers how to structure content.
If a website were a house:
Without HTML, there would be no headings, paragraphs, images, or links. Just a wall of text.
<!DOCTYPE html>
<html>
<head>
<title>My First Page</title>
</head>
<body>
<h1>Hello World!</h1>
<p>This is my first webpage.</p>
</body>
</html>
How HTML becomes DOM - the browser parses HTML into a structured tree
A tag is a keyword surrounded by angle brackets that tells the browser what type of content follows.
<tagname>
Tags usually come in pairs:
| Type | Example | Purpose |
|---|---|---|
| Opening Tag | <p> | Starts the element |
| Closing Tag | </p> | Ends the element |
Closing tags have a forward slash (/) before the tag name: </p>
Here's where it gets important. An element is the complete package:
Element = Opening Tag + Content + Closing Tag
HTML Element breakdown showing opening tag, content, and closing tag
┌─────────────────────────────────────┐
│ HTML ELEMENT │
├─────────────────────────────────────┤
│ │
│ <p> Hello World! </p> │
│ ↑ ↑ ↑ │
│ Opening Content Closing │
│ Tag Tag │
│ │
└─────────────────────────────────────┘
<h1>Welcome to My Site</h1>
| Part | Value |
|---|---|
| Opening Tag | <h1> |
| Content | Welcome to My Site |
| Closing Tag | </h1> |
| Complete Element | <h1>Welcome to My Site</h1> |
Tag = Just the brackets and name (<p>)
Element = The whole thing including content (<p>Hello</p>)
Most developers use these terms interchangeably, but now you know the difference!
See where a tag stops being text and becomes a node:
Some elements don't have content or closing tags. These are called void elements or self-closing elements.
| Element | Purpose |
|---|---|
<img> | Display an image |
<br> | Line break |
<hr> | Horizontal rule (line) |
<input> | Form input field |
<meta> | Metadata |
<link> | Link external resources |
<!-- Both are valid -->
<img src="photo.jpg" alt="A photo">
<img src="photo.jpg" alt="A photo" />
<br>
<br />
In HTML5, the trailing slash (/>) is optional. Both <br> and <br /> are valid.
Void elements can't contain content. An image is an image – there's no text "inside" it. Same with a line break.
This is crucial for understanding how elements behave on a page.
Block-level vs Inline HTML elements comparison
Block elements:
┌─────────────────────────────────────┐
│ <div> │
│ (full width block) │
└─────────────────────────────────────┘
┌─────────────────────────────────────┐
│ <p> │
│ (full width block) │
└─────────────────────────────────────┘
┌─────────────────────────────────────┐
│ <h1> │
│ (full width block) │
└─────────────────────────────────────┘
| Element | Purpose |
|---|---|
<div> | Generic container |
<p> | Paragraph |
<h1> to <h6> | Headings |
<ul>, <ol> | Lists |
<section> | Page section |
<article> | Article content |
<header> | Page/section header |
<footer> | Page/section footer |
Inline elements:
┌─────────────────────────────────────┐
│ <span>text</span> <a>link</a> <strong>bold</strong> │
│ ↑ ↑ ↑ │
│ inline inline inline │
└─────────────────────────────────────┘
| Element | Purpose |
|---|---|
<span> | Generic inline container |
<a> | Hyperlink |
<strong> | Bold (important) text |
<em> | Italic (emphasized) text |
<img> | Image (inline by default) |
<code> | Code snippet |
<br> | Line break |
| Feature | Block | Inline |
|---|---|---|
| New line? | Yes | No |
| Width | Full available | Content only |
| Can contain | Block & Inline | Inline only |
| Example | <div>, <p> | <span>, <a> |
Let's go through the tags you'll use every day:
<h1> to <h6><h1>Main Title (Largest)</h1>
<h2>Section Title</h2>
<h3>Subsection Title</h3>
<h4>Smaller Heading</h4>
<h5>Even Smaller</h5>
<h6>Smallest Heading</h6>
Use only one <h1> per page (your main title). Use <h2> to <h6> for subsections in order.
<p><p>This is a paragraph of text. It can contain multiple sentences.</p>
<p>This is another paragraph. Each paragraph gets its own space.</p>
<a><a href="https://google.com">Visit Google</a>
<a href="/about">About Page</a>
<a href="#section">Jump to Section</a>
<img><img src="photo.jpg" alt="Description of the photo">
The alt attribute is crucial for accessibility and SEO. Describe what the image shows.
<!-- Block container -->
<div class="container">
<p>Content inside a div</p>
</div>
<!-- Inline container -->
<p>This is <span class="highlight">highlighted</span> text.</p>
<!-- Unordered list (bullets) -->
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<!-- Ordered list (numbers) -->
<ol>
<li>First step</li>
<li>Second step</li>
<li>Third step</li>
</ol>
Elements can be nested inside each other:
<div class="card">
<h2>Card Title</h2>
<p>Card description with <strong>bold text</strong> inside.</p>
<a href="#">Read More</a>
</div>
Nested HTML structure showing parent-child relationships
<!-- ✅ Correct nesting -->
<p>This is <strong>correct</strong> nesting.</p>
<!-- ❌ Wrong - tags overlap -->
<p>This is <strong>wrong</p></strong>
<!-- ❌ Wrong - paragraph inside span -->
<span><p>Invalid nesting</p></span>
Attributes provide extra information about elements:
<tagname attribute="value">Content</tagname>
| Attribute | Used On | Purpose |
|---|---|---|
class | Any | CSS styling hook |
id | Any | Unique identifier |
href | <a> | Link destination |
src | <img> | Image source |
alt | <img> | Alternative text |
type | <input> | Input type |
style | Any | Inline CSS |
<a href="https://example.com" class="btn" id="main-cta">
Click Me
</a>
<img src="logo.png" alt="Company Logo" class="logo" id="header-logo">
Want to see HTML in action? Use DevTools!
| Browser | Shortcut |
|---|---|
| Chrome | F12 or Ctrl+Shift+I |
| Firefox | F12 or Ctrl+Shift+I |
| Safari | Cmd+Opt+I |
| Edge | F12 or Ctrl+Shift+I |
Right-click any element on a webpage and select "Inspect" to jump directly to its HTML in DevTools.
Let's put it all together:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Portfolio</title>
</head>
<body>
<!-- Header -->
<header>
<h1>John Doe</h1>
<nav>
<a href="#about">About</a>
<a href="#projects">Projects</a>
<a href="#contact">Contact</a>
</nav>
</header>
<!-- Main Content -->
<main>
<section id="about">
<h2>About Me</h2>
<p>I'm a <strong>web developer</strong> who loves building things.</p>
<img src="profile.jpg" alt="John Doe profile photo">
</section>
<section id="projects">
<h2>My Projects</h2>
<ul>
<li>Project One</li>
<li>Project Two</li>
<li>Project Three</li>
</ul>
</section>
</main>
<!-- Footer -->
<footer>
<p>© 2025 John Doe. All rights reserved.</p>
</footer>
</body>
</html>
| Concept | Description |
|---|---|
| Tag | Keyword in angle brackets (<p>) |
| Element | Complete tag + content + closing tag |
| Void Element | Self-closing, no content (<img>, <br>) |
| Block Element | Takes full width, new line (<div>) |
| Inline Element | Content width, same line (<span>) |
| Attribute | Extra info on elements (class="name") |
| Nesting | Elements inside elements |
<p>, </p>)<img>, <br>)Now that you understand HTML tags and elements, you're ready to:
<article>, <section>, <nav>The best way to learn HTML is to write HTML. Open your code editor and start creating!
Happy coding! 🚀
Have questions about HTML? Drop a comment or reach out on Twitter @srtenginamath!

Written by Sharanayya R Tenginamath
Software Engineer at McD BERL with 4+ years building scalable full-stack applications with React.js, Next.js, TypeScript, FastAPI and Python. Available to join from Oct 12, 2026.

Master CSS selectors from basics to advanced. Learn element, class, ID, group, and descendant selectors with practical examples. Build a solid foundation for styling web pages.
11 min read
Master JavaScript Promises from scratch — lifecycle, .then()/.catch()/.finally(), all static methods (all, allSettled, race, any), real-world examples, visual diagrams, and hands-on assignments. Written from 4+ years of full-stack development experience.
17 min read
Master JavaScript operators — arithmetic, comparison, logical, and assignment — with real-world examples, visual diagrams, truth tables, and hands-on assignments. A practical guide from 4+ years of full-stack development.
19 min read