Curriculum
Course: CSS Advanced
Login

Curriculum

CSS Advanced

CSS Rounded Corners

0/1

CSS Border Images

0/1

CSS Color Keywords

0/1

CSS Text Effects

0/1

CSS 2D Transforms

0/1

CSS 3D Transforms

0/1

CSS Transitions

0/1

CSS Animations

0/1

CSS Tooltip

0/1

CSS Style Images

0/1

CSS Image Reflection

0/1

CSS Masking

0/1

CSS Buttons

0/1

CSS Multiple Columns

0/1

CSS User Interface

0/1

CSS Box Sizing

0/1

CSS Media Queries

0/1
Text lesson

CSS Colors

CSS provides support for over 140 color names as well as various color representations including HEX values, RGB values, RGBA values, HSL values, HSLA values, and opacity settings.

RGBA Colors

RGBA color values extend RGB color values by incorporating an alpha channel, determining the opacity level for a color.

The syntax for specifying an RGBA color value is: rgba(red, green, blue, alpha), where the alpha parameter ranges from 0.0 (fully transparent) to 1.0 (fully opaque).

IMG_3637

Below is an example showcasing various RGBA color definitions:

Example 

#p1 {background-color: rgba(255, 0, 0, 0.3);}  /* red with opacity */
#p2 {background-color: rgba(0, 255, 0, 0.3);}  /* green with opacity */
#p3 {background-color: rgba(0, 0, 255, 0.3);}  /* blue with opacity */

HSL Colors

HSL represents Hue, Saturation, and Lightness.

An HSL color value is defined as: hsl(hue, saturation, lightness).

1. Hue corresponds to a degree on the color wheel ranging from 0 to 360:

  • 0 (or 360) represents red,
  • 120 represents green, and
  • 240 represents blue.

2. Saturation is expressed as a percentage, where 100% represents the full color intensity.

3. Lightness is also a percentage, where 0% signifies dark (black) and 100% indicates white.

hsl(0, 100%, 30%);
hsl(0, 100%, 50%);
hsl(0, 100%, 70%);
hsl(0, 100%, 90%);

Below is an example showcasing various HSL color definitions:

Example 

#p1 {background-color: hsl(120, 100%, 50%);}  /* green */
#p2 {background-color: hsl(120, 100%, 75%);}  /* light green */
#p3 {background-color: hsl(120, 100%, 25%);}  /* dark green */
#p4 {background-color: hsl(120, 60%, 70%);}   /* pastel green */

HSLA Colors

HSLA color values expand upon HSL color values by incorporating an alpha channel, determining the opacity level for a color.

The syntax for specifying an HSLA color value is: hsla(hue, saturation, lightness, alpha), where the alpha parameter defines the opacity level. It ranges from 0.0 (fully transparent) to 1.0 (fully opaque).

IMG_3638

Below is an example illustrating various HSLA color definitions:

Example 

#p1 {background-color: hsla(120, 100%, 50%, 0.3);}  /* green with opacity */
#p2 {background-color: hsla(120, 100%, 75%, 0.3);}  /* light green with opacity */
#p3 {background-color: hsla(120, 100%, 25%, 0.3);}  /* dark green with opacity */
#p4 {background-color: hsla(120, 60%, 70%, 0.3);}   /* pastel green with opacity */

Opacity

The CSS opacity property adjusts the transparency of the entire element, affecting both background color and text.

Opacity values must range from 0.0 (fully transparent) to 1.0 (fully opaque).

IMG_3639

Note that the text above will also exhibit transparency or opacity.

Below is an example demonstrating various elements with different opacity settings:

Example 

#p1 {background-color:rgb(255,0,0);opacity:0.6;}  /* red with opacity */
#p2 {background-color:rgb(0,255,0);opacity:0.6;}  /* green with opacity */
#p3 {background-color:rgb(0,0,255);opacity:0.6;}  /* blue with opacity */