HTML attributes, online
Six activities your students do on their own devices. See who's finished, and their scores.
HTML attributes in one minute
What students need to know
id="main-title" follows the name="value" format. It is placed inside the <h1> opening tag. Three attributes are listed in the opening tag, each separated by a space - no commas or other separators.
Attributes always go in the opening tag, never in the closing tag. For example: <p class="note"> not </p class="note">. Attribute values must be wrapped in double quotes. class="header" is correct; class=header without quotes is invalid.
Mistakes students make
- The attribute value must be wrapped in double quotes. The correct form is class="intro" not class=intro without quotes.
- There must be no spaces around the equals sign in an attribute. The correct form is class="main" not class = "main" with spaces.
- The anchor element is missing the closing > on the opening tag. It should be <a href="...">Contact us</a> with a properly formed opening tag.
- An element cannot have the same attribute listed twice. To apply multiple classes, use a single class attribute with space-separated values: class="note highlight".
What students will learn in this module
Every question in Module 13
Quick questions
- Where are HTML attributes written?AInside the closing tagBInside the opening tag
- Which of these is correct attribute syntax?Aclass=headerBclass="header"
- True or false: an element can have more than one attribute.ATrueBFalse
- True or false: spaces are allowed around the = sign in an attribute.AFalseBTrue
- Which attribute is used to link an anchor element to another page?AhrefBsrc
Key terms
Students type the meaning of:
attribute
Match the pairs
<p class="intro">Welcome</p>Match it to what it does<a href="about.html">About</a>Match it to what it doesAn attribute is written as name="value" inside the opening tagMatch it to what it doesMultiple attributes on one element are separated by spacesMatch it to what it does<p class=intro>Text</p>Match it to what it does<p>Text</p class="footer">Match it to what it doesFill in the blanks
<p ___="intro">Hello</p>
Hint: Type the attribute name that assigns a CSS class to an element
<a ___="contact.html">Contact</a>
Hint: Type the attribute name used on anchor elements to specify the link destination
<h2 ___="section-one">Introduction</h2>
Hint: Type the attribute name that gives an element a unique identifier
<img src="photo.jpg" ___="A cat sitting">
Hint: Type the attribute name that provides alternative text for an image
<p ___="color: blue;">Blue text.</p>
Hint: Type the attribute name used to apply inline CSS to an element
Spot the error
Question 1
A<p class=intro>Hello there.</p>B<p id="note">A note here.</p>C<p>Normal text.</p>
Question 2
A<h1>Page Title</h1>B <p class = "main">Content here.</p>C <p>More text.</p>
Question 3
A<h2>Heading</h2>B<p id="first">First.</p>C<a Contact us</a>D<p>Footer text.</p>
Question 4
A<p>Normal paragraph.</p>B<p class="note">A note.</p>C<p style="color: red;">Red text.</p>D<p class="note" class="highlight">Two classes.</p>
Question 5
A<a href="index.html">Home</a>B<a href="about.html">About</a>C<a href="contact.html">Contact</a>D<a href="blog.html">Blog</a>E</a href="shop.html">Shop</a>
