0
0
HTMLmarkup~5 mins

Class attribute in HTML - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the class attribute in HTML?
The <code>class</code> attribute assigns one or more class names to an HTML element. These class names can be used to apply CSS styles or select elements with JavaScript.
Click to reveal answer
beginner
How do you assign multiple classes to a single HTML element?
You list multiple class names separated by spaces inside the <code>class</code> attribute, like <code>class="class1 class2"</code>.
Click to reveal answer
beginner
True or False: The class attribute can be used to group elements for styling and scripting.
True. The class attribute groups elements so CSS and JavaScript can target them easily.
Click to reveal answer
beginner
Example: What classes are assigned in this tag? <div class="box highlight"></div>
The element has two classes: box and highlight. Both can be used to style or select this element.
Click to reveal answer
intermediate
Why should you avoid using the same class name for unrelated elements?
Using the same class name for unrelated elements can cause unexpected styling or scripting effects because all elements with that class share the same rules.
Click to reveal answer
What does the class attribute do in HTML?
ASpecifies the element's type
BDefines the element's ID
CSets the element's text content
DAssigns a name to an element for styling and scripting
How do you add two classes named 'red' and 'bold' to a paragraph?
A<code>&lt;p class="red,bold"&gt;</code>
B<code>&lt;p class="red bold"&gt;</code>
C<code>&lt;p class="red;bold"&gt;</code>
D<code>&lt;p class="red+bold"&gt;</code>
Can multiple elements share the same class name?
AOnly if they are inside the same parent
BNo, class names must be unique
CYes, many elements can share the same class
DOnly if they are the same element type
Which is the correct way to select all elements with class 'menu' in CSS?
A.menu { }
B#menu { }
Cmenu { }
D*menu { }
What happens if you use the same class name for different types of elements?
AThey all get the same styles and scripts targeting that class
BOnly the first element gets styled
CThe browser ignores the class
DIt causes an error
Explain how the class attribute helps in styling and scripting HTML elements.
Think about how you can group elements to style them all at once.
You got /4 concepts.
    Describe the correct way to add multiple classes to an HTML element and why it is useful.
    Imagine you want one element to look like a box and also be highlighted.
    You got /4 concepts.