HTML colors are used to set the visual appearance of text, backgrounds, borders, and other elements on a webpage. They can be applied using CSS properties like color, background-color, border, etc.
Ways to Define HTML Colors:
1. Color Names
<!DOCTYPE html>
<html>
<head>
<title> Page Title </title>
</head>
<body>
<p style="color: red;" > This is red text. </p>
</body>
</html>
Output
2. Hex Codes (#RRGGBB)
<!DOCTYPE html>
<html>
<head>
<title> Page Title </title>
</head>
<body>
<p style="color: #00FF00;" > This is green text. </p>
</body>
</html>
Output
3. RGB Values (rgb(red, green, blue))
<!DOCTYPE html>
<html>
<head>
<title> Page Title </title>
</head>
<body>
<p style="color: rgb(0, 0, 255);" > This is blue text. </p>
</body>
</html>
Output
4. RGBA (adds transparency)
<!DOCTYPE html>
<html>
<head>
<title> Page Title </title>
</head>
<body>
<p style="color: rgba(255, 0, 0, 0.5);" > This is semi-transparent red. </p>
</body>
</html>
Output
5. HSL (Hue, Saturation, Lightness)
<!DOCTYPE html>
<html>
<head>
<title> Page Title </title>
</head>
<body>
<p style="color: color: hsl(120, 100%, 50%);" > This is semi-transparent red. </p>