CSS Colors

Description

When using CSS you can specify colors in a range of different ways.

We can use the predefined color names. Or we can use a decimal or hexadecimal value for each of the red, green, and blue components.

Decimal values are separated by a comma, and hex values are usually prefixed with #-such as #ffffff, which represents white.

Example

The following table has some of the predefined names for colors and their decimal and hex equivalents.

Color NameHexDecimal
black#0000000,0,0
green#0080000,128,0
silver#C0C0C0192,192,192
lime#00FF000,255,0
gray#808080128,128,128
olive#808000128,128,0
white#FFFFFF255,255,255
yellow#FFFF00255,255,0
maroon#800000128,0,0
navy#0000800,0,128
red#FF0000255,0,0
blue#0000FF0,0,255
purple#800080128,0,128
teal#0080800,128,128
aqua#00FFFF0,255,255

These are known as the basic color names.

The following table shows the extended set of gray shades that can be used.

Color NameHexDecimal
darkgray#a9a9a9169,169,169
darkslategray#2f4f4f47,79,79
dimgray#696969105,105,105
gray#808080128,128,128
lightgray#d3d3d3211,211,211
lightslategray#778899119,136,153
slategray#708090112,128,144

RGB value short form

Use hexadecimal value for each of the red, green, and blue components. Each pair is in hexadecimal notation in the range 00 - FF.

hex values are usually prefixed with #, such as #ffffff, which represents white. A "pure" blue would be written #0000FF, "pure" red is written #FF0000.

#RGB is a shorter form of the six-digit notation described above. In this format, each digit is replicated to get an equivalent six-digit value, for example #F7C becomes #FF77CC.


<!DOCTYPE HTML>
<html>
    <head>
        <style>
body {<!--  ww w . j  ava  2 s.c  o  m-->
    background-color: yellow;
}

div#one {
    width: 50px;
    height: 50px;
    border: 1px solid rgb(128, 128, 128);
    margin: 5px;
    float: left;
    background-color: #000;
}
        </style>
    </head>
    <body>
        <div id='one'></div>
    </body>
</html>

Click to view the demo





















Home »
  HTML CSS »
    CSS »




CSS Introduction
CSS Background
CSS Border
CSS Box Layout
CSS Text
CSS Font
CSS Form
CSS List
CSS Selectors
CSS Others
CSS Table