Progressive Enhancement with CSS
Issue № 270

Progressive Enhancement with CSS

In the previous article in this series, we covered the basic concept of progressive enhancement; now, we can begin discussing how to use it. There are many ways to integrate progressive enhancement into your work using Cascading Style Sheets (CSS), and this article will cover a few of the biggies and get you thinking about other ways to progressively enhance your sites.

Article Continues Below

Style sheet organization#section2

A lot of web designers and developers don’t think much about how they incorporate stylesheets into their documents, but there is a real art to it. With the right methods, you can immediately gain many of the benefits of progressive enhancement.

Use multiple style sheets#section3

There are many benefits to getting a little separation in your styles. Obviously, stylesheets that are 1500+ lines long are a bit hard to maintain and separating them into multiple stylesheets can improve your workflow (and your sanity). Another benefit not often considered is that this separation can help you obtain greater consistency of presentation across the media types you are targeting.

Consider taking your main.css file, which contains all of the style rules for your site, and breaking it up into individual stylesheets containing typographic, layout, and color information. Name the files accordingly: type.css, layout.css, color.css.

A graphic depicting the breakup of a single stylesheet into multiple, contextual stylesheets.

How a single stylesheet is divided into multiple, contextual stylesheets.

Once you’ve done that, you can use a little wizardry to automatically provide a “low-fi” experience to older browsers (such as Internet Explorer 5/Mac) and many other browsers lacking solid support for CSS layouts. How? Well, it’s all in how you link to the files. Let’s assume we started with a main.css file included via a link element:

<link rel="stylesheet" type="text/css" href="main.css" />

First, we’ll break it into separate calls to our three contextual stylesheets:

<link rel="stylesheet" type="text/css" href="type.css" />
<link rel="stylesheet" type="text/css" href="layout.css" />
<link rel="stylesheet" type="text/css" href="color.css" />

In the past, many of us used a media value of “screen,projection” to put the kibosh on Netscape 4.x getting the layout styles, but there’s a better way. Before we look at that solution though, let’s think about alternate media types.

Working with alternate media types#section4

Since content delivery is the main focus of progressive enhancement and we want to deliver an “enhanced” experience to any device that will support it, we should really begin to think beyond the browser; most importantly, we should be thinking about print and mobile.

Unfortunately, the mobile market is still fragmented and immature (don’t get me started on all the handheld browsers that think they should render styles targeted at the “screen” media type). Consequently, a discussion of the ins and outs of handling that medium in a progressively-enhanced way would take several articles, if not a whole book. But don’t despair: things are beginning to gel a bit in the mobile world, and some very smart people are starting to put together resources to help you. But in the interest of time, and our collective sanity, we’ll focus on print.

Now, normally, we would add print styles with another link element:

<link rel="stylesheet" type="text/css" media="print" 
href="print.css" />

Traditionally, this stylesheet would contain all of our print-related rules, including typographic and color rules. In the case of typography in particular, the rules in our print stylesheet most likely mirror those in our main stylesheet. In other words, we have a lot of duplication.

This is where the separation of typographic and color styles from layout styles becomes a great asset: we no longer need those rules in our print stylesheet. On top of that, we can use another little organizational technique to improve the scalability of our site and hide certain layout styles from problematic browsers.

Let’s start by revisiting our stylesheets. Consider the following:

<link rel="stylesheet" type="text/css" href="type.css" />
<link rel="stylesheet" type="text/css" href="layout.css" />
<link rel="stylesheet" type="text/css" href="color.css" />

Now, since we don’t have a media type declared, Netscape 4.x will read any styles in these three files, but we can use its very basic understanding of CSS against it and provide further organization for our style rules by moving all of the styles that layout.css contained into a new stylesheet, appropriately named screen.css. Finally, we update the contents of layout.css to import screen.css and NS4.x and its ilk won’t be any the wiser (as they don’t understand the @import directive).

@import 'screen.css';

There’s still a bit of room for improvement though—we should really declare which media that this stylesheet is for, and we’ll do that by adding a media type to the @import declaration:

@import 'screen.css' screen;

The problem is that IE7 and below won’t understand this syntax and will ignore the stylesheet, but if you want to provide these styles to those browsers as well (which you probably will), you can do that quite easily using Conditional Comments, which we’ll cover below. Those of you with eagle eyes may also have noticed the use of single quotes (’) instead of a double quotes (”) around the stylesheet name. This is a nifty trick for getting IE5/Mac to ignore a stylesheet. And since IE5/Mac’s CSS layout is pretty sketchy (especially when it comes to floats and positioning), hiding layout rules is a perfectly acceptable way to treat it. After all, it will still get the color and typography information, which counts for something.

Using the same technique, we can import our print.css file (which contains, you guessed it, print-layout–specific rules).

@import 'screen.css' screen;
@import 'print.css' print;

Not only do we have nicely organized stylesheets now, we also have an effective means of progressively enhancing the design of our site.

<!-- missing illustration?

The interrelationship of multiple stylesheets and the method by which they are applied to the document.


Now for the $10M question: how do we deal with IE6?#section5

To many folks, Internet Explorer 6 is the new Netscape 4—everyone just wishes it would go away.

We’ll skip the litany of problems in IE6; its issues are well-documented and, honestly, not all that difficult to work around. Furthermore, the adoption of IE7 has been especially swift (particularly in the consumer market) and IE8 is already in beta, meaning that one day, we may actually be able to bid adieu to the aging 6.

Whether it was intentional or not, Microsoft delivered a great tool for enabling progressive enhancement when it shipped IE5: conditional comments. These ingenious little bits of logic (which degrade to HTML comments in all other browsers) allow us not only to direct certain bits of markup at IE, but also to direct them at particular versions of IE.

As web standards-aware developers, we should always start by testing our designs in the most standards-compliant browsers available, and then provide fixes for those browsers that just need a little nudge to get them on the right track. Everyone’s workflow is different, but I have found it best to start every project with a standard set of files. My base set includes the following:

  • type.css
  • layout.css
  • screen.css
  • print.css
  • color.css

Then, depending on the requirements of the project, I add browser-specific CSS files that contain the “nudges.” In most current projects those are ie7.css and ie6.css, though if the project calls for supporting an IE version earlier than 6, I will create a corresponding file for that one as well (ie5.5.css, etc.). With those files in place, I begin adding my style rules to the applicable stylesheet in my base set.

I start all of my CSS testing in Mozilla Firefox because I write the bulk of my CSS using its Edit CSS sidebar. As soon as I have wrapped a page design in Firefox, I fire up other browsers to take a peek. Most perform flawlessly, as they grok web standards. Then it’s on to IE7. In most cases, I don’t find many issues, but occasionally there’s a need to invoke hasLayout or fix another minor layout glitch. Instead of adding those fixes to my base set of stylesheets, I add them to ie7.css and then link that file in the HEAD of the document, inside a conditional comment:

<!--[if lte IE 7]>
<link rel="stylesheet" type="text/css" href="ie7.css" />

That conditional comment directs that particular stylesheet to any version of IE less than or equal to (lte) 7. So, if someone comes to this page in IE7, they will get the fixes I have applied within, but if they come in a newer version—which may have fixed those rendering issues as IE8 has done by abolishing hasLayout—the stylesheet will be ignored. On the flip side, if someone comes to this page with IE6, they will get the fixes from this stylesheet, which is perfect, as any rendering error present in IE7 is likely to be present in IE6 as well. One such fix would be to cover for IE’s inability (in versions 7 and below) to understand a media-typed @import (as mentioned above) by adding an @import for screen.css to the top of ie7.css without declaring a media type, thereby importing the styles that were missed the first time around.

Once I am done adding the fixes for IE7, I open IE6 and see if it needs a little hand-holding as well. If it does, I add another conditional comment to the document, linking out to ie6.css.

<!--[if lte IE 7]>
<link rel="stylesheet" type="text/css" href="ie7.css" />

<link rel="stylesheet" type="text/css" href="ie6.css" />

Then, I simply add the fixes required for IE6 to that stylesheet and they will be ignored by IE7, but will still trickle down to IE5.5.5, etc.

Using conditional comments in this way allows you to easily manage the browsers you need to target for your project and keep your CSS files hack free.

Other considerations#section6

Progressive enhancements in CSS aren’t limited to how we associate our stylesheets with our documents: we can also apply the concept to how we write our CSS.

Consider generated content, for instance. Not all browsers can handle it yet, but it is a great way to add in additional bits of design or text that are not necessary to the usability of the page, but that provide some visual or other enhancement.

For example, take this simple contact form:

A screenshot of the HTML form used in this example (code is provided below).

The HTML form used in this example (code is provided below).

When coding this, you may be tempted to put those colons (:) inside the label element. Why? Do they add anything to the labels? No. While they do serve a purpose, to provide additional visual cues to a user, they are superfluous to the label and should be left out (Line wraps marked » —Ed.):

<form id="contact-form" method="post">
    <legend>Contact Us
    <p>Send us a message. All fields are required.</p>
        <label for="contact-name">Name</label>
        <input type="text" id="contact-name" name="name" />
      </li>    <li>
        <label for="contact-email">Email</label>
        <input type="text" id="contact-email" name="email" />
    <li><label for="contact-message">Message</label>
        <textarea id="contact-message" name="message" rows="4" »
    <button type="submit">Send It</button>  </fieldset>

Generated content is a perfectly appropriate way to add them back into the document:

label:after {
  content: ":";

Approaching the form in this way gives us the flexibility to remove those decorations from our entire site by simply editing the CSS, rather than having to touch each and every form (and yes, I’ve been there). This technique also degrades nicely because the form is not rendered useless without the colons—a perfect example of progressive enhancement.

You may also find that writing rules with more advanced selectors helps you progressively enhance your site by targeting certain styles to more advanced browsers. One great example is the attribute selector, which is not understood (and is, therefore, ignored) by IE6 and others of its generation and earlier. Egor Kloos played with this concept beautifully in his submission to the CSS Zen Garden titled “Gemination.”

A comparison of Egor Kloos' CSS Zen Garden entry (“Gemination”) as viewed in standards aware browsers and IE6.

A comparison of Egor Kloos’ CSS Zen Garden entry (“Gemination”) as viewed in standards aware browsers and IE6.

How did he do it? Well, the following is a slightly modified sampling from his code:

/* <= IE 6 */
body {
  margin: 0;
  text-align: center;
  background: #600 none;
}/* IE 7, Mozilla, Safari, Opera */
body[id=css-zen-garden] {
  margin: 100px 0 0;
  padding: 0;
  text-align: center;
  background: transparent url(squidback.gif);

The differences are striking and illustrate beautifully how progressive enhancement can be implemented in your CSS.

In a similar vein, Andy Clarke had a little fun with IE6 on his site. By tapping into the filters available in IE and employing some conditional comments, he was able to strip all of the color from his website and provide some alternative imagery for a truly “low-fi” experience.

A comparison of Andy Clark's website in standards-aware browsers and IE6.

A comparison of Andy Clark’s website in standards-aware browsers and IE6.

The image-graying technique is accomplished by adding the following declaration block in a stylesheet directed at IE6 (and under) by using conditional comments:

/* =img for Internet Explorer < 6 */
img {
  filter: gray;

Though these two examples may include more tricks than you can get away with in your day-to-day work, they certainly serve as excellent proofs-of-concept for the ways in which you can practice progressive enhancement with CSS.

Putting it all together#section7

As we’ve discussed, there are numerous ways to begin implementing progressive enhancement on your site using CSS. The easiest, and perhaps best, way to begin is by organizing your stylesheets and making informed decisions about how those stylesheets will be connected to your document. Handling the idiosyncrasies of IE is a breeze once you understand the power of conditional comments, and you can accomplish more granular tweaking in the CSS itself if you’re discerning about the selectors you choose and the situations in which you use them.

Armed with this knowledge, you should be well on your way to becoming a progressive enhancement expert. Join me next time, when we discuss progressive enhancement with JavaScript.

70 Reader Comments

  1. Hi,

    At Concordia University in Montreal, we actually used to do this (separate the style sheets as you described). In the end, we found it very cumbersome especially with so many sites to work on at any given time.

    For example, when we have to style, say, a div. We’d have to edit color.css to change the color of the div, then open type.css to change the font, etc. Things got worse for us when we had to throw in unique homepage styles. Then say, for some reason we had text in a background graphic (not lately, but we used to), then some workers got confused where to find the style.

    What we do (now, until I can figure out a better way), is simply organize the stylesheet into sections with a table of contents at the top, e.g., head, body, sidebar sections. We share a common.css with all the websites (to save bandwidth as it would be stored in the browser’s cache), and each has a custom.css to modify any styles. IE5,6, and 7 stylesheets are added on top of that, then finally, print.css.

    Just my two cents of course.


  2. We also have options on our pages at the university to change the layout (including font-size). It got really cumbersome to separate those into type, color, etc.

  3. I’m not really in favour of adding multiple style sheets for the simple reason that it becomes very difficult to track them down when you are editing the page. I have found that I spend more time trying to work out what styles are doing and where they located.

    I agree with Rommil, I prefer to have a table of contents at the top of the page and break up the style sheet into sections.

    To date I have not found the perfect solution for laying out my styles but thats a work in progress. It is also only very recently that I have started to add browser specific styles as previously it was all about getting it looking the same in all browsers, after all thats what the client wants.

  4. As others have mentioned before, separating css files like this is hell. You’re not splitting up 1500 lines of css across 3 files, you’re creating 3 files with 1500 lines of code each. This is hell to maintain.

    As for the ‘:’, they can have a function, depending on the context they are used in. It might be good to leave them out of a form, but for a caption/detail structure they are definitely needed when both caption and detail are separated by spans.

    Not a big fan of this article, which is pretty basic, lacks focus and preaches the wrong things.

  5. Just another great inspirational piece. Again, I have learned some new tools to do what I want to do in a better way.

    Some of the ideas in this article I was using already, but this is well thought out solution. I will once again sharpen my skills using A List Apart.

    Thanks Aaron!

  6. I agree with Aaron and actually implemented something similar on “a project”: “I worked on”: “a few years ago”:

    It certainly can become cumbersome, but I think if you’re strict about breaking up the declarations into different files based on the properties as Aaron mentions, then it’s a logical deduction that if you’re changing font, colour, or other properties, there is an appropriate file for those declarations and so all you have to look for is the id or class handle that calls it.

    If elements have clearly identifiable classes and ids, tracking them down is very easy. This system also forces you to think about how to make the CSS robust and reusable, which introduces its own efficiencies.

  7. I think it’s naïve to think that the media type only requires different layout styles (as shown in your stylesheet diagram). For instance, I usually specify a serif font (TNR/Georgia) for printed pages because it’s more readable in that format. I’m considering this approach:

    * style.css (includes everything needed)
    * print.css, screen.css, and other media types: all included from style.css via @media (as shown in this article): These contain all styles unique to the media type
    * layout.css, type.css, forms.css, etc: Common styles that work for all media types: Imported from the media types (minor duplication of filenames)

    Of course, such a complex structure (like the one in this article) should be compiled down to one stylesheet per media type, plus a common one for common styles included for all media types, minimizing HTTP requests.

    Anyway, great article; it definitely got me thinking!

  8. I get separating out the style sheets, though I don’t fragment them as much as Aaron does in the article. I’ve found myself going with a single master style sheet – which I minimize if necessary, one for any IE bugfixes, then a print style sheet. I haven’t had any client ask for supporting any browser “lower” than IE6, so accounting for Communicator 4’s acceptance of @import doesn’t factor in at all.

    I found the idea of using CSS to render the colons after form labels a gem. I struggled with that thought just last week. From a screen reader perspective, Aaron’s idea makes good sense.

    Progressive enhancement – the yin to graceful degradation’s yang. Good stuff to generate conversations.

  9. I found useful to use separate stylesheets for both IE6 and IE7, but I don’t think further fragmentation is a good idea. With type.css, layout.css, color.css you’ll end up with 3 times more selectors than if you use only 1 file. If you want to define style of a particular element you have to write definitions on 3 places in 3 files. Also debugging is harder.

  10. I agree with most commenters.
    Unfortunately this is not a workable solutions in a lot of cases. Changing a single website module/feature/widget requires you to open 3 CSS files. Considering that you’re making additional HTTP requests as well makes me think one nicely ordered stylesheet with a table of contents does the job a lot better.

  11. I like this method it’s very handy if you want to organize your code. I use it also in my CSS Frameworks, but there is one serious problem -> “HTTP Requests”. There are N.1 problem for the page speed. I think that is great to divide the CSS code in logical parts but in the end you should merge into one for the screen,one for the print .. Also compress if you can!

  12. 1.) To split complex stylesheets into reusable modules and to @import {…} them within a central stylesheet is nothing new. For example, the CSS framework “YAML”: uses this method since more than 3 years now.

    2.) There’s a big problem with your recommendation to put _@import {…}_ rules into _ @media {…}_ rules, e.g.:

    _@media screen { @import ‘screen.css’; }_

    This leads to *invalid* CSS code. The CSS 2.1 specification tells us in “chapter 6.3”:

    bq. The ‘@import’ rule allows users to import style rules from other style sheets. Any @import rules must precede all other rules (except the @charset rule, if present).

    Therefore, if I would follow your example, e.g. Firefox would show a website without any styles. The W3C validator also has problems with your recommendation and outputs error messages.

    So, I don’t think this is a best practice.

  13. hello, it’s 2008… anyone talking about netscape 4 is just retarded. and for ie6, try conditional comments. this article is the gayest of the gay

  14. On a tiny site with little to style, this many sheets might work. But once you get large enough to care about things like bandwidth and server utilization, having that many style sheets on each page is overwhelming.

    However, the principle is sound, and I’ve used a very condensed version of it in my current enterprise position, which is comprised of three style sheets only. One core sheet. One for IE 6 or 7. One unique to each property that overrides some core styles.

    Maintenance wise, it’s at the point where I only have to perform modifications to the core sheet, and the IE sheets as needed.

    I really would like to see people think for themselves more. You don’t have to do *exactly* what’s suggested. As a Designer (nay, as a human!), it’s up to you to determine the right level of graininess for optimum maintenance.

  15. It’s almost 2009- F Netscape and IE5. As far as multiple stylesheet files, I do try to break them down sometimes depending on the complexity of the site, but usually just into one layout/reset file, and the other a type/color file. Cutting down on http requests is usually my main priority when structuring css. And @import? I threw that away years ago.

  16. This technique doesn’t take performance into consideration at all. Perhaps using multiple style sheets for development is OK if it suits that developer, but honestly why does this matter with firebug telling you exactly where to find the styles in the style-sheet?

    Something should be said about using conditional comments to add extra special ‘ie6’ and ‘ie7’ classes and keeping everything in one style-sheet so that it performs much quicker.

  17. Separating style sheets is an inherently good idea, because a large site can easily have 1000+ lines of code, even _without_ print or cross-browser styles. The scrollbar and even Ctrl+F can become your enemy, as may other people working on the same project.

    But I have to say, I have no love for the separation into type/colour/layout, because these three are intrinsically linked, and you’ll end up having all three open at all times anyway, moreso because their distinction isn’t always as clear. Colour, for example is both a property of type and of layout, so who could agree on the proper separation of css?

    What we do at my place is make a main.css with the complete set of CSS for generic parts and layout for the entire site. Separate CSS files are created per functionality “module”, such as the news section in its entirety, or an online document search interface, or your google maps page.

    Functionalty is always easily separable from the rest of the site, and we apply this concept in all code, from css to js to the ASP on the server end.

    I toy with the idea of separating main.css into common things like formstyles, user messages etc., and the unique layout of the site at hand, but that’s missing the point, which is to _make maintenance easy_. Once that goal has been reached, further “optimization” leads to over-engineered solutions that can only, excuse the term, suck hard.

    On another note, I frowned when I saw mention of Netscape4 and IE5/Mac. I doubt it’s practical to give these browsers more than just a casual though on a lost evening, let alone _support_ them with coding techniques. Both browsers do not exist anymore, and devising ways of supporting them, I think, is a waste of resources. In fact, the lowest browser we support here is IE6. We would love to drop that one as well, but alas.

    For heavy lifting, I’m in favour of conditional comments, but otherwise, I’ve never needed more CSS trickery than the well-known _ and * bugs in IE.

  18. I agree with everyone who commented that editing multiple stylesheets after the fact is hell. I personally divide my styles into five sections in a single stylesheet: reset, base elements, universal classes, specific IDs/layout, page-specific overrides. Makes overriding a style extremely straight-forward, too, which hasn’t been mentioned yet. Changing styles isn’t always what you need to do.

    It’s also worth noting that putting @import in your stylesheet, aside from increasing HTTP requests, has an additional downside in IE: IE doesn’t cache any stylesheet that’s two layers out. So if you link to main.css, and then have an @import in man.css to screen.css, IE won’t cache screen.css. This won’t matter for most small sites, but in environments where you need to watch your server load and bandwidth it will bite you.

  19. This is good general programming practice (being modular), but creating so many separate style sheets really increases your HTTP request and can significantly damage the load time of you site. From an optimization stand point it’s just more efficient to lump all your CSS into 1 file (same with your javascript, if you can).


  20. A firefox addon was referenced “edit css sidebar” however I cannot seem to find it. The only add on I found has not been updated in quite some time and does not appear to work in ff3. What addon do you use regularly?

  21. Matt Tucker: Look for “Web Developer Toolbar” – it should have what you need and should work in FF3.

    As for the article, I tend to agree with everyone else: less CSS files are better for the sake of HTTP requests. We (my company) had a significant difference in load speed and therefore conversion when we grouped our CSS and Javascript stuff.

  22. We have been working tirelessly to separate form and content for years- and yet this article is encouraging the use of CSS that embeds content directly within the stylesheet!

    label:after {
    content: “:”;

    From a standards based approach how is this remotely acceptable and when exactly did punctuation become merely a “visual cue”?

  23. I was tremendously disappointed by this article. When Fx2, Fx3, Fx3.1, Opera 9.6, IE6, IE7, IE8, Safari, Chrome, iPhone, and Android are all about to share the stage, I was eager to read about progressive enhancement techniques from the Web-capable handhelds to the judicious use of previously unsafe CSS 2.1 and CSS 3 properties where now applicable.

    Boy was I wrong! Instead, a litany of hacks to hide CSS for NN4(!) and IE5 Mac, praise for conditional comments as if we haven’t already been using them for years, and some seemingly pointless examples of giving different styles to IE7 and IE6 as if for fun. Why? We’re barely two months from 2009.

    This article feels like it was written in late 2005 with sloppy mentions of IE7 hastily added prior to submission.

    I still look forward to an article on progressive enhancement relating to the current state of the Web.

  24. I’ve tried separating stylesheets into separate files for layout, colors and text and found that it works great on a small scale.

    Throw in conditional styles for IE versions and things get a little more complicated. Most of the rules aimed at IE x.x are related to layout so maintenance only becomes an issue on redesigns. But still, it’s something to consider.

    Scale things up to the point where thousands of pages call up to 6 files, and suddenly you’re taking a hit in performance and facing increased bandwidth. Even with caching, you’re still going to see a slower load on the visitor’s first visit to the site. And since first impressions are lasting ones, I want to make sure that first page loads as quickly as possible. Maybe just keeping it simple is the best way to go.

  25. Great article it’s a larger scale of something I’ve currently been doing.

    I work on sites smaller then 1500 + lines so my idea was to organize everything in 3 rows.

    – First row being layout
    – Second row is text
    – Third row is borders backgrounds

    See the example below:

    #id_name {
    width:100px; height:auto; margin:0; padding:0;
    color:red; font-size:1.3em; text-align:center;
    border:solid 1px green; background:white;

    Within each row everything is organized consistently. For example the first row is always width then height then margin then padding.

    The reason I started doing this was to reduce the amount of lines that one class or id would take up, and more importantly so i could always find what i was looking for in each class or id quicker.

  26. So the text box didn’t render my example how I expected it do so here it is again. Sorry.

    width:100px; height:auto: margin:0 10px; padding:20px 0;
    color:red; font-size:1.3em; text-align:center;
    border:solid 1px green; background:white;

  27. Wow, I guess this thing doesn’t like my returns. Last try at it.

    width:100px; height:auto: margin:0 10px; padding:20px 0; (—-NEWLINE—-) color:red; font-size:1.3em; text-align:center; (————NEWLINE————) border:solid 1px green; background:white;

  28. I agree with many of the above. You should limit the number of http-requests.

    If I want to split the css in multiple files, I usually create a main.css.php file, which sends itself with a text/css header. This file includes the other css files server side.

    This may not be a good idea in every situation, but has been helpful for me on several occasions.

  29. I’d like a CSS Style editor that databases my style choices and automagically generates CSS files and (x)html linkages (separated and conditionally commented as needed) based on the current state of known browser quirks and failings.

  30. “Dirk”:”:” (and others) were completely right in calling me out on the @import inside an @media crap, it was a last-minute change I made to the article shortly before publication and which I realized — a little too late — was neither valid or supported (and rightly so). I was looking for a way around the media declaration issue with IE and thought I had found it, but only managed to find *massive fail*. Again, I apologize profusely for not catching it earlier, but I have corrected that now and reverted the article to use my previous method.

    _Mea culpas_ out of the way, I’d like to take a moment to address a few other bits and bobs being brought up on the thread:

    # *server requests* – yup, this means more server requests which _can_ cause site performance issues, but there are many ways you can reduce that performance hit. CDNs are a good option, but you could also weight the benefits of PE with CSS against your performance needs. Perhaps you don’t need to worry as much about playing a game of “hide the stylesheet” from those _special_ browsers. If that’s true, you should count yourself lucky. Which brings me to…
    # *the point of this article* – contrary to what you might think, this isn’t a “check out this nifty trick” piece. In fact it’s not even about trying to convince you to do what I have found works… it’s about getting you to think about how you can apply CSS in a progressively-enhanced way. Thankfully, most browsers in use today have a fairly comparable feature set CSS-wise (or at least they will when IE8 comes out of beta), so PE with CSS isn’t as big a deal as it used to be (since CSS hasn’t gotten an overhaul in quite a few years), but it’s still a good thing to think about, especially since CSS3 is (hopefully) right around the corner.

    Anyway, I’m off to bed, but thanks so much for all of your feedback.

  31. Define your three-letter-acronyms please. Thanks for the answer, Aaron, but you could expand your acronyms. It’s late and I’m not able to expand them in my head, hurting your intended clarity:
    * PE
    * CDN

  32. I was very happy and interested into the first part, now part 2 was for me, like others above a bit of a shock. ^-^ I actually cannot and do not want to think about anything before IE6.
    I work for social network, so backwards compatibility is absolutely necessary. But we decided to draw a clear line (the bottom is IE 6).
    I personally prefer to use 2 to 3 stylesheets (main for screen and print!, IE 6 and if necessary IE7). I used to split stylesheets in colors / backgrounds, typo and layout, but ended up with 1000 lines each, that was not main table.
    The idea of using a table of contents is great, and when I will get myself deeper into mobile development (thanx for the links!!) more extra sheets might be interesting.
    But I believe the less the better.

  33. Different stylesheets like you describe is not easy to maintain. All that switching between files when changing the properties of an object. I’ve tried it ones. Never again.

    I’m in favour of a table of contents at the top and only one well organized stylesheet. Only for cms admin pages and for print I do you use different stylesheets.

  34. *Chris Pond –*
    The ALA comment textarea uses Textile for formatting. See the line just above it for a link to documentation and a sandbox.

    The comment preview is a tad limited, it seems.

    *Matthew Goodenough –*
    Colons have been stylistic elements and a “visual cue” since their inception in modern typography, and are not part of content. Putting them in CSS is entirely correct and acceptable. The same goes for periods, capitals, semicolons, quotes, dashes, italics-for-emphasis, large size for headers etc.

    In this context, an equivalent alternative to the semicolon, as an example, would be a little extra padding on the right and a small background image to indicate the connection between the label and the field.

    I agree that the distinction can get a little hard to enforce, because without all the visual cues we put in text, the content would be very hard to read, and thus it’s odd to not lock them inside the text as though they were content. But here we talk about colons on a label; not colons in a sentence, and taking advantage of CSS is recommendable.

  35. @William Jeffery

    Come, now, Mr. Jeffery! Continuing your logic, the spaces between words themselves are merely “visual cues,” not “content.” After all, Mayan, Olmec, Aramaic, Coptic, Hebrew, Classical Greek, and Phoenician were written for centuries without them. Let’s strip these newfangled presentational elements from the true content, wrap every word in its proper span tag, and let the user agents use pseudoclasses to render the visual cues to the wusses who visit our Web pages, if and only if their browsers prove them worthy!

  36. I don’t think you can support all kinds of browsers and devices if you have a common markup for all. But it can be used in conjunction with the XUL i suppose. So that you always have your data in xml format and it will be common item. Then you can seperate the browsers/devices into groups and create different markups for each group. And at last for each group you can apply progressive enhancement.

  37. @Willem Jeffery – I agree with Jon Zuck: colons, periods, capitals, semicolons, quotes and dashes aren’t stylistic elements, they’re punctuation. However, I don’t have a problem with the CSS content example that Aaron’s used, because a label / input pairing isn’t really a sentence, so it’s debatable whether the colon would be considered ‘content’ or not. (You’d also need to be mindful of labels that are actually questions which would need to end with a question mark rather than a colon.)

    Re: editing CSS with the webdev edit CSS pane – does anyone else do this? I imagine it’d be a bit of a chore but maybe that’s because I’ve got used to using programs that autocomplete lines when you type a few characters.

  38. It is “interesting”? that this article completely ignores performance and maintainability, and yet these are critical to modern, professional web development.

    I respect ALA too much to go into any further detail – instead I do offer an article that would clarify these concerns.

  39. @Aaron – Using a CDN to compensate for the additional http requests doesn’t make sense to me. The network does nothing to reduce the amount of requests. It just adds another DNS lookup into the mix and adds cost to the project for no reason. If I’m not mistaken, the point of a CDN is to have the files served from a location closer to the client.

    However, if you merge the CSS files into a single file that is served compressed (as mentioned on earlier comments) you mitigate the performance issues in one swoop.

  40. Having worked on several social networking sites, the shear number of HTTP requests is our biggest enemy. I’ve settled on a modular based approach. Many social networking pages have similar “boxes” of content or modules. We have one common.css file which contains styles used by multiple modules, and then each module gets its own style sheet.

    Say several pages list forum topics and have a comment box (like a profile page). It makes sense to have a comments.css and a forums.css file. This greatly reduces the amount of CSS I need to write and maintain, with the additional benefit that simpler pages do not need all the CSS overhead that more complex pages do.

    The average page then loads the common file, probably one or two module files, a common print file, and then IE-only style sheets.

    Now if only we could target JavaScript for specific media types…

  41. I really like the idea of fragmenting styles. It’s tough, though, to decide if the fragmentation should be by topic (fonts, colors, etc.) or by DOM location (header, footer, sidebar, etc.); or by media type, as addressed by this article. The problem, though, is that each new fragment would require another HTTP request. Efficient HTTP caching makes this a moot point for successive requests, but a slow first page load may influence whether successive requests are made (maybe the visitor deems the site too slow and hits the back button).

    YSlow preaches the reduction of HTTP requests, suggesting that maybe we should have just one CSS and one JS file for the site, and serve it via CDN. This seems to preclude CSS fragmentation… but not really.

    Rails developers have the option of using “SASS”: (packaged with “Haml”: ) to generate Syntactically Awesome Style Sheets. Styles can be managed in fragmented files (as many as you wish), and compiled into one compressed CSS file—and by “compressed” I mean compacted (one line per selector) or compressed (entire stylesheet on one line).

    A clever author could use one stylesheet per media type with virtually no repetition (keeping the fragmented files DRY, folowing the Rails Way). Really, the possibilities with SASS are endless: it even supports color math!

  42. First, I think some are overreacting to Gustavson’s casual mention of NN4 and IE5. My own feeling is that if you want to accomodate user agents going that far back, stick to Quirks+HTML3 but let’s give the author points for being thorough and move on… OK?

    What I liked about the article was it’s tone with regards to the need to accomodate IE6 and IE7 as a given, as something which simply must be done at this point in time, period. Just a fact of life.
    To some this is completely obvious; a no-brainer. But in other forums, I’ve run into designers and developers who I find are, frankly, near-delusional about this. (IMHO) There’s two memes worming their way through the technosphere:
    1) An inflated sense of the installed user base for FireFox – to the point where IE is talked about as if it no longer mattered because “it’s days are numbered”.
    2) The belief that there is a magic button that can (and will!) be pushed soon whereby all the remaining IE users (poor saps) will suddenly find themselves using FireFox 3, or Opera 9.6 or Safari for Windows.

    Now, whether these ideas turn into sites which no longer look good or behave well with IE6 (or even 7) remains to be seen.
    But IE6 has an installed user base of, at a very conservative guess, what, a hundred million users?
    Their numbers will dwindle but it will still be some years before we can design confidently without taking IE6 into account. IE7, even longer. No matter how hard Microsoft pushes an upgrade to IE8.
    And in the meantime, conditional comments or their equivalents will be the order of the day.

  43. @”Richard Fink”:
    I don´t think it will take that much longer for IE7 to disappear, than it will take IE6. IE8 installs on the same platforms as IE7 and has the version switch. This makes switching from IE7 to IE8 pretty easy, not like switching from IE6 to IE7. I can even imagine that for that reason IE7 will again have a smaller market share than IE6 in the end. Certainly hope not though.

  44. I agree with a lot of commenters here that splitting all your stylesheets into colour, type and layout is unhelpful. The suggestion that the print styles for any of these three will relate to the screen styles is pretty unimaginative too – on most of my sites, there is very little correlation between type (sans serif for screen, serif for print), colour (may use light-on-dark for screen, not for print – may use background colours on screen, often doesn’t work in print) and layout (print sheet removes most layout styles, and removes some elements completely!).

    No, where multiple stylesheets come into their own is when you have a site with a set of generic styles across all pages, but with a different colour scheme for different sections. That is exactly what ALA does! Each edition has a different colour scheme, which keeps all the colours in a separate stylesheet so they don’t clog up the main one.

    When CSS can recognise user-defined variables, this may become redundant, or at least less useful, but in the meantime, it’s a very good use for multiple stylesheets.

  45. I think the article title was a little misleading, I (like others) expected more e.g. bit’s and bobs from CSS3 (and browser extensions) e.g. multiple background images, css gradients, css transforms, @font-face, css tables etc, etc, (with IE 6 as a baseline browser).

    Having used third party software that utilises multiple stylesheets I have to agree with most of the comments:

    1. It’s a maintenance nightmare… 8+ stylesheets!!
    2. It will slow down the initial load of the site
    3. A CDN is used to serve content based on the (network) proximity of the user requesting the resource – the fewer the network hops to the server the quicker the response time.

    There is an “alternative”: (better?) way of using conditional comments to target specific versions of IE without having to result to multiple stylesheets.

    There are lies, dam lies, and statistics but… I’ve access to the log stats of a (non-technical) public facing website and over the last 12 months there has been 1 visitor using IE5(Mac) and none using Netscape 4… I wouldn’t spend anytime designing for those browsers…

    This might be worth a look for writing maintainable css “CSS Systems”:

    Just my 2p.

  46. recent articles have been below par in quality. I think even Sixrevisions and Smashing magazines are getting a lot better. This article really does sounds like it was written in 2005. IE 5.5? Netscape? Which world are we living in? Splitting css into so many files is a maintenance nightmare that I am glad to do without. I use 1 stylesheet and if a page is complicated, I use another style sheet for a specific page when working with sites with more than 30 templates.

    I only hope the next articles are of a better standard.

  47. I’m really surprised to read this article in _2008_ from somebody as experienced as Aaron. Everybody is trying to _reduce_ HTTP requests these days, and we all know that @import is the *worst, slowest way* to add more stylesheets. Kids, don’t try this at home — you will hurt the web!

    Apart from the maintenance nightmare it’s simply superfluous to create extra stylesheets for print, not to mention handheld styles. Usually my print stylesheets just involve setting a few elements to display:none and fixing a few colors and widths. That can be perfectly done in one stylesheets with the @media print rule:

    @media print { #stuff-that-doesnt-get-printed { display: none } }

  48. This all sounds really awesome in theory. We are all about separating content and style, so why not break up the styles into logical units as well?

    But in practice I don’t know how good this is…
    Has anyone come up with actual metrics on whether it’s better to have everything in one css file (large initial size, but only one http request) versus broken up (small individual sizes, but multiple http requests) in terms of bandwidth, and perhaps page loading? If multiple http requests causes the bigger hit, then in many cases the separation is a weakness.

    Also, initially it seems good to break everything up into different chunks of style. Typography, layout, color, etc. But, as has been mentioned this can make maintenance, and especially development, hell. Currently, if I want to change an element, or there is a bug with an element, I can go directly to that element’s style definition and play with all of its properties in one place. Using this method, I would have to jump around between files searching for the right places.

    Also, with page loading, what if one stylesheet hangs when its being downloaded. So the user might see a giant red colored eyesore for a while until the next stylesheet jumps in and fixes it. With one stylesheet, it may take a bit longer for the page to completely load, but for the most part each element receives all of its styles at once.

  49. @sander
    IE7 ships with Vista. That’s the big problem. Every new computer with Vista = 1 new IE7 user.
    If the results of Microsoft’s efforts at pushing out IE7 to IE6 users – as a “critical update”, no less – is any guide, efforts at pushing out IE8 will come nowhere near eradication. We’ll be dealing with IE7 for many years.
    BTW, Microsoft publishes a schedule of product lifecycles listing when they will drop support (exclusive of security updates) for different products.
    IE6 on Windows XP gets shelved in late Spring 2010.

  50. I’m barely learning C++ and Objective C, would you guys have a recomendation for a book to learn about HTML, XHTML, and CSS? I’ve seen too many and I can’t figure out how to separate the good one from the average ones. Thank you guys.

  51. As much as I hate when it’s time to apple+tab over to IE6 and 7 from firefox and hit refresh, I must admit that the 2 browsers help to point out a lot of problems with my CSS that sometimes FF/Safari etc. “ignore” and “appear” to render correctly anyway. I find that making small adjustments to my CSS to fix IE6 and 7 issues cause no problems in FF/Safari renders and am embarrassingly grateful that my foes (IE6 and 7) pointed those things out to me. Usually, the fixes make sense too. I very rarely even need to make a separate style for IE6 and 7, thanks especially to standards-compliant ways of invoking has-layout and clearing floats. The last site I made has an IE stylesheet for ONE element, the “behavior” element for PNG support in IE. My continuing inspiration is found in the fact that even the most elite CSS designers today are still abusing CSS because it wasn’t intended to do what we’ve made it do at all. Floating for layout? Although necessary for us now, DIVs were intended to stack one on top of the other. So, in exaggeration, we’re all just hacking our way to the coming days of CSS3 table support, but thank you W3C for current CSS 2.1 spec.

    Have a look at a “new book from sitepoint titled Everything You Know About CSS is Wrong”: .

    In contrast to the parts of this article you’re dissapointed with, you’ll appreciate “the book’s”: _drive toward the future_ in regards to preparing for new CSS and Browsers and what to do about older browsers, _rather than discussing support for NN5 and IE older than 6_.

  52. “This is a nifty trick for getting IE5/Mac to ignore a stylesheet.”

    It may seem nifty but it makes the code brittle and easily broken. It means that everyone who ever works on this code must recognize all the tricks you are using so they don’t break them.

    I don’t call that nifty … I call that hard to maintain.

  53. To have the cake and eat it.

    (i build sites based on PHP, but similar prospects exist for other methods, such as SASS for ruby…)

    Write yourself a simple “css compiler”, let it concatenate (and minify) your many, many css files into one block and return that to the browser.

    I now have simply a css link tag with an href like:


    the PHP spits out a condensed result of loading those files in turn (vars.php allows me to define global values such as “$ugly_red=’#faa'” and then use those values throughout my other css files. (parameterised CSS is good – should have been in the spec all along)

    When production time comes along, I just load that css url into the browser as is, and copy/paste the result into “site.css” and change the value in the link tag of the template to remove the time spent by PHP producing my css.

    Best of both worlds: single http request, minified css code, and I get to work on small, reusable, maintainable and understandale CSS

    As a bonus I also get to parameterise my CSS when I want to as well.

    The (very basic) ‘compiler’ I use is here – “”:

    Its probably bug-ridden, and its VITAL that you don’t put such a script onto a public server (it only gets used on the dev server that lives under my desk and isn’t externally routable …)

  54. In my current position I work on a site that has many dynamic pages. I would find it too timely to maintain the site wide and page specific CSS in this manner (i just prototyped a page to test). This seems as though it is geared for a small / static site.

    We load a few different CSS files (I don’t think load times from different CSS files causing multiple requests is a problem), which are usually a global.css, a portal specific CSS file, and then a page specific CSS file. I prefer to have my CSS rules in one place, because this removes the chance that you may have identical mistakes hidden throughout your 2k lines of CSS. Keep it simple, keep it fresh.

  55. Sorry, this is kind of an off topic question. I am using the same kind of browser detector the author used in the article. I have gotten it to work in all version of IE but not Mozilla and Firefox. Is there a browser detector I can use for Mozilla and Firefox similar to the one used in the article that doesn’t require any Javascript? Can anyone help?

  56. I just wanted to say that I really enjoyed the article as well as the discussion that has followed.

    I would like to respond to some of the comments with relation to actually having multiple style sheets. I think a good technique or tip, is to create one style sheet when in development of the site. Only after the CSS design is complete should you break it up. I think this process with help designers better structure their markup and make it not as cumbersome as first thought.

  57. Using a CDN to compensate for the additional HTTP requests doesn’t make sense to i want to apply this on the craps dice site.The network does nothing to reduce the amount of requests. It just adds another DNS look up into the mix and adds cost to the project for no reason. If I’m not mistaken, the point of a CDN is to have the files served from a location closer to the client.Say several pages list forum topics and have a comment box (like a profile page). It makes sense to have a comments.css and a forums.css file. This greatly reduces the amount of CSS I need to write and maintain, with the additional benefit that simpler pages do not need all the CSS overhead that more complex pages do.I agree with Jens Meiert, performance and maintainability needs more digging.I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well.

  58. Using a CDN to compensate for the additional HTTP requests doesn’t make sense to i want to apply this on the craps dice site.The network does nothing to reduce the amount of requests. It just adds another DNS look up into the mix and adds cost to the project for no reason. If I’m not mistaken, the point of a CDN is to have the files served from a location closer to the client.Say several pages list forum topics and have a comment box (like a profile page). It makes sense to have a comments.css and a forums.css file. This greatly reduces the amount of CSS I need to write and maintain, with the additional benefit that simpler pages do not need all the CSS overhead that more complex pages do.I agree with Jens Meiert, performance and maintainability needs more digging.I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well.

  59. I generally try to optimize my website css using gzip or defalte methods. These methods are for Apache Server versions.

    You can simply create “.htaccess” file and modify accordingly. This will speed up your css and website as well when it get loads.

Got something to say?

We have turned off comments, but you can see what folks had to say before we did so.

More from ALA