CSS guru Jonathan Snook is a regular on SitePoint and the podcast. His latest project tackles a subject few developers consider until it’s too late: CSS architecture. If you’ve ever struggled to manage a large complex site with dozens of layouts and widgets, I suggest you read Scalable and Modular Architecture for CSS — or SMACSS (pronounced “smacks”) for short.
It’s not a how-to guide, framework, snippet library or even a set of recommendations. Jonathan has documented his own observations when structuring CSS code for larger projects. The online book suggests techniques to keep your code better organized and easier to maintain. It’s a unique approach about a topic which is rarely discussed in other CSS guides.
The first section identifies four main types of CSS:
- Base: primary HTML elements such as the body, form tags, links etc.
- Layout: how the page is divided into sections including headers, footers, sidebars etc.
- Modules: discrete, reusable, modular components, e.g. navigation bars, product lists, contact forms, etc.
- State: how modules or layouts change when in a specific state, e.g. errors, hidden, expanded, active, inactive, etc.
If you’ve been developing layouts for a while you’re likely to recognize many of the patterns. You may disagree with some of Jonathan’s suggestions. However, the book is reassuringly concise and you will begin to consider your own approach to scalable CSS.
Craig is a freelance UK web consultant who built his first page for IE2.0 in 1995. Since that time he's been advocating standards, accessibility, and best-practice HTML5 techniques. He's created enterprise specifications, websites and online applications for companies and organisations including the UK Parliament, the European Parliament, the Department of Energy & Climate Change, Microsoft, and more. He's written more than 1,000 articles for SitePoint and you can find him @craigbuckler.
Jump Start Git, 2nd Edition
Visual Studio Code: End-to-End Editing and Debugging Tools for Web Developers
Form Design Patterns