CSS @apply rule(If you don't know about it) basically lets you define native CSS mixins that are similar to SASS or LESS mixins with one key difference being that you cannot pass variables to these native mixins.
Without the support for passing variables as arguments, I don't see a possible use case where a native CSS mixin would be helpful.
Does CSS @apply rule solve any real problems? or are we just making CSS harder and harder with complex/unnecessary features??
Could be a nice replacement for cluttering up your HTML with utility classes. https://tabatkins.github.io/specs/css-apply-rule/ This page here has a couple of examples of its use, and thats about what it seems to amount to.
@apply should become the new mixin I reckon, combined with native CSS variables. It will take a lot of time (making specs, getting vendors to implement), but it might remove the use for SASS/LESS in a lot of cases.
Does CSS @apply rule solve any real problems? or are we just making CSS harder and harder with complex/unnecessary features??
If @apply works like a SASS/LESS mixin, it does. CSS will evolve and it makes sense to copy the good parts of SASS/LESS and make that native CSS behaviour :)
Alkshendra Maurya
Frontend Engineer | Hashnode Alumnus
Apart from helping avoid redundant code, I could not imagine many use-cases for this.
However, more than that, I see it as a possibility for creating CSS that is not dependant on the class-names you put in the markup.
So, instead of using instead of cluttering your markup with classes like
<a class=“btn btn-red price-btn”>Buy Now</a>and your CSS like
You would would be writing
<a class=“price-btn”>Buy Now</a>and your CSS would look something like this:
.price-btn { @apply --btn; @apply --btn-red; font-weight: 700; ... }Which, I think is a pretty neat as it separates your markup from additional style-dependent classes.