CSS Basic Tutorial
In CSS, colors can be applied to elements in various ways using different color formats. Here’s an overview of how colors are specified and used in CSS.
Currently Active Property:
Color Format
|
Description
|
---|---|
Named Colors
|
CSS provides a set of named colors that you can use directly without needing to define the color value.
|
Hexadecimal Colors
|
Hexadecimal colors are defined using a # followed by either 3 or 6 hexadecimal characters (0-9, A-F). The first two digits represent red, the next two represent green, and the last two represent blue.
|
RGB Colors
|
RGB colors are specified with the rgb() function, which defines colors by setting red, green, and blue channels with values between 0 and 255.
|
RGBA Colors
|
RGBA is the same as RGB but includes an alpha channel that controls the transparency of the color. The alpha value is a number between 0 (completely transparent) and 1 (completely opaque).
|
HSL Colors
|
HSL stands for Hue, Saturation, and Lightness. The hsl() function is another way to represent colors:
|
HSLA Colors
|
HSLA is the same as HSL but includes an alpha channel to control the transparency.
|
CurrentColor Keyword
|
currentColor is a special keyword that uses the current value of the color property.
|
Transparent Keyword
|
The transparent keyword sets a fully transparent color. It's often used as a fallback or default value in CSS backgrounds or borders.
|
CSS provides a set of named colors that you can use directly without needing to define the color value.
Hexadecimal colors are defined using a #
followed by either 3 or 6 hexadecimal characters (0-9
, A-F
). The first two digits represent red, the next two represent green, and the last two represent blue.
Try it yourself
RGB colors are specified with the rgb()
function, which defines colors by setting red, green, and blue channels with values between 0
and 255
Try it yourself
RGBA is the same as RGB but includes an alpha channel that controls the transparency of the color. The alpha value is a number between 0
(completely transparent) and 1
(completely opaque).
Try it yourself
HSL stands for Hue, Saturation, and Lightness. The hsl()
function is another way to represent colors:
0%
is grey, 100%
is full color).0%
is black, 100%
is white).HSLA is the same as HSL but includes an alpha channel to control the transparency.
Try it yourself
currentColor
is a special keyword that uses the current value of the color
property.
Try it yourself
The transparent
keyword sets a fully transparent color. It's often used as a fallback or default value in CSS backgrounds or borders.