can i still use @apply in css modules in tailwind 4?
- User
can i still use @apply in css modules in tailwind 4?
Assistant
In Tailwind CSS 4, the
@applydirective has been deprecated. The Tailwind team recommends moving away from@applyin favor of using Tailwind's utility classes directly in your HTML or using the new@layerdirective for custom styles.Here are some alternatives:
- Use utility classes directly in your HTML:
<div class="text-red-500 font-bold p-4"> Content </div>- If you need to create reusable components, you can use the
@layerdirective in your CSS:
@layer components { .my-custom-button { @apply bg-blue-500 text-white px-4 py-2 rounded; } }- For more complex scenarios, consider using CSS modules with Tailwind's utility classes or creating custom components in your framework.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.