<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Francesco Improta</title>
    <description>The latest articles on DEV Community by Francesco Improta (@zetareticoli).</description>
    <link>https://dev.to/zetareticoli</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F133021%2F950a5df8-def9-4317-b07e-0ec462fb8b1c.jpg</url>
      <title>DEV Community: Francesco Improta</title>
      <link>https://dev.to/zetareticoli</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zetareticoli"/>
    <language>en</language>
    <item>
      <title>Why your design tokens and your CSS are probably out of sync (and how to check)</title>
      <dc:creator>Francesco Improta</dc:creator>
      <pubDate>Wed, 04 Mar 2026 16:27:31 +0000</pubDate>
      <link>https://dev.to/zetareticoli/why-your-design-tokens-and-your-css-are-probably-out-of-sync-and-how-to-check-3od6</link>
      <guid>https://dev.to/zetareticoli/why-your-design-tokens-and-your-css-are-probably-out-of-sync-and-how-to-check-3od6</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4nrdgw0x3x5id2tas3ox.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4nrdgw0x3x5id2tas3ox.png" alt="Preview of TokenLens web interface" width="800" height="568"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You defined the tokens. You documented them. You probably even built a Storybook page showing the full palette with variable names.&lt;/p&gt;

&lt;p&gt;And then six months passed.&lt;/p&gt;

&lt;p&gt;Now your codebase has color: &lt;code&gt;#1A1A1A&lt;/code&gt; in fourteen places, a spacing value of &lt;code&gt;12px&lt;/code&gt; scattered across components, and three tokens that haven't been referenced in any CSS file since the last rebrand.&lt;/p&gt;

&lt;p&gt;Nobody did this on purpose. It just happened — and that's exactly what makes it hard to catch.&lt;/p&gt;

&lt;h2&gt;
  
  
  The silent drift problem
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Design tokens are a bridge that connects design decisions and code&lt;/strong&gt;. Instead of hardcoding values, you reference a named token. Colors, spacing, typography, radius, everything flows from a single source of truth.&lt;/p&gt;

&lt;p&gt;In practice, here's how it usually goes:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A deadline hits&lt;/strong&gt;. Someone needs to ship a component fast.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A token gets renamed&lt;/strong&gt;. The design team updates the naming convention from color-primary to brand-blue-600. The JSON gets updated. The documentation gets updated. Some CSS files get updated. Not all of them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A new developer joins&lt;/strong&gt;. They're onboarding fast, looking at existing code for patterns. They find a hardcoded value used in three components and assume that's the convention. They follow it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A rebrand happens&lt;/strong&gt;. The token values change. But the hardcoded values don't, because nobody knows they exist.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;None of these are catastrophic events. They're small, reasonable decisions made under normal constraints&lt;/strong&gt;. The problem is that they compound invisibly — until you're maintaining a design system that's theoretically rigorous but practically inconsistent.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The drift is invisible for a simple reason: it doesn't break anything.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You only notice the problem when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A token value changes, but the hardcoded version doesn't update with it&lt;/li&gt;
&lt;li&gt;You try to do a systematic audit and realize you have no way to know where direct values are hiding&lt;/li&gt;
&lt;li&gt;You onboard a new designer who asks "so what's the real source of truth here?" and you don't have a clean answer&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At that point, &lt;strong&gt;the audit is manual and painful&lt;/strong&gt;. You're grepping through CSS, cross-referencing token files, and building a picture of coverage in a spreadsheet.&lt;/p&gt;

&lt;h2&gt;
  
  
  What a token coverage audit actually needs to surface
&lt;/h2&gt;

&lt;p&gt;When I ran into this problem on a project, I wrote down what I actually wanted to know:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Which tokens are defined but never used in CSS?&lt;/li&gt;
&lt;li&gt;Where are hardcoded values hiding?&lt;/li&gt;
&lt;li&gt;What's the coverage by category? &lt;/li&gt;
&lt;li&gt;Which components are the worst offenders?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This felt like a well-defined problem. &lt;/p&gt;

&lt;p&gt;So I built a tool to solve it: &lt;strong&gt;TokenLens&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How TokenLens works
&lt;/h2&gt;

&lt;p&gt;TokenLens is a browser-based auditing tool. You give it two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Your design token definitions in JSON&lt;/li&gt;
&lt;li&gt;Your CSS files&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here's the flow in more detail.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Upload your files
&lt;/h3&gt;

&lt;p&gt;TokenLens accepts multiple files at once — useful if your tokens are split across multiple JSON files, or your CSS is organized by component. There's no account, no install, no build step.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Get the report
&lt;/h3&gt;

&lt;p&gt;The output covers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Token coverage for each token category, what percentage of relevant CSS properties reference a token vs. a hardcoded value&lt;/li&gt;
&lt;li&gt;Unused tokens, defined in JSON that don't appear in any CSS file&lt;/li&gt;
&lt;li&gt;Hardcoded value instances, specific lines where direct values are used instead of tokens, grouped by property type&lt;/li&gt;
&lt;li&gt;Component breakdown,  which CSS selectors (inferred from class names) have the worst coverage&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  An example
&lt;/h4&gt;

&lt;p&gt;Let's say you have a token file with 40 color tokens and a set of component CSS files.&lt;/p&gt;

&lt;p&gt;After running the audit, you might find:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;28 of your 40&lt;/strong&gt; color tokens are actually referenced in CSS&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;12 tokensexist in the definition&lt;/strong&gt;  but aren't used anywhere&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;23 instances of hardcoded hex values&lt;/strong&gt; across 8 component files&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's a picture you can act on. &lt;/p&gt;

&lt;p&gt;You know where to focus, what to clean up first, and what questions to ask the design team.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I learned building this
&lt;/h2&gt;

&lt;p&gt;Designers use this tool as much as developers. Not because they're reading the JSON, but because the report gives a shared vocabulary for a conversation that's usually fuzzy — "our design system isn't being followed" becomes "here are 23 specific places where it isn't, grouped by component."&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;p&gt;If you maintain a design system, or you're inheriting one, I'd genuinely recommend running an audit on your current codebase. The results are usually more actionable than you'd expect.&lt;/p&gt;

&lt;p&gt;→ &lt;a href="https://tokenlens.app" rel="noopener noreferrer"&gt;https://tokenlens.app&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Let me know what you think in the comments!&lt;/em&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>CSSUI - Interactive Components in Pure CSS</title>
      <dc:creator>Francesco Improta</dc:creator>
      <pubDate>Thu, 23 Sep 2021 08:37:52 +0000</pubDate>
      <link>https://dev.to/zetareticoli/cssui-interactive-components-in-pure-css-3aio</link>
      <guid>https://dev.to/zetareticoli/cssui-interactive-components-in-pure-css-3aio</guid>
      <description>&lt;p&gt;🎉 Last week I published &lt;a href="https://www.cssui.dev" rel="noopener noreferrer"&gt;CSSUI&lt;/a&gt;, a library of interactive components in pure CSS.&lt;/p&gt;

&lt;p&gt;The idea behind this project was pretty clear to me since the start: create a &lt;strong&gt;library&lt;/strong&gt; of the most used &lt;strong&gt;interactive components withour any Javascript at all&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Remember the jQueryUI components?&lt;/em&gt; So old fashioned today. &lt;/p&gt;

&lt;p&gt;Well, I took that list and re-created it in pure CSS. &lt;/p&gt;

&lt;h2&gt;
  
  
  Components
&lt;/h2&gt;

&lt;p&gt;A list of available components included in this release:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.cssui.dev/docs/components/accordion/" rel="noopener noreferrer"&gt;Accordion&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.cssui.dev/docs/components/dropdown/" rel="noopener noreferrer"&gt;Dropdown&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.cssui.dev/docs/components/modal/" rel="noopener noreferrer"&gt;Modal&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.cssui.dev/docs/components/tabs/" rel="noopener noreferrer"&gt;Tabs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.cssui.dev/docs/components/tooltip/" rel="noopener noreferrer"&gt;Tooltip&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.cssui.dev/docs/components/slideout/" rel="noopener noreferrer"&gt;Slideout&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For any of these you get both the HTML template and the CSS file. Just simple as that. 🙂&lt;/p&gt;

&lt;p&gt;New components are in the roadmap and I plan to release them very soon.&lt;/p&gt;

&lt;h2&gt;
  
  
  Agnostic Approach
&lt;/h2&gt;

&lt;p&gt;I focused my work on making it as &lt;em&gt;"agnostic"&lt;/em&gt; as possibile. No CSS classes are used to style elements. &lt;strong&gt;No naming conventions&lt;/strong&gt; to rely on.&lt;/p&gt;

&lt;p&gt;Yout can &lt;a href="https://www.cssui.dev/docs/getting-started/customize/" rel="noopener noreferrer"&gt;customize components&lt;/a&gt; using &lt;strong&gt;CSS Variables&lt;/strong&gt; or apply your own classes depending on project's architecture.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why to use CSSUI
&lt;/h2&gt;

&lt;p&gt;Use CSSUI to &lt;strong&gt;quickly design and build interactive components&lt;/strong&gt; without any additional scripts. You haven't to reinvent the wheel to create a modal or a dropdown. Just use pure HTML and CSS. &lt;/p&gt;

&lt;h3&gt;
  
  
  CSSUI is perfect for:
&lt;/h3&gt;

&lt;p&gt;✅ Prototypes&lt;br&gt;
✅ Websites&lt;br&gt;
✅ SaaS Software&lt;br&gt;
✅ Mobile applications&lt;/p&gt;

&lt;p&gt;It isn't a framework like Bootstrap or Tailwind. You can't build an entire website with it. &lt;/p&gt;

&lt;h2&gt;
  
  
  What's next
&lt;/h2&gt;

&lt;p&gt;The very first release &lt;a href="https://github.com/zetareticoli/cssui/releases/tag/v0.1.0" rel="noopener noreferrer"&gt;v0.1.0&lt;/a&gt; was published a week ago but many other updates will follow.&lt;/p&gt;

&lt;p&gt;I work on this project in my spare time so there isn't a structured release planning. But, I just get some great feedback and interest. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/omaxel" rel="noopener noreferrer"&gt;Omar&lt;/a&gt; just joined the project as collaborator. I'm pretty excited about what we're planning to do in the next weeks. Stay tuned 😎&lt;/p&gt;

&lt;p&gt;🐞 Please, if you notice bugs &lt;a href="https://github.com/zetareticoli/cssui/issues" rel="noopener noreferrer"&gt;open an issue&lt;/a&gt;. We'll take care of it.&lt;/p&gt;




&lt;h3&gt;
  
  
  Links
&lt;/h3&gt;

&lt;p&gt;➡️ &lt;a href="https://www.cssui.dev" rel="noopener noreferrer"&gt;Website&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;➡️ &lt;a href="https://github.com/zetareticoli/cssui" rel="noopener noreferrer"&gt;Github&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;➡️ &lt;a href="https://www.npmjs.com/package/css-ui-lib" rel="noopener noreferrer"&gt;npm package&lt;/a&gt; &lt;/p&gt;

</description>
      <category>css</category>
      <category>opensource</category>
      <category>html</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Dark/Light Mode Toggle: a Usability Issue</title>
      <dc:creator>Francesco Improta</dc:creator>
      <pubDate>Thu, 14 Jan 2021 14:47:58 +0000</pubDate>
      <link>https://dev.to/zetareticoli/dark-light-mode-toggle-a-usability-issue-1gg2</link>
      <guid>https://dev.to/zetareticoli/dark-light-mode-toggle-a-usability-issue-1gg2</guid>
      <description>&lt;p&gt;Most of the solutions adopted for the toggle light / dark mode suffer a &lt;strong&gt;usability problem&lt;/strong&gt;. The &lt;strong&gt;status&lt;/strong&gt; of the toggle does not represent the current one of the interface, visible by the user. Too much minimalism isn't always a good solution in UI Design.&lt;/p&gt;

&lt;h2&gt;
  
  
  Approach 1: icon only
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ff74lghic6ecuj9hbo00m.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ff74lghic6ecuj9hbo00m.jpeg" alt="image" width="800" height="600"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Dark mode toggle on feathericons.com&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Let's take the toggle visible on the &lt;em&gt;feathericons.com&lt;/em&gt; site as an example. The toggle is located in the top-right positon of the screen. In &lt;em&gt;light mode&lt;/em&gt; the user sees the moon icon, in &lt;em&gt;dark mode&lt;/em&gt; that of the sun. The two symbols are used in an &lt;strong&gt;exclusive and inconsistent way&lt;/strong&gt; because they do not represent the interface current state.&lt;/p&gt;

&lt;h2&gt;
  
  
  Approach 2: icon and label
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvxp02qjkmubvib166h1i.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvxp02qjkmubvib166h1i.jpeg" alt="image" width="800" height="400"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Similar to the previous approach but with the addition of a label. However, I get confused by seeing the “dark” word and the moon icon on a white background. The same happens for "light" and sun. &lt;/p&gt;

&lt;h2&gt;
  
  
  Visibility of system status
&lt;/h2&gt;

&lt;p&gt;Norman's &lt;a href="https://www.nngroup.com/articles/ten-usability-heuristics/" rel="noopener noreferrer"&gt;first usability heuristic&lt;/a&gt; reminds us of what is really important in user interface design:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Communicating the current state allows users to feel in control of the system  &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;An interface should always keep users informed of what's happening, through appropriate feedback. Only in this way can the user feel in control of it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution: be coherent
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fidkij0192qsjo9450g1j.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fidkij0192qsjo9450g1j.jpeg" alt="image" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Pure CSS dark mode toggle switcher - by Demilade Olaleye&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A good solution is also the simplest one. The two options are both visible, in the example with a label but it can also be just an icon. The selected option coincides with the current state of the system and is highlighted.&lt;/p&gt;

&lt;p&gt;See this &lt;a href="https://codepen.io/demilad/pen/bZRjpb" rel="noopener noreferrer"&gt;demo on CodePen&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  System prefences
&lt;/h2&gt;

&lt;p&gt;Since both Windows/Mac OS have introduced the ability to choose between light and dark mode at the system level, many sites have added this feature to their design without informing the user. Probably you land to a website and see it in dark mode without choose.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4p76jqslmj5wcaryh3j6.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4p76jqslmj5wcaryh3j6.jpeg" alt="image" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Possibile solution with three options&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A better solution provide a third "system" option, in this example represented with a monitor icon.&lt;/p&gt;




&lt;h2&gt;
  
  
  In conclusion
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Only by knowing what the current system status is can you change it&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A &lt;strong&gt;lack of information&lt;/strong&gt; implies a &lt;strong&gt;lack of control&lt;/strong&gt;. It's a common usability rule that we could find applied to many objects that surround us in the physical world. As designers of digital products, we just have to remember to use it.&lt;/p&gt;

</description>
      <category>uidesign</category>
      <category>ux</category>
      <category>darkmode</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Dark Mode with Sass and CSS variables</title>
      <dc:creator>Francesco Improta</dc:creator>
      <pubDate>Sat, 02 May 2020 17:01:19 +0000</pubDate>
      <link>https://dev.to/zetareticoli/dark-mode-with-sass-and-css-variables-4f9b</link>
      <guid>https://dev.to/zetareticoli/dark-mode-with-sass-and-css-variables-4f9b</guid>
      <description>&lt;p&gt;Implementing dark mode with Sass is hard because it is a preprocessor language. Any changes implies a new generating process and a page refresh. Therefore it is impossible to switch from light to dark - or the way around - in real time.&lt;/p&gt;

&lt;p&gt;The CSS variables instead are accessible and can be changed dynamically at any time. &lt;/p&gt;

&lt;p&gt;Why not take advantage of potential of the two languages ​​together?&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1 - Create colors variables in Sass
&lt;/h2&gt;

&lt;p&gt;Declare the Sass variables dedicated to colors:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="nv"&gt;$color-black&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;rgb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$color-white&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;rgb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;255&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="m"&gt;255&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="m"&gt;255&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$color-gray-light&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;rgba&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$color-white&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;.15&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$color-gray-dark&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;rgba&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$color-black&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;.15&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Generally I use dedicated files to store project variables like _settings.scss or _design-tokens.scss depending on project complexity. &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2 - Create element-scoped CSS variables
&lt;/h2&gt;

&lt;p&gt;I declare the CSS variables that will be affected by theme switch, using element-scoped naming:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="na"&gt;:root&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
&lt;span class="err"&gt;  &lt;/span&gt;&lt;span class="na"&gt;--color-page-background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="nv"&gt;$color-white&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;  &lt;/span&gt;&lt;span class="na"&gt;--color-text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="nv"&gt;$color-black&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Pay attention to use escaping Sass syntax &lt;code&gt;#{$variable}&lt;/code&gt; otherwise the code is not compiled.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3 - Create basic CSS styles
&lt;/h2&gt;

&lt;p&gt;I declare the two background-color and color properties on the &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; using the dedicated CSS variables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="err"&gt;  &lt;/span&gt;&lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--color-page-background&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="err"&gt;  &lt;/span&gt;&lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--color-text&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 4 - Add dark mode variables change
&lt;/h2&gt;

&lt;p&gt;Through the use of a &lt;code&gt;.dark&lt;/code&gt; class to be added to the &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; I change the value of the CSS variables by inverting the Sass variables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="nc"&gt;.dark&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
&lt;span class="err"&gt;  &lt;/span&gt;&lt;span class="na"&gt;--color-page-background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="nv"&gt;$color-black&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;  &lt;/span&gt;&lt;span class="na"&gt;--color-text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="nv"&gt;$color-white&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can also decide to use data-attributes if you prefer such as &lt;code&gt;data-theme="dark"&lt;/code&gt;. The decision is up to you and the coding conventions defined with your team.&lt;/p&gt;

&lt;h2&gt;
  
  
  A single style.scss file
&lt;/h2&gt;

&lt;p&gt;If you use a single &lt;code&gt;style.scss&lt;/code&gt; you could import setting variables first using Sass partials. Then put dark mode at the end of the file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight sass"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Settings&lt;/span&gt;
&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="s"&gt;'setting/tokens'&lt;/span&gt; &lt;span class="s"&gt;//&lt;/span&gt; &lt;span class="s"&gt;Sass&lt;/span&gt; &lt;span class="s"&gt;variables&lt;/span&gt;
&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="s"&gt;'settings/global';&lt;/span&gt; &lt;span class="s"&gt;//&lt;/span&gt; &lt;span class="s"&gt;CSS&lt;/span&gt; &lt;span class="s"&gt;variables&lt;/span&gt;

&lt;span class="c1"&gt;// other CSS stuff here&lt;/span&gt;

&lt;span class="c1"&gt;// Dark mode&lt;/span&gt;
&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="s"&gt;'trumps/dark';&lt;/span&gt; &lt;span class="s"&gt;//&lt;/span&gt; &lt;span class="s"&gt;CSS&lt;/span&gt; &lt;span class="s"&gt;variables&lt;/span&gt; &lt;span class="s"&gt;for&lt;/span&gt; &lt;span class="s"&gt;dark&lt;/span&gt; &lt;span class="s"&gt;mode&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Remind to use CSS variables for all those components you want to control with dark mode.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits
&lt;/h2&gt;

&lt;p&gt;Following this way, we can &lt;strong&gt;manage layout changes&lt;/strong&gt; foreseen by the light/dark switch with few lines of code, &lt;strong&gt;using Sass partials for code modularity&lt;/strong&gt; without having to create dedicated dark theme files or introduce complex logic in Sass. &lt;/p&gt;

&lt;p&gt;Try this &lt;a href="https://codepen.io/zetareticoli/pen/MROMZE"&gt;demo con CodePen&lt;/a&gt;&lt;/p&gt;

</description>
      <category>sass</category>
      <category>darkmode</category>
      <category>cssvariables</category>
      <category>css</category>
    </item>
  </channel>
</rss>
