HTML Colors
Colors in HTML/CSS can be specified using names (like "red"), HEX codes (like #ff0000), RGB values (like rgb(255,0,0)), or HSL values.
HEX and RGB are the most common formats used in professional development, since they allow precise control over exact shades, while named colors are handy for quick prototyping.
color: #ff0000; / color: rgb(255,0,0);Color formats
HEX codes use six hexadecimal digits (#RRGGBB). RGB uses rgb(red, green, blue) with values 0-255. RGBA adds an alpha (transparency) channel.
Using colors
Colors are usually applied via CSS properties like color (text) and background-color, often set through the style attribute or a stylesheet.
<p style="color:#ff0000;">Red text using HEX</p>Red text using HEX#ff0000 represents full red, no green, no blue.
<p style="background-color: rgba(0,0,255,0.3);">Semi-transparent blue background</p>Semi-transparent blue backgroundrgba adds an alpha channel controlling opacity from 0 to 1.
Key points
- Colors can be named, HEX, RGB, or HSL.
- HEX format is #RRGGBB, each pair from 00 to ff.
- RGBA and HSLA add transparency with an alpha value.
- Color values are applied via CSS properties, not raw HTML.
