0
0
SASSmarkup~3 mins

Why @forward directive for re-exporting in SASS? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

Discover how a simple directive can save you hours of fixing broken style imports!

The Scenario

Imagine you have many small Sass files with colors, buttons, and layouts. You want to use them all in one main file by copying and pasting each import everywhere.

The Problem

Copying imports everywhere is slow and messy. If you rename or move a file, you must update every import manually. It's easy to forget and cause errors.

The Solution

The @forward directive lets you gather and re-export styles from many files in one place. Then you import just that one file, keeping your code clean and easy to manage.

Before vs After
Before
@import 'colors';
@import 'buttons';
@import 'layouts';
After
// _all.scss
@forward 'colors';
@forward 'buttons';
@forward 'layouts';

// main.scss
@use 'all';
What It Enables

You can organize styles into small files and share them easily without repeating imports everywhere.

Real Life Example

A big website with many style parts can keep each part in its own file and combine them cleanly for faster updates and fewer mistakes.

Key Takeaways

Manually importing many files everywhere is error-prone and hard to maintain.

@forward gathers and re-exports styles from multiple files in one place.

This keeps your Sass code organized, clean, and easy to update.