CSS hsla() Function
Example
Define an HSL color with transparency:
#p1
{
background-color:
hsl
(
120
,
100
%
,
50
%
,
0.3
)
;
}
/*
Green
*/
#p2
{
background-color:
hsl
(
120
,
100
%
,
75
%
,
0.3
)
;
}
/*
Light green
*/
#p3
{
background-color:
hsl
(
120
,
100
%
,
25
%
,
0.3
)
;
}
/*
Dark green
*/
#p4
{
background-color:
hsl
(
120
,
60
%
,
70
%
,
0.3
)
;
}
/*
Soft green
*/
Try it »
Definition and usage
The hsla() function defines a color using hue, saturation, lightness, and alpha.
HSLA stands for Hue, Saturation, Lightness, Alpha.
- **Hue (H)** is the basic property of a color, what we normally call the color name, such as red, yellow, and so on.
- **Saturation (S)** refers to the purity of a color; the higher it is, the purer the color, and the lower it is, the grayer it becomes, with values from 0-100%.
- Lightness (L) From 0-100%; increasing lightness makes the color move toward white, decreasing it makes the color move toward black.
- Alpha (A) Ranges from 0 to 1, representing transparency.
Supported version: CSS3
Browser support
The numbers in the table indicate the first browser version that supports the function.
| function | |||||
|---|---|---|---|---|---|
| hsla() | 1.0 | 9.0 | 1.0 | 3.1 | 9.5 |
CSS Syntax
hsla(hue, saturation, lightness, alpha)
| Value | Description |
|---|---|
| hue - Hue | Defines the hue (0 to 360) - 0 (or 360) is red, 120 is green, 240 is blue |
| saturation - Saturation | Defines saturation; 0% is gray, 100% is full color |
| lightness - Lightness | Defines lightness; 0% is dark, 50% is normal, 100% is white |
| alpha - Alpha | Defines alpha: 0 (fully transparent) to 1 (fully opaque) |
CSS Functions