The class attribute, online
Six activities your students do on their own devices. See who's finished, and their scores.
The class attribute in one minute
What students need to know
Both paragraphs share class="lead". CSS targeting .lead { } will style both paragraphs identically. class="btn primary" applies two classes. CSS can target .btn or .primary independently or together.
Unlike id, class values can be reused across many elements - that is the whole point of class-based styling. Class values must be wrapped in double quotes. class=btn without quotes is invalid HTML.
Mistakes students make
- Attribute names must be lowercase in HTML. CLASS should be written as class.
- Class values must be enclosed in double quotes: class="intro", not class=intro without quotes.
- The class attribute value is missing its closing double quote. It should be class="note">.
- There must be no space between class and =. The correct form is class="logo" with no space before the equals sign.
What students will learn in this module
Every question in Module 15
Quick questions
- Can two elements on the same page share the same class value?ANoBYes
- Which of these is the correct class attribute syntax?Aclass="btn"Bclass=btn
- True or false: class="my class" with a space applies one class named 'my class'.AFalseBTrue
- How do you apply two separate classes to one element?Aclass="btn primary"Bclass="btn" class="primary"
- True or false: CLASS with capital letters is valid HTML.ATrueBFalse
Key terms
Students type the meaning of:
class
Match the pairs
<p class="note">Remember this.</p>Match it to what it does<li class="item">One</li> <li class="item">Two</li>Match it to what it does
class values can be reused across many elements for shared CSS stylingMatch it to what it doesMultiple classes are applied with space-separated values inside one class attributeMatch it to what it does<p CLASS="note">Text.</p>Match it to what it does<p class="my note">Text.</p>Match it to what it doesFill in the blanks
<p ___="intro">Hello</p>
Hint: Type the attribute name used to assign a CSS class to an element
<h1 ___="title">Welcome</h1>
Hint: Type the attribute name that assigns a reusable CSS class
<div ___="card">Content here.</div>
Hint: Type the attribute name used to group elements for CSS styling
<span ___="highlight">key term</span>
Hint: Type the attribute name that assigns a CSS class to this span
<button ___="btn">Click me</button>
Hint: Type the attribute name used to style this button with a CSS class
Spot the error
Question 1
A<p CLASS="intro">Hello</p>B<p class="body">More text.</p>C<p class="end">Last.</p>
Question 2
A<h1>Title</h1>B<p class=intro>First paragraph.</p>C<p>More text.</p>
Question 3
A<div class="box">B <p>Content here.</p>C <p class="note"Text.</p>D</div>
Question 4
A<header>B <h1 class="title">Site</h1>C <nav class="menu">Links</nav>D <p class="slogan">Hello.</p>E <div class ="logo">Logo</div>F</header>
Question 5
A<header>B <h1 class="title">Site</h1>C <nav class="menu">Links</nav>D <p class="tag line">Slogan.</p>E</header>
