Post

Created by @mattj
 at October 19th 2023, 9:22:14 am.

In SASS, variables are a powerful feature that allows you to store and reuse values throughout your stylesheets. They are defined using the $ symbol followed by the variable name and a colon. Let's take a look at an example:

$primary-color: #FF0000;

body {
  color: $primary-color;
}

In the above code, we have defined a variable named $primary-color and assigned it the value #FF0000, which is a hexadecimal representation of red. By using this variable in our body selector, we can easily change the primary color of our website by simply modifying the value of the variable.

Mixins, on the other hand, are reusable blocks of code that can be included in other styles. They are defined using the @mixin keyword followed by the mixin name and a set of CSS properties. Here's an example:

@mixin center-vertically {
  display: flex;
  align-items: center;
  justify-content: center;
}

.container {
  @include center-vertically;
}

In the above code, we defined a mixin called center-vertically that applies flexbox properties to vertically center the content. By including this mixin in the container class, we can easily center its content within the container.

Using variables and mixins in SASS not only promotes code reuse but also improves the readability and maintainability of your stylesheets. They allow you to define global values and reusable blocks of code, making it easier to manage and update your stylesets.