HTML Basics
HTML Elements
Everything you build in HTML is made of elements. This page explains exactly what an element is, how they nest, and which ones have no closing tag.
What is an HTML Element?
An HTML element is a complete piece of content marked up with tags. It normally consists of a start tag, the content, and an end tag. For example, in <h1>Hello</h1>, the whole thing — tags plus content — is the element.
Elements can contain other elements. This is called nesting, and it is how you build a page: a <body> contains paragraphs, a paragraph contains links, and so on. Correct nesting is essential.
Basic Usage
<p>This is a paragraph element.</p>Example: Nested Elements
<!DOCTYPE html>
<html>
<body>
<div>
<h2>A card title</h2>
<p>Some text with a <a href="#">link</a> and <strong>bold words</strong>.</p>
</div>
</body>
</html>More Examples
<p>Line one<br>Line two on a new line.</p>
<hr>
<img src="https://picsum.photos/200" alt="Placeholder"><ol>
<li>First step</li>
<li>Second step
<ul>
<li>A sub-point</li>
<li>Another sub-point</li>
</ul>
</li>
</ol>Common Elements at a Glance
| Element | Meaning | Closing tag? |
|---|---|---|
| <h1>-<h6> | Headings | Yes |
| <p> | Paragraph | Yes |
| <a> | Link | Yes |
| <img> | Image | No (empty) |
| <br> | Line break | No (empty) |
| <div> | Generic container | Yes |
Indent nested elements with two spaces per level. It makes the parent-child structure obvious and helps you spot missing closing tags.
Never overlap elements. <b><i>text</b></i> is invalid — the inner <i> must close before the outer <b>.
Key Takeaways
- An element is a start tag, content, and an end tag.
- Elements nest inside one another to build a page.
- Empty elements such as <img> and <br> have no closing tag.
- Always close inner elements before outer ones.
