CINXE.COM
Sass: Code Style Guide
<!doctype html> <html lang="en" class="no-js"> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="description" content="Syntactically Awesome Style Sheets" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Sass: Code Style Guide</title> <link rel="alternate" type="application/atom+xml" href="/feed.xml" /> <link rel="apple-touch-icon" sizes="152x152" type="image/png" href="/icon.png"> <link rel="icon" type="image/png" sizes="152x152" href="/icon.png"> <link rel="icon" type="image/x-icon" href="/favicon.ico" /> <link href="https://fonts.googleapis.com/css?family=Source+Code+Pro::ital,wght@0,400;0,600;1,400|Source+Sans+Pro:300,400,600|Source+Serif+Pro" media="screen" rel="stylesheet" /> <link href="https://cdn.jsdelivr.net/npm/@docsearch/css@alpha" media="screen" rel="stylesheet" /> <link href="/assets/dist/css/sass.css" media="screen" rel="stylesheet" /> <noscript> <link href="/assets/dist/css/noscript.css" media="screen" rel="stylesheet" /> </noscript> <!-- Google Analytics (https://developers.google.com/analytics/devguides/collection/gtagjs). --> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-535380-14"></script> <script> window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } gtag('js', new Date()); gtag('config', 'UA-535380-14'); </script> </head><body data-layout="body" class="styleguide code"> <!--[if lt IE 9]> <p class="browserupgrade"> You are using an <strong>outdated</strong> browser. Please <a href="https://browsehappy.com/">upgrade your browser</a> to improve your experience and security. </p> <![endif]--> <header class="sl-r-banner" itemtype="https://schema.org/WPHeader" itemscope="itemscope" role="banner"> <div class="sl-c-alert" style="--sl-background--alert: black"> <div class="sl-l-container"> <p><strong>Free Palestine</strong></p> </div> </div> <div class="sl-c-pop-stripe"></div> <div class="sl-l-container"> <div class="sl-l-grid sl-l-grid--full sl-l-large-grid--fit sl-l-large-grid--center sl-l-large-grid--gutters"> <p class="sl-l-grid__column sl-r-banner__brand"> <a href="/"><img height="48" alt="Sass" src="/assets/img/logos/logo.svg"></a> </p> <nav class="sl-r-banner__navigation sl-l-grid__column sl-l-large-grid sl-l-large-grid__column--auto-size sl-c-list-horizontal-wrapper" itemtype="https://schema.org/SiteNavigationElement" itemscope="itemscope" role="navigation" aria-label="Site navigation"> <ul> <li><a href="/playground">Playground</a></li> <li><a href="/install">Install</a></li> <li><a href="/guide">Learn Sass</a></li> <li><a href="/blog">Blog</a></li> <li><a href="/documentation">Documentation</a></li> <li><a href="/community">Get Involved</a></li> <li> <div id="docsearch"></div> </li> </ul> </nav> </div> </div> </header> <main class="content" id="main-content" itemprop="mainContentOfPage" role="main"> <h1 class="sl-l-container">Code Style Guide</h1> <div class="sl-l-container sl-color--white-background sl-l-section"> <div class="sl-l-medium-holy-grail"> <div class="sl-l-medium-holy-grail__body"> <nav class="sl-l-medium-holy-grail__navigation" role="navigation" aria-label="Content navigation"> <nav class="sl-c-list-navigation-wrapper"> <h3><a href="/styleguide">Style Guide</a></h3> <ul> <li><a href="/styleguide/brand">Brand</a></li> <li><a href="/styleguide/color">Color</a></li> <li><a href="/styleguide/typography">Typography</a></li> <li><a href="/styleguide/layout">Layout</a></li> <li><a href="/styleguide/components">Components</a></li> <li><a href="/styleguide/code">Code</a></li> </ul> </nav> </nav> <div class="sl-l-medium-holy-grail__main"> <div class="sl-l-container sl-l-container--small"> <div class="sl-c-introduction"> <p>If you would like to contribute to this website’s code, please adhere to the following code style<span class="widont"> </span>guidelines.</p> </div> <ul> <li>Please try to keep lines at a maximum of 80<span class="widont"> </span>characters.</li> <li>Favor clarity over brevity in naming<span class="widont"> </span>anything.</li> <li>Pages, partials, and layouts end with <code>.liquid</code> or <code>.md</code>.</li> </ul> <h2 id="markup" tabindex="-1">Markup<a class="anchor" href="#markup"><span class="visuallyhidden">Markup permalink</span></a></h2> <p>For the most part, we use <a href="https://liquidjs.com/">LiquidJS</a> and <a href="https://daringfireball.net/projects/markdown/">Markdown</a> for writing markup. If you need to use regular <span class="caps">HTML</span> anywhere, write <span class="caps">HTML5</span>, but favor a strict <span class="caps">XHTML</span><span class="widont"> </span>style:</p> <ul> <li>Use well-formed markup; elements are nested properly and do not<span class="widont"> </span>overlap.</li> <li>Write elements and attributes in<span class="widont"> </span>lowercase.</li> <li>Quote all attributes.</li> <li>Self-close empty elements with a space before the trailing slash: (<code><hr /></code>)</li> </ul> <h2 id="style" tabindex="-1">Style<a class="anchor" href="#style"><span class="visuallyhidden">Style permalink</span></a></h2> <p>This website uses Sass in the <span class="caps">SCSS</span> syntax. Make sure you’re using the classes that we have to offer before rewriting something, unless you can justify<span class="widont"> </span>otherwise.</p> <ul> <li>Use the style <a href="https://bradfrost.com/blog/post/css-architecture-for-design-systems/">Brad Frost writes about</a> for clarity: <ul> <li>Note that older classes do not use this style yet, but we will refactor over<span class="widont"> </span>time.</li> <li>Use a <code>sl-</code> global namespace.</li> <li>Use the class prefixes <a href="https://csswizardry.com/2015/08/bemit-taking-the-bem-naming-convention-a-step-further/">Harry Roberts</a> advocates, though we are using a much simpler set: <ul> <li><code>c-</code> is for <strong>components</strong>. Example: <code>sl-c-card</code>.</li> <li><code>l-</code> is for <strong>layouts</strong>. Example: <code>sl-l-grid</code>.</li> <li><code>is-</code> and <code>has-</code> for states. Example: <code>sl-is-active</code>.</li> <li><code>js-</code> is for classes specifically created for JavaScript targeting. Example: <code>sl-js-toggle-navigation</code>.</li> </ul> </li> <li>Use the <a href="https://getbem.com/introduction/"><span class="caps">BEM</span></a> syntax. <ul> <li><strong>Block</strong> – the overall component object. Example: <code>sl-c-card</code>.</li> <li><strong>Element</strong> – any child of the block. Example: <code>sl-c-card__header</code>.</li> <li><strong>Modifier</strong> – any variation. This can be put on a block. Example: <code>sl-c-card--primary</code>. It can also be put on an element. Example: <code>sl-c-card__header--large</code>.</li> </ul> </li> </ul> </li> <li>Keep classes as flat as possible, and avoid nesting too<span class="widont"> </span>deep.</li> <li>Avoid using element selectors <strong>unless</strong> you’re using a wrapper utility to target everything inside (such as a class around a block of markdown or other longform text to style all its elements properly). This is specifically for when it doesn’t make sense to use classes. Be mindful when do this. We can give you feedback in a code review for instances like<span class="widont"> </span>this.</li> <li>For naming of variables, mixins, placeholder selectors, or classes, use the general-to-specific approach. See <a href="https://webdesign.tutsplus.com/articles/quick-tip-name-your-sass-variables-modularly--webdesign-13364">this article</a> for more<span class="widont"> </span>details.</li> <li>Write comma-delimited selectors on separate<span class="widont"> </span>lines.</li> </ul> </div> </div> </div> </div> </div> <div class="sl-c-alert"> <div class="sl-l-container sl-c-list-horizontal-wrapper" aria-labelledby="release-nav"> <ul class="sl-l-grid--justify-center"> <li id="release-nav">Current Releases:</li> <li><span class="release-name"><a href="/dart-sass">Dart Sass</a> <a href="https://github.com/sass/dart-sass/releases/tag/1.85.0">1.85.0</a></span></li> <li><span class="release-name"><a href="/libsass">LibSass</a> <a href="https://github.com/sass/libsass/releases/tag/3.6.6">3.6.6</a></span></li> <li><span class="release-name"><a href="/ruby-sass">Ruby Sass</a> <span aria-label="coffin" role="presentation">⚰</span></span></li> <li class="sl-l-grid__column sl-l-large-grid__column--auto-size"><a href="/implementation">Implementation Guide</a></li> </ul> </div> </div> </main> <footer class="site-footer contentinfo" itemtype="https://schema.org/WPFooter" itemscope="itemscope" role="contentinfo"> <div class="sl-l-container"> <div class="sl-l-grid sl-l-grid--full sl-l-large-grid--fit sl-l-large-grid--center sl-l-large-grid--gutters"> <div class="sl-l-grid__column"> <p>Sass © 2006–2025 the Sass team, and numerous contributors. It is available for use and modification under the <a href="https://github.com/sass/dart-sass/blob/main/LICENSE"><span class="caps">MIT</span><span class="widont"> </span>License</a>.</p> <nav class="sl-c-list-horizontal-wrapper sl-c-list-wrap"> <ul> <li><a href="https://github.com/sass">Sass on GitHub</a></li> <li><a href="https://github.com/sass/sass-site">Website Source Code</a></li> <li><a href="/styleguide">Style Guide</a></li> <li><a href="/community-guidelines">Community Guidelines</a></li> </ul> </nav> </div> <div class="sl-l-grid__column sl-l-large-grid__column--auto-size sl-l-large-grid--justify-right sl-c-footer-link-grid"> <a class="sl-c-button sl-c-button--icon sl-c-button--icon-text" href="https://front-end.social/@sass"><svg width="20" height="20" viewBox="0 0 61 65" fill="none" xmlns="http://www.w3.org/2000/svg" > <path d="M60.7539 14.3904C59.8143 7.40642 53.7273 1.90257 46.5117 0.836066C45.2943 0.655854 40.6819 0 29.9973 0H29.9175C19.2299 0 16.937 0.655854 15.7196 0.836066C8.70488 1.87302 2.29885 6.81852 0.744617 13.8852C-0.00294988 17.3654 -0.0827298 21.2237 0.0561464 24.7629C0.254119 29.8384 0.292531 34.905 0.753482 39.9598C1.07215 43.3175 1.62806 46.6484 2.41704 49.9276C3.89445 55.9839 9.87499 61.0239 15.7344 63.0801C22.0077 65.2244 28.7542 65.5804 35.2184 64.1082C35.9295 63.9428 36.6318 63.7508 37.3252 63.5321C38.8971 63.0329 40.738 62.4745 42.0913 61.4937C42.1099 61.4799 42.1251 61.4621 42.1358 61.4417C42.1466 61.4212 42.1526 61.3986 42.1534 61.3755V56.4773C42.153 56.4557 42.1479 56.4345 42.1383 56.4151C42.1287 56.3958 42.1149 56.3788 42.0979 56.3655C42.0809 56.3522 42.0611 56.3429 42.04 56.3382C42.019 56.3335 41.9971 56.3336 41.9761 56.3384C37.8345 57.3276 33.5905 57.8234 29.3324 57.8156C22.0045 57.8156 20.0336 54.3384 19.4693 52.8908C19.0156 51.6397 18.7275 50.3346 18.6124 49.0088C18.6112 48.9866 18.6153 48.9643 18.6243 48.9439C18.6333 48.9236 18.647 48.9056 18.6643 48.8915C18.6816 48.8774 18.7019 48.8675 18.7237 48.8628C18.7455 48.858 18.7681 48.8585 18.7897 48.8641C22.8622 49.8465 27.037 50.3423 31.2265 50.3412C32.234 50.3412 33.2387 50.3412 34.2463 50.3146C38.4598 50.1964 42.9009 49.9808 47.0465 49.1713C47.1499 49.1506 47.2534 49.1329 47.342 49.1063C53.881 47.8507 60.1038 43.9097 60.7362 33.9301C60.7598 33.5372 60.8189 29.8148 60.8189 29.4071C60.8218 28.0215 61.2651 19.5781 60.7539 14.3904Z" fill="url(#paint0_linear_89_8)" /> <path d="M50.3943 22.237V39.5876H43.5185V22.7481C43.5185 19.2029 42.0411 17.3949 39.036 17.3949C35.7325 17.3949 34.0778 19.5338 34.0778 23.7585V32.9759H27.2434V23.7585C27.2434 19.5338 25.5857 17.3949 22.2822 17.3949C19.2949 17.3949 17.8027 19.2029 17.8027 22.7481V39.5876H10.9298V22.237C10.9298 18.6918 11.835 15.8754 13.6453 13.7877C15.5128 11.7049 17.9623 10.6355 21.0028 10.6355C24.522 10.6355 27.1813 11.9885 28.9542 14.6917L30.665 17.5633L32.3788 14.6917C34.1517 11.9885 36.811 10.6355 40.3243 10.6355C43.3619 10.6355 45.8114 11.7049 47.6847 13.7877C49.4931 15.8734 50.3963 18.6899 50.3943 22.237Z" fill="white" /> <defs> <linearGradient id="paint0_linear_89_8" x1="30.5" y1="0" x2="30.5" y2="65" gradientUnits="userSpaceOnUse" > <stop stop-color="#6364FF" /> <stop offset="1" stop-color="#563ACC" /> </linearGradient> </defs> </svg> @sass@front-end.social </a> <a class="sl-image-link" href="https://www.netlify.com"><img alt="Deploys by Netlify" src="https://www.netlify.com/v3/img/components/netlify-color-bg.svg"/></a> </div> </div> </div> </footer> <script src="https://cdn.jsdelivr.net/npm/@docsearch/js@alpha"></script> <script> docsearch({ container: '#docsearch', appId: 'Q9MULQONSV', indexName: 'sass-lang', apiKey: '2ebc7881b79986f58dc2f424769bf3fc', transformItems: function(hits) { var domain = window.location.origin + "/"; hits.forEach(function(hit) { if (! hit.url.startsWith(domain)) { hit.url = hit.url.replace(/^https?:\/\/[^\/]+\//, domain); } }); return hits; } }); </script> <script src="/assets/dist/js/sass.js"></script> <!-- Current page: /styleguide/code/ --> </body> </html>