HTML Basics

HTML Elements & Tags

Master the building blocks of HTML. Learn how elements and tags work together to create structured, semantic web content.

What is the difference between an HTML tag and an element?

A tag is the markup itself, like <p> (opening) or </p> (closing). An element is the whole thing: opening tag, content and closing tag together, as in <p>Hello</p>. Void elements like <img>, <br>, <input> and <meta> have no content and no closing tag.

<p>This is a paragraph element.</p>
<a href="/about">Link text</a>
<img src="cat.jpg" alt="A sleeping cat">   <!-- void element -->

HTML Elements and Tags — step by step

1 / 4
1

Understand the difference between elements and tags

A tag is the markup syntax like opening or closing angle-bracket notation. An element includes the opening tag, content, and closing tag together. Some elements are void elements — they have no content or closing tag, like img, br, input, and meta.

1 of 4
🔍All HTML Elements Have a Default Display Value
Every HTML element has a default CSS display value — block, inline, inline-block, table, or flex. These defaults come from the browser's user agent stylesheet. Understanding these defaults helps you predict layout behavior before applying any custom CSS.

🎯 Quick Check

Which of the following is a void element that cannot have a closing tag?

Understanding Elements & Tags

HTML elements are the building blocks of web pages, defined by tags that tell browsers how to structure and display content.

Key Concepts:

  • Element: Complete structure with opening/closing tags and content
  • Tag: Markup that defines element boundaries
  • Content: Text or other elements inside tags
  • Attributes: Additional properties for elements

Element Anatomy

<h1 id="title">Hello World</h1>
↑ Opening Tag ↑ Content ↑ Closing Tag
└─ Element ─────────────────┘

Opening Tag

Starts the element with <tagname>. May include attributes.

Content

Text, other elements, or both between opening and closing tags.

Closing Tag

Ends the element with </tagname>. Always matches opening tag.

Types of HTML Elements

1. Container Elements (Paired Tags)

Have both opening and closing tags, can contain content and other elements.

Examples:

<h1>Title</h1>
<p>Paragraph</p>
<div>Container</div>
<span>Inline</span>

Common Uses:

  • • Text content (paragraphs, headings)
  • • Grouping elements (div, section)
  • • Styling containers (span)
  • • Interactive elements (button, a)

2. Self-Closing Elements (Void Elements)

Don't have closing tags and cannot contain content. They're self-contained.

Examples:

<img src="...">
<br> (line break)
<hr> (horizontal rule)
<input type="...">

Common Uses:

  • • Images and media (img, audio, video)
  • • Form inputs (input, textarea)
  • • Layout breaks (br, hr)
  • • Metadata (meta, link)

Essential Elements Example

Try this basic example showing different types of HTML elements:

Code Editor

<!-- opening tag, content, closing tag = one element -->
<p>This is a <strong>paragraph</strong> element.</p>

<!-- void elements have no closing tag -->
<img src="https://picsum.photos/id/20/160/90" alt="Desk with notebook" width="160" height="90">
<br>
<input placeholder="I'm a void element too">

<!-- nesting: close in reverse order -->
<ul>
  <li><a href="#">A link inside a list item</a></li>
</ul>

Preview

Common HTML Elements Reference

Text Elements

<h1>-<h6>Headings
<p>Paragraph
<span>Inline text
<strong>Bold text

Structure Elements

<div>Block container
<section>Content section
<header>Page/section header
<main>Main content

Media Elements

<img>Image
<video>Video player
<audio>Audio player
<canvas>Drawing area

Interactive Elements

<a>Link
<button>Button
<input>Form input
<select>Dropdown

Elements & Tags Best Practices

✅ Best Practices:

  • Always close container elements
  • Use semantic elements when possible
  • Nest elements properly
  • Use lowercase for tag names

❌ Common Mistakes:

  • • Forgetting closing tags
  • • Improper nesting (overlapping elements)
  • • Using deprecated elements
  • • Mixing uppercase and lowercase
  • • Adding content to void elements
  • • Not using semantic alternatives

Elements & Tags Mastery Complete! 🎯

Excellent! You understand HTML elements and tags - the building blocks of web pages. Ready to learn about HTML Attributes?

HTML Elements and Tags: summary

Key points

  • Elements can be nested, but they must close in reverse order: <p><strong>bold</strong></p>.
  • Tag names aren't case-sensitive, but lowercase is the convention.
  • Browsers forgive many mistakes, but unclosed or mis-nested tags lead to unexpected layouts.

Frequently asked questions

›Do void elements need a slash, like <br />?

No. In HTML, <br> and <br /> are equivalent. The slash is optional and only required in XHTML or JSX.

›What happens if I forget a closing tag?

Browsers try to auto-close elements, but the result may not match what you intended. A validator such as validator.w3.org will catch the problem.