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

Theory in plain words

Anatomy of an element<p class="intro">Hello world</p>Element = all three parts
Anatomy of an element

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.

Paragraph elementTry it Yourself
Bold and italicTry it Yourself

Empty elements

Some elements have no content, so they have no end tag. Examples: br, hr, img, input.

Line break and ruleTry it Yourself
Image (empty element)Try it Yourself
Input (empty element)Try it Yourself

Nesting

Put elements inside others. Close them in the reverse order you opened them.

Correct nestingTry it Yourself

Opened b then i, closed i then b.

Wrong nestingTry it Yourself

Do not cross tags like this. Fix it to match the example above.

Nested listsTry it Yourself

Block and inline

Block elements take a full lineTry it Yourself
Inline elements stay in the lineTry it Yourself
Tip:Tag names are not case sensitive, but write them in lower case.

Quick quiz

1. Which tag has no end tag?

2. An element is

3. Correct nesting is

My notes
Ask a question about this lesson