Loading...

Using Colors in HTML

Colors are one of the key visual elements of websites. They help set the tone, highlight content, and define overall design. In HTML, there are several ways to define colors.

Ways to Define Colors

In HTML, you can define colors by name (e.g., red), HEX codes (e.g., #ff0000), RGB format (e.g., rgb(255, 0, 0)), or HSL format (e.g., hsl(0, 100%, 50%)).

Code Details

<p style="color: red;">Red text</p>
<p style="color: #00ff00;">Green text (HEX)</p>
<p style="color: rgb(0, 0, 255);">Blue text (RGB)</p>
<p style="color: hsl(60, 100%, 50%);">Yellow text (HSL)</p>

Preview

Red text

HEX Format

HEX (hexadecimal) codes start with a # and contain six characters. The first two define red, the next two green, and the last two blue.

RGB Format

RGB format uses three numbers in parentheses: red, green, and blue. Each value ranges from 0 to 255. For example, rgb(255, 0, 0) represents red.

HSL Format

HSL (Hue, Saturation, Lightness) is another way to describe colors. Hue defines the color’s angle in degrees, Saturation defines intensity, and Lightness defines brightness.

Named Colors

HTML supports more than 140 predefined color names, such as red, blue, green, orange, etc. These are easy to read and quick to apply.

red
green
blue
orange
purple
black
gray
brown

Text and Background Contrast

It's important to ensure sufficient contrast between text and background color. Otherwise, the content may become hard to read. Use light text on a dark background or vice versa.

Colors and Accessibility

Always consider visually impaired users when choosing colors. Avoid combinations that are unreadable for colorblind users. Content should not rely solely on color.

Task: Drag in the missing line that turns the text green!

Code

<!DOCTYPE html>

<html>

<head>

<style>

body {

Drag the item here

}

</style>

</head>

<body>

<blockquote>

<p>When you have something to say, silence is a lie.</p>

<footer>- Jordan B. Peterson</footer>

</blockquote>

</body>

</html>

Answers

color: green;
font-size: 18px;
border: 1px solid red;

Preview

Tips for Using Colors

  • Use a consistent color scheme across your site.
  • Avoid overusing strong, flashy colors.
  • Test your design in both light and dark modes.
  • Don’t rely on color alone to convey information.
  • Use a contrast checker to meet accessibility standards (WCAG).

Track Your Progress 🚀

Learn more easily by tracking your progress completely for free.


Top tools

CodeHubBoardly NEWLinksy NEWChromo NEW

Select Language

Set theme

© 2025 ReadyTools. All rights reserved.