Bird
Raised Fist0
CSSmarkup~20 mins

!important usage in CSS - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Important CSS Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What does !important do in CSS?
Consider the CSS rule color: red !important;. What effect does !important have on this style declaration?
AIt makes the style apply only when the user hovers over the element.
BIt disables the style so it won't apply to the element.
CIt only applies the style if the element has a class named <code>important</code>.
DIt makes the style override other conflicting styles, even inline styles without <code>!important</code>.
Attempts:
2 left
💡 Hint
Think about how CSS decides which style wins when multiple rules apply.
📝 Syntax
intermediate
1:00remaining
Which CSS rule correctly uses !important?
Select the CSS rule that correctly applies !important to the background-color property.
Abackground-color: blue !important;
Bbackground-color: !important blue;
Cbackground-color !important: blue;
Dbackground-color: blue important!;
Attempts:
2 left
💡 Hint
Remember the order: property, colon, value, then !important.
rendering
advanced
1:30remaining
What color will the text be?
Given the HTML and CSS below, what color will the paragraph text appear as in the browser?

<style> p { color: green !important; } #special { color: red; } </style> <p id="special">Hello!</p>
CSS
<style>
p { color: green !important; }
#special { color: red; }
</style>
<p id="special">Hello!</p>
ARed
BGreen
CBlack (default)
DBlue
Attempts:
2 left
💡 Hint
Which rule has higher priority, the one with !important or the ID selector without it?
selector
advanced
1:30remaining
Which selector's !important style applies?
Consider these CSS rules:

.box { border: 1px solid black !important; } #unique { border: 2px dashed red !important; }

Which border style will an element with class="box" and id="unique" have?
CSS
.box { border: 1px solid black !important; }
#unique { border: 2px dashed red !important; }
ANo border because of conflicting !important rules
B1px solid black border from .box
C2px dashed red border from #unique
DDefault border (none) because !important cancels out
Attempts:
2 left
💡 Hint
When multiple !important rules apply, which selector wins?
accessibility
expert
2:00remaining
Why should !important be used carefully for accessibility?
Using !important can sometimes harm accessibility. Which reason below best explains why?
AIt can override user styles or browser settings that help users with disabilities.
BIt makes the page load slower, causing delays for screen readers.
CIt disables keyboard navigation on the page.
DIt hides content from assistive technologies.
Attempts:
2 left
💡 Hint
Think about how users might customize styles for better reading.

Practice

(1/5)
1. What does the !important declaration do in CSS?
easy
A. It makes the style apply only on hover.
B. It comments out the CSS rule.
C. It disables the CSS rule.
D. It forces a style to override other conflicting styles.

Solution

  1. Step 1: Understand the role of !important

    The !important declaration is used to make a CSS rule stronger than others that might conflict.
  2. Step 2: Compare with other options

    Options A, B, and D describe unrelated CSS behaviors like hover effects, commenting out the CSS rule, or disabling, which !important does not do.
  3. Final Answer:

    It forces a style to override other conflicting styles. -> Option D
  4. Quick Check:

    !important = override styles [OK]
Hint: Remember: !important beats other styles [OK]
Common Mistakes:
  • Thinking it comments out CSS
  • Confusing it with pseudo-classes like :hover
  • Believing it disables styles
2. Which of the following is the correct syntax to make a CSS color red with !important?
easy
A. !important color: red;
B. color: !important red;
C. color: red !important;
D. color: red important!;

Solution

  1. Step 1: Recall correct !important syntax

    The !important keyword comes immediately after the value and before the semicolon, like color: red !important;.
  2. Step 2: Check each option

    Options B, C, and D place !important incorrectly or miss the exclamation mark, making them invalid CSS syntax.
  3. Final Answer:

    color: red !important; -> Option C
  4. Quick Check:

    Correct syntax = value + !important [OK]
Hint: Put !important right after the value [OK]
Common Mistakes:
  • Placing !important before the property
  • Missing the exclamation mark
  • Putting !important after the semicolon
3. Given the CSS below, what color will the paragraph text be?
p { color: blue; }
p { color: red !important; }
medium
A. Blue
B. Red
C. Default browser color
D. No color applied

Solution

  1. Step 1: Identify conflicting styles

    There are two rules for p: one sets color to blue, the other to red with !important.
  2. Step 2: Apply !important precedence

    The rule with !important overrides the other, so the paragraph text color will be red.
  3. Final Answer:

    Red -> Option B
  4. Quick Check:

    !important beats normal styles [OK]
Hint: Styles with !important override others [OK]
Common Mistakes:
  • Ignoring !important and picking first style
  • Thinking both colors apply simultaneously
  • Assuming default browser color applies
4. Why does this CSS not make the text green?
p { color: green; }
p.special { color: red !important; }

HTML:
<p class="special">Hello</p>
medium
A. Because p.special has higher specificity and uses !important.
B. Because color: green; has !important missing.
C. Because the HTML class is misspelled.
D. Because !important only works on IDs.

Solution

  1. Step 1: Analyze selector specificity and !important

    The selector p.special is more specific than just p, and it uses !important, so it overrides the green color.
  2. Step 2: Check other options for errors

    The class name matches the HTML, and !important works on any selector, not just IDs.
  3. Final Answer:

    Because p.special has higher specificity and uses !important. -> Option A
  4. Quick Check:

    Specificity + !important = override [OK]
Hint: Higher specificity + !important wins [OK]
Common Mistakes:
  • Thinking !important only works on IDs
  • Ignoring selector specificity
  • Assuming class name typo without checking
5. You want to override a third-party CSS library's button color which uses .btn { color: blue !important; }. Which CSS rule will successfully change the button text color to green?
hard
A. .btn { color: green !important; }
B. #btn { color: green !important; }
C. .btn { color: green; }
D. button { color: green !important; }

Solution

  1. Step 1: Understand !important override rules

    To override a style with !important, your rule must also use !important and have equal or higher specificity (or same specificity but appear later).
  2. Step 2: Compare selector specificity

    The library uses class selector .btn with !important. .btn { color: green !important; } uses the same selector and !important, overriding if your CSS loads later. A (#btn) has higher specificity but targets id="btn", not class="btn". C lacks !important. D (button) has lower specificity (1 vs 10).
  3. Final Answer:

    .btn { color: green !important; } -> Option A
  4. Quick Check:

    Matching selector + !important wins [OK]
Hint: Use !important with matching selector to override [OK]
Common Mistakes:
  • Not using !important when overriding another !important
  • Using lower specificity selectors
  • Confusing class and ID selectors