Search code examples
cssstylesheet

One CSS File or individual CSS files for each page?


When I am building pages, do I want to have individual stylesheets for each page or one large stylesheet for the entire site? For loading purposes, wouldn't individual files be a better practice because it would be less total css on load?


Solution

  • Use a single file, CSS files are cached and therefore reduce the need to download a new file for each new page visited.

    To help, I usually process my CSS through a CSS cleaner to reduce its file size, additionally, you can GZip CSS using .htaccess too, making it smaller yet again.

    Finally putting all CSS in a single file will make making system-wide changes to presentation easier in the future (the entire reason we use CSS in the first place), it will also make debugging easier.

    Edit, May 2017

    A lot has changed in 7+ years, and anyone looking at this answer should consider researching newer asset delivery methods, especially now that HTTP2 and preprocessors are more commonplace.