What if you could fix a color change in one place and see it everywhere instantly?
Why Function definition with @function in SASS? - Purpose & Use Cases
Imagine you want to reuse a color calculation in many places in your stylesheet. You write the same math over and over, like darkening a color by 20% each time.
Copying and pasting the same calculation everywhere is slow and risky. If you want to change the darkening amount, you must find and update every single place manually. This wastes time and causes mistakes.
Using @function lets you write the calculation once with a name. Then you call it anywhere in your styles. Change the function once, and all uses update automatically.
color: darken(#3498db, 20%); color: darken(#3498db, 20%);
@function darken20($color) {
@return darken($color, 20%);
}
color: darken20(#3498db);
color: darken20(#3498db);You can create reusable, easy-to-update style calculations that keep your code clean and consistent.
A design system where button colors need consistent shading. Define a darken function once, then use it for all buttons to keep colors uniform and easy to tweak.
Writing repeated calculations manually wastes time and causes errors.
@function lets you define reusable style calculations.
Updating the function updates all uses, saving effort and ensuring consistency.