Skip to content
KodeTrail

Camp 1 · Step 3 of 14

Tags, elements, and attributes

The complete grammar of HTML in one lesson — opening tags, closing tags, nesting, and attributes.

12 min+50 XP

Good news: HTML has one grammatical pattern, repeated everywhere. Learn it once and you can read any page on the internet.

The pattern

<p class="intro">Welcome to the trail.</p>
PieceName
<p ...>opening tag
class="intro"an attribute (extra information: name="value")
Welcome to the trail.the content
</p>closing tag (note the slash)

The whole package — open tag, content, close tag — is an element.

Nesting: elements inside elements

HTML
Live preview

<strong> (importance, usually bold) and <em> (emphasis, usually italic) sit inside the paragraph. One rule governs all nesting: last opened, first closed.

<p>This is <strong>right</strong></p>     ✅
<p>This is <strong>wrong</p></strong>     ❌ overlapping

Self-closing elements

A few elements have no content, so they need no closing tag:

HTML
Live preview

<br> is a line break, <hr> a horizontal rule. You'll meet <img> (an image) — the most important one — in the next module.

Checkpoint

In <a href='https://example.com'>Visit</a>, what is href='…'?

Checkpoint

Which nesting is correct?