HTML Tags

Beginner
⏱️ 14 min read
📚 Updated: Jul 2026
🎯 6 Examples + 6 Try It
100+ HTML elements

Introduction

HTML tags are the building blocks of every web page. Each tag names an element—a piece of content with a specific role, from the page title in <title> to a paragraph in <p> or a link in <a>.

This hub explains how tags work, groups them by purpose, lists the most important HTML5 elements with links to detailed tutorials, and walks through six hands-on examples you can edit live.

What You’ll Learn

01

Tag basics

Opening & closing.

02

Void elements

Self-closing tags.

03

Categories

Structure, text, forms.

04

Reference

HTML5 tag index.

05

Semantic HTML

Meaningful markup.

06

Examples

Real page patterns.

What Are HTML Tags?

An HTML tag is markup written inside angle brackets. Tags tell the browser how to interpret content: headings, links, images, tables, forms, and more. Together with attributes, tags form the structure and meaning of a document.

A typical element looks like this:

html
<p class="intro">Hello, world!</p>

Here <p> is the opening tag, class="intro" is an attribute, Hello, world! is the content, and </p> is the closing tag.

💡
Beginner Tip

Tags describe what content is, not how it looks. Use CSS for colors, fonts, and layout—use HTML tags for structure and meaning.

How HTML Tags Work

Opening and closing tags

Most elements use a pair of tags. The opening tag starts the element; the closing tag ends it with a forward slash:

html
<div>
  <p>This paragraph is inside a division.</p>
</div>

Closing tags must match the opening tag name. <p> closes with </p>, not </div>.

Void (self-closing) elements

Some elements never wrap content and have no closing tag. These are called void elements:

html
<br>
<hr>
<img src="photo.jpg" alt="A sunset">
<input type="text" name="email">
<meta charset="UTF-8">

In HTML5, writing <br> and <br /> are both valid. Void elements cannot contain child elements or text.

Nesting rules

Elements can contain other elements, but nesting must be properly layered—close inner tags before outer ones:

ValidInvalid
<p><strong>Bold</strong></p><p><strong>Bold</p></strong>
<ul><li>Item</li></ul><li>Item</ul> (missing ul wrapper)
  • Block in blockdiv inside section is fine.
  • Inline in blockspan or em inside p is fine.
  • Block in inline — do not put div inside span.
  • Lists — only li may be direct children of ul or ol.

HTML Tag Categories

HTML elements are grouped by purpose. Knowing the categories helps you pick the right tag quickly.

Document & structure

Define the page shell: <!DOCTYPE html>, <html>, <head>, <body>, <title>, <meta>, <link>, <style>, and <script>. Every HTML document starts with these.

Text & phrasing

Mark up readable content: <p>, <h1–h6>, <br>, <hr>, <em>, <strong>, <code>, <pre>, <blockquote>, and inline emphasis tags like <mark>, <sub>, and <sup>.

Links & media

Connect pages and embed resources: <a>, <img>, <picture>, <audio>, <video>, <source>, <iframe>, <svg>, and <canvas>.

Forms & interactive

Collect user input: <form>, <input>, <textarea>, <button>, <select>, <label>, <fieldset>, and <datalist>.

Tables

Display tabular data: <table>, <thead>, <tbody>, <tr>, <th>, <td>, <caption>, <colgroup>, and <col>.

Semantic layout

Describe page regions by meaning: <header>, <nav>, <main>, <section>, <article>, <aside>, <footer>, <figure>, and <details>.

📝 HTML5 Tags Reference

Quick lookup for common HTML5 elements. Tags with tutorials link to their dedicated guide.

Document & metadata

Sectioning & layout

Text & phrasing

Lists

Links & media

Tables

Forms

Interactive & figures

Browse the sidebar for the full tag index, or start with the anchor tag tutorial.

Void Elements in HTML5

Void elements cannot contain children or text. They are written with a single tag and never need a closing tag.

Remember

Do not write <br></br> or <img>...</img>. Void elements stand alone. Attributes like src on img or type on input configure them instead.

Semantic HTML Tags

Semantic tags describe the meaning of content, not just its box on screen. Search engines, screen readers, and other tools rely on semantics to understand your page.

Use div and span when no semantic tag fits—they are generic containers. But reach for header, nav, main, article, and footer first when building page layouts.

Common Pitfalls

  • Using tags for stylingb and i change appearance but carry weak semantics. Prefer strong/em for meaning, CSS for look.
  • Skipping heading levels — jumping from h1 to h4 confuses outline and screen readers. Use sequential levels.
  • Div soup — wrapping everything in div loses semantics. Use section, article, nav, and main.
  • Invalid nesting — putting block elements inside p or span breaks the DOM. Browsers may auto-close tags unexpectedly.
  • Missing alt on images — every img needs an alt attribute (even if empty for decorative images).
  • Multiple main elements — only one main per page. Use section for additional content areas.
  • Tables for layout — use CSS Grid or Flexbox for layout; reserve table for tabular data.

⚡ Quick Reference

PatternExample
Opening + closing<p>Text</p>
Void element<img src="x.jpg" alt="">
Attribute<a href="/about">About</a>
Nested<ul><li>Item</li></ul>
Comment<!-- not rendered -->
DOCTYPE<!DOCTYPE html>
Shell
html head body

Page structure

Text
p h1–h6 em

Readable content

Media
a img video

Links & embeds

Layout
header nav main

Semantic regions

Examples Gallery

Six examples showing common HTML tag patterns. Each includes View Output and Try It Yourself links to the live editor.

Example 1 — Minimal HTML5 Skeleton

Every HTML page starts with a doctype, root html element, head for metadata, and body for visible content.

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

How It Works

<!DOCTYPE html> triggers standards mode. lang="en" sets the document language. meta charset and viewport are essential for encoding and mobile layout.

Example 2 — Headings and Paragraph

Use h1h6 for headings (one main h1 per page) and p for body text.

html
<h1>HTML Tags Guide</h1>
<p>Learn how HTML elements structure web content.</p>
<h2>Why Tags Matter</h2>
<p>Tags give meaning to text, links, images, and forms.</p>
Try It Yourself

How It Works

Heading levels create a document outline. h1 is the top-level title; h2 introduces a subsection. Never skip levels for styling—use CSS instead.

Example 4 — Unordered List

Group related items with ul and li. Browsers render bullets by default; style with CSS.

html
<h2>Essential HTML Tags</h2>
<ul>
  <li><code>&lt;p&gt;</code> — paragraphs</li>
  <li><code>&lt;a&gt;</code> — links</li>
  <li><code>&lt;img&gt;</code> — images</li>
  <li><code>&lt;form&gt;</code> — forms</li>
</ul>
Try It Yourself

How It Works

Only li elements may be direct children of ul. For numbered steps, swap ul for ol.

Example 5 — Simple Contact Form

Forms use form, label, input, textarea, and button to collect user data.

html
<form action="/contact" 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="msg">Message:</label>
  <textarea id="msg" name="message" rows="3"></textarea>

  <button type="submit">Send</button>
</form>
Try It Yourself

How It Works

for on label links to id on the control, improving accessibility. name attributes identify fields when the form is submitted.

Example 6 — Complete Semantic Page

A real page layout using header, nav, main, and footer instead of anonymous div wrappers.

html
<header>
  <h1>CodeToFun</h1>
  <nav>
    <a href="/html">HTML</a>
    <a href="/css">CSS</a>
    <a href="/js">JavaScript</a>
  </nav>
</header>

<main>
  <article>
    <h2>HTML Tags Overview</h2>
    <p>Learn every essential HTML element.</p>
  </article>
</main>

<footer>
  <p>&copy; 2026 CodeToFun</p>
</footer>
Try It Yourself

How It Works

Semantic landmarks help screen readers jump between regions. main should appear once per page and contain the primary content.

💡 Best Practices

✅ Do

  • Choose tags by meaning—nav for navigation, article for posts
  • Include lang on <html> and alt on every img
  • Use one h1 per page for the main title
  • Close tags in the correct nesting order
  • Validate markup with the W3C validator or browser DevTools
  • Link labels to inputs with for and id

❌ Don’t

  • Use div for everything when a semantic tag exists
  • Pick heading levels based on font size alone
  • Nest block elements inside p or span
  • Omit alt on informative images
  • Use table for page layout
  • Rely on deprecated tags like center or font

Universal Browser Support

Core HTML tags—html, head, body, p, a, img, ul, table, and form—have been supported since the earliest browsers. HTML5 semantic tags (header, nav, main, article, footer) and elements like picture, dialog, and details work in all modern browsers.

Baseline · Since HTML

HTML tags

Core HTML tags work in every browser. HTML5 semantic elements and modern form/media tags are supported in all current Chrome, Firefox, Safari, and Edge releases.

100% Core tag support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
HTML elements Universal

Bottom line: HTML is the most stable layer of the web platform. Focus on valid, semantic markup—it will work everywhere.

Conclusion

HTML tags are the vocabulary of the web. Opening and closing tags wrap content; void elements stand alone; nesting must stay valid. Group tags by purpose—document shell, text, links, forms, tables, and semantic layout—and pick the most specific element for each job.

Use this page as your hub, then explore individual guides starting with the anchor tag, or jump to the head section, lists, and forms for deeper topic tutorials.

Key Takeaways

Knowledge Unlocked

Six things to remember about HTML tags

Use these points when writing any HTML document.

6
Core concepts
📝 02

Open & close

Most tags come in pairs.

Syntax
03

Void elements

br, img, input, meta.

Syntax
📚 04

Categories

Structure, text, forms.

Reference
05

Semantics

Meaning over divs.

A11y
🎯 06

Practice

Try the live examples.

Hands-on

❓ Frequently Asked Questions

An HTML tag is a keyword wrapped in angle brackets that marks the start or end of an element. For example, <p> opens a paragraph and </p> closes it. Tags tell the browser what kind of content each part of the page is.
A tag is the markup syntax (<p>, </p>). An element is the complete unit: opening tag, optional content, and closing tag—or a void tag like <br>. People often use the terms interchangeably in tutorials.
Void elements have no closing tag and no inner content—examples include br, img, input, meta, link, and hr. In HTML5 you write them as <br> or <br />; both are valid.
Choose tags by meaning, not appearance. Use semantic tags like header, nav, main, and article for page structure; p for paragraphs; a for links; ul/ol/li for lists. Avoid using div for everything when a more specific tag exists.
No. Normal elements like div, p, and span require a closing tag. Void elements like img, br, and input do not. Some elements like li, td, and option may omit closing tags in HTML but including them is clearer and recommended.
Core HTML tags have been supported for decades. Newer semantic tags (article, section, main) and elements like dialog and picture work in all modern browsers. Always test media elements (video, audio) and form input types in your target browsers.
Did you know?

The first version of HTML had only about 18 elements. Today’s living standard defines over 100, but most pages use a focused subset—mastering roughly 30 core tags covers the vast majority of real-world markup tasks.

Practice HTML tags in the editor

Build a skeleton page, semantic layout, or contact form—then preview it live.

Open Try It editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful