0
0
Tailwindmarkup~20 mins

Button component patterns in Tailwind - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
šŸŽ–ļø
Button Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ā“ rendering
intermediate
2:00remaining
What will this button look like in the browser?
Given this Tailwind CSS button code, what is the visual style you will see when rendered?
Tailwind
<button class="bg-blue-600 hover:bg-blue-700 text-white font-semibold py-2 px-4 rounded">Click me</button>
AA transparent button with blue text and no hover effect.
BA red button with white text and rounded corners that becomes darker red on hover.
CA blue button with white text, rounded corners, and a darker blue background on hover.
DA white button with blue text and square corners that changes to light blue on hover.
Attempts:
2 left
šŸ’” Hint
Look at the background and text color classes, and the hover prefix.
ā“ selector
intermediate
1:30remaining
Which Tailwind class applies padding inside a button?
You want to add vertical and horizontal padding inside a button. Which class correctly adds 0.5rem vertical and 1rem horizontal padding?
Apad-2x4
Bp-2-4
Cpadding-y-2 padding-x-4
Dpy-2 px-4
Attempts:
2 left
šŸ’” Hint
Tailwind uses 'py' for vertical padding and 'px' for horizontal padding.
🧠 Conceptual
advanced
2:30remaining
Why use 'focus:outline-none' with 'focus:ring' on buttons?
Consider this button code snippet:
<button class="focus:outline-none focus:ring-2 focus:ring-blue-500">Press</button>

Why is it important to use both 'focus:outline-none' and 'focus:ring' classes together?
A'focus:outline-none' removes the default focus outline, and 'focus:ring' adds a custom visible ring for accessibility.
B'focus:outline-none' disables all focus styles, and 'focus:ring' disables hover effects.
C'focus:outline-none' adds a shadow, and 'focus:ring' removes the shadow on focus.
D'focus:outline-none' makes the button unclickable, and 'focus:ring' makes it clickable.
Attempts:
2 left
šŸ’” Hint
Think about keyboard users and visible focus indicators.
ā“ layout
advanced
2:30remaining
How to center a button horizontally and vertically inside a container?
You have a container div and a button inside it. Which Tailwind classes on the container will center the button both horizontally and vertically?
Tailwind
<div class="???">
  <button class="bg-green-500 text-white px-4 py-2 rounded">Submit</button>
</div>
Aflex items-center justify-center h-64
Binline-flex items-start justify-end h-64
Cgrid place-items-start h-64
Dblock text-center h-64
Attempts:
2 left
šŸ’” Hint
Use flexbox to center items both ways.
ā“ accessibility
expert
3:00remaining
Which button code is most accessible for screen readers and keyboard users?
Choose the button code that best supports accessibility:
A<button class="p-2">Ɨ</button>
B<button aria-label="Close modal" class="p-2">Ɨ</button>
C<div role="button" tabindex="0" class="p-2">Ɨ</div>
D<span class="p-2" onclick="closeModal()">Ɨ</span>
Attempts:
2 left
šŸ’” Hint
Consider semantic elements and ARIA labels.