Elements, Tags, and the Ones That Never Close
An element, a tag, an attribute, and a value are four different things that everybody calls tags. Take one line of HTML apart piece by piece, and meet the handful of elements that have no closing tag at all.
Worth reading first: One File, One Browser, Nothing Installed
An element, a tag, an attribute, and a value are four different things that everybody calls tags. Take one line of HTML apart piece by piece, and meet the handful of elements that have no closing tag at all.
An element is an opening tag, content, and a closing tag
HTML marks text up by wrapping it. The wrapper says what the text is.
<p>This is a paragraph.</p>│ │ └──────┬──────────┘ └┬─┘│ │ │ └── closing tag│ │ └── content│ └── element name└── opening tag starts hereThe three parts together are the element. The angle-bracket bits on either end are its tags. People say "the p tag" when they mean the whole element, and that is fine in conversation — but the distinction matters the moment you read an error message.
Element name
Which element this is. `a` is an anchor — a link. The name decides what the browser does with it and what it means, and there are about 110 of them, of which you will use perhaps 25.
The word people reach for is “tag”, and it is used for at least three of these. Being able to say attribute valuewhen you mean the attribute value is what makes an error message like “unexpected token in attribute name” readable rather than alarming.
Element names are case-insensitive, so <P> and <p> are the same element. Write them lowercase anyway; it is the universal convention and mixed case reads as a mistake.
Attributes live in the opening tag only
An attribute adds information to an element, and it goes inside the opening tag — never the closing one.
<a href="/about">About us</a><img src="cat.jpg" alt="A cat asleep on a keyboard"><p class="intro" id="lead">Some text.</p><input type="email" required>Always. HTML permits unquoted values in simple cases, and a value containing a space silently becomes two attributes. Double quotes are the convention.
Irrelevant. class before id or id before class, no difference. Pick a habit for readability, not correctness.
Some attributes are on or off with no value: required, disabled, checked. Present means true. There is no required="false" — removing it is the only way to turn it off.
class, id, style, title, lang, hidden, and data-* work on every element. Everything else belongs to specific ones — href on an anchor, src on an image.
Void elements have nothing to close around
A handful of elements have no content — they are not wrappers, they are markers. They take no closing tag, and writing one is an error.
<img src="photo.jpg" alt="Description"><br><hr><input type="text" name="email"><meta charset="utf-8"><link rel="stylesheet" href="styles.css">There are about fourteen in total and those six are all you will use. Note that <link> is void — it points at a stylesheet — while <a>, the one people call a link, wraps content and definitely closes.
You will also see this
<br /> with a trailing slash. Legal, harmless, and completely ignored by HTML — it is left over from XHTML, and it is still required in JSX. Neither style is wrong.
This is wrong
<img>photo</img> and </br>. There is no content to wrap and nothing to close. Browsers ignore the stray closing tag, so it looks like it works.
Elements nest, and they must not overlap
Elements go inside other elements, and that nesting is what makes a document a tree. The one rule: an element opened inside another must close inside it too.
<p>This is <strong>very</strong> important.</p> correct<p>This is <strong>very important.</p></strong> WRONGIn the second line, strong opens inside the paragraph and closes outside it. The elements overlap rather than nest, which describes no possible tree. The browser will silently invent one, and it will not be the one you meant.
Indent one level per nesting level. It is purely for humans — the browser ignores all of it — and it is the difference between spotting an unclosed tag in two seconds and hunting it for ten minutes.
<article> <h2>A post</h2> <p> Some text with a <a href="/more">link</a> in it. </p> <ul> <li>First</li> <li>Second</li> </ul></article>The browser will forgive you, and that is the problem
HTML has no error messages. Nothing refuses to load, nothing turns red, and nothing tells you a tag never closed. The browser guesses, patches your document into something it can render, and shows you the result.
This was a deliberate design decision in the 1990s and it is why the web still works. It is also why a broken page can be so hard to debug: your mistake produced a page, just not the one you wrote.
<p>First paragraph.<p>Second paragraph.</p> <!-- The browser silently closes the first p before the second opens, because a p cannot contain a p. Here it does the right thing. It will not always. -->The habits that avoid most of it are small: close every tag as you write the opening one, indent consistently, and validate before you publish anything you care about.
Key takeaways
- An element is an opening tag, content, and a closing tag. The tags are the bracket parts; the element is the whole thing.
- Element names are case-insensitive; write them lowercase because everyone does.
- Attributes go in the opening tag only, and their values are always quoted.
- Boolean attributes are true when present. required="false" is a required field.
- Void elements — img, br, hr, input, meta, link — have no content and take no closing tag.
- <link> is void and points at a stylesheet; <a> wraps content and is the clickable one.
- Elements must nest, not overlap: opened inside means closed inside.
- Indent one level per level of nesting. The browser ignores it; you will not.
- HTML never reports an error. The browser patches your mistake and renders something else.
- The W3C validator is the error messages HTML does not give you.
Quick check
Answer these to unlock the next chapter — 3 of 4 to pass. You can retake it anytime.
Answer every question to check.
Make a free account to read on
Every chapter is free — an account is how your progress, XP, and streak follow you from your laptop to your phone, and how you show up on the leaderboard. No payment, no trial.