Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk3 min

What Are HTML Color Codes? Definition, Examples, and CSS Formats

“HTML color codes” is an informal term for web colors now specified with CSS. Learn how named colors, hex, RGB, HSL, and other formats work.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

“HTML color codes” is a familiar informal name for web color values—especially names such as black and hexadecimal values such as #000000. Today, these colors are specified with CSS, so CSS colors or web colors is more accurate terminology. As MDN Web Docs puts it, “It is no longer accurate to refer to colors on the web as "HTML color codes" or "HTML color names".”

What does an HTML color code mean?

In everyday use, an “HTML color code” usually means a value that tells a browser what color to display on a web page. The phrase comes from older ways of describing web colors, but current pages use CSS color values and CSS properties to set text, backgrounds, borders, and other colors.

A CSS declaration might look like this:

p {
  color: #663399;
  background-color: white;
}

Here, color and background-color are CSS properties. Their values can be written in different color notations; the notation alone does not change the color.

What are the main CSS color formats?

Format Example What it expresses Useful when
Named color rebeccapurple A standard color keyword Readability matters and a built-in keyword matches the intended shade.
Hexadecimal #663399 Red, green, and blue channel values, written with hexadecimal digits You need to copy or specify an exact channel value from a design.
RGB rgb(102 51 153) Red, green, and blue components You want to write channel values in a function form.
HSL hsl(270 50% 40%) Hue, saturation, and lightness You want to reason about or adjust those dimensions.
HWB hwb(270 20% 40%) Hue, whiteness, and blackness You prefer to express color in terms of hue, whiteness, and blackness.
Other color functions oklch(), lab(), lch(), color() Values in other color spaces You need a color-space representation beyond the familiar RGB-based forms.

The examples illustrate syntax; they are not a claim that one notation is inherently more accurate or better. CSS supports multiple color functions and spaces, and one color can have equivalent representations in several notations.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

How do hexadecimal color codes work?

A six-digit hex value has the form #rrggbb: the pairs represent red, green, and blue components. For example, #ff0000 is red. CSS also accepts shorthand forms when each pair uses matching digits: #f00 is equivalent to #ff0000. Hexadecimal letters can be uppercase or lowercase.

CSS also supports four- and eight-digit hex forms that include alpha, the component used for transparency. In an eight-digit value such as #rrggbbaa, the final pair represents alpha. Use an alpha-bearing value only when transparency is intended; ordinary six-digit values are fully opaque. See MDN’s hex color reference for the syntax.

How do the formats differ in practice?

  • Named colors: Easy to read, but limited to the standard keywords. MDN Web Docs lists over 160 named colors; its reference does not state a publication year. The names include values such as red, lightseagreen, and rebeccapurple.
  • Hex and RGB: Both express red, green, and blue components, making them useful when you have exact channel values to copy. Hex is compact; RGB makes the channel structure explicit.
  • HSL: Separates hue, saturation, and lightness, which can make it more intuitive to adjust those qualities than to change red, green, and blue channels individually.
  • HWB: Describes hue alongside whiteness and blackness.
  • Alpha: Supported in hex and functional color notation when you need transparency. It is a separate concern from choosing between RGB and HSL-style descriptions.

These formats are different ways of expressing color, not necessarily different colors. MDN’s CSS color guide includes a converter that shows equivalent RGB, HEX, HSL, and HWB values for a selected color.

How do you change a color in HTML or CSS?

Put the color value in a CSS declaration, then apply that rule to the relevant element. For example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<style>
  h1 {
    color: rebeccapurple;
  }

  .notice {
    background-color: #f0e6ff;
  }
</style>

<h1>Page heading</h1>
<p class="notice">A highlighted notice.</p>

The HTML supplies the heading and paragraph; the CSS supplies their color styling. The historical HTML 4.01 reference described color values using hexadecimal numbers or one of sixteen names, and marked HTML color attributes as deprecated. For modern pages, use CSS properties such as color and background-color rather than old presentational HTML attributes.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Which color notation should you choose?

  • Choose a named color for a quick, readable value when its standard shade is the one you want.
  • Choose hex or RGB when a design specification gives exact channel values or you need to copy a color value precisely.
  • Choose HSL when adjusting hue, saturation, or lightness is the clearest way to express the change.
  • Include alpha only when the color should be transparent or translucent.

If you have a color in one format and need another, use the converter in MDN’s CSS color guide to inspect equivalent values.

Best Value
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.