bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/CSS/Advanced Styling
CSS•Advanced Styling

CSS Colors

CSS supports 140+ color names, HEX values, RGB values , RGBA values, HSL values, HSLA values, and opacity.

RGBA Colors

RGBA color values are an extension of RGB colors with an alpha channel - which specifies the opacity for a color.

An RGBA color value is specified with:

rgba( red, green , blue, alpha )

The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (fully opaque).

The following example defines different RGBA colors:

Example

Formatted code
#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 */

Live preview

HSLA Colors

HSLA color values are an extension of HSL colors with an alpha channel - which specifies the opacity for a color.

An HSLA color value is specified with:

hsla( hue, saturation , lightness, alpha )

The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (fully opaque):

The following example defines different HSLA colors:

Example

Formatted code
#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 */

Live preview

CSS opacity Property

The opacity property sets the opacity for the whole element (both background color and text will be opaque/transparent).

The opacity property value must be a number between 0.0 (fully transparent) and 1.0 (fully opaque).

Notice that the text inside the element will also be transparent/opaque!

The following example shows different elements with opacity:

Example

Formatted code
#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 */

Live preview

Previous

CSS Background Clip

Next

CSS Color Keywords

This chapter

Overview
53

Lessons

154m

Read time

1. CSS Rounded Corners2. Sass Tutorial3. CSS Border Images4. CSS Multiple Backgrounds5. CSS Background Size6. CSS Background Origin7. CSS Background Clip8. CSS Colors9. CSS Color Keywords10. CSS Gradients11. CSS Radial Gradients12. CSS Conic Gradients13. CSS Shadow Effects14. CSS Box Shadow15. CSS Text Effects16. CSS Custom Fonts17. CSS 2D Transforms18. CSS 2D Transform Scale19. CSS 2D Transform Skew / Matrix20. CSS 3D Transforms21. CSS Transitions22. CSS Transition Timing23. CSS Animations24. CSS Animation Timing25. CSS Animation Properties26. CSS Tooltip27. CSS Tooltip Arrows28. CSS Styling Images29. CSS Image Effects30. CSS Image Hover Overlays31. CSS Responsive Modal Images32. CSS Centering Images33. CSS Image Filter Effects34. CSS Image Shapes35. CSS object-fit Property36. CSS object-position Property37. CSS Masking38. CSS Gradient Mask Layers39. CSS SVG Mask Layers40. CSS Styling Buttons41. CSS Button Hover Effects42. CSS Button Groups43. CSS Pagination Styles44. CSS Multiple Columns45. CSS Column Rules46. CSS User Interface47. CSS Variables - var() Function48. CSS Overriding Variables49. CSS Variables and JavaScript50. CSS Variables in Media Queries51. CSS @property Rule52. CSS Box Sizing53. CSS Media Queries

On this page

RGBA ColorsHSLA ColorsCSS opacity Property