📖 Scenario: You are creating a simple style sheet for a website. You want to use Sass functions to make colors lighter or darker easily. This helps keep your design consistent and easy to update.
🎯 Goal: Build a Sass file that defines a base color, sets a percentage for lightening and darkening, then uses the lighten() and darken() functions to create lighter and darker color variants. Finally, apply these colors to CSS classes.
📋 What You'll Learn
Create a variable $base-color with the exact value #3498db
Create a variable $change-percent with the exact value 20%
Use the lighten() function with $base-color and $change-percent to create $light-color
Use the darken() function with $base-color and $change-percent to create $dark-color
Create CSS classes .light and .dark that use $light-color and $dark-color as background colors respectively
💡 Why This Matters
🌍 Real World
Designers and developers often need to create color palettes with consistent light and dark shades for buttons, backgrounds, and themes.
💼 Career
Knowing how to use Sass functions like lighten() and darken() helps you write maintainable and scalable CSS for professional web projects.
Progress0 / 4 steps
1
Create the base color variable
Create a Sass variable called $base-color and set it to the hex color #3498db.
SASS
Hint
Use $base-color: #3498db; to define the color variable.
2
Create the percentage variable for color change
Create a Sass variable called $change-percent and set it to 20%.
SASS
Hint
Use $change-percent: 20%; to define the percentage variable.
3
Create lighter and darker color variables using lighten() and darken()
Create a variable $light-color using lighten($base-color, $change-percent) and a variable $dark-color using darken($base-color, $change-percent).
SASS
Hint
Use lighten($base-color, $change-percent) and darken($base-color, $change-percent) to create the new color variables.
4
Apply the colors to CSS classes
Create CSS classes .light and .dark. Set the background color of .light to $light-color and the background color of .dark to $dark-color.
SASS
Hint
Use .light { background-color: $light-color; } and .dark { background-color: $dark-color; } to style the classes.
Practice
(1/5)
1. What does the lighten() function do in Sass?
easy
A. Changes a color to grayscale
B. Makes a color darker by decreasing its brightness
C. Inverts the color completely
D. Makes a color lighter by increasing its brightness
Solution
Step 1: Understand the purpose of lighten()
The lighten() function increases the lightness of a color, making it appear lighter.
Step 2: Compare with other options
Other options describe darkening, grayscale, or inversion, which are not what lighten() does.
Final Answer:
Makes a color lighter by increasing its brightness -> Option D
Quick Check:
lighten() = makes color lighter [OK]
Hint: Lighten means make color brighter or lighter [OK]
Common Mistakes:
Confusing lighten() with darken()
Thinking lighten() changes color hue
Assuming lighten() inverts colors
2. Which of the following is the correct syntax to darken a color by 20% in Sass?
easy
A. darken(20%, #3498db)
B. darken(#3498db 20%)
C. darken(#3498db, 20%)
D. darken(#3498db; 20%)
Solution
Step 1: Recall function syntax
The darken() function takes two arguments: a color and a percentage, in that order, separated by a comma.
Step 2: Check each option
darken(#3498db, 20%) matches the correct syntax: darken(#3498db, 20%). Others have wrong order or missing comma/semicolon.
Final Answer:
darken(#3498db, 20%) -> Option C
Quick Check:
darken(color, percent) syntax [OK]
Hint: Function args: color first, then percentage with comma [OK]
Common Mistakes:
Swapping argument order
Omitting comma between arguments
Using semicolon instead of comma
3. What color will be produced by this Sass code?
$base-color: #800000;
$light-color: lighten($base-color, 50%);
body { background-color: $light-color; }
medium
A. A very dark red color
B. A very light pinkish color
C. Pure white
D. Bright green
Solution
Step 1: Understand lighten effect on #800000
The base color #800000 is a dark red. Lightening it by 50% will add a lot of white, making it much lighter and pinkish.
Step 2: Eliminate other options
It won't be dark (B), pure white (C), or green (D) because lighten only adds lightness to the original red color.
Final Answer:
A very light pinkish color -> Option B
Quick Check:
lighten dark red by 50% = light pink [OK]
Hint: Lighten dark red by 50% = light pinkish color [OK]
The darken() function requires a comma between the color and percentage arguments.
Step 2: Identify the missing comma
In the code, darken($color 30%) lacks a comma, causing a syntax error.
Final Answer:
Missing comma between arguments in darken() -> Option A
Quick Check:
darken(color, percent) needs comma [OK]
Hint: Remember comma separates arguments in functions [OK]
Common Mistakes:
Omitting comma between function arguments
Using invalid color codes
Removing % sign from percentage
5. You want to create a button with a base blue color #007BFF. On hover, the button should become 15% darker. Which Sass code correctly achieves this with variables and hover style?