
This is the first part in a three part series. Today we will be covering the Background attribute. The second article will cover the border attribute, and finally the third article will cover the font attribute, so be sure to subscribe to catch the other two articles.
A little bit of “Background” (* Pun Intended *)
The Background attribute is probably the most frequently used attribute in CSS. In this article we will cover the different properties that go with the background attribute, and how to use them correctly. We will also have a showcase at the end of the article of sites that have used the attribute to it’s fullest potential.
Overview
There are 5 properties available in CSS2 relating to the background attribute.
- background-color : Set’s a solid background color to the given element
- background-image : Specifies an image to set as the background of an element
- background-position : Set’s the position of the image that was set
- background-repeat : Determines whether the image is tiled or not
- background-attachment : Specifies whether an image scrolls with the page or is in a fixed position
Usage of basic properties
Background Color
The background-color property sets a solid color for an entire element. Here are some of the different values you can use to define the desired color.
background-color: #2bb7da; background-color: red; background-color: rgb(145, 100, 140); background-color: transparent;

Background Image
The background-image property specifies an image on the server or locally to place as the background of the specific element.
background-image: url(path to image); background-image: url(logo.png);

There is a huge advantage of using the background property to call in your images because it makes it harder for the “Average Joe” to take the pictures from your site. For example if you place an image in an IMG tag in your html I can right-click it and save it, if you put it in your CSS using a div and the background image property then it would be much harder for me to get to that image. So in other words it adds extra security to your images.
Background Position
The background-position property specifies where your background image should be placed in your elements background.
background-position: 50px -10px; /* Moves image to the right 50px and up 10px */ background-position: 0% 50%; background-position: center center; background-position: 0% 70%;

Background Repeat
The background-repeat property specifies whether or not your background image tiles and if so how to tile. This property should only be used in conjunction with the background-image property or it will have no effect.
background-repeat: repeat; /* Default value for bg images */ background-repeat: repeat-y; /* Tiles image vertically */ background-repeat: repeat-x; /* Tiles image horizontally */ background-repeat: no-repeat; /* Stops tiling */

Background Attachment
The background-attachment property is not one that you see often in CSS code. It defines whether the a background image scrolls with the page or stays in a fixed position when scrolling.
background-image: url(logo.png); background-repeat: no-repeat; background-attachment: fixed;
Background Attribute Shorthand
Shorthand it!
Instead of declaring each one of these properties seperately we can save a lot of time by using the shorthand for the background attribute.
background: color image position attachment repeat; background: #fff url(logo.png) 50px -10px scroll no-repeat;
Beautiful Uses of the Background Attribute
Here are a few sites that have really nailed the use of background images in there web design.
Web Designer Wall

Nick La creator of Web Designer Wall does an amazing job on his blog with background images. He uses multiple background images to create an astonishing effect.
Web Designer Depot

Web Designer Depot also does an amazing job of using elaborate background images to enhance the user experience.
PSD Vibe

PSD Vibe uses subtle background images that blend in with the solid background color of the site.
Thats All
As web designers and developers we must learn to use the background attribute and all it’s properties to the fullest. If you enjoyed this post please bump, re-tweet, moo, etc…


October 26th, 2009 at 2:35 pm
Interesting post, Shane. Thanks. I would love it in the font attribute post if you could cover using custom fonts (either through @font-face (css) or through image replacement). I am really tired of being stuck with arial, verdana, tahoma, or georgia
October 28th, 2009 at 3:05 am
Great post, very conclusive – do you think you can do a post on the 4 CSS position properties?
Thanks in advanced
postin’ from LA
October 28th, 2009 at 10:46 pm
@Matt – Thanks for the complements. I will cover @font-face in the font attribute post!
@Abraham – The position attribute is a little more in-depth than the others so it make take a little more time, but I do hope to do a post about those too. So be sure to subscribe so you catch it!
October 29th, 2009 at 10:03 pm
Thanks for this!
I am new to web design and am working on a website at the moment.
I keep having the same problem- its driving me nuts!
After I slice and import to DW, I try to add text to the page. But in doing so, the slices go all wonky and everything gets out of place. Also, my content overflows the layout…
Any ideas?
Thanks in advance
-Vik
October 30th, 2009 at 12:08 am
@vik the problem with splicing and exporting from Photoshop is that it builds your layout using tables. I reccomend that you take it upon yourself to learn how to create layouts using CSS. I will hopefully be doing a tutorial on how to take a Photoshop layout and convert it to XHTML/CSS.
November 16th, 2009 at 4:43 pm
[...] be on the Font Attribute so stay tuned and subscribe. Part one of this CSS series is linked below. In-Depth Look at CSS’s Background AttributeSome background on the Border AttributeBorders used to be those ugly gray things that surrounded [...]
November 20th, 2009 at 1:03 am
[...] @threestyles An In-Depth Look into CSS’s Background Attribute An In-Depth Look into CSS’s Background Attribute [...]