A CSS Starter File

Posted August 4th, 2006 by Mike Cherim

If you’re into web standards as I am, you will of course use Cascading Style Sheets or CSS for presentational purposes; you won’t use mark-up to control this aspect of your web pages. If you’re into web standards, you’ll also use proper elements, just like me. I use heading elements for headings, the paragraph element for paragraphs, etc. And you do, too, right? See how much we have in common?

There are only so many elements and we all put them to use in pretty much the same ways. Our differences come not from the use of these elements, but how we style them, position them, and what images we add as embellishments. And our work sequence may also vary as Tommy Olsson’s recent Accessites article, Visual Vs. Structural makes clear. With all this in common, and after we strip away a few unique classes and IDs, my style sheet and your style sheet are basically one and the same.

In light of this, I decided to create a common-use CSS that anyone and everyone can copy and put to use. A CSS foundation if you will. It may save a little work on your next project. So, without further ado, here it is, complete with some hopefully helpful comments (it is also available without comments below or you can download it as text):


First the main stuff

/*
  The star selector is used to target every element.  This is
  often used to zero out the margin and padding.  This
  creates some common ground from which to begin.
*/
* {
}

/*
  body is used to provide basic page styles meant to be inherited
  by nearly all of the page’s children: font-face, size, alignment,
  etc. Some use the html selector, but I have never done that so
  it’s not listed.
*/
body {
}  

/*
  The wrapper div can be used to contain the page itself. It can
  also redefine some characteristics inherited from the body. It
  is high on this page as it’ll contain everything else used.
*/
#wrapper {
}

Now to offer some very common elements
/*
  Here are the headings. These may be redefined throughout the
  document as needed, if needed. This is especially true of the h1
  element as it may have special usage as the main page heading,
  and maybe as a link.
*/
h1, h2, h3, h4, h5, h6 {
}

/*
  A page without paragraphs would be pretty unusual. Let’s make
  sure the p element is included. This, too, may be redefined
  throughout the document  as needed, if needed.
*/
p {
}

/*
  Most pages will have links. Let’s style them using a anchor
  element. Some will write this as a:link. I don’t — I don’t
  see the need
*/
a {
}

/*
  Links really should have some interactivity characteristics for
  accessibility and usability reasons. The a:hover pseudo-class is
  offered as is a:focus. Internet Explorer (IE) doesn’t support
  a:focus, but it does use the a:active state so it’s here too.
*/
a:hover, a:focus, a:active {
}

/*
  Focus/active should be different than hover is some regards, such
  as providing a background color to make it highly visible to
  keyboard users. Thus, certain focal styles may be redefined.
*/

a:focus, a:active {
}

/*
  In addition to background images, most web pages will offer
  embedded images (img), so I will offer them here. Mostly this
  is used to remove borders and text-decoration
  (if the image is a link).
*/
img, a img {
}

Less Common Elements

/*
  I’m not going to add the table element as its purpose is quite
  specific and not used very often by the typical CSS developer
  (unless they are offering tabular data). This is also the case
  for dfn (definition), code, pre (preserve [whitespace]),
  kbd (keyboard), ins (insert),  del (delete),
  i (italic [presentational]), and b (bold [presentational]).
  But you will likely want to use those I am offering — though
  you may not style them all.
*/

small {
}

abbr, acronym { /* Also see .abbr class for a span used by IE */
}

blockquote {
}

cite {
}

em {
}

strong {
}

Form Elements

/*
  Offering some form styles, since most sites have a form or two,
  are really quite common. And offering focal styles is quite
  useful to accessibility for those using keyboards. But please
  know that neither the :focus or :active pseudo classes (on
  elements other than anchors) are available to IE user so
  JavaScript will be needed to make it work. Since not everyone
  has JavaScript enabled, it is important that the form’s
  contrast is usable without script support.
  Since submit- and reset-type inputs are affected by
  the text-type input styles, you may want to offer an
  input.button class. The same applies to checkboxes and radio
  buttons.
*/

form {
}

fieldset {
}

legend {
}

label {
}

input {
}

select {
}

option {
}

textarea {
}

input:focus, select:focus, option:focus, textarea:focus {
}

Some typical IDs

/*
  Call them what you like, but these are some really common IDs
  you may use yourself. I try to make the names as informative as
  possible so as to not confuse myself down the road. Using common
  names like this offers insight to any editor later on. Note that
  the “wrapper” ID is covered above as it needs
  to be high up in the cascade.
*/

#header { /* may also be masthead, banner, etc., and may include
                                     the h1 element */
}

#content {
}

#sidebar {
}

#navigation {
}

#footer {
}

Some typical Classes

/*
  Just like the IDs above, I use these on nearly every site I make.
  These should be pretty self-explanatory with exception to offset
  which I’ve filled in. It’s used in lieu of display : none;
  (.hidden class) so as to remove items from view while still
  making them available to other users. If anchors,  you can use
  a:focus/a:active to bring them back in view. Useful for hidden 

  skip/jump links, etc.
*/

.bold {
}

.italic {
}

.hidden {
}

.offset { /* would be position : abosolute; top : -9000px;
                                 left : -9000px; */
}

.highlight { /* useful for adding spot colors */
}

.tiny { /* use small element to make small, but for styled-only
                               small text, this is class. */
}

.error {
}

.abbr { /* use with a span to style abbr for IE as abbr isn’t
                                supported */
}

Here it is again, without comments


/* Starter CSS by Mike Cherim - http://green-beast.com */

* {
}

body {
}  

#wrapper {
}

h1, h2, h3, h4, h5, h6 {
}

p {
}

a {
}

a:hover, a:focus, a:active {
}

a:focus, a:active {
}

img, a img {
}

small {
}

abbr, acronym {
}

blockquote {
}

cite {
}

em {
}

strong {
}

form {
}

fieldset {
}

legend {
}

label {
}

input {
}

select {
}

option {
}

textarea {
}

input:focus, select:focus, option:focus, textarea:focus {
}

#header {
}

#content {
}

#sidebar {
}

#navigation {
}

#footer {
}

.bold {
}

.italic {
}

.hidden {
}

.offset {
}

.highlight {
}

.tiny {
}

.error {
}

.abbr {
}

Summary

This is a starter style sheet. You will likely want to move some stuff around and make associations I haven’t provided. Moreover, you will also want to add some more special classes and IDs. It all depends upon your needs. But do know this: Using what I have provided herein is sufficient to create thousands if not millions of web page/web site style permutations. Maybe I just saved you a half hour. Though you’re certainly under no obligation to do so, if you do use this, it’d be cool of you to add a link to me on your blog roll or whatever.

<a href="http://green-beast.com/">Mike Cherim</a>


18 Responses to: “A CSS Starter File”

  1. Martin Neczypor responds:
    Posted: August 4th, 2006 at 11:58 pm

    Great idea Mike- one question though, what is the difference between line 19 and line 22, where a:focus and a:active are defined again?

  2. Joshua Kendall responds:
    Posted: August 5th, 2006 at 5:49 pm

    “[…] my style sheet and your style sheet are basically one and the same.” – Mike Cherim

    I beg to differ. Your sheet is organized. My organization breaks down after day one (who am I kidding, after the first hour).

    Good article though.

  3. Joshua Kendall responds:
    Posted: August 5th, 2006 at 5:50 pm

    Odd, the ‘cite’ tag did not work.

  4. Dave Z. responds:
    Posted: August 5th, 2006 at 6:48 pm

    I don’t know how you find the time to keep doing all you do, Mike, and then find time to write great articles for the rest of us in your blog. Thanks for sharing!

  5. Joshua Kendall responds:
    Posted: August 5th, 2006 at 9:21 pm

    Mike, I meant that when I tried to quote what you said in the article in my comment, it did not work. I should of used a blockquote, it would of worked.

  6. Martin Neczypor responds:
    Posted: August 6th, 2006 at 6:38 am

    Oh! That makes total sense. I usually find myself redefining information for things such as anchors over and over again. This will definitely simplify that.

  7. Joe Dolson responds:
    Posted: August 6th, 2006 at 11:21 am

    Nice, Mike…this is one of those things I’ve always meant to do…and now you’ve saved me the trouble!

  8. veeliam responds:
    Posted: August 11th, 2006 at 11:01 am

    I’m really curious what you think of starting your template with something like undohtml.css that Tantek wrote about instead of the asterisk.

    I try to use a variation of it on most of my projects.

  9. Dennis responds:
    Posted: August 14th, 2006 at 8:36 pm

    I also suggest the following CSS for your base:


    img {
    border:0;
    }
    acronym, abbr {
    border-bottom: #000 1px dashed;
    cursor: help;
    }

  10. The man who forgot his own ideas responds:
    Posted: August 15th, 2006 at 11:36 pm

    I love the source. Do you get sausages with that? ;)

  11. Rick Dean responds:
    Posted: August 15th, 2006 at 11:39 pm

    or should I say fries?
    Cheers Great site!

  12. Keith Krieger at lab 188 responds:
    Posted: September 6th, 2006 at 5:20 pm

    […] lab188 Tuesday, August 15, 2006
    CSS file frameworks

    Nice approach to starting a CSS file from Mike Cherim’s blog. This approach will help me to stay consistent for starters. This […]

Sorry. Comments are closed.




Note: This is the end of the usable page. The image(s) below are preloaded for performance only.