Mixin or Extend #40899
-
Now, I'm trying to decide between using @extend or @mixin for my project. They work differently: @mixin allows us to reuse style blocks, while @extend applies the same style to multiple selectors without duplicating code like @mixin does. For the bundled file size, @extend is more efficient because it avoids code duplication by adding selectors to existing rules. However, the downside of @extend is that we can’t use dynamic values like passing parameters. My question is: should I always use @extend and only switch to @mixin when I need dynamic values? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Using
Therefore, it is best to use them according to the situation. |
Beta Was this translation helpful? Give feedback.
Using
@extend
is more efficient for the bundled file size as it avoids code duplication by applying the same style to multiple selectors. However, since@extend
cannot use dynamic values, it is recommended to switch to@mixin
only when you need dynamic values.@mixin
is used for creating styles that require additional features like conditionals, loops, or user overrides, while@extend
is used for simply copying existing styles.Therefore, it is best to use them according to the situation.