HTML Elements
What is an HTML Element?
Beginners often use the words "tag" and "element" interchangeably — but they mean different things. A tag is just the angle-bracket notation: <p> or </p>. An element is the full structure: the opening tag, the content inside, and the closing tag together.
<!-- This is a TAG (opening) --> <p> <!-- This is a complete ELEMENT --> <p>Hello, world!</p>
Every element has a content model — a set of rules about what it is allowed to contain. Some elements can hold text and other elements. Some can only hold specific child elements. Some hold nothing at all. Understanding content models is what separates valid HTML from broken HTML.
Block vs Inline Elements
Every HTML element has a default display behaviour. The two most important categories are block-level and inline.
div, p, h1.span, a, strong, em.| Block Elements | Inline Elements |
|---|---|
div — generic block container | span — generic inline container |
p — paragraph | a — anchor / link |
h1–h6 — headings | strong — bold importance |
ul, ol — lists | em — italic emphasis |
section, article — semantic | img — image (inline by default) |
Void (Self-Closing) Elements
Some elements have no content and no closing tag. These are called void elements (or self-closing elements). They cannot wrap text or child elements — they represent a single piece of content or metadata on their own.
<!-- HTML5 syntax — no closing slash needed --> <img src="photo.jpg" alt="A scenic view"> <br> <hr> <input type="text" name="email"> <!-- XHTML style (trailing slash) — valid but unnecessary in HTML5 --> <img src="photo.jpg" alt="A scenic view" />
<br></br> or <img></img> is invalid HTML. Void elements genuinely cannot have closing tags — the browser will treat the </br> as an unknown tag and produce unexpected results.Nesting Rules
HTML elements can be placed inside other elements — this creates parent, child, and sibling relationships. The element that contains another is the parent. The element inside is the child. Two elements at the same level sharing a parent are siblings.
The golden rules of nesting:
div can contain a p. A section can contain a div. Block containers are designed for this.p can contain a strong or em. A div can contain a span. This is normal and expected.div or p inside a span or a. Browsers will try to auto-fix this but the results are unpredictable.<!-- WRONG — block inside inline --> <p> <div>This is invalid HTML.</div> </p> <!-- CORRECT — inline inside block --> <p> This paragraph has <strong>important text</strong> inside it. </p> <!-- CORRECT — block inside block --> <div> <p>First paragraph.</p> <p>Second paragraph.</p> </div>
<div><p> you must close them as </p></div> — innermost first. Crossing tags like <div><p></div></p> is invalid and will confuse the browser's parser.The Most Common HTML Elements
HTML has over 100 elements, but you'll use about 30 of them for 95% of all web pages. Here's a quick reference:
| Element | Category | Purpose |
|---|---|---|
h1–h6 | Heading | Six levels of headings for document structure |
p | Text | Paragraph of text |
div | Container | Generic block-level container |
span | Container | Generic inline container |
a | Link | Hyperlink to another page or anchor |
img | Media | Embed an image (void element) |
ul / ol | List | Unordered / ordered list |
li | List | Individual list item |
form | Form | Container for user input fields |
input | Form | Text field, checkbox, button, etc. (void) |
button | Form | Clickable button |
table | Table | Tabular data container |
header | Semantic | Introductory content or navigation area |
nav | Semantic | Navigation links block |
main | Semantic | Primary content of the page |
footer | Semantic | Footer content, links, copyright |
section | Semantic | Thematic grouping of content |
article | Semantic | Self-contained content (blog post, card) |
aside | Semantic | Tangentially related content (sidebar) |
Semantic vs Generic Elements
Generic elements like <div> and <span> are just boxes with no built-in meaning. They're perfectly valid for layout and styling hooks, but they tell browsers, screen readers, and search engines nothing about what the content actually is.
Semantic elements carry meaning. When you write <nav>, you're declaring "this block contains navigation links." When you write <article>, you're saying "this block is a self-contained piece of content." That meaning matters in three important ways:
nav, main, and footer — giving blind users a page map.article, h1, and section to rank and display content accurately.<!-- Generic — technically works, but meaningless --> <div class="nav"> <div class="nav-item">Home</div> </div> <!-- Semantic — immediately clear what this is --> <nav> <a href="/">Home</a> </nav>
div or span when no semantic element fits — for example, a pure styling wrapper with no inherent meaning.Build a
<div> container that holds:• An
<h2> heading• Two
<p> paragraphs• An
<ul> unordered list with exactly 3 <li> itemsInside one of the paragraphs, use
<strong> and <em> for emphasis within the text. Keep all block-level elements as containers and inline elements only inside paragraph text.
Show hints
- Start with
<div>as the outer wrapper - Add the
<h2>as the first child of the div - Place both
<p>tags after the heading, still inside the div - Add
<ul>last — each list item must be wrapped in<li></li> - Remember:
<strong>and<em>go inside<p>, not outside it