The id attribute, online

Six activities your students do on their own devices. See who's finished, and their scores.

The id attribute in one minute

What students need to know

Both elements have different id values: wrapper and content. This is correct - every id on the page must be unique. about-us uses a hyphen to separate words. This is valid. A space like id="about us" would be invalid.

id values cannot contain spaces. Use hyphens or underscores to separate words: main-heading or main_heading. id values are case-sensitive. Header and header are treated as different identifiers.

Mistakes students make

  • id values cannot contain spaces. Use a hyphen or underscore instead: id="main-title" or id="main_title".
  • HTML attribute names must be lowercase. ID with a capital letter is non-standard. The correct form is id="main-nav".
  • The id value "about" is used twice on the same page. Every id must be unique - change one of them, for example to id="about-text".
  • The id attribute on the fourth paragraph is missing its value. An id attribute must always have a value in double quotes: id="unique-name".

Discover other journeys with this module

What students will learn in this module

Every question in Module 14

Quick questions

  1. True or false: two elements on the same page can share the same id value.AFalseBTrue
  2. Which of these is a valid id value?Amain headingBmain-heading
  3. True or false: id="Header" and id="header" are the same id value.AFalseBTrue
  4. Where is the id attribute written?AInside the closing tagBInside the opening tag
  5. True or false: id=intro without quotes is valid HTML.AFalseBTrue

Key terms

Students type the meaning of:

  • id

Match the pairs

<h1 id="main-title">Welcome</h1>Match it to what it does
<p id="intro">First paragraph.</p>Match it to what it does
id values must be unique - no two elements on the same page may share the same idMatch it to what it does
id values cannot contain spaces - use hyphens or underscores to separate wordsMatch it to what it does
<p id="intro">First.</p>
<p id="intro">Second.</p>
Match it to what it does
<div id="my section">Content.</div>Match it to what it does

Fill in the blanks

  1. <h1 ___="main-title">Welcome</h1>

    Hint: Type the attribute name that gives an element a unique identifier

  2. <section ___="about"><p>About us.</p></section>

    Hint: Type the attribute that uniquely identifies this section element

  3. <p ___="intro">First paragraph.</p>

    Hint: Type the attribute name used to uniquely identify this paragraph

  4. <body>
      <div ___="wrapper">Content here.</div>
    </body>

    Hint: Type the attribute that gives this div a unique name on the page

  5. <footer ___="site-footer"><p>Copyright 2024.</p></footer>

    Hint: Type the attribute name that uniquely identifies this footer element

Spot the error

Question 1

A<h1 id="main title">Page Title</h1>B<p id="intro">Introduction.</p>C<p id="body-text">Content.</p>

Question 2

A<header id="site-header">B  <nav ID="main-nav">C  </nav>D</header>

Question 3

A<section id="about">B  <h2>About Us</h2>C  <p id="about">Our story.</p>D</section>

Question 4

A<p id="intro">First.</p>B<p id="body">Second.</p>C<p id="outro">Third.</p>D<p id>Fourth.</p>

Question 5

A<body>B  <div id="wrapper">C    <p id="lead">Lead paragraph.</p>D    <p id="lead">Second paragraph.</p>E  </div>F</body>