Ask questions via twitter! Message any question to @answers on twitter. We'll publish the question and send you a reply each time there's a new answer.
Next Question

Answered Question

 
February 05, 2009 11:51 AM

Which is better, single or multiple css files? What are the benefits?

Is it better to use multiple css files for building a site or using a single file that contains all styles?
Interesting Question?  Yes (1)   No (0)   
RSS
 
 

Best Answer  Chosen by Asker

 
February 05, 2009 03:16 PM
It really depends on the situation, and your own or teams preferences and what you want to achieve.

For readability and understandability it is good to clearly organize and label (comment, indent and space out) your styles as well as separate them into common groups. If you have a single file, it can become a bit long with lots of content, and this affects readability, and the ability to find a specific portion of the file.

So if the CSS file becomes too large, you might want to consider separating different sections into different files. This is largely based on your CSS editor also. Editors that do not manage multiple files well can be a hindrance. Screen size also plays a factor, as large screens are well suited for single files.

Too many files can make things more complex then necessary. Here, it makes more sense to make each file more readable, then to separate them.

It also helps to have good version control. For this you can use SVN, or GIT.
SVN - http://subversion.tigris.org/
GIT - http://git-scm.com/
This helps the management of the CSS files as well as other files.

For organizing CSS see:
http://www.smashingmagazine.com/2007/05/10/70-expert-ideas-for-better-css-coding/

To consider how single or multiple CSS files affect load time. The browser usually has to wait for all the files to load before rendering styles. Multiple files mean that there are more HTTP requests made, and this usually means it will take longer.
There are many factors affecting how the CSS files will load. Browser usually only have a 2 connection limit per domain (2 TCP sockets) concurrently. So multiple files may or may not be downloaded concurrently due to this limit. There are other factors such as HTTP version used, support HTTP features on both server and browser (eg: HTTP pipelining), intermediate or browser cache, etc.

For loading multiple CSS files see:
http://www.cherny.com/webdev/53/on-http-page-load-times-multiple-file-requests-and-deferred-javascript
Source(s):
Web Development experience - http://www.fijiwebdesign.com/
http://www.cherny.com/webdev/53/on-http-page-load-times-multiple-file-reque...
http://www.smashingmagazine.com/2007/05/10/70-expert-ideas-for-better-css-c...



Helpful Answer?  (3)   (0)    Tip bucabay for this answer
Permalink | Report
   Reply  
 
 
 
February 05, 2009 03:52 PM
Agreed. Good Answer.

Report
 
 
 
February 05, 2009 04:10 PM
Good Answer!

Report
 
 

Other Answers (2)

Sort By
 
February 05, 2009 01:03 PM
I prefer to use one CSS file. I delineate each section (the reset section, layout, typography, etc...) using commented out lines of dashes/underscores, and navigate around it using whatever code editor I'm using's "find" functionality.
Having multiple files can get confusing, and requires more HTTP requests (even though it's only for the initial pageview).

Helpful Answer?  (1)   (0)    Tip toofat2serve for this answer
Permalink | Report
   Reply  
 
 
 
February 06, 2009 02:30 PM
Thanks!

Report
 
 
 
February 05, 2009 04:13 PM
The only reason to use multiple CSS files is if you are going to share them across different sections of a site or across multiple sites. Think of it like having common files in another computer language.

Helpful Answer?  (1)   (0)    Tip w3ace for this answer
Permalink | Report
   Reply  
 
 
 
February 06, 2009 02:30 PM
Thanks

Report
 
 
Buy Mahalo Dollars with Credit Card or PayPal

Top Members

This Week All Time
  • buddawiggi
    buddawiggi
    2nd Degree Black Belt
    27808 Points
    M$799.16 Earned
  • opher
    opher
    Purple Belt
    4473 Points
    M$196.22 Earned
  • annelisle
    annelisle
    Purple Belt
    3110 Points
    M$95.22 Earned
   See All
 

Most Popular Tags

mahalo(1635)
iphone(466)
music(464)
google(359)
food(322)
online(298)
beer(279)
money(263)
movies(262)
apple(252)
aotd(235)
health(220)
video(208)
free(206)
dog(205)
   See All
 

Categories

Welcome New Members


 
 
Mahalo Dollars are the currency of Mahalo Answers.

Each Mahalo Dollar costs $1.

Once you earn more than 40 Mahalo Dollars, you can request to be paid via PayPal. Each Mahalo Dollar is currently worth $0.75 when paid out via PayPal. Learn More

 
 

Please log in to use this function.