Episode Summary
Executive Summary: Syntax hosts Wes Bos and Scott Tolinski explain CSS custom properties, commonly called CSS variables: how to declare and scope them, and why their runtime flexibility makes them useful for theming, JavaScript-driven updates, and modifying parts of compound CSS values. They also cover calculations and transitions, while noting that Internet Explorer 11 lacks support and that PostCSS can provide a build-time fallback.
Main Topics: Custom-property syntax and scope: The hosts show how to define properties with names beginning with --, reference them using var(), and scope them globally with :root or locally to a selector and its descendants. Normal CSS cascade and specificity rules apply. Runtime updates and JavaScript integration: Unlike preprocessor variables that are resolved during compilation, custom properties remain in the browser’s CSS and can be changed through JavaScript. Updates affect every applicable use within the property’s scope. Design systems and theming: Custom properties can represent semantic roles such as primary, accent, or secondary colors, making it easier to change an application’s theme by updating a small set of values rather than searching and replacing individual declarations. Managing compound CSS values and animation: Variables let developers change individual components of transforms, shadows, or other compound values without copying and re-declaring the entire property. They can also be used with calc() and transitions to produce variable-driven animations. Compatibility limitations and fallback options: Internet Explorer 11 does not support custom properties, and CSS has limited fallback and polyfill options. The hosts describe duplicate declarations as a manual fallback and mention a PostCSS plugin that can emit static values while retaining custom-property declarations. Relationship to preprocessors and future CSS: The speakers see native custom properties as bringing familiar preprocessor capabilities into CSS while adding runtime behavior. They also discuss anticipated CSS color functions, while acknowledging that preprocessors may remain useful as CSS continues to evolve.
Key Arguments: Custom properties are especially valuable because they are native CSS values resolved in the browser, so they can change at runtime rather than being fixed when a preprocessor compiles the stylesheet. Their behavior follows the CSS cascade and inheritance model: properties can be scoped to :root or a component and overridden in more specific or nested contexts. Semantic variables support maintainable theming; changing a handful of design tokens can restyle an application without editing every rule that uses those colors. Variables can isolate components of compound values such as transforms and box shadows, avoiding repeated declarations that are easy to let drift out of sync. JavaScript can update custom properties through style APIs, enabling application state or user choices to control CSS without separately rewriting every affected style. IE11 support remains a practical constraint. Duplicate declarations or a build-time PostCSS transformation can help, but the speakers stress that CSS lacks the comprehensive polyfill options developers may have for JavaScript.
Data Points: IE usage on one course website: About 0.3% of roughly 20,000 visitors in one week; the discussion refers to 50 and later to 58 IE visitors - The hosts checked analytics for an advanced React course and report slightly inconsistent counts in the conversation. IE11 share among that site's IE visitors: 53 of 58 - The remaining five visitors were reported as using IE8. IE usage on the other host's site: 0.25% - The host says about 70% of those Internet Explorer users were on IE11. Browser mix on one site: Chrome 74%, Safari 16%, Firefox 5% - Approximate analytics figures shared during the discussion of whether supporting older browsers is worthwhile. Browser mix on the other site: Chrome 75%, Safari 15%, Firefox 5% - A second set of approximate analytics figures; the speakers also say Edge usage exceeded IE usage. Freelancing-course discount: 25% off with code SYNTAX - Sponsor promotion for Kyle Prinslu’s freelancing bundle, mentioned in the episode introduction.
Pivotal Quotes: "the interesting aspects of CSS custom properties is really just that it's just CSS." — Scott Tolinski: He emphasizes that custom properties work with familiar CSS rules and do not require a separate styling system. "you don't have to change the way you're writing your CSS or organizing it." — Wes Bos: He explains how changing a small set of custom properties can make application-wide theming easier. "there's not a lot of great fallbacks for CSS, whereas JavaScript, you have access to the actual prototype of everything and you can polyfill almost everything." — Wes Bos: He summarizes the compatibility challenge posed by browsers such as IE11.
Implications: Custom properties can make CSS more adaptable and easier to theme, especially when JavaScript or user preferences must change styles at runtime. Teams should assess browser analytics and decide whether to accept limited legacy support or add fallbacks through duplicate declarations or a build tool.
About Syntax - Tasty Web Development Treats
View all episodes from Syntax - Tasty Web Development Treats