0
0
HTMLmarkup~20 mins

Class attribute in HTML - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Class Attribute Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
rendering
intermediate
2:00remaining
What color will the text be?
Given the following HTML and CSS, what color will the text inside the <p> tag appear as in the browser?
HTML
<style>
.red { color: red; }
.blue { color: blue; }
</style>
<p class="red blue">Hello World!</p>
ARed
BBlue
CBlack (default)
DPurple
Attempts:
2 left
💡 Hint
CSS rules applied later or with higher specificity override earlier ones.
selector
intermediate
2:00remaining
Which CSS selector targets all elements with both classes?
You want to style only elements that have both classes btn and primary. Which CSS selector should you use?
A.btn.primary
B.btn, .primary
C#btn.primary
D.btn .primary
Attempts:
2 left
💡 Hint
No spaces means both classes on the same element.
🧠 Conceptual
advanced
2:00remaining
What happens if you use the same class name multiple times in class attribute?
Consider this HTML: <div class="box box highlight">Content</div>. How does the browser treat the repeated class box?
AThe repeated class is ignored; it behaves as if the class appears once.
BThe element gets styled twice by the box class, doubling the effect.
CThe browser throws an error and does not render the element.
DOnly the first occurrence of the class is applied; the rest are ignored.
Attempts:
2 left
💡 Hint
Think about how class names are used for styling and scripting.
accessibility
advanced
2:00remaining
How to improve accessibility when using class names for styling?
You use class names like red-text or big-font to style elements. What is a better practice to improve accessibility?
AAvoid using any class names to keep HTML clean.
BUse only inline styles instead of class names for better accessibility.
CUse class names with colors and sizes because screen readers read them aloud.
DUse class names that describe the content or role, not just appearance.
Attempts:
2 left
💡 Hint
Think about how assistive technologies understand your page.
📝 Syntax
expert
2:00remaining
What error occurs with this class attribute syntax?
What error will the browser show for this HTML snippet?
<div class=red blue>Text</div>
HTML
<div class=red blue>Text</div>
ASyntaxError: class attribute must be quoted.
BThe browser ignores the class attribute completely.
CThe browser treats 'red' as the class and 'blue' as an unknown attribute, no error but unexpected styling.
DThe browser applies both classes correctly without error.
Attempts:
2 left
💡 Hint
Look at how HTML attributes are parsed when quotes are missing.