Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

Sass Color

Sass saturation() Function

Posted in Sass Tutorial
Updated on Sep 29, 2024
By Mari Selvan
👁ī¸ 14 - Views
âŗ 4 mins
đŸ’Ŧ 1 Comment
Sass saturation() Function

Photo Credit to CodeToFun

🙋 Introduction

The saturate() function in Sass is a useful tool for enhancing the intensity of a color by increasing its saturation.

This function is particularly helpful when you want to make colors more vibrant or when you need to emphasize certain elements in your design. By controlling the saturation of colors, you can create dynamic and visually appealing interfaces.

💡 Syntax

The saturate() function is simple to use. It takes two arguments:

Syntax
Copied
Copy To Clipboard
saturate(color, amount)

đŸ”ĸ Parameters

  • color: A color value (e.g., #ff0000, rgb(255, 0, 0), hsl(0, 100%, 50%)).
  • amount: A percentage value indicating how much to increase the color's saturation (e.g., 20%).

↩ī¸ Return Value

The function returns a color with its saturation increased by the specified amount.

📝 Example Usage

Let's explore some examples to see how saturate() can be applied in your Sass projects.

📜 Example 1: Basic Usage

example.scss
Copied
Copy To Clipboard
$original-color: #808080; // Gray
$saturated-color: saturate($original-color, 50%);

p {
  color: $saturated-color;
}

In this example, the gray color #808080 is saturated by 50%, resulting in a more colorful version of the original gray.

📜 Example 2: Using HSL Colors

example.scss
Copied
Copy To Clipboard
$original-color: hsl(200, 50%, 50%); // A muted blue
$saturated-color: saturate($original-color, 30%);

header {
  background-color: $saturated-color;
}

Here, a muted blue color specified in HSL is saturated by 30%, making it more vibrant.

📜 Example 3: Saturating Multiple Colors in a Map

example.scss
Copied
Copy To Clipboard
$colors: (
  primary: #ff4500,
  secondary: #2e8b57,
  accent: #4682b4
);

@each $name, $color in $colors {
  .saturate-#{$name} {
    color: saturate($color, 20%);
  }
}

In this example, multiple colors are saturated by 20% using a loop, creating classes that apply these more vibrant colors.

🎉 Conclusion

The saturate() function in Sass is an excellent way to intensify colors, making your design elements stand out. Whether you're looking to enhance the vibrancy of a color palette or draw attention to specific elements, saturate() provides a flexible and powerful solution. By mastering this function, you can take greater control over the visual impact of your web designs.

Experiment with different colors and saturation levels to discover the full potential of the saturate() function in your Sass workflows.

👨‍đŸ’ģ Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy