{"id":2124,"date":"2016-09-07T08:03:16","date_gmt":"2016-09-07T06:03:16","guid":{"rendered":"https:\/\/intu.io\/blog\/?p=2124"},"modified":"2016-09-07T15:28:29","modified_gmt":"2016-09-07T13:28:29","slug":"sass-css-custom-properties","status":"publish","type":"post","link":"https:\/\/intu.io\/blog\/sass-css-custom-properties\/","title":{"rendered":"SASS Variables vs. CSS Custom Properties"},"content":{"rendered":"<p>Maybe you&#8217;ve heard it: There&#8217;s a new game in town. The town being CSS and the game is called variables. For a while, the only options to make CSS more manageable with the help of variables were <strong>SASS<\/strong> and <strong>LESS<\/strong>, which do have subtle differences in how they handle variables, but essentially do the same thing. Now most modern browsers (except IE) <a href=\"http:\/\/caniuse.com\/#feat=css-variables\" target=\"_blank\">support<\/a>\u00a0variables in the form of <strong>CSS custom properties<\/strong>.<\/p>\n<p>So what does that mean for CSS architecture? Do you have to migrate to the new variable format from your trusted SASS variables or is a new preprocessor like <a href=\"http:\/\/cssnext.io\/\" target=\"_blank\">CSS Next<\/a> the answer to this situation?<\/p>\n<p>To answer this question, you have to understand that SASS variables and CSS custom properties <strong>live in very different worlds<\/strong> which give them different possibilities: SASS variables are replaced with their values as the preprocessor produces its CSS output long before the browser interprets the code, while\u00a0CSS custom properties are evaluated by the browser at runtime.<\/p>\n<p>And while SASS variables closely model the syntax you might be used from traditional programming languages, CSS custom properties <strong>introduce a new syntax<\/strong> which frankly is as awkward as their title: each variable has to start with a double dash and for a variable to be evaluated it needs to be wrapped in <code>var()<\/code>, comparable to how <code>attr()<\/code> works with data-attributes:<\/p>\n<pre class=\"language-css\"><code class=\"language-css\">:root {\r\n--my-blue: #00f;\r\n}\r\n\r\n.button {\r\nbackground-color: var(--my-blue);\r\n}\r\n<\/code><\/pre>\n<p>In the example, the variable is set in the root scope, which cascades down into every element, but can be overwritten along the way. So if you redefine the variable <code>--my-blue<\/code> in <code>.button<\/code>, <code>&lt;button class=\"button\"&gt;&lt;\/button&gt;<\/code> and all its children will use the new value. Here lies a major difference to SASS variables, which have no knowledge of the DOM-tree whatsoever.<\/p>\n<p>Also, media-queries can override the default root scope, which allows for very powerful changes at a breakpoint. For example, increasing the default paddings of a lot of modules for bigger screens at once \u2013 or changing a lot of font-sizes depending on the screen size. Both of these changes are possible without CSS custom properties, but they result in\u00a0a large number\u00a0of media queries, if a lot of different modules need to be changed. Now all that needs to be modified\u00a0is one variable:<\/p>\n<p class=\"codepen\" data-height=\"335\" data-theme-id=\"0\" data-slug-hash=\"ORPOWA\" data-default-tab=\"css,result\" data-user=\"Ansimorph\" data-embed-version=\"2\">See the Pen <a href=\"http:\/\/codepen.io\/Ansimorph\/pen\/ORPOWA\/\" target=\"_blank\">Responsive CSS Custom Properties<\/a> by Bjorn Ganslandt (<a href=\"http:\/\/codepen.io\/Ansimorph\" target=\"_blank\">@Ansimorph<\/a>) on <a href=\"http:\/\/codepen.io\" target=\"_blank\">CodePen<\/a>.<\/p>\n<p><script async src=\"\/\/assets.codepen.io\/assets\/embed\/ei.js\"><\/script><\/p>\n<p>Similarly, <strong>theming<\/strong> is possible with the current CSS tools, but poses a big architectural challenge: If\u00a0SASS is being used for theming, it makes\u00a0real-time previews very difficult, because the code has to be preprocessed on a server, or a lot of CSS needs to be overwritten with theme-specific classes, making the code hard to maintain. CSS variables allow for themes that are easy to maintain, and that can be previewed by a user in real time with minimal effort.<\/p>\n<p>The drawback of evaluation in the browser is that SASS can not do anything to variables such as <code>--my-blue<\/code>. No <code>lighten<\/code> function or mixin can access the value that will fill the variable at runtime, because is it unknown while preprocessing. This means that manipulations of the CSS Custom Property are limited to <code>calc<\/code>, which is not much, once you&#8217;re used to the functionality SASS provides. Eventually, CSS will get its own <a href=\"https:\/\/drafts.csswg.org\/css-color\/#modifying-colors\" target=\"_blank\">color() function<\/a>, but even then CSS will be no match for the functionality and readability of SASS.<\/p>\n<p>Where do <strong>PostCSS<\/strong> and <strong>CSS Next<\/strong> come into all of this? CSS Next is built on top of PostCSS to allow the usage of future CSS syntax, which it transpiles into CSS that current browsers understand. This includes both the <code>color()<\/code> function, and CSS custom properties. It is however bound to\u00a0the same limitations as SASS, because its output is plain CSS without any knowledge of the DOM or changes at runtime. So CSS Next allows you to use CSS custom properties today in all browsers, but it removes the aspects that make them truly interesting, leaving only the new syntax.<\/p>\n<p><strong>Understanding the strengths and weaknesses of SASS\u00a0variables<\/strong> allows to decide when to use which technology. If your project requires dynamic theming, CSS custom properties will be the way to go very shortly. Otherwise, SASS variables are still a good choice, because they give you access to the power of a wide range of\u00a0SASS functions. Since the two techniques are by no means exclusive, dynamic variables can be fed with content from SASS variables allowing you to sprinkle dynamic magic throughout your project \u2013 comparable to <code>currentColor<\/code> which also lives happily in many SASS projects.<\/p>\n<p><strong>CSS Next<\/strong> is currently only a good solution <strong>if you want to get used to the syntax<\/strong>. Given how long the combination of CSS custom properties and functions tend to get, I can imagine that even when CSS has caught up with SASS in terms of functionality, some syntactic sugar will still be in high demand. And I will not be surprised if PostCSS provides that sugar in the future.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Maybe you&#8217;ve heard it: There&#8217;s a new game in town. The town being CSS and the game is called variables. For a while, the only options to make CSS more manageable with the help of variables were SASS and LESS, which do have subtle differences in how they handle variables, but essentially do the same [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2162,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,3],"tags":[30,195,196,199,198,166,194,197,136,141],"class_list":["post-2124","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-allgemein","category-blog","tag-css","tag-css-next","tag-css-variables","tag-future-friendly","tag-less","tag-mobile-web","tag-postcss","tag-sass","tag-ux","tag-web-design"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SASS Variables vs. CSS Custom Properties - intuio Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/intu.io\/blog\/sass-css-custom-properties\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SASS Variables vs. CSS Custom Properties - intuio Blog\" \/>\n<meta property=\"og:description\" content=\"Maybe you&#8217;ve heard it: There&#8217;s a new game in town. The town being CSS and the game is called variables. For a while, the only options to make CSS more manageable with the help of variables were SASS and LESS, which do have subtle differences in how they handle variables, but essentially do the same [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/intu.io\/blog\/sass-css-custom-properties\/\" \/>\n<meta property=\"og:site_name\" content=\"intuio Blog\" \/>\n<meta property=\"article:published_time\" content=\"2016-09-07T06:03:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-09-07T13:28:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/intu.io\/blog\/wp-content\/uploads\/2016\/09\/Screen-Shot-2016-09-07-at-11.53.19.png\" \/>\n\t<meta property=\"og:image:width\" content=\"717\" \/>\n\t<meta property=\"og:image:height\" content=\"329\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"intuio\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@intuio\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"intuio\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/intu.io\\\/blog\\\/sass-css-custom-properties\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/intu.io\\\/blog\\\/sass-css-custom-properties\\\/\"},\"author\":{\"name\":\"intuio\",\"@id\":\"https:\\\/\\\/intu.io\\\/blog\\\/#\\\/schema\\\/person\\\/9be7154f89eb1c979c8e224658ddd11e\"},\"headline\":\"SASS Variables vs. CSS Custom Properties\",\"datePublished\":\"2016-09-07T06:03:16+00:00\",\"dateModified\":\"2016-09-07T13:28:29+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/intu.io\\\/blog\\\/sass-css-custom-properties\\\/\"},\"wordCount\":815,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/intu.io\\\/blog\\\/sass-css-custom-properties\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/intu.io\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/09\\\/Screen-Shot-2016-09-07-at-11.53.19.png\",\"keywords\":[\"css\",\"css next\",\"css variables\",\"future-friendly\",\"less\",\"mobile web\",\"postcss\",\"sass\",\"ux\",\"web design\"],\"articleSection\":[\"Allgemein\",\"Blog\"],\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/intu.io\\\/blog\\\/sass-css-custom-properties\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/intu.io\\\/blog\\\/sass-css-custom-properties\\\/\",\"url\":\"https:\\\/\\\/intu.io\\\/blog\\\/sass-css-custom-properties\\\/\",\"name\":\"SASS Variables vs. CSS Custom Properties - intuio Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/intu.io\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/intu.io\\\/blog\\\/sass-css-custom-properties\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/intu.io\\\/blog\\\/sass-css-custom-properties\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/intu.io\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/09\\\/Screen-Shot-2016-09-07-at-11.53.19.png\",\"datePublished\":\"2016-09-07T06:03:16+00:00\",\"dateModified\":\"2016-09-07T13:28:29+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/intu.io\\\/blog\\\/#\\\/schema\\\/person\\\/9be7154f89eb1c979c8e224658ddd11e\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/intu.io\\\/blog\\\/sass-css-custom-properties\\\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/intu.io\\\/blog\\\/sass-css-custom-properties\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/intu.io\\\/blog\\\/sass-css-custom-properties\\\/#primaryimage\",\"url\":\"https:\\\/\\\/intu.io\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/09\\\/Screen-Shot-2016-09-07-at-11.53.19.png\",\"contentUrl\":\"https:\\\/\\\/intu.io\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/09\\\/Screen-Shot-2016-09-07-at-11.53.19.png\",\"width\":717,\"height\":329},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/intu.io\\\/blog\\\/sass-css-custom-properties\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/intu.io\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SASS Variables vs. CSS Custom Properties\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/intu.io\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/intu.io\\\/blog\\\/\",\"name\":\"intuio Blog\",\"description\":\"Blogging on User Experience Design, Usability Engineering &amp; User Interface Development\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/intu.io\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/intu.io\\\/blog\\\/#\\\/schema\\\/person\\\/9be7154f89eb1c979c8e224658ddd11e\",\"name\":\"intuio\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/201c39808860b4ea7fccc26a8778ccaba7aa737fe4d7bd79868bcc8f0e9ba6c8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/201c39808860b4ea7fccc26a8778ccaba7aa737fe4d7bd79868bcc8f0e9ba6c8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/201c39808860b4ea7fccc26a8778ccaba7aa737fe4d7bd79868bcc8f0e9ba6c8?s=96&d=mm&r=g\",\"caption\":\"intuio\"},\"sameAs\":[\"https:\\\/\\\/x.com\\\/intuio\"],\"url\":\"https:\\\/\\\/intu.io\\\/blog\\\/author\\\/intuio\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SASS Variables vs. CSS Custom Properties - intuio Blog","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:\/\/intu.io\/blog\/sass-css-custom-properties\/","og_locale":"en_GB","og_type":"article","og_title":"SASS Variables vs. CSS Custom Properties - intuio Blog","og_description":"Maybe you&#8217;ve heard it: There&#8217;s a new game in town. The town being CSS and the game is called variables. For a while, the only options to make CSS more manageable with the help of variables were SASS and LESS, which do have subtle differences in how they handle variables, but essentially do the same [&hellip;]","og_url":"https:\/\/intu.io\/blog\/sass-css-custom-properties\/","og_site_name":"intuio Blog","article_published_time":"2016-09-07T06:03:16+00:00","article_modified_time":"2016-09-07T13:28:29+00:00","og_image":[{"width":717,"height":329,"url":"https:\/\/intu.io\/blog\/wp-content\/uploads\/2016\/09\/Screen-Shot-2016-09-07-at-11.53.19.png","type":"image\/png"}],"author":"intuio","twitter_card":"summary_large_image","twitter_creator":"@intuio","twitter_misc":{"Written by":"intuio","Estimated reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/intu.io\/blog\/sass-css-custom-properties\/#article","isPartOf":{"@id":"https:\/\/intu.io\/blog\/sass-css-custom-properties\/"},"author":{"name":"intuio","@id":"https:\/\/intu.io\/blog\/#\/schema\/person\/9be7154f89eb1c979c8e224658ddd11e"},"headline":"SASS Variables vs. CSS Custom Properties","datePublished":"2016-09-07T06:03:16+00:00","dateModified":"2016-09-07T13:28:29+00:00","mainEntityOfPage":{"@id":"https:\/\/intu.io\/blog\/sass-css-custom-properties\/"},"wordCount":815,"commentCount":0,"image":{"@id":"https:\/\/intu.io\/blog\/sass-css-custom-properties\/#primaryimage"},"thumbnailUrl":"https:\/\/intu.io\/blog\/wp-content\/uploads\/2016\/09\/Screen-Shot-2016-09-07-at-11.53.19.png","keywords":["css","css next","css variables","future-friendly","less","mobile web","postcss","sass","ux","web design"],"articleSection":["Allgemein","Blog"],"inLanguage":"en-GB","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/intu.io\/blog\/sass-css-custom-properties\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/intu.io\/blog\/sass-css-custom-properties\/","url":"https:\/\/intu.io\/blog\/sass-css-custom-properties\/","name":"SASS Variables vs. CSS Custom Properties - intuio Blog","isPartOf":{"@id":"https:\/\/intu.io\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/intu.io\/blog\/sass-css-custom-properties\/#primaryimage"},"image":{"@id":"https:\/\/intu.io\/blog\/sass-css-custom-properties\/#primaryimage"},"thumbnailUrl":"https:\/\/intu.io\/blog\/wp-content\/uploads\/2016\/09\/Screen-Shot-2016-09-07-at-11.53.19.png","datePublished":"2016-09-07T06:03:16+00:00","dateModified":"2016-09-07T13:28:29+00:00","author":{"@id":"https:\/\/intu.io\/blog\/#\/schema\/person\/9be7154f89eb1c979c8e224658ddd11e"},"breadcrumb":{"@id":"https:\/\/intu.io\/blog\/sass-css-custom-properties\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/intu.io\/blog\/sass-css-custom-properties\/"]}]},{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/intu.io\/blog\/sass-css-custom-properties\/#primaryimage","url":"https:\/\/intu.io\/blog\/wp-content\/uploads\/2016\/09\/Screen-Shot-2016-09-07-at-11.53.19.png","contentUrl":"https:\/\/intu.io\/blog\/wp-content\/uploads\/2016\/09\/Screen-Shot-2016-09-07-at-11.53.19.png","width":717,"height":329},{"@type":"BreadcrumbList","@id":"https:\/\/intu.io\/blog\/sass-css-custom-properties\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/intu.io\/blog\/"},{"@type":"ListItem","position":2,"name":"SASS Variables vs. CSS Custom Properties"}]},{"@type":"WebSite","@id":"https:\/\/intu.io\/blog\/#website","url":"https:\/\/intu.io\/blog\/","name":"intuio Blog","description":"Blogging on User Experience Design, Usability Engineering &amp; User Interface Development","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/intu.io\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/intu.io\/blog\/#\/schema\/person\/9be7154f89eb1c979c8e224658ddd11e","name":"intuio","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/secure.gravatar.com\/avatar\/201c39808860b4ea7fccc26a8778ccaba7aa737fe4d7bd79868bcc8f0e9ba6c8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/201c39808860b4ea7fccc26a8778ccaba7aa737fe4d7bd79868bcc8f0e9ba6c8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/201c39808860b4ea7fccc26a8778ccaba7aa737fe4d7bd79868bcc8f0e9ba6c8?s=96&d=mm&r=g","caption":"intuio"},"sameAs":["https:\/\/x.com\/intuio"],"url":"https:\/\/intu.io\/blog\/author\/intuio\/"}]}},"_links":{"self":[{"href":"https:\/\/intu.io\/blog\/wp-json\/wp\/v2\/posts\/2124","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/intu.io\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/intu.io\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/intu.io\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/intu.io\/blog\/wp-json\/wp\/v2\/comments?post=2124"}],"version-history":[{"count":30,"href":"https:\/\/intu.io\/blog\/wp-json\/wp\/v2\/posts\/2124\/revisions"}],"predecessor-version":[{"id":2164,"href":"https:\/\/intu.io\/blog\/wp-json\/wp\/v2\/posts\/2124\/revisions\/2164"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/intu.io\/blog\/wp-json\/wp\/v2\/media\/2162"}],"wp:attachment":[{"href":"https:\/\/intu.io\/blog\/wp-json\/wp\/v2\/media?parent=2124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/intu.io\/blog\/wp-json\/wp\/v2\/categories?post=2124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/intu.io\/blog\/wp-json\/wp\/v2\/tags?post=2124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}