...

/

Using @apply for Duplication

Using @apply for Duplication

Learn the usage of @apply and @layer directives.

@apply directive

The @apply directive lets us use Tailwind classes in the definition of other CSS selectors. So, we can redefine our header classes in CSS like this:

@layer components {
  .title { @apply text-6xl font-bold }
  .subtitle { @apply text-4xl font-semibold }
  .subsubtitle { @apply text-lg font-medium italic }
}

We can use these like any other CSS classes:

<div class="title">Title</div>

@layer directive

The @layer directive can either be base, components, or utilities. As far as the browser is concerned, if we use @layer, the selectors are defined as part of whatever layer we declare, no matter where the selector definitions are actually ...