Lighten and darken functions help you make colors lighter or darker easily. This is useful to create different shades of the same color for your website design.
Lighten and darken functions in SASS
lighten($color, $amount) darken($color, $amount)
$color is the base color you want to change.
$amount is how much you want to lighten or darken, usually in percentages (e.g., 20%).
$light-blue: lighten(#007BFF, 20%);
$dark-red: darken(#FF0000, 15%);
button {
background-color: lighten(#28a745, 10%);
}p {
color: darken(#333333, 30%);
}This code creates a button with a blue background that is lighter than the base color. When you hover over the button, the background becomes darker. This gives a nice visual effect showing interaction.
@use 'sass:color'; $base-color: #3498db; .button { background-color: color.lighten($base-color, 20%); color: white; padding: 1rem 2rem; border: none; border-radius: 0.5rem; font-size: 1.2rem; cursor: pointer; transition: background-color 0.3s ease; } .button:hover { background-color: color.darken($base-color, 15%); }
Always use percentages for the amount to control how much lighter or darker the color becomes.
Lighten and darken work best with colors in hex, rgb, or named color formats.
Use these functions to keep your color scheme consistent and easy to adjust.
Lighten and darken functions adjust colors by making them lighter or darker.
They take a color and a percentage amount as inputs.
Use them to create hover effects, improve readability, and build color palettes.
Practice
lighten() function do in Sass?Solution
Step 1: Understand the purpose of lighten()
Thelighten()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 whatlighten()does.Final Answer:
Makes a color lighter by increasing its brightness -> Option DQuick Check:
lighten() = makes color lighter [OK]
- Confusing lighten() with darken()
- Thinking lighten() changes color hue
- Assuming lighten() inverts colors
Solution
Step 1: Recall function syntax
Thedarken()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 CQuick Check:
darken(color, percent) syntax [OK]
- Swapping argument order
- Omitting comma between arguments
- Using semicolon instead of comma
$base-color: #800000;
$light-color: lighten($base-color, 50%);
body { background-color: $light-color; }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 BQuick Check:
lighten dark red by 50% = light pink [OK]
- Thinking lighten makes color darker
- Confusing lighten with color inversion
- Expecting pure white after lighten
$color: #123456;
$dark: darken($color 30%);
.button { background: $dark; }Solution
Step 1: Check darken() function syntax
Thedarken()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 AQuick Check:
darken(color, percent) needs comma [OK]
- Omitting comma between function arguments
- Using invalid color codes
- Removing % sign from percentage
#007BFF. On hover, the button should become 15% darker. Which Sass code correctly achieves this with variables and hover style?Solution
Step 1: Set base color variable
The variable$btn-coloris set to the base blue color#007BFF.Step 2: Apply base color and darken on hover
The button background uses$btn-colornormally, and on hover usesdarken($btn-color, 15%)to make it 15% darker.Step 3: Verify hover effect logic
$btn-color: #007BFF; .button { background-color: $btn-color; &:hover { background-color: darken($btn-color, 15%); } }correctly darkens on hover.$btn-color: #007BFF; .button { background-color: darken($btn-color, 15%); &:hover { background-color: $btn-color; } }reverses colors.$btn-color: #007BFF; .button { background-color: lighten($btn-color, 15%); &:hover { background-color: darken($btn-color, 15%); } }lightens base color incorrectly.$btn-color: #007BFF; .button { background-color: $btn-color; &:hover { background-color: lighten($btn-color, 15%); } }lightens on hover instead of darkening.Final Answer:
Code with base $btn-color and darken on hover -> Option AQuick Check:
Hover darken 15% =$btn-color: #007BFF; .button { background-color: $btn-color; &:hover { background-color: darken($btn-color, 15%); } }[OK]
- Swapping lighten and darken functions
- Applying darken on base instead of hover
- Forgetting to use & for hover selector
Ready to prove it?
Pass the test and this pattern moves unknown
