Default Styles for CSS

Coding CSS can quickly run into difficulties with different browsers interpreting code in different ways. Designs will never look the same in every browser but you can help yourself by using a default style set when you start coding.

Comment your code

To start with it is important that you document your code. I like Andy Budd's approach of writing the version number and adding your email and website address before applying any rules. You can ease maintenance by noting changes, or at least saying where the log of amends is kept.

[client] Screen Stylesheet
version:   1.0
date:      01/03/07
author:    [your email]
email:     [you at domain dot com]
website:   [your domain]
version history: [location of file]

Decide how you want to divide your stylesheets

I find that most of the time I can get away with one stylesheet. Sometimes though a site will become large enough to warrant more than one stylesheet. Indeed some CSS authors prefer to split them up. It is a matter of personal choice. So next in my default stylesheet I have a section where any other stylesheets can be pulled in to the main one.

/* Import other stylesheets
@import url("typography.css");

Remove default styles

Tantek Celik wrote a stylesheet to remove default styles from elements. This might suit you so have a look. Personally I find that one universal rule is enough to rebase elements. I haven't experience any performance issues using this on many different projects.

/* Remove padding and margin */
    margin: 0;
padding: 0;
border: 0;

Why do this? Browsers apply different styles to different elements. So it makes sense for me to know where I am starting from. This simple rule allows me to know that all elements will start by having no margin, padding or border.

Have classes for floating and clearing

Next I have a class for clearing, again something I learnt from Andy Budd and his excellent book. Clearing floated elements is a common task so it is well worth it. Also you will probably want to float elements left and right so I like to have these too. I use these for images quite a lot.

    float: right;
    float: left;

Set the document up

I have found that a good framework for setting up a document is to set font size and colour on the body tag. I apply any background image here to act as wallpaper. I use Richard Rutter's approach to sizing text using ems which I really recommend for maximum control over typography.

Then I have a wrapper div to hold the content and set the width of the page. This also centres the content and applies a white background.

    font: 62.5%/1.5  "Lucida Grande", "Lucida Sans", Tahoma, Verdana, sans-serif;
background: url(/images/wallpaper.png) repeat;
color: #000000;    
background-color: #FFFFFF;

Handling typography

Then I like to set up the default font sizes. Using Richard Rutter's method we know the default size is 10pt so we can create accurate sizings.

    font-size: 2.2em;
    font-size: 2.0em;    
    font-size: 1.8em;
    font-size: 1.6em;    
    font-size: 1.4em;    
    font-size: 1.2em;    

Create sections

Large CSS documents are diffiuclt to manage. I like to divide mine up using sections of the page or even templates. Each project will vary but I like put some sections in by default and then change it if necessary:

/* Header
/* Navigation
/* Footer
/* Homepage
/* Your template


By default on forms I like to give text input boxes a little padding to move the text away from the edge of the box and give it a grey border.

/* Forms
    padding: 3px;
border: 1px solid #999999;    


Finally for tables I again use Andy Budd's default to know where I am in tables - I've found it works well.

/* Tables
      border-spacing: 0;
border-collapse: collapse;
      text-align: left;
font-weight: normal;

Default XHTML

My default XTHML is as follows. Normally I add in print stylesheets, icons and RSS feeds as the project progresses.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">
<html xmlns="" xml:lang="en" lang="en">
    <title>Page title here</title>
    <style type="text/css" media="screen">@import "/css/screen.css";</style>
    <meta name="DC.title" content="Title here" />
    <meta name="DC.subject" content="Keywords here" />
    <meta name="DC.description" content="Description here" />
    <meta name="DC.format" content="text/html" />
    <meta name="DC.publisher" content="Publisher here" />
    <meta name="DC.language" content="en" />
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
    <div id="wrapper">

A matter of personal choice

Of course I am not saying this is the best way to have a default template to begin coding templates. But it works for me. I'd be interested to hear what others do so please do leave a comment if there is anything you strongly agree or disagree with.

If you'd like to download a copy of my default files you can get them here.