{"id":19356,"date":"2018-09-11T11:30:03","date_gmt":"2018-09-11T11:30:03","guid":{"rendered":"https:\/\/www.heartinternet.uk\/blog\/?p=19356"},"modified":"2018-09-11T11:30:03","modified_gmt":"2018-09-11T11:30:03","slug":"scalable-css-top-tips-for-writing-and-maintaining-css-for-scale","status":"publish","type":"post","link":"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/","title":{"rendered":"Scalable CSS: Top tips for writing and maintaining CSS for scale"},"content":{"rendered":"<p>Writing and maintaining CSS for a small site is very different from a large site or multiple sites. How exactly we developers can and should write CSS for scale varies according to the specifics of what we&#8217;re working on.\n<\/p>\n<p>\nFrom my experience, what happens all too often is CSS files become an unstructured mess. Changes require new code, which gets tacked on at the end. Or somewhere in the middle. Or maybe somewhere else.\n<\/p>\n<p>\nIn this article, I&#8217;ll go through various methods I&#8217;ve used trying not to write too much CSS, while also generally keeping my sanity. Ideally, the methods presented here can be used to scale up your development practices in such a way that, even if you don&#8217;t need a certain method right now, you&#8217;ll have an idea what you might do to avoid losing control.<\/p>\n<h2>Defining scale<\/h2>\n<p>The &#8220;add new styles at the end&#8221; method might be widely used but it&#8217;s not going to help you past a certain point.\n<\/p>\n<p>\nWhen you&#8217;ve built a site and deployed it, you&#8217;re free and can now bask in its glory. That basking will end when your team expands or the scope of your work changes.<\/p>\n<h3>Themes<\/h3>\n<p>Sales: &#8220;We promised a client they can have their own colours.&#8221;\n<\/p>\n<p>\nYou: \ud83d\ude31\n<\/p>\n<p>\nSales: &#8220;Here are the PowerPoint slides.&#8221;\n<\/p>\n<p>\nYou: \ud83d\ude31\ud83d\ude31\n<\/p>\n<p>\nSales: &#8220;We&#8217;ve shown you which colours we want to change.&#8221;\n<\/p>\n<p>\nYou: \ud83d\ude31\ud83d\ude31\ud83d\ude31\n<\/p>\n<p>\nSales: &#8220;How hard can it be to set some colours?&#8221;\n<\/p>\n<p>\n(Note: Everyone&#8217;s job looks easy if you don&#8217;t understand it.)\n<\/p>\n<p>\nSales: &#8220;We showed all the other clients the customisations.&#8221;\n<\/p>\n<p>\nYou: \ud83d\ude31\n<\/p>\n<p>\nSales: &#8220;They love it&#8221;\n<\/p>\n<p>\nYou: \ud83d\ude31\ud83d\ude31\n<\/p>\n<p>\nSales: &#8220;There are ten of them&#8221;\n<\/p>\n<p>\nYou: \ud83d\ude31\ud83d\ude31\ud83d\ude31\n<\/p>\n<p>\nSales: &#8220;I think I should call an ambulance.&#8221;\n<\/p>\n<p>\nSales: &#8220;You seem to have passed out. Does that happen often? Should I send for help?&#8221;\n<\/p>\n<p>\n(Note: Playing dead might work with bears but it&#8217;s less effective with sales staff.)<\/p>\n<h3>Large team<\/h3>\n<p>A <a href=\"https:\/\/css-tricks.com\/poll-wrapup-the-number-of-people-touching-css\" target=\"_blank\">2015 poll on CSS Tricks<\/a> showed 75 percent of CSS is edited by one or two people. As with any programming language, structure and consistency become more crucial the more people are involved. Even if you are only one person who edits a project, remembering what you wrote six months ago can be as much of a challenge as working with someone else.<\/p>\n<h3>Multiple architectures<\/h3>\n<p>Maintaining your styles across multiple architectures is as much a branding problem as a technical problem even if the impact is technical. How exactly do you keep your look and feel consistent when one team is using React and another Jekyll?<\/p>\n<h2>Ingredients<\/h2>\n<p>A good thing about structuring your CSS is knowing that you&#8217;re not alone and many others have gone ahead of you. A bad thing is the realisation that there are many varied solutions out there, which makes it hard to know what&#8217;s right for you.<\/p>\n<h3>Vanilla CSS<\/h3>\n<p>Plain old native CSS has structure by way of the various selectors it offers. Irrespective of what solution you choose, having a good understanding of CSS selectors will help make your life as a CSS developer significantly easier.\n<\/p>\n<p>\nIf they&#8217;re used well, you might not need to go any further.\n<\/p>\n<p>\nIn the modern CSS world, <em>ID selectors<\/em> are generally considered to be too specific and, as such, are best avoided. The key problem with ID selectors is they&#8217;re really difficult to override which makes scaling all the more difficult.\n<\/p>\n<p>\n<em>Class selectors<\/em> can be pretty much anything, which is both good and bad. Without a clear naming scheme, classes can quickly devolve into chaos.\n<\/p>\n<p>\n<em>Attribute selectors<\/em> can also be pretty much anything but they do carry great semantics with them. The semantic meaning of attributes makes them extremely powerful when used carefully.\n<\/p>\n<p>\nFinally, <em>element selectors<\/em> are broadly useful but can also be too specific. If you set margins on a simple p, then you&#8217;ll need to override that p over and over.\n<\/p>\n<p>\nEvery selector in CSS is defined in the global scope. That is, each selector is available to the entire rendered document at once.\n<\/p>\n<p>\nThis core feature of CSS is often seen as a bug and several attempts have been made to &#8220;correct&#8221; it. <a href=\"https:\/\/twitter.com\/heydonworks\" target=\"_blank\">Heydon Pickering<\/a> raised a storm discussing such CSS features in 2016 (<a href=\"https:\/\/www.smashingmagazine.com\/2016\/11\/css-inheritance-cascade-global-scope-new-old-worst-best-friends\/\" target=\"_blank\">CSS Inheritance, The Cascade And Global Scope: Your New Old Worst Best Friends<\/a>).<\/p>\n<h3>SMACSS<\/h3>\n<p>With the name <a href=\"https:\/\/smacss.com\/\" target=\"_blank\">Scalable and Modular Architecture for CSS<\/a>, SMACSS seems to offer everything we want to cope with scale. It&#8217;s scalable! It&#8217;s modular! Perfect!\n<\/p>\n<p>\nSMACSS takes us beyond using one file for everything by splitting CSS files into a logical order. This improves maintainability even for small projects.\n<\/p>\n<p>\nWhile SMACSS lists five categories of splitting CSS (base, layout, module, state and theme), I&#8217;ve taken to using a modified structure: core, blocks, components, and site, which are detailed in the File Structures section below.<\/p>\n<h3>BEM<\/h3>\n<p>When I first looked into the <a href=\"http:\/\/getbem.com\/\" target=\"_blank\">Block Element Modifier<\/a> naming method, I found it very confusing. The broad concept seems clear enough but specifics of implementation are lacking. I assume this is somewhat intentional as BEM provides a loose structure that can be used however you like.\n<\/p>\n<p>\nThe key feature of BEM is to apply a structured definition to classes. Once you wrap your head around it, it makes writing components highly beneficial.\n<\/p>\n<p>\nBeyond standard BEM syntax, <a href=\"https:\/\/twitter.com\/csswizardry\" target=\"_blank\">Harry Roberts<\/a> describes adding namespacing to provide additional scope to the naming structure under the name <a href=\"https:\/\/csswizardry.com\/2015\/08\/bemit-taking-the-bem-naming-convention-a-step-further\/\" target=\"_blank\">BEMIT<\/a>.<\/p>\n<h3>Atomic Design<\/h3>\n<p>What does a design system have to do with CSS? <a href=\"http:\/\/atomicdesign.bradfrost.com\/\" target=\"_blank\">Atomic Design<\/a> provides a way of structuring designs into separate interrelated parts. The methodology makes as much sense when applied to user interface code and hence CSS.\n<\/p>\n<p>\nThe key advantage to scalable CSS is in providing an easy-to-understand structure, which helps immensely when working in dispersed teams.<\/p>\n<h3>Sass<\/h3>\n<p>I&#8217;m generally reluctant to go near variations over core language features in part to reduce dependencies. It took me a long time to adopt jQuery, and I&#8217;m reluctant to go near TypeScript.\n<\/p>\n<p>\nIn similar ways, it took considerable thought and consideration before I adopted a CSS pre-processor, in this case <a href=\"https:\/\/sass-lang.com\/\" target=\"_blank\">Sass<\/a>. The key features of variables and nesting were enough in the end to convince me, especially given Sass compiles to vanilla CSS.\n<\/p>\n<p>\nEven having adopted Sass, I remain reluctant to push too deep into the framework to make it easier to drop it whenever the time comes.<\/p>\n<h2>Left on the shelf<\/h2>\n<p>Not every design pattern scales well. Here are the methodologies I&#8217;ve looked at but haven&#8217;t yet found a use for.<\/p>\n<h3>Atomic CSS<\/h3>\n<p><a href=\"https:\/\/acss.io\/\" target=\"_blank\">Atomic CSS<\/a> uses functional classes to control scope. However, it essentially reverts back to compact inline styles. If you want to learn more about Atomic CSS, <a href=\"https:\/\/twitter.com\/johnpolacek\" target=\"_blank\">John Polacek<\/a> wrote a great summary of the methodology, &#8220;<a href=\"https:\/\/css-tricks.com\/lets-define-exactly-atomic-css\/\" target=\"_blank\">Let\u2019s Define Exactly What Atomic CSS is<\/a>&#8220;.\n<\/p>\n<p>\nWhile there are certainly proponents of Atomic CSS out there, I&#8217;m not one of them. I find Atomic CSS to be abstracted to the point of nonsense and overrides don&#8217;t really make sense.\n<\/p>\n<p>\nIf you need to set a blue background, the class is easy enough for one project.<\/p>\n<pre><code>.bgr-blue {\n  Background: #00f;\n}<\/code><\/pre>\n<p>The problem comes in as soon as you need to change that background in a subsequent project. You\u2019re left with the difficult choice of either repurposing <code>.bgr-blue<\/code> and set another colour in the CSS or modifying your HTML.<\/p>\n<h3>CSS in JS<\/h3>\n<p>The first line on the <a href=\"http:\/\/cssinjs.org\/\" target=\"_blank\">JSS<\/a> site declares, &#8220;JSS is a more powerful abstraction over CSS&#8221;, which immediately prompts questions such as, &#8220;How exactly does JavaScript improve CSS?&#8221; and &#8220;<a href=\"https:\/\/twitter.com\/brucel\/status\/908021799404875777\" target=\"_blank\">Is CSS broken?<\/a>&#8220;. I&#8217;m in fair agreement with both <a href=\"https:\/\/twitter.com\/brucel\/\" target=\"_blank\">Bruce Lawson<\/a> above and Kevin Ball&#8217;s article &#8220;<a href=\"https:\/\/zendev.com\/2017\/09\/11\/css-in-js.html\" target=\"_blank\">CSS in JS is like replacing a broken screwdriver with your favorite hammer<\/a>&#8220;. JSS has never particularly made sense to me. It&#8217;s as if we never learned from <a href=\"https:\/\/en.wikipedia.org\/wiki\/JavaScript_Style_Sheets\" target=\"_blank\">JSSS<\/a>.<\/p>\n<h3>CSS Modules<\/h3>\n<p>The global scope of CSS can become a problem when CSS scales and <a href=\"https:\/\/github.com\/css-modules\/css-modules\" target=\"_blank\">CSS Modules<\/a> set out to ease exactly that by providing automated prefixing.\n<\/p>\n<p>\nCSS Modules may provide everything you need to scale CSS. Each module contains vanilla CSS (or whatever your like), which is automatically scoped by the framework. Sheer brilliance.\n<\/p>\n<p>\nShould you ever decide to shift away from CSS Modules, the code in each module is ready to go. You would have to manually scope but that&#8217;s it \u2014 no need for a significant rewrite.\n<\/p>\n<p>\nFor widely distributed CSS libraries, platform neutrality is essential, and it&#8217;s at this point that CSS Modules become difficult to implement. While your team may be at the cutting edge of web methodologies, the industry has a long tail. What happens when you inherit a project built with an unsupported framework? Unfortunately, the answer is you don&#8217;t use CSS Modules.<\/p>\n<h3>CSS Blocks<\/h3>\n<p>Relatively new in this space, <a href=\"http:\/\/css-blocks.com\/\" target=\"_blank\">CSS Blocks<\/a> aim a step further beyond the automated scoping of CSS Modules and offer build-time error catching, dead code elimination and static analysis amongst other features. This requires a very tight integration between HTML, JavaScript and CSS, which is great if you have a tight control over your environments.<\/p>\n<h3>Stylable<\/h3>\n<p>Once again fixing the problem (or otherwise) of scope in CSS, <a href=\"https:\/\/github.com\/wix\/stylable\" target=\"_blank\">Stylable<\/a> also has tight programmatic integration with JavaScript and HTML.\n<\/p>\n<p>\nThe rise of CSS Modules, CSS Blocks and Stylable is somewhat reminiscent of the early days of JavaScript frameworks when MooTools, jQuery and YUI all offered variations of the same thing. While much of the power of those frameworks has been integrated into the JavaScript language and browser DOM itself, it will be interesting to see what impact these tools will have on CSS itself.<\/p>\n<h2>The recipe for scalable CSS<\/h2>\n<p>Putting it all together involves a combination of solutions. Not every technique is required for every project and, if you set the right patterns early, you will be able to add complexity as and when you need to.\n<\/p>\n<p>\nYou can see a working version of everything here on <a href=\"https:\/\/github.com\/cliener\/scalable-css\/tree\/master\/demo\/\" target=\"_blank\">GitHub<\/a>.<\/p>\n<h3>Code integrity<\/h3>\n<p>Before you get to writing any code, take the time to set up a linting tool such as <a href=\"https:\/\/stylelint.io\/\" target=\"_blank\">Stylelint<\/a>, <a href=\"https:\/\/github.com\/CSSLint\/csslint\" target=\"_blank\">CSSLint<\/a> or <a href=\"https:\/\/github.com\/sasstools\/sass-lint\" target=\"_blank\">Sass Lint<\/a> if you&#8217;re using a pre-processor. Linters ensure consistent syntax across your project and can catch errors before you get too far. It doesn&#8217;t really matter what rules you set as long as you follow them.<\/p>\n<h3>Naming<\/h3>\n<p>Finding names for things is notoriously difficult. However, the effort spent to get there is well worth it.<\/p>\n<h4>Component naming<\/h4>\n<p>Sparing use of BEM syntax provides a structure to a project&#8217;s components. Rather than applying BEM naming to every element, I find it much easier to only name those elements that require it in order to scope the subsequent styles.\n<\/p>\n<p>\nSimple components may only need blocks to be named:<\/p>\n<pre><code>.nav { \/* navigation component *\/\n  \u2026\n\n  &gt; ul { \/* list directly under the nav *\/\n    \u2026\n\n    &gt; li { \/* list item directly under the list *\/\n      \u2026\n    }\n  }\n\n  a { \/* all anchors inside the navigation block *\/\n    \u2026\n  }\n}<\/code><\/pre>\n<p>More complex components can add BEM naming as and when required:<\/p>\n<pre><code>.tab { \/* tab component *\/\n  &amp;__tab-list { \/* tab list *\/\n    \u2026\n  }\n\n  &amp;__tab { \/* tab item *\/\n    \u2026\n\n    a { \/* anchor inside a tab item *\/\n      \u2026\n    }\n  }\n}<\/code><\/pre>\n<p>In effect, this is a BEM-light implementation, which combines the strength of the pattern with the flexibility of vanilla CSS.<\/p>\n<h4>Namespacing<\/h4>\n<p>Namespacing is used as a way of scoping in programming languages, and there&#8217;s nothing stopping us from using the method in CSS. I favour a broad three-letter namespacing method to clearly show the origin of each class name.\n<\/p>\n<p>\nNamespacing may not be required if you only work on one project. With pre-processed nesting, it&#8217;s easy enough to add at a later date should you find it necessary.\n<\/p>\n<p>\nFor example, in the <em>primary<\/em> project, the namespace will be <code>pri-<\/code>:<\/p>\n<pre><code>\/* without namespacing *\/\n.tab {\n  \u2026\n}\n\n\/* with namespacing *\/\n.pri-tab {\n  \u2026\n}<\/code><\/pre>\n<p>Blocks unique to an inheriting project use their own namespace:<\/p>\n<pre><code>\/* secondary project *\/\n.sec-nav {\n  \u2026\n}<\/code><\/pre>\n<p>When inspecting the corresponding HTML, it&#8217;s immediately clear where the source can be found. Depending on the level of customisation, the odds are you won&#8217;t need to use a secondary namespace very often.<\/p>\n<h3>File structures<\/h3>\n<p>Rather than one big file or several big files, there&#8217;s a lot of benefit in splitting your CSS into logical folders. The original inspiration for this came from <a href=\"https:\/\/smacss.com\/\" target=\"_blank\">SMACSS<\/a>. However, I&#8217;ve adapted the folders and structure over several years of practical use.\n<\/p>\n<p>\nDepending on the complexity of the project, it may help to version each file. Implementing <a href=\"https:\/\/semver.org\/\" target=\"_blank\">Semantic Versioning<\/a> allows you to make breaking changes on an individual file with ease. If you don&#8217;t think you need to reach that point yet, it&#8217;s very easy to append versions to the file names when you do.<\/p>\n<h4>Core<\/h4>\n<p>The <em>Core<\/em> folder is home to the basics for your CSS library: global styles, utilities, typography and variables. Anything that you define once and use frequently belongs here. The content of this folder isn\u2019t expected to change much once it\u2019s written.\n<\/p>\n<p>\nWhile <a href=\"https:\/\/css-tricks.com\/reboot-resets-reasoning\/\" target=\"_blank\">CSS resets<\/a> have been popular in the past, the commonality of modern browsers means you should be fine without one. Be brave and move on from that reset!\n<\/p>\n<p>\nShift all your break points, font faces and colour palettes into a <code>variables<\/code> file. I also set a global <code>measure<\/code>, on which many sizes such as grid-gap, padding and margins are derived and place it here.\n<\/p>\n<p>\nBase typographic sizing also lives here (see <a href=\"http:\/\/typecast.com\/blog\/a-more-modern-scale-for-web-typography\" target=\"_blank\">A More Modern Scale for Web Typography<\/a> for a great reference to get you going) along with any basic structures such as a common grid.<\/p>\n<h4>Blocks<\/h4>\n<p>Home to broad constructs from which the site is built, such as header, content, and footer. Each of these is essentially an <em>organism<\/em> following the <a href=\"http:\/\/atomicdesign.bradfrost.com\/chapter-2\/#organisms\" target=\"_blank\">Atomic Design<\/a> methodology and, from a CSS perspective, the organisms don&#8217;t need to know what components do underneath them limiting the amount of CSS required in each file.<\/p>\n<h4>Components<\/h4>\n<p>Each encapsulated component is contained in the <em>Components<\/em> folder. You could potentially replace this with Atomic Design\u2019s <em>molecules<\/em> and <em>organisms<\/em> or similar depending on the complexity you have.<\/p>\n<h4>All<\/h4>\n<p>Styles that <em>aren&#8217;t<\/em> shared are in the <em>all<\/em> file first, inheriting everything from core, blocks, and components.\n<\/p>\n<p>\nFor simple themed sites, a new <code>all.css<\/code> for the inheriting project will be enough with each override (typically colour) contained in there.\n<\/p>\n<p>\nMore complex themes may require a deeper level of infrastructure, mirroring the base project as required.<\/p>\n<pre><code>tertiary.css\n\/tertiary\/buttons.css\n\/tertiary\/footer.css\n\/tertiary\/header.css\n\/tertiary\/nav.css<\/code><\/pre>\n<p>Notice the structure doesn&#8217;t completely reflect the original project. Only the complexity required has been added.<\/p>\n<h3>Ye Olde Browsers<\/h3>\n<p>It&#8217;s tempting to add legacy browser code inline or in a separate file. However, a better approach is to add the code to the base of the relevant file with as many comments as you can.<\/p>\n<pre><code>.pri-grid {\n  \u2026\n}\n\n\/*\nNo-flex\nSupport for non-flexbox browsers. Remove this once IE10 support is no longer required.\nMinimum width fixed to 900px to make things easier\n*\/\n.no-flexbox {\n  .pri-grid {\n    \u2026\n  }\n}<\/code><\/pre>\n<p>While the scoped class above is derived from <a href=\"https:\/\/modernizr.com\/\" target=\"_blank\">Modernizr<\/a>, feature queries (<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/@supports\" target=\"_blank\">@supports<\/a>) are a native browser method of feature detection to achieve the same concept.<\/p>\n<h3>Theming<\/h3>\n<p>When variables in CSS first became possible with the likes of SCSS, my first thought was to use them for themes.<\/p>\n<pre><code>button {\n  color: $main-colour;\n  background: $secondary-colour;\n  border-color: $main-colour;    \n}<\/code><\/pre>\n<p>This is great until <code>$secondary-color<\/code> clashes with <code>$main-colour<\/code> when you apply a different palette.\n<\/p>\n<p>\nBreaking my rule of investing too heavily in pre-processing variants, I use <a href=\"https:\/\/sass-lang.com\/documentation\/file.SASS_REFERENCE.html#maps\" target=\"_blank\">Sass maps<\/a> and functions to provide structure to colour palettes and make them easier to use.\n<\/p>\n<p>\nDefining a palette for each project and calling them with a function ensures that only colours from your colour palette are used ensuring strict brand adhesion and love from designers.<\/p>\n<pre><code>\/* colour map unique to this theme *\/\n$pri-palette: (\n  neutral: ( \/* neutral palette *\/\n    pure-white: #fff,\n    mid-grey: #808080,\n    pure-black: #000,\n  ),\n  accent: ( \/* accent palette *\/\n    mint: #28765c,\n    corn: #b1ab3c,\n  )\n)\n\n\/* Return colour value from given palette map *\/\n@function colour($palette, $group, $name) {\n  $colour: map-get(map-get($palette, $group), $name);\n\n  \/\/ if the colour isn't found in the provided palette, throw an error\n  @if $colour == null {\n    @error \"Colour #{$name} not found in this palette #{$group}.\";\n  }\n\n  @return $colour;\n}\n\n\/* Project-specific implemetation *\/\n@function pri-colour($group, $name) {\n  @return colour($pri-palette, $group, $name);\n}<\/code><\/pre>\n<p>While that&#8217;s somewhat complicated to set up, implementing the colours is easy.<\/p>\n<pre><code>.pri-button {\n  \/* theme, palette and colour all in one go *\/\n  background: pri-colour(neutral, mid-grey);\n  color: pri-colour(neutral, pure-white);\n  border-color: pri-colour(neutral, pure-black);\n}<\/code><\/pre>\n<p>When overriding these declarations, it&#8217;s immediately clear what has been themed.<\/p>\n<pre><code>.pri-button {\n  background-color: sec-colour(primary, dark-cool-blue);\n  color: pri-colour(neutral, pure-white);\n  border-color: pri-colour(neutral, pure-black);\n}<\/code><\/pre>\n<h3>Levelling up<\/h3>\n<p>To take your CSS library to the next level, give it a name, create a separate versioned source repository, and add an <a href=\"https:\/\/www.npmjs.com\/\" target=\"_blank\">npm<\/a> package. If you don&#8217;t want to open your code to the public, a private package will work just as well.\n<\/p>\n<p>\nYour library will take a life of its own when it exists as its own project.<\/p>\n<h2>To infinity and beyond<\/h2>\n<p>As scale adds complexity to a project, so also does it have a variety of potential solutions.\n<\/p>\n<p>\nThe methods described here have been hammered together over many projects, teams, and years. I recommend that, rather than adopt everything here as is, that you instead choose what works for your project(s), then scale up or down as you need.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Is CSS sprawl giving you a headache? Find out what methods you should be employing to help make sure you can scale up your development practices in a way that keeps your CSS clean and easy to understand.<\/p>\n","protected":false},"author":2,"featured_media":19370,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,24],"tags":[],"class_list":{"0":"post-19356","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-guest-posts","8":"category-web-design"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Scalable CSS: Top tips for writing and maintaining CSS for scale - Heart Internet<\/title>\n<meta name=\"description\" content=\"Find out how to write scalable CSS and make sure your CSS files don&#039;t become an unstructured mess with this in depth guide.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Scalable CSS: Top tips for writing and maintaining CSS for scale - Heart Internet\" \/>\n<meta property=\"og:description\" content=\"Find out how to write scalable CSS and make sure your CSS files don&#039;t become an unstructured mess with this in depth guide.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/\" \/>\n<meta property=\"og:site_name\" content=\"Heart Internet\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/heartinternet\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-09-11T11:30:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.heartinternet.uk\/blog\/wp-content\/uploads\/2018\/09\/man-using-laptop-at-wooden-table-cropped.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"816\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Eliot Chambers-Ostler\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@heartinternet\" \/>\n<meta name=\"twitter:site\" content=\"@heartinternet\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Eliot Chambers-Ostler\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"14 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/\"},\"author\":{\"name\":\"Eliot Chambers-Ostler\",\"@id\":\"https:\/\/heartblog.victory.digital\/#\/schema\/person\/58ed7f27cc0f3ab6e69135742a5eee28\"},\"headline\":\"Scalable CSS: Top tips for writing and maintaining CSS for scale\",\"datePublished\":\"2018-09-11T11:30:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/\"},\"wordCount\":2603,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/heartblog.victory.digital\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.heartinternet.uk\/blog\/wp-content\/uploads\/2018\/09\/man-using-laptop-at-wooden-table-cropped.jpg\",\"articleSection\":[\"Guest Posts\",\"Web Design\"],\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/\",\"url\":\"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/\",\"name\":\"Scalable CSS: Top tips for writing and maintaining CSS for scale - Heart Internet\",\"isPartOf\":{\"@id\":\"https:\/\/heartblog.victory.digital\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.heartinternet.uk\/blog\/wp-content\/uploads\/2018\/09\/man-using-laptop-at-wooden-table-cropped.jpg\",\"datePublished\":\"2018-09-11T11:30:03+00:00\",\"description\":\"Find out how to write scalable CSS and make sure your CSS files don't become an unstructured mess with this in depth guide.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/#primaryimage\",\"url\":\"https:\/\/www.heartinternet.uk\/blog\/wp-content\/uploads\/2018\/09\/man-using-laptop-at-wooden-table-cropped.jpg\",\"contentUrl\":\"https:\/\/www.heartinternet.uk\/blog\/wp-content\/uploads\/2018\/09\/man-using-laptop-at-wooden-table-cropped.jpg\",\"width\":1100,\"height\":816,\"caption\":\"man using laptop at wooden table\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.heartinternet.uk\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Scalable CSS: Top tips for writing and maintaining CSS for scale\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/heartblog.victory.digital\/#website\",\"url\":\"https:\/\/heartblog.victory.digital\/\",\"name\":\"Heart Internet\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/heartblog.victory.digital\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/heartblog.victory.digital\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/heartblog.victory.digital\/#organization\",\"name\":\"Heart Internet\",\"url\":\"https:\/\/heartblog.victory.digital\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/heartblog.victory.digital\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.heartinternet.uk\/blog\/wp-content\/uploads\/2025\/02\/HeartInternet_Logo_Colour.webp\",\"contentUrl\":\"https:\/\/www.heartinternet.uk\/blog\/wp-content\/uploads\/2025\/02\/HeartInternet_Logo_Colour.webp\",\"width\":992,\"height\":252,\"caption\":\"Heart Internet\"},\"image\":{\"@id\":\"https:\/\/heartblog.victory.digital\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/heartinternet\/\",\"https:\/\/x.com\/heartinternet\",\"https:\/\/www.linkedin.com\/company\/heart-internet-ltd\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/heartblog.victory.digital\/#\/schema\/person\/58ed7f27cc0f3ab6e69135742a5eee28\",\"name\":\"Eliot Chambers-Ostler\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/heartblog.victory.digital\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.heartinternet.uk\/blog\/wp-content\/uploads\/2025\/08\/cropped-Eliot-96x96.jpg\",\"contentUrl\":\"https:\/\/www.heartinternet.uk\/blog\/wp-content\/uploads\/2025\/08\/cropped-Eliot-96x96.jpg\",\"caption\":\"Eliot Chambers-Ostler\"},\"url\":\"https:\/\/www.heartinternet.uk\/blog\/author\/eliot-chambers-ostler\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Scalable CSS: Top tips for writing and maintaining CSS for scale - Heart Internet","description":"Find out how to write scalable CSS and make sure your CSS files don't become an unstructured mess with this in depth guide.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/","og_locale":"en_GB","og_type":"article","og_title":"Scalable CSS: Top tips for writing and maintaining CSS for scale - Heart Internet","og_description":"Find out how to write scalable CSS and make sure your CSS files don't become an unstructured mess with this in depth guide.","og_url":"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/","og_site_name":"Heart Internet","article_publisher":"https:\/\/www.facebook.com\/heartinternet\/","article_published_time":"2018-09-11T11:30:03+00:00","og_image":[{"width":1100,"height":816,"url":"https:\/\/www.heartinternet.uk\/blog\/wp-content\/uploads\/2018\/09\/man-using-laptop-at-wooden-table-cropped.jpg","type":"image\/jpeg"}],"author":"Eliot Chambers-Ostler","twitter_card":"summary_large_image","twitter_creator":"@heartinternet","twitter_site":"@heartinternet","twitter_misc":{"Written by":"Eliot Chambers-Ostler","Estimated reading time":"14 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/#article","isPartOf":{"@id":"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/"},"author":{"name":"Eliot Chambers-Ostler","@id":"https:\/\/heartblog.victory.digital\/#\/schema\/person\/58ed7f27cc0f3ab6e69135742a5eee28"},"headline":"Scalable CSS: Top tips for writing and maintaining CSS for scale","datePublished":"2018-09-11T11:30:03+00:00","mainEntityOfPage":{"@id":"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/"},"wordCount":2603,"commentCount":0,"publisher":{"@id":"https:\/\/heartblog.victory.digital\/#organization"},"image":{"@id":"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/#primaryimage"},"thumbnailUrl":"https:\/\/www.heartinternet.uk\/blog\/wp-content\/uploads\/2018\/09\/man-using-laptop-at-wooden-table-cropped.jpg","articleSection":["Guest Posts","Web Design"],"inLanguage":"en-GB","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/","url":"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/","name":"Scalable CSS: Top tips for writing and maintaining CSS for scale - Heart Internet","isPartOf":{"@id":"https:\/\/heartblog.victory.digital\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/#primaryimage"},"image":{"@id":"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/#primaryimage"},"thumbnailUrl":"https:\/\/www.heartinternet.uk\/blog\/wp-content\/uploads\/2018\/09\/man-using-laptop-at-wooden-table-cropped.jpg","datePublished":"2018-09-11T11:30:03+00:00","description":"Find out how to write scalable CSS and make sure your CSS files don't become an unstructured mess with this in depth guide.","breadcrumb":{"@id":"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/"]}]},{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/#primaryimage","url":"https:\/\/www.heartinternet.uk\/blog\/wp-content\/uploads\/2018\/09\/man-using-laptop-at-wooden-table-cropped.jpg","contentUrl":"https:\/\/www.heartinternet.uk\/blog\/wp-content\/uploads\/2018\/09\/man-using-laptop-at-wooden-table-cropped.jpg","width":1100,"height":816,"caption":"man using laptop at wooden table"},{"@type":"BreadcrumbList","@id":"https:\/\/www.heartinternet.uk\/blog\/scalable-css-top-tips-for-writing-and-maintaining-css-for-scale\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.heartinternet.uk\/blog\/"},{"@type":"ListItem","position":2,"name":"Scalable CSS: Top tips for writing and maintaining CSS for scale"}]},{"@type":"WebSite","@id":"https:\/\/heartblog.victory.digital\/#website","url":"https:\/\/heartblog.victory.digital\/","name":"Heart Internet","description":"","publisher":{"@id":"https:\/\/heartblog.victory.digital\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/heartblog.victory.digital\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Organization","@id":"https:\/\/heartblog.victory.digital\/#organization","name":"Heart Internet","url":"https:\/\/heartblog.victory.digital\/","logo":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/heartblog.victory.digital\/#\/schema\/logo\/image\/","url":"https:\/\/www.heartinternet.uk\/blog\/wp-content\/uploads\/2025\/02\/HeartInternet_Logo_Colour.webp","contentUrl":"https:\/\/www.heartinternet.uk\/blog\/wp-content\/uploads\/2025\/02\/HeartInternet_Logo_Colour.webp","width":992,"height":252,"caption":"Heart Internet"},"image":{"@id":"https:\/\/heartblog.victory.digital\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/heartinternet\/","https:\/\/x.com\/heartinternet","https:\/\/www.linkedin.com\/company\/heart-internet-ltd"]},{"@type":"Person","@id":"https:\/\/heartblog.victory.digital\/#\/schema\/person\/58ed7f27cc0f3ab6e69135742a5eee28","name":"Eliot Chambers-Ostler","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/heartblog.victory.digital\/#\/schema\/person\/image\/","url":"https:\/\/www.heartinternet.uk\/blog\/wp-content\/uploads\/2025\/08\/cropped-Eliot-96x96.jpg","contentUrl":"https:\/\/www.heartinternet.uk\/blog\/wp-content\/uploads\/2025\/08\/cropped-Eliot-96x96.jpg","caption":"Eliot Chambers-Ostler"},"url":"https:\/\/www.heartinternet.uk\/blog\/author\/eliot-chambers-ostler\/"}]}},"_links":{"self":[{"href":"https:\/\/www.heartinternet.uk\/blog\/wp-json\/wp\/v2\/posts\/19356","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.heartinternet.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.heartinternet.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.heartinternet.uk\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.heartinternet.uk\/blog\/wp-json\/wp\/v2\/comments?post=19356"}],"version-history":[{"count":0,"href":"https:\/\/www.heartinternet.uk\/blog\/wp-json\/wp\/v2\/posts\/19356\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.heartinternet.uk\/blog\/wp-json\/wp\/v2\/media\/19370"}],"wp:attachment":[{"href":"https:\/\/www.heartinternet.uk\/blog\/wp-json\/wp\/v2\/media?parent=19356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.heartinternet.uk\/blog\/wp-json\/wp\/v2\/categories?post=19356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.heartinternet.uk\/blog\/wp-json\/wp\/v2\/tags?post=19356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}