Basics
CSS Colors
Specifying CSS Colors
CSS colors use hex, RGB, HSL, and named keywords for styling elements.
Introduction to CSS Colors
CSS Colors are essential for giving web pages a unique and vibrant look. They can be specified using different formats such as hexadecimal (hex), RGB, HSL, and predefined named colors.
Hexadecimal Colors
Hexadecimal colors are expressed as a six-digit combination of numbers and letters defined by their hex values. Each pair of digits represents the intensity of red, green, and blue, respectively.
RGB Colors
RGB colors define a color using the Red, Green, and Blue components. Values range from 0 to 255 for each component, allowing for over 16 million possible colors.
HSL Colors
HSL stands for Hue, Saturation, and Lightness. Hue is represented as a degree on the color wheel (0-360), saturation is a percentage (0% means a shade of gray), and lightness is also a percentage (0% is black, 100% is white).
Named Colors
CSS provides 140 named colors that you can use without needing to remember any numeric values. Common examples include red, blue, green, and orange.
Opacity and Alpha Channel
CSS allows you to define colors with transparency using the alpha channel. You can specify this using the rgba() or hsla() functions, where the alpha value ranges from 0 (fully transparent) to 1 (fully opaque).