Nearby lessons
6 of 19π¨ CSS Colors
π What are CSS Colors?
CSS Colors allow you to apply vibrant styling to your webpages using various color formats like named colors, hexadecimal, RGB, RGBA, HSL, and HSLA. Colors can be applied to text, background, borders, and other elements.
π Color Formats
- Named Colors β Predefined keywords like
red,blue,green - Hexadecimal β Six-digit codes starting with
#(e.g.,#FF0000) - RGB β Based on red, green, and blue channels (e.g.,
rgb(255,0,0)) - RGBA β Like RGB, but adds opacity (alpha) (e.g.,
rgba(255,0,0,0.5)) - HSL/HSLA β Defines color using hue, saturation, lightness (+ alpha for HSLA)
π Color Overview
CSS provides multiple methods to define colors for elements. Understanding how each method works gives you flexibility and control over your design.
ποΈ Named Colors Example
Named colors are predefined color names in CSS, such as red, blue, and green. They are easy to remember and use.
Code Example
π’ Hexadecimal Color Example
Hexadecimal colors are represented using a # followed by six digits (0β9, AβF) indicating red, green, and blue values. Example: #00FF00 for green.
Code Example
π RGB Color Example
RGB colors use the format rgb(red, green, blue) with values between 0 and 255. Example: rgb(0, 0, 255) for blue.
Code Example
π RGBA Color Example
RGBA colors are similar to RGB but include an alpha (opacity) value between 0 and 1. Example: rgba(255, 0, 0, 0.5) creates a semi-transparent red.
Code Example
π Common Colors Reference
- π΄ Red β #FF0000 β rgb(255,0,0)
- π Orange β #FFA500 β rgb(255,165,0)
- π‘ Yellow β #FFFF00 β rgb(255,255,0)
- π’ Green β #008000 β rgb(0,128,0)
- π΅ Blue β #0000FF β rgb(0,0,255)
- π£ Purple β #800080 β rgb(128,0,128)
- π€ Brown β #A52A2A β rgb(165,42,42)
- βͺ White β #FFFFFF β rgb(255,255,255)
- β« Black β #000000 β rgb(0,0,0)
- π Gray β #808080 β rgb(128,128,128)