Quick CSS tip: Declare your body background!

Nov 23 2005

I keep seeing this on sites that I visit, and this evening the latest culprit (Shopify, via Particletree) has prompted me to write about it.

ATTENTION, CSS DEVELOPERS! ALWAYS DECLARE A COLOUR FOR YOUR DOCUMENT’S BACKGROUND!!

In case you missed that, let me say it again. Always declare a colour on the <body> element in your stylesheet – because, if you don’t, then someone with a non-default background setting might see something a bit like this:

Screenshot of Shopify site with orange background

Yup, I have an orange background as my default. Why? So I don’t make the same stupid mistake…

body { background: #fff; }

That’s not too much to ask, is it?

Filed under: CSS.

Technorati tags:

Digg this article

Bookmark this article with del.icio.us

Previously: Random song lyrics: Update

Next: The iPod of self-consciousness


Comments

Justin Palmer
1009 days ago
Whoops, thanks for the slap in the face. But yellow? Surely pink would be more appropriate. ;-)
#1
Matthew Pennell
1009 days ago
Har de har. You’ve got the same issue on your main site as well, by the way.
#2
Tobi
1008 days ago
I’m not so sure about this. If you change your default background color you probably have a good reason to (say a color disability). Why then should pages dictate the background color if they don’t have to?
#3
Matthew Pennell
1008 days ago
While it is true that there may be users who have changed their background colour to counteract a disability (although given that nobody ever leaves out the ‘color’ declaration in their CSS, a user’s preferences are never going to be fully respected unless they’ve used a user-defined stylesheet), your page background can also be affected by stuff like Windows Themes; I’ve often seen people with off-white pages because they’ve changed their theme without realising.
#4
Christian Montoya
1006 days ago
So very true, there really is no reason not to declare a body background.
#5
jordan
1006 days ago
I hate hate hate it when people don’t specify a background colour. I, too, use a different coloured background just to catch this, but I found that the orange grates on my eyes after a while. Just a few days ago I switched it to #3399bb instead, which is more of an aquamarine. Note that the colour can’t be written out in shorthand for some reason.

I can’t understand why people forget or ignore setting a background colour on their page. It’s not like it takes that much effort; it’s one line.

By the way, in Firefox there’s a checkbox to make a user’s custom styles always override a site’s CSS, so that argument doesn’t count for anything.
#6
WD Milner
1006 days ago
I have been on this campaign for months from the day I changed the default browser background to grey during some local testing anf forgot to change it back. Since then I have left it and it is just amazing to see the number of sites that have not set a default backgound colour but relied on people having the browser default to white. It isn’t little sites either, large corporate sites and ever a few web designers. I usually drop a note to the webmaster. I haven’t seen any change on the corporates yet but the web designers usually fix it pretty quick :-)
#7