💻
HTML/CSS
  • Overview
  • How the Web Works
    • DNS, TCP/IP, HTTP, HTML
    • Anatomy of a Web Page
    • How a Web Page Gets Loaded
  • HTML/CSS intro
    • HTML
      • Boilerplate HTML
      • HTML Hierarchy
      • Meta Section
      • Text-formatting Elements
      • Image
      • Video
      • Anchor
      • Tables
      • Semantic Elements
    • CSS
      • Properties
      • Selectors
      • Box-Model
      • Block vs Inline
      • The Cascade
    • Layout
      • Container Elements
      • Grid vs Flexbox
      • Flexbox
      • Grid
  • Miscellaneous Topics
    • Background Image
    • Border-radius
    • Box-shadow
    • Centering Elements
    • Colors
    • Custom Properties
    • Forms
    • Typography
    • Units
  • Appendix
    • Google Fonts
    • Lorem Ipsum
    • HTML Cheatsheet
    • CSS Cheatsheet
    • Browser Support for HTML/CSS
    • unsplash.com (free images)
    • pexels.com (free images)
    • Chrome Default Stylesheet
  • Further Learning Resources
    • FE Mentor Challenges
    • Free Scrimba Courses
    • Kevin Powell Youtube
Powered by GitBook
On this page
  • Named Colors
  • Hex Codes
  • RGB Values
  • HSL
  • Resources

Was this helpful?

  1. Miscellaneous Topics

Colors

PreviousCentering ElementsNextCustom Properties

Last updated 3 years ago

Was this helpful?

Computer monitors are made up of thousands of tiny squares called pixels. Each pixel can be a different color. The color of each pixel is a mixture of the amounts of red, green and blue.

We're going to cover the three most common ways to specify colors in CSS:

  • named colors

  • hex codes

  • RGB values

Named Colors

p {
    color: red;
}

Using named colors is the easiest format for adding color in CSS, but is primarily used for prototypes, since they only represent a small fraction of the available colors.

There are currently 140 color names supported by modern browsers. Red, blue gold, and maroon are just a few examples. You can find the full list below.

Hex Codes

p {
    color: #644B92;
}

Hex color codes are specified by a hashtag followed by three pairs of characters that represent the intensity of the three primary colors (red, green, and blue). Possible values range from 0 to 255, but are expressed in hexadecimal. 00 (the lowest intensity) to FF (the highest intensity).

  • White: #FFFFFF (highest intensity for all)

  • Black: #000000 (lowest intensity for all)

  • Red: #FF0000

  • Green: #00FF00

  • Blue: #0000FF

Transparency can be specified by adding two additional digits. Values range from 00 (completely transparent) to 99 (completely opaque).

.p1 {
  background-color: #FF0000;
}
.p2 {
  background-color: #FF000050;
}

Since there are so many possibilities, web developers use color picker tools to find the hex values for colors.

p {
    rgb(116, 96, 152);
}

RGB Values

RBG color codes are similar to hex, except represented by decimal values between 0 and 255 for the intensity of the red, green and blue colors.

  • White: rgb(255, 255, 255) (highest intensity for all)

  • Black: rgb(0, 0, 0) (lowest intensity for all)

  • Red: rgb(255, 0, 0)

  • Green: rgb(0, 255, 0)

  • Blue: rgb(0, 0, 255)

Transparency : add a fourth value to indicate the transparency. Values range from 0 (completely transparent) to 1 (completely opaque).

.p1 {
    background-color: rgb(255, 0, 0);
}

.p2 {
    background-color: rgb(255, 0, 0, .5);
}

HSL

Resources

The following page has a very good overview of the different options and formats for specifying colors.

Color Names — HTML Color CodesHTML Color Codes
Color Picker — HTML Color CodesHTML Color Codes
Defining Colors in CSS
Defining Colors in CSS
Logo
Logo