0
0
Tailwindmarkup~5 mins

@apply for extracting patterns in Tailwind - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the @apply directive do in Tailwind CSS?

The @apply directive lets you reuse Tailwind utility classes inside your own CSS rules. It helps you extract repeated patterns into one place.

Click to reveal answer
beginner
How do you use @apply to create a custom button style?
<p>Write a CSS rule with a class name, then inside it use <code>@apply</code> followed by the Tailwind utilities you want to combine. For example:<br><code>.btn { @apply bg-blue-500 text-white py-2 px-4 rounded; }</code></p>
Click to reveal answer
beginner
Why is using @apply helpful for maintaining your CSS?

It keeps your code DRY (Don't Repeat Yourself). Instead of repeating many utility classes in HTML, you write them once in CSS. This makes updates easier and your HTML cleaner.

Click to reveal answer
intermediate
Can @apply be used with responsive or state variants like hover: or md:?

Yes, you can use variants with @apply. For example, @apply hover:bg-blue-700 md:text-lg; applies styles on hover and at medium screen sizes.

Click to reveal answer
intermediate
What happens if you try to <code>@apply</code> a class that includes complex CSS like pseudo-elements or animations?

Tailwind's @apply works best with simple utility classes. Complex classes with pseudo-elements or animations may cause errors or not work as expected.

Click to reveal answer
What is the main purpose of the @apply directive in Tailwind CSS?
ATo add JavaScript functionality
BTo reuse utility classes inside CSS rules
CTo create new HTML elements
DTo import external CSS files
Which of these is a valid use of @apply?
A.card { @apply bg-white p-4 rounded shadow; }
Bbody { @apply text-center; }
Ch1 { @apply font-bold hover:underline; }
DAll of the above
Can you use @apply with responsive prefixes like sm: or lg:?
AOnly with JavaScript enabled
BNo, @apply only works with base classes
CYes, you can use responsive prefixes with @apply
DOnly in inline styles
What is a benefit of using @apply instead of repeating utility classes in HTML?
ACleaner HTML and easier style updates
BFaster JavaScript execution
CBetter SEO ranking
DAutomatic image optimization
What might happen if you try to @apply a Tailwind class with pseudo-elements like before:?
AIt may cause errors or not work properly
BIt will work perfectly every time
CIt will add JavaScript animations
DIt will convert to inline styles
Explain how the @apply directive helps you write cleaner CSS with Tailwind.
Think about how you avoid writing the same styles many times.
You got /4 concepts.
    Describe a situation where using @apply with responsive or hover variants would be useful.
    Consider buttons that change color on hover or text size on mobile.
    You got /4 concepts.