Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

The Shape of an HTML Document · Lesson 8 of 18

Opening, Closing, and Self-Closing Tags

A free lesson from Swipe Coding · HTML, level 1 · updated October 2026

By the Swipe team, founded by Colin · how we make lessons

Most HTML tags come in pairs: an opening tag like <p> and a matching closing tag like </p>, with content sandwiched between them. The closing tag is identical to the opening one except for the forward slash right after the <.

<p>This is a paragraph.</p>
An opening tag, some content, and a matching closing tag.
🤖
No content, no closing tag needed — the tag says everything on its own. ✅

Some tags never wrap content at all, so they have no separate closing tag — they're called self-closing (or void) elements. <img>, <br>, and <input> are common examples: an image tag doesn't wrap text, a line break doesn't wrap anything, so neither needs </img> or </br>.

<img src="photo.jpg" alt="A photo">
<br>
Neither of these tags has, or needs, a closing tag.

Forgetting a closing tag on a paired element is one of the most common beginner mistakes, and it's often the cause of a page looking subtly broken — content nested in the wrong place, or formatting bleeding further than intended. Getting into the habit of closing every paired tag prevents most of these bugs before they happen.

Quick check

Which of these is a self-closing (void) element that never needs a closing tag?

Fill in the blank

A closing tag is written the same as an opening tag, but with a forward ____ right after the <.

True or false

Every single HTML tag requires a matching closing tag.

Keep your streak going in Swipe Coding

Swipe through every level of HTML on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.

Get the Swipe apps →