@forward directive accomplishes in Sass.The @forward directive in Sass re-exports styles from one file so that when another file imports the current file, it also gets the forwarded styles. This helps organize and share styles across many files.
_buttons.scss.When forwarding a Sass partial, you use @forward "filename"; with quotes and without the underscore or file extension.
main.scss?@forward "colors"; // colors.scss $primary: #06c; @mixin button-style { background-color: $primary; color: white; } // main.scss @use "buttons"; .button { @include buttons.button-style; }
The @forward directive in buttons.scss re-exports the variables and mixins from colors.scss. When main.scss uses buttons, it can access button-style mixin and the variable $primary. The compiled CSS shows the actual color value.
_base.scss defines styles for body and is forwarded by _theme.scss, which file's styles apply when importing theme.scss?// base.scss body { background: white; } // theme.scss @forward "base"; // main.scss @use "theme";
The @forward directive re-exports all styles, variables, and mixins from the forwarded file. So styles defined in base.scss will apply when importing theme.scss.
@forward help achieve this?Using @forward to share a single file with color variables ensures all parts of the project use the same accessible color tokens. This helps maintain consistent contrast and accessibility.