Search code examples
sasshtml-helperscss-mixins

Sass mixin or helper class which one is better to use?


Which one is better, using Sass mixin and include it using @include or defining a helper class and use in Html where ever you need ? for example I need to use {display:flex; justify-content:center; align-items:center} in my project over and over. so should I use @mixin and @include or it's better to define a helper class such as .flex{display:flex; justify-content:center; align-items:center} and use class="flex" where ever I need in my project?


Solution

  • Well this seems more like a preference question. I would personally define a helper and use it in html when you need as it may be easier to read the project overall. But if the project starts to grow and html starts getting bloated, it might not be ideal to apply this coding style, and so a mixin might be a cleaner solution.

    I would say it depends on how large the project is or the scalability you're looking forward to, but also depends on your code style and preferences.