Bird
Raised Fist0
Tailwindmarkup~20 mins

Disabled state styling in Tailwind - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Disabled State Styling Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ selector
intermediate
2:00remaining
Identify the correct Tailwind CSS selector for disabled buttons
Which Tailwind CSS class combination correctly applies a gray background and disables pointer events only when a button is disabled?
Tailwind
<button class="btn">Click me</button>
Abtn disabled:bg-gray-400 disabled:pointer-events-none
Bbtn [disabled]:bg-gray-400 [disabled]:pointer-events-none
Cbtn :disabled:bg-gray-400 :disabled:pointer-events-none
Dbtn .disabled:bg-gray-400 .disabled:pointer-events-none
Attempts:
2 left
💡 Hint
Tailwind uses square brackets for attribute selectors in class names.
❓ rendering
intermediate
2:00remaining
What visual effect does this disabled button have?
Given this button code, what will the user see when the button is disabled?
<button disabled class="bg-blue-600 text-white px-4 py-2 rounded [disabled]:bg-gray-400 [disabled]:cursor-not-allowed">Submit</button>
AButton with blue background and cursor changes to not-allowed always
BButton with blue background and cursor changes to pointer on hover
CButton with gray background and cursor changes to not-allowed on hover
DButton with gray background and cursor changes to not-allowed always
Attempts:
2 left
💡 Hint
The cursor style applies only when disabled.
🧠 Conceptual
advanced
2:00remaining
Why use pointer-events-none on disabled elements?
What is the main reason to add pointer-events-none to a disabled button in Tailwind CSS?
ATo prevent the button from receiving mouse events like clicks and hovers
BTo make the button invisible when disabled
CTo change the button text color automatically
DTo enable keyboard navigation on the button
Attempts:
2 left
💡 Hint
Think about how users interact with disabled buttons.
📝 Syntax
advanced
2:00remaining
Which Tailwind class syntax is invalid for disabled styling?
Which option contains an invalid Tailwind CSS class for styling disabled elements?
Adisabled:opacity-50
B[disabled]:bg-gray-300
C[disabled]:cursor-not-allowed
D[disabled]:opacity-50
Attempts:
2 left
💡 Hint
Tailwind uses square brackets for attribute selectors, not just the word 'disabled'.
❓ accessibility
expert
3:00remaining
Best practice for accessible disabled buttons
Which approach best improves accessibility for disabled buttons styled with Tailwind CSS?
AOnly use the disabled attribute and style with <code>[disabled]</code> classes
BRemove the disabled attribute and only use CSS to make the button look disabled
CUse <code>aria-disabled="true"</code> and style with <code>[aria-disabled='true']</code> classes
DUse <code>tabindex="-1"</code> without any disabled attribute or aria attributes
Attempts:
2 left
💡 Hint
Consider screen readers and keyboard users.

Practice

(1/5)
1. What does the disabled: prefix in Tailwind CSS do?
easy
A. Removes the element from the page
B. Disables the element functionality
C. Applies styles only when the element has the disabled attribute
D. Makes the element visible only on hover

Solution

  1. Step 1: Understand the disabled attribute

    The HTML disabled attribute marks an element as inactive or unusable.
  2. Step 2: Role of Tailwind's disabled: prefix

    The disabled: prefix applies CSS styles only when the element is disabled, allowing visual changes without affecting functionality.
  3. Final Answer:

    Applies styles only when the element has the disabled attribute -> Option C
  4. Quick Check:

    disabled: prefix = style on disabled [OK]
Hint: Remember disabled: styles only affect disabled elements [OK]
Common Mistakes:
  • Thinking disabled: disables functionality
  • Confusing disabled: with hover: or focus:
  • Assuming disabled: removes elements
2. Which Tailwind CSS class correctly changes the cursor to 'not-allowed' when a button is disabled?
easy
A. disabled:cursor-not-allowed
B. cursor-not-allowed
C. cursor-disabled
D. disabled:cursor-disabled

Solution

  1. Step 1: Identify the cursor style for disabled state

    The cursor style for disabled elements is not-allowed, which shows a 'no' symbol.
  2. Step 2: Use Tailwind's disabled prefix

    To apply this style only when disabled, use disabled:cursor-not-allowed. Plain cursor-not-allowed applies always.
  3. Final Answer:

    disabled:cursor-not-allowed -> Option A
  4. Quick Check:

    disabled:cursor-not-allowed = correct syntax [OK]
Hint: Use disabled: prefix before cursor class for disabled styling [OK]
Common Mistakes:
  • Using cursor-not-allowed without disabled:
  • Using non-existent cursor-disabled class
  • Placing disabled: after the class name
3. What will be the background color of this button when disabled?
<button disabled class="bg-blue-500 disabled:bg-gray-400">Click me</button>
medium
A. Red (#ef4444)
B. Blue (#3b82f6)
C. No background color
D. Gray (#9ca3af)

Solution

  1. Step 1: Check the button's disabled attribute

    The button has the disabled attribute, so disabled styles apply.
  2. Step 2: Analyze Tailwind classes for background

    The normal background is bg-blue-500. When disabled, disabled:bg-gray-400 overrides it to gray.
  3. Final Answer:

    Gray (#9ca3af) -> Option D
  4. Quick Check:

    disabled attribute triggers disabled:bg-gray-400 [OK]
Hint: Disabled attribute triggers disabled: styles override base [OK]
Common Mistakes:
  • Ignoring disabled: prefix effect
  • Assuming base bg-blue-500 stays
  • Confusing gray-400 with gray-500
4. Identify the error in this Tailwind usage for disabled styling:
<input disabled class="disabled:bg-gray-300 cursor-not-allowed" />
medium
A. Cursor style should use disabled: prefix
B. Cannot style input elements with Tailwind
C. disabled:bg-gray-300 is invalid syntax
D. Missing disabled attribute on input

Solution

  1. Step 1: Check the disabled attribute presence

    The input has the disabled attribute, so disabled styles can apply.
  2. Step 2: Analyze cursor style usage

    The cursor style cursor-not-allowed applies always. To apply only when disabled, it should be disabled:cursor-not-allowed.
  3. Final Answer:

    Cursor style should use disabled: prefix -> Option A
  4. Quick Check:

    Cursor needs disabled: prefix for disabled state [OK]
Hint: Add disabled: prefix to cursor styles for disabled elements [OK]
Common Mistakes:
  • Forgetting disabled: prefix on cursor
  • Thinking disabled:bg-gray-300 is wrong
  • Assuming inputs can't be styled
5. You want a button to have a blue background normally, but when disabled, it should have a gray background and the text should be lighter gray. Which Tailwind classes achieve this?
hard
A. bg-blue-600 disabled:bg-gray-400 text-white text-gray-300
B. bg-blue-600 disabled:bg-gray-400 disabled:text-gray-300 text-white
C. bg-blue-600 bg-gray-400 disabled:text-gray-300 text-white
D. bg-blue-600 disabled:bg-gray-400 text-gray-300 disabled:text-white

Solution

  1. Step 1: Set normal background and text colors

    Use bg-blue-600 for blue background and text-white for white text normally.
  2. Step 2: Apply disabled styles with prefix

    Use disabled:bg-gray-400 for gray background and disabled:text-gray-300 for lighter gray text when disabled.
  3. Step 3: Verify order and prefixes

    Classes must have disabled: prefix for disabled styles; base styles apply otherwise.
  4. Final Answer:

    bg-blue-600 disabled:bg-gray-400 disabled:text-gray-300 text-white -> Option B
  5. Quick Check:

    Disabled styles need disabled: prefix [OK]
Hint: Use disabled: prefix on all styles changing when disabled [OK]
Common Mistakes:
  • Missing disabled: prefix on text color
  • Placing disabled classes without prefix
  • Mixing order causing style override issues
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard