Skip to content

Strategies for Using @apply vs. theme() #13064

Answered by adamwathan
Mahrryie asked this question in Help
Discussion options

You must be logged in to vote

The biggest difference is that @apply is an enormously complicated beast that does a lot more than you think, while theme() is a very simple function that just grabs a value from your theme and dumps it in the spot where you called the function.

Here's an example that has shown up in our issues/discussions a number of times over the years — say you have some custom CSS using @apply in a pretty innocent way like this:

.foo {
  @apply text-red-500;
}

This generates the CSS you'd expect:

.foo {
  color: rgb(239 68 68)
}

Now say somewhere on your site you have some markup like this:

<div>
  <h1>The <span class="text-red-500">absolute best</span> tool for tracking your spending.</h1>
</div>

..…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@Mahrryie
Comment options

@wongjn
Comment options

Comment options

You must be logged in to vote
1 reply
@harrygreen
Comment options

Answer selected by Mahrryie
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
5 participants