CSS Color in HTML

Color Examples

Red
#00FF00
RGB
RGBA
HSL
HSLA
Gradient

Example Code

<div style="background-color: red;">Red</div>
<div style="background-color: #00FF00;">Green (#00FF00)</div>
<div style="background-color: rgb(0, 0, 255);">Blue (rgb)</div>
<div style="background-color: rgba(255, 165, 0, 0.7);">Orange (rgba)</div>
<div style="background-color: hsl(240, 100%, 50%);">Blue (hsl)</div>
<div style="background-color: hsla(120, 100%, 50%, 0.7);">Green (hsla)</div>
<div style="background: linear-gradient(to right, red, blue);">Red-Blue Gradient</div>

HTML Color Methods

Color Names

Predefined names like red, blue, or green.

Hexadecimal (HEX)

Colors in #RRGGBB format. Example: #FF0000.

RGB / RGBA

Define colors with rgb() or rgba() (with alpha transparency).

HSL / HSLA

Colors based on Hue, Saturation, Lightness (and Alpha for HSLA). Example: hsl(240, 100%, 50%).

CMYK (Printing)

Used in print, not supported in browsers. Example: cmyk(0%, 100%, 100%, 0%).

Gradients

Smooth transition between colors with linear-gradient().