Specifying colors with CSS

As we said in our intro to CSS lesson, one of the things you can use CSS for is specifying the color of text, borders and backgrounds.

Here are the CSS attributes that go with the different things you can give a color:

  • To set the text color, use the color attribute.
  • To set the background color of an element, use the background-color attribute.
  • To set the border color of an element, use the border-color attribute.

So here’s how that would look in CSS, combining all three to indicate that H1 elements with class uglyheading should be colored:

<h1 class="uglyheading">Ugly Heading</h1> 
<style>
h1.uglyheading { color:red;
 background-color:yellow;
 border-size:3px;
 border-style:solid;
 border-color:green;
 }
 </style>

Here’s how all of that would look in your browser:

Screen Shot 2014-01-20 at 13.26.05

But, we hear ya: enough with the ugly already!

3 Ways to define colors in CSS

CSS offers three different ways to specify colors. Luckily you can pretty much forget about 2 of them right away, because everybody overwhelmingly uses the third (and weirdest) one, and thus so should you.

  • Using a color name. This is what we used so far. Things like ‘red’,’blue’, but also ‘CornFlowerBlue’ and weird shit like that. HTML supports lots of them, all listed here if you’re curious.
  • Using rgb values, meaning red-green-blue, where you specify an amount of each of those color components as a number from 0 to 255. The syntax is as follows: rgb(0,0,0) would be black, rgb(255,255,255) white, rgb(255,0,0) red, rgb(100,100,100) a dark shade of grey, etc… You’ll get used to it, well you HAVE to get used to it, because everybody uses an even weirder form of specifying colors:
  • Using HEX values. Here you also specify the amounts of red, green and blue, but instead of counting from 0 to 255 with a simple number, we use a two-digit hexadecimal number for it. HEX colors always are specified with a # in front, like this: #FFFFFF is white, #000000 is black, #A1A1A1 is grey, #0000FF is blue etc…

And, yes, the one everybody uses to specify colors is the last, weird hexadecimal way.

HEX color codes in HTML

As said above, a HEX color code, which is what almost everybody uses in real-world web sites, consists of three times 2 digits. Each of the three groups counts how much red, green and blue there are in the color, counting from 00 to FF.

So here is white in hex: #FFFFFF. Here is black: #000000. Here is a very flashy, intense green: #00FF00. Here is a lighter green: #AAFFAA.  Funny how a low number makes it darker rather than lighter, right? You’ll get used to it.

Here’s how you would set a paragraph to have a salmon-ish background color with brown-ish text:

<p class="fancycoloredparagraph">This is my paragraph. Look how fancy the colors are!</p>
 <style>
 p.fancycoloredparagraph {
 background-color:#FFA07A;
 color:#8B4513;
 }
 </style>

And the outcome:

Screen Shot 2014-01-20 at 13.38.21

The good news is, you can forget about all this theory, and just google ‘html color codes’ to find one of a bazillion online tools that generate the color code you want. Or even better: keep scrolling down.

(quick tip: if you fancy stealing from others, like all great artists do, check out ColorPic, a free Windows tool that gives you the hex code of any color you see on your screen)

List of HTML colors

To get you started, here’s a table with all kinds of colors and their respective hex code for your copy-pasting pleasure!

Now if people call your site ugly – and they will, and they will be right – you no longer have a lack of color options to use as an excuse. We’re sorry.

Just so you don’t have to scroll all the way to the bottom: the next lesson we will see how to specify the position and size of our elements using CSS.

Pink colors
Pink #FFC0CB
LightPink #FFB6C1
HotPink #FF69B4
DeepPink #FF1493
PaleVioletRed #DB7093
MediumVioletRed #C71585
Red colors
LightSalmon #FFA07A
Salmon #FA8072
DarkSalmon #E9967A
LightCoral #F08080
IndianRed #CD5C5C
Crimson #DC143C
FireBrick #B22222
DarkRed #8B0000
Red #FF0000
Orange colors
OrangeRed #FF4500
Tomato #FF6347
Coral #FF7F50
DarkOrange #FF8C00
Orange #FFA500
Gold #FFD700
Yellow colors
Yellow #FFFF00
LightYellow #FFFFE0
LemonChiffon #FFFACD
LightGoldenrodYellow #FAFAD2
PapayaWhip #FFEFD5
Moccasin #FFE4B5
PeachPuff #FFDAB9
PaleGoldenrod #EEE8AA
Khaki #F0E68C
DarkKhaki #BDB76B
Brown colors
Cornsilk #FFF8DC
BlanchedAlmond #FFEBCD
Bisque #FFE4C4
NavajoWhite #FFDEAD
Wheat #F5DEB3
BurlyWood #DEB887
Tan #D2B48C
RosyBrown #BC8F8F
SandyBrown #F4A460
Goldenrod #DAA520
DarkGoldenrod #B8860B
Peru #CD853F
Chocolate #D2691E
SaddleBrown #8B4513
Sienna #A0522D
Brown #A52A2A
Maroon #800000
Green colors
DarkOliveGreen #556B2F
Olive #808000
OliveDrab #6B8E23
YellowGreen #9ACD32
LimeGreen #32CD32
Lime #00FF00
LawnGreen #7CFC00
Chartreuse #7FFF00
GreenYellow #ADFF2F
SpringGreen #00FF7F
MediumSpringGreen #00FA9A
LightGreen #90EE90
PaleGreen #98FB98
DarkSeaGreen #8FBC8F
MediumSeaGreen #3CB371
SeaGreen #2E8B57
ForestGreen #228B22
Green #008000
DarkGreen #006400
Cyan colors
MediumAquamarine #66CDAA
Aqua #00FFFF
Cyan #00FFFF
LightCyan #E0FFFF
PaleTurquoise #AFEEEE
Aquamarine #7FFFD4
Turquoise #40E0D0
MediumTurquoise #48D1CC
DarkTurquoise #00CED1
LightSeaGreen #20B2AA
CadetBlue #5F9EA0
DarkCyan #008B8B
Teal #008080
Blue colors
LightSteelBlue #B0C4DE
PowderBlue #B0E0E6
LightBlue #ADD8E6
SkyBlue #87CEEB
LightSkyBlue #87CEFA
DeepSkyBlue #00BFFF
DodgerBlue #1E90FF
CornflowerBlue #6495ED
SteelBlue #4682B4
RoyalBlue #4169E1
Blue #0000FF
MediumBlue #0000CD
DarkBlue #00008B
Navy #000080
MidnightBlue #191970
Purple colors
Lavender #E6E6FA
Thistle #D8BFD8
Plum #DDA0DD
Violet #EE82EE
Orchid #DA70D6
Fuchsia #FF00FF
Magenta #FF00FF
MediumOrchid #BA55D3
MediumPurple #9370DB
BlueViolet #8A2BE2
DarkViolet #9400D3
DarkOrchid #9932CC
DarkMagenta #8B008B
Purple #800080
Indigo #4B0082
DarkSlateBlue #483D8B
SlateBlue #6A5ACD
MediumSlateBlue #7B68EE
White colors
White #FFFFFF
Snow #FFFAFA
Honeydew #F0FFF0
MintCream #F5FFFA
Azure #F0FFFF
AliceBlue #F0F8FF
GhostWhite #F8F8FF
WhiteSmoke #F5F5F5
Seashell #FFF5EE
Beige #F5F5DC
OldLace #FDF5E6
FloralWhite #FFFAF0
Ivory #FFFFF0
AntiqueWhite #FAEBD7
Linen #FAF0E6
LavenderBlush #FFF0F5
MistyRose #FFE4E1
Grey/Black colors
Gainsboro #DCDCDC
LightGray #D3D3D3
Silver #C0C0C0
DarkGray #A9A9A9
Gray #808080
DimGray #696969
LightSlateGray #778899
SlateGray #708090
DarkSlateGray #2F4F4F
Black #000000

Oh wow, you did scroll all the way to the bottom? Get a life, seriously. But, there’s the link you came looking for: how to specify the position and size of our elements using CSS.

Advertisements

2 comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s