edubun
English
1 / 16

2 / 10 · Intro

Tags and elements

An element is usually three things in a row: an opening tag, some content and a closing tag with a slash.

Jump to the 10 practice questions

You will learn

  • Name the parts of an element: tags, attributes, content
  • Nest elements and close them in reverse order
  • Mark meaning with strong and em, and show special characters

Before this: What a web page is

1Explain

The parts of an element

Look at <p>Bread is ready.</p>. The opening tag <p> says a paragraph starts here. The closing tag </p>, with a slash after the first angle bracket, says it ends. Everything between them is the content. The whole thing, tags plus content, is the element.

Edit the text between the tags, then the tags themselves, and watch the preview.

Your code
<p>Bread is <strong>ready</strong>.</p>
Preview

2Explain

Attributes add details

An opening tag can carry attributes, extra settings written as name="value". In <a href="menu.html">Menu</a> the attribute href says where the link goes. In <html lang="en"> the attribute lang names the language. Put the value in double quotes; the standard allows some unquoted values, but quotes never cause trouble.

Your code
<p class="note" id="opening">We open at <strong>7 am</strong>.</p>
Preview

3Explain

Example: reading one element

Read this line part by part, from left to right.

<abbr title="kilogram">kg</abbr>
  1. <abbr starts an element: abbr, an abbreviation.
  2. title="kilogram" is an attribute: its name is title and its value, in quotes, is the full word.
  3. > ends the opening tag. The content follows: kg.
  4. </abbr> is the closing tag. Opening tag, content and closing tag together are one element.
  5. On screen only kg is drawn. Most browsers show the title value when the pointer rests on it.

4Problem

What href is

In <a href="menu.html">Menu</a>, what is href?

Hint

It is written inside the opening tag as name="value".

Solution

Answer: an attribute

It is a name="value" setting inside the opening tag.

5Explore

Close in reverse order

Elements go inside other elements. In the example above, <strong> sits inside <p>. The rule is the same as with brackets in arithmetic: whatever opened last must close first. <p><strong>7 am</p></strong> is wrong because the paragraph closes while the strong element is still open. Browsers will guess what you meant, but different mistakes lead to different guesses.

Pick a content: elements sit inside each other, and character references draw signs that would otherwise start a tag.

Tap a choice: the code and the preview change together.

Inside p
<p>Bread is <strong>ready</strong>.</p>
Preview

6Problem

Correctly nested?

Is <p><em>Hi</p></em> correctly nested?

Hint

Which tag was opened last? It must close first.

Solution

Answer: No, em must close before p

The last element opened must be the first one closed: <p><em>Hi</em></p>.

7Problem

Closing tags in order

<p><strong><em>Hot

The line opens p, then strong, then em. Put the closing tags in the order they must be written.

  1. </strong>
  2. </em>
  3. </p>
Hint

The element opened last closes first.

Solution

Answer:

  1. </em>
  2. </strong>
  3. </p>

em was opened last, so it closes first; p was opened first, so it closes last.

8Problem

Elements in one line

<p>
  <em>Rye bread</em><br>
  <strong>Ready at 7 am</strong>
</p>

How many elements does this line contain? Count the outer p as well.

Hint

A void element counts as an element too.

Solution

Answer: 4

p, em, strong and br: 4. br has no content and no closing tag, but it is still an element.

9Explain

Void elements

Some elements cannot have content, so they have no closing tag. These are called void elements. The common ones are <br> (a line break), <hr> (a thematic break), <img>, <input>, <meta> and <link>. You may see them written with a slash, such as <br />; in HTML the slash is allowed and ignored, so both forms work.

Your code
<p>12 Mill Street<br>Springfield</p>
<hr>
<p>Open from 7 am.</p>
Preview

10Problem

An element with no content

Which of these is a void element?

Hint

It has no closing tag.

Solution

Answer: br

br has no content and no closing tag.

11Problem

A closing tag that should not be there

Which of these is not valid HTML?

Hint

A void element has no closing tag.

Solution

Answer: <br></br>

br is a void element. The slash in <br /> is allowed and ignored, but </br> is an error; browsers even read it as a second line break.

12Problem

Show a less-than sign

Because < starts a tag, you cannot type it as ordinary text. Write a character reference instead: &lt; for less than, &gt; for greater than, and &amp; for the ampersand itself. A comment, <!-- like this -->, is ignored by the browser and is handy for notes to yourself. Finally, HTML collapses white space: ten spaces or three line breaks in your file show up as a single space.

Type the character reference that shows a less-than sign as text.

Hint

A character reference starts with & and ends with ;.

Solution

Answer: &lt;

&lt; stands for less than, &gt; for greater than and &amp; for the ampersand.

13Practice

strong and em

Wrap 24 hours in <strong> and a day ahead in <em>. Keep both inside the paragraph.

Checks
  • strong inside p
  • em inside p
Your code
<p>Our sourdough takes 24 hours to make, so order it a day ahead.</p>
Preview
Hint

Put the opening tag right before the words and the closing tag right after them.

A solution
<p>Our sourdough takes <strong>24 hours</strong> to make, so order it <em>a day ahead</em>.</p>

14Practice

Show a tag as text

Make the paragraph show the tag itself: change the text so it reads To start a paragraph, type <p>. on screen. Use character references.

Checks
  • shows

    as text

Your code
<p id="demo">To start a paragraph, type p.</p>
Preview
Hint

Write &lt; for < and &gt; for >.

A solution
<p id="demo">To start a paragraph, type &lt;p&gt;.</p>

15Explain

Common mistakes

Mistake
<p>Open <strong>daily</p></strong>
<p>Closed on Monday.</p>
Fixed
<p>Open <strong>daily</strong></p>
<p>Closed on Monday.</p>

strong was opened inside p, so it must close before p does.

16

Summary

  • Element = opening tag + content + closing tag.
  • Attributes are name="value" pairs inside the opening tag.
  • Close elements in reverse order of opening; void elements have no closing tag.
  • Use &lt; &gt; &amp; for special characters; white space collapses.

Next unitHeadings and paragraphs
Full text · The whole lesson as one text

The parts of an element

Look at <p>Bread is ready.</p>. The opening tag <p> says a paragraph starts here. The closing tag </p>, with a slash after the first angle bracket, says it ends. Everything between them is the content. The whole thing, tags plus content, is the element. People often say tag when they mean element. A tag is the part in angle brackets. An element is the complete piece, usually including its tags and content.

Attributes add details

An opening tag can carry attributes, extra settings written as name="value". In <a href="menu.html">Menu</a> the attribute href says where the link goes. In <html lang="en"> the attribute lang names the language. Put the value in double quotes; the standard allows some unquoted values, but quotes never cause trouble. Several attributes are separated by spaces, and their order does not matter. A few attributes, such as required on a form field, are boolean: writing the name alone switches them on.

<p class="note" id="opening">We open at <strong>7 am</strong>.</p>
One paragraph element with two attributes (class and id) and a strong element nested inside.

Nesting: close in reverse order

Elements go inside other elements. In the example above, <strong> sits inside <p>. The rule is the same as with brackets in arithmetic: whatever opened last must close first. <p><strong>7 am</p></strong> is wrong because the paragraph closes while the strong element is still open. Browsers will guess what you meant, but different mistakes lead to different guesses. Indenting child elements by two spaces, as the examples in this course do, makes the nesting easy to see.

Void elements

Some elements cannot have content, so they have no closing tag. These are called void elements. The common ones are <br> (a line break), <hr> (a thematic break), <img>, <input>, <meta> and <link>. You may see them written with a slash, such as <br />; in HTML the slash is allowed and ignored, so both forms work.

Meaning, not looks

Inside a paragraph you can mark words with <strong> for strong importance and <em> for stress emphasis, the kind that changes how a sentence is spoken. Browsers show strong as bold and em as italic, but the point is the meaning. A screen reader may read them with a different voice, and a search engine treats them as important words. If you only want bold text for decoration, that is a job for CSS. <b> and <i> still exist for text that is set apart without extra importance, such as a ship name or a foreign word.

Special characters and comments

Because < starts a tag, you cannot type it as ordinary text. Write a character reference instead: &lt; for less than, &gt; for greater than, and &amp; for the ampersand itself. A comment, <!-- like this -->, is ignored by the browser and is handy for notes to yourself. Finally, HTML collapses white space: ten spaces or three line breaks in your file show up as a single space. Layout comes from elements and CSS, not from pressing the space bar.

Key points
  • Element = opening tag + content + closing tag.
  • Attributes are name="value" pairs inside the opening tag.
  • Close elements in reverse order of opening; void elements have no closing tag.
  • Use &lt; &gt; &amp; for special characters; white space collapses.

Practice questions from Tags and elements on edubun

Embed this quiz

Free to embed. Please keep the credit line.

Sources for this course (9)
  • WHATWG, HTML Living Standard (html.spec.whatwg.org, checked 2026-10-17)
  • MDN Web Docs, Learn web development: Structuring content with HTML, and the HTML element reference (developer.mozilla.org/en-US/docs/Learn_web_development/Core/Structuring_content and developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements, checked 2026-10-17)
  • MDN, HTML images (alt text guidance, checked 2026-10-17)
  • W3C WAI, Images tutorial and alt decision tree (w3.org/WAI/tutorials/images/decision-tree, checked 2026-10-17)
  • CERN, A short history of the Web (home.cern/science/computing/the-birth-of-the-web/short-history-web/, checked 2026-10-17)
  • W3C and WHATWG memorandum of understanding, 28 May 2019 (w3.org/2019/04/WHATWG-W3C-MOU.html, checked 2026-10-17)
  • W3C, Using ARIA, first rule of ARIA use (w3.org/TR/using-aria/, checked 2026-10-17)
  • W3C Markup Validation Service (validator.w3.org, checked 2026-10-17)
  • MDN, Viewport meta element (checked 2026-10-17).

Checked: 2026-10-17