HTML Colors

HTML Colors are used to set text color, background color, borders, and more on a web page.
Colors improve the design, readability, and user experience.

In this tutorial, you will learn different ways to use colors in HTML, with examples and output.

 What Are HTML Colors

HTML colors are used to style elements using:

  • Text color
  • Background color
  • Border color

Colors are usually applied using the style attribute (CSS).


Ways to Use Colors in HTML

There are three main ways to define colors:

Color Types Table

TypeExample
Color Namered, blue, green
HEX Value#ff0000
RGB Valuergb(255, 0, 0)

Using Color Names

Example Code

<p style="color: red;">This is red text.</p>

Output

This is red text.


Using HEX Colors

HEX colors use a 6-digit code.

Example Code

<p style="color: #0000ff;">This is blue text.</p>

Output

This is blue text.


Using RGB Colors

RGB stands for Red, Green, Blue.

Example Code

<p style="color: rgb(0, 128, 0);">This is green text.</p>

Output

This is green text.


Background Color Example

Example Code

<p style="background-color: yellow;">Yellow background</p>

Output

Yellow background (with yellow background)


Text and Background Together

Example Code

<p style="color: white; background-color: black;">
White text on black background
</p>

Output

White text on black background


Common Color Names

Popular HTML Colors

Color NamePreview
Redred
Blueblue
Greengreen
Yellowyellow
Blackblack
Whitewhite

HEX Color Structure

HEX colors start with #.

Format

#RRGGBB
PartMeaning
RRRed value
GGGreen value
BBBlue value

RGB Color Structure

Format

rgb(red, green, blue)

| Value Range | 0 to 255 |


Multiple Color Styling Example

Example Code

<h1 style="color: blue;">Heading</h1>
<p style="color: red;">Paragraph text</p>
<p style="background-color: lightgray;">Background color</p>

Output

Heading (blue)
Paragraph text (red)
Background color (gray background)


HTML Colors Summary Table

MethodFormatExample
Nametextred
HEX#RRGGBB#ff0000
RGBrgb()rgb(255,0,0)

Best Practices for Using Colors

PracticeDescription
Use readable colorsEnsure good contrast
Avoid too many colorsKeep design simple
Use HEX/RGB for accuracyBetter control
Test on devicesCheck visibility

Common Mistakes

MistakeResult
Low contrastHard to read
Wrong HEX codeInvalid color
Overuse of colorsPoor design
Missing # in HEXNot applied

Colour Names

A colour name can be used to specify a colour in HTML:

Names of Colours List
WhiteBlackOrangeMaroon
RedYellowLime greenSalmon
GreenSky blueCrimsonAqua
GreyPurpleMustardPeach
VioletMagentaCoralSaffron
BrownPinkTanTeal
Navy BlueTurquoiseLavenderBeige
Lemon yellowGrape vineIndigoFuchsia
AmberSea greenDark greenBurgundy
CharcoalBronzeCreamMauve
OliveCyanSilverRust
RubyAzureMintPearl
IvoryTangerineCherry redGarnet
EmeraldSapphireRosewoodLilac
Arctic bluePista greenCoffee brownUmber
BrunetteMochaAshJet black

There are 140 recognised colour names in HTML.

 

An summary of colour specification techniques:

English name, for example, white
RGB colour code in hexadecimal, for example: #ff0000
Soft colours have the hexadecimal RGB value of #f00.
RGB values in decimal form, such as: rgb (255, 0, 0)
RGBA value in decimal form, for example: rgba (255, 0, 0, 0.2)
A color\’s HSL value is hsl(120, 100%, 50%).
Color is an example of an HSLA value: hsla(0, 100%, 50%, 0.5).

Furthermore, RGB, HEX, HSL, RGBA, and HSLA values can be used in HTML to specify colours.

ColorFull-FormCSS Version
RGBRed Green blueCSS2
RGBARed Green Blue AlphaCSS3
HSLHue Saturation LightnessCSS3
HSLAHue Saturation Lightness AlphaCSS3

Read more


Frequently Asked Questions (FAQ)

1. What are HTML colors?

HTML colors are used to style text and backgrounds.

2. How many ways can colors be defined?

Three: Name, HEX, and RGB.

3. Which color format is best?

HEX and RGB provide more control.

4. Can I use multiple colors?

Yes, using style attribute or CSS.

5. Are HTML colors part of CSS?

Yes, colors are applied using CSS.

Related Article
Introduction to HTML

HTML Introduction – Learn the Basics of HTML HTML is the starting point of web development. Every website you see Read more

What is HTML

What Is HTML – Complete Beginner Explanation HTML is the foundation of the web. Every website you visit, from simple Read more

HTML Basic Examples

HTML Basic Examples – Learn HTML by Practice The best way to learn HTML is by writing and testing simple Read more

HTML text Editors

HTML Text Editors – Learn How to Write HTML Code To write HTML code, you need a text editor. A Read more

HTML Tags

HTML Tags are the basic units used to create HTML elements.They define how content is displayed in a web browser. Read more

HTML Elements

HTML Elements are the building blocks of every web page.Each element defines a part of the webpage, such as headings, Read more

HTML Attributes

HTML Attributes provide additional information about HTML elements.They help control how elements behave, display, or store extra data. In this Read more

HTML Headings

HTML Headings are used to define titles and subtitles on a web page.They help organize content and improve readability for Read more