π‘ CSS Tutorial: brightness()
π Introduction
The brightness() function in CSS is part of thefilter property. It allows you to increase or decrease the brightness of an element β commonly used for images, backgrounds, buttons, hover effects, and UI feedback. You can make an element appear lighter, darker, or completely black/white. β¨
π― What Does brightness() Do?
- Adjusts the light level (brightness) of an element
- Value greater than 1 β brighter
- Value less than 1 β darker
- Value 0 β pure black
- Useful for hover effects and dynamic UI states
β¨ Syntax
Syntax
selector {
filter: brightness(<percentage> | <number>);
}Note
You can use percentages or decimal numbers:
β’
β’
brightness(150%) = brightness(1.5)β’ brightness(50%) = brightness(0.5)π§© Accepted Values
1. brightness(1) β Normal (no change)
Code Snippet
filter: brightness(1);2. brightness(0) β Completely Dark
Code Snippet
filter: brightness(0); /* pure black */3. brightness(0.5) β 50% Dimmer
Code Snippet
filter: brightness(0.5);4. brightness(1.5) β 50% Brighter
Code Snippet
filter: brightness(1.5);5. brightness(2) β Double Brightness
Code Snippet
filter: brightness(2);π₯ Practical Examples
1. Hover to Brighten Image
Image Hover Brighten
img:hover {
filter: brightness(1.3);
transition: filter 0.3s ease;
}2. Hover to Dim a Button
Button Dim
button:hover {
filter: brightness(0.8);
}3. Combining brightness() With Other Filters
Multiple Filters
.card {
filter: brightness(0.8) blur(2px);
}4. Dark Mode Simulation
Dark Mode
.dark-mode img {
filter: brightness(0.6);
}π Brightness Levels Table
| Value | Effect |
|---|---|
| brightness(0) | Completely black |
| brightness(0.5) | 50% darker |
| brightness(1) | No change |
| brightness(1.5) | 50% brighter |
| brightness(2) | Very bright |
π§ Tips & Best Practices
- Use transition for smooth hover effects
- Dimming backgrounds improves text contrast
- Don't overuse high brightness β can look washed out
- Combine with
contrast()andblur()for advanced UI
>>βBrightness is one of the simplest but most effective ways to create responsive & interactive visual effects.β β¨
π Conclusion
The brightness() filter gives you fine control over light levels in your UI. Whether youβre dimming elements, brightening hover states, or building dark mode variations, this tool brings subtle but powerful visual expression to your designs. Master it alongside blur(), contrast(), and opacity for professional-grade effects. π