Home / Learn HTML / HTML Elements and Tags
HTML Elements and Tags
An element is a start tag, some content and an end tag. Pages are built by putting elements inside elements.
Definition: element, tag and attribute
An HTML element is a piece of the page made of a start tag, some content and an end tag. For example <p>Hello</p> is a paragraph element. The start tag is <p>, the end tag is </p> (it has a slash) and the content is Hello.
People often say tag when they mean element. Strictly, a tag is only the label in angle brackets; an element is the complete thing: tags plus content. Tag names are not case sensitive, but write them in lowercase by convention.
Rules of elements
- Most elements need an end tag. If you forget it, the browser guesses where it ends, often wrongly.
- Some elements are empty (they have no content and no end tag):
br,hr,img,input,meta,link. - Elements can be placed inside other elements. This is called nesting. Close the inner element before the outer one.
- Elements are either block (start on a new line and take the full width, like
panddiv) or inline (stay inside a line, likeaandstrong).
Theory in plain words
What it is
An element is a building block of a page: a start tag, content and an end tag, such as <p>Hello</p>. Some elements are empty and have no end tag, such as <br>.
Why we use it
Elements tell the browser what each piece of content means. The meaning decides how it looks by default and how screen readers and search engines understand it.
How it works
The browser turns every element into a node in a tree. Elements can sit inside other elements (nesting), and tags must close in the reverse order.
Where it is used
- Headings, paragraphs, links and images
- Layout containers
- Form controls
Anatomy of an element
<p>Hello</p> has a start tag <p>, content Hello and an end tag </p>. The end tag has a slash.
Empty elements
Some elements have no content, so they have no end tag. Examples: br, hr, img, input.
Nesting
Put elements inside others. Close them in the reverse order you opened them.
Opened b then i, closed i then b.
Do not cross tags like this. Fix it to match the example above.
Block and inline
Quick quiz
1. Which tag has no end tag?
br is an empty element.
2. An element is
That is the definition.
3. Correct nesting is
Close tags in reverse order.