SASS/SCSS / Color Manipulation in SASS/SCSS

Manipulating Colors with SASS/SCSS Functions

This tutorial covers the various color manipulation functions provided by SASS/SCSS. You'll learn how to darken, lighten, mix, and adjust colors to achieve your desired results.

Tutorial 1 of 5 5 resources in this section

Section overview

5 resources

Covers built-in functions to manipulate and modify colors dynamically.

1. Introduction

In this tutorial, we will explore the color manipulation functions provided by SASS/SCSS, a preprocessor scripting language that is interpreted or compiled into CSS.

You will learn how to:
- Darken and lighten colors
- Mix colors
- Adjust colors

Prerequisites: Basic understanding of CSS and SASS/SCSS is required.

2. Step-by-Step Guide

In SASS, we can use in-built functions to manipulate colors. These functions include lighten(), darken(), mix(), and adjust() among others.

Lighten Function: This function makes a color lighter.

.lighten {
  background: lighten(red, 20%);
}

Here we are making the red color 20% lighter.

Darken Function: This function makes a color darker.

.darken {
  background: darken(blue, 30%);
}

In the above example, we are making the blue color 30% darker.

Mix Function: This function allows you to mix two colors.

.mix {
  background: mix(red, blue, 50%);
}

Here, red and blue colors are mixed evenly because we set the weight to 50%.

Adjust Function: This function lets you increase or decrease one or more components of a color.

.adjust {
  background: adjust-color($color: #b37399, $red: 20, $blue: -30, $green: 50);
}

In the above example, we're adjusting the color #b37399 by increasing red by 20, decreasing blue by 30, and increasing green by 50.

3. Code Examples

Example 1:

$color: #b37399;

.darken {
  background: darken($color, 20%);
  // This will darken the color #b37399 by 20%
}

.lighten {
  background: lighten($color, 30%);
  // This will lighten the color #b37399 by 30%
}

.mix {
  background: mix($color, red, 50%);
  // This will mix the color #b37399 and red evenly
}

.adjust {
  background: adjust-color($color: $color, $red: -10, $blue: 20, $green: 30);
  // This will adjust the color #b37399 by decreasing red by 10, increasing blue by 20 and increasing green by 30
}

4. Summary

In this tutorial, we've covered how to use SASS/SCSS to manipulate colors. We've learned how to darken, lighten, mix, and adjust colors.

To continue learning about SASS/SCSS, you can explore more about other SASS/SCSS functions and how they can be used.

5. Practice Exercises

  1. Create a class to darken the color #b37399 by 50%.
  2. Create a class to mix the color red and blue with the weight of red being 30%.
  3. Create a class to adjust the color #b37399 by increasing blue by 40 and decreasing green by 20.

Solutions:

.darken-practice {
  background: darken(#b37399, 50%);
}
.mix-practice {
  background: mix(red, blue, 30%);
}
.adjust-practice {
  background: adjust-color($color: #b37399, $blue: 40, $green: -20);
}

Continue practicing with different color codes and percentages to get a better grasp of these functions. Happy coding!

Need Help Implementing This?

We build custom systems, plugins, and scalable infrastructure.

Discuss Your Project

Related topics

Keep learning with adjacent tracks.

View category

HTML

Learn the fundamental building blocks of the web using HTML.

Explore

CSS

Master CSS to style and format web pages effectively.

Explore

JavaScript

Learn JavaScript to add interactivity and dynamic behavior to web pages.

Explore

Python

Explore Python for web development, data analysis, and automation.

Explore

SQL

Learn SQL to manage and query relational databases.

Explore

PHP

Master PHP to build dynamic and secure web applications.

Explore

Popular tools

Helpful utilities for quick tasks.

Browse tools

JSON Formatter & Validator

Beautify, minify, and validate JSON data.

Use tool

CSS Minifier & Formatter

Clean and compress CSS files.

Use tool

Hex to Decimal Converter

Convert between hexadecimal and decimal values.

Use tool

Time Zone Converter

Convert time between different time zones.

Use tool

PDF Compressor

Reduce the size of PDF files without losing quality.

Use tool

Latest articles

Fresh insights from the CodiWiki team.

Visit blog

AI in Drug Discovery: Accelerating Medical Breakthroughs

In the rapidly evolving landscape of healthcare and pharmaceuticals, Artificial Intelligence (AI) in drug dis…

Read article

AI in Retail: Personalized Shopping and Inventory Management

In the rapidly evolving retail landscape, the integration of Artificial Intelligence (AI) is revolutionizing …

Read article

AI in Public Safety: Predictive Policing and Crime Prevention

In the realm of public safety, the integration of Artificial Intelligence (AI) stands as a beacon of innovati…

Read article

AI in Mental Health: Assisting with Therapy and Diagnostics

In the realm of mental health, the integration of Artificial Intelligence (AI) stands as a beacon of hope and…

Read article

AI in Legal Compliance: Ensuring Regulatory Adherence

In an era where technology continually reshapes the boundaries of industries, Artificial Intelligence (AI) in…

Read article

Need help implementing this?

Get senior engineering support to ship it cleanly and on time.

Get Implementation Help