<?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: Nathaniel Blackburn</title>
    <description>The latest articles on DEV Community by Nathaniel Blackburn (@nblackburn).</description>
    <link>https://dev.to/nblackburn</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%2F1109%2F2931085.jpeg</url>
      <title>DEV Community: Nathaniel Blackburn</title>
      <link>https://dev.to/nblackburn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nblackburn"/>
    <language>en</language>
    <item>
      <title>The Magic of Theming</title>
      <dc:creator>Nathaniel Blackburn</dc:creator>
      <pubDate>Thu, 30 Jan 2025 21:42:08 +0000</pubDate>
      <link>https://dev.to/nblackburn/the-magic-of-theming-4np9</link>
      <guid>https://dev.to/nblackburn/the-magic-of-theming-4np9</guid>
      <description>&lt;p&gt;It's fair to say that changing the look of your website or app at the tap of a button can feel pretty magical. But if we were to pull back the curtain, you might wonder how it's done.&lt;/p&gt;

&lt;p&gt;Join me for a few moments, and I will show you how.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a theme?
&lt;/h2&gt;

&lt;p&gt;Before we begin, let's explore what a theme is. A theme is simply a collection of properties that define your visual identity. One property might define how large your text is, while another determines how round your buttons are. Together, these properties create what's known as a "theme".&lt;/p&gt;

&lt;h2&gt;
  
  
  Using properties
&lt;/h2&gt;

&lt;p&gt;Properties, on the other hand, allow us to share values across our website or app. These values can be anything from a colour to milliseconds for a transition.&lt;/p&gt;

&lt;p&gt;A classic example would be brand colours. In the past, you would have had to set those colours each time they were used. Multiply that over hundreds if not thousands of files, and you have yourself...well, a mess.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.button&lt;/span&gt; &lt;span class="p"&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="m"&gt;#6F00FF&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.link&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#6F00FF&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;p&gt;But it doesn't have to be this way. We can use properties to share this colour. This means we can change the brand colour from a single place instead of many.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;--brand&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#6F00FF&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* This is a property in CSS */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;:root&lt;/code&gt; pseudo class targets the highest-level element on your page, in the case of HTML this would be the &lt;code&gt;html&lt;/code&gt; element. This makes it perfect for declaring global CSS properties which can be accessed from anywhere.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.button&lt;/span&gt; &lt;span class="p"&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;--brand&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c"&gt;/* Here we use that property */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.link&lt;/span&gt; &lt;span class="p"&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;--brand&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c"&gt;/* And once again here */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice &lt;code&gt;--brand&lt;/code&gt;, that is how we create properties in CSS. When using them, we use the &lt;code&gt;var&lt;/code&gt; function followed by the property name, in this case, &lt;code&gt;var(--brand)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you want to set some properties for a single class, you can do that too. This makes the properties only available to that class and is known as a scoped-property.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;--brand&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#6F00FF&lt;/span&gt;&lt;span class="p"&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;--brand&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;
  
  
  Creating themes
&lt;/h2&gt;

&lt;p&gt;By using scoped properties, we form the basis for theming.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Create some themes. */&lt;/span&gt;
&lt;span class="nc"&gt;.theme-one&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;--brand&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.theme-two&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;--brand&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* Use the properties from the active theme. */&lt;/span&gt;
&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&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;--brand&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;p&gt;Once we have a theme, we simply apply its class, and we can start using its properties.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"theme-one"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Hello World!&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Changing the theme is as simple as swapping the theme class for another, and everything will update as if by magic.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TIP&lt;/strong&gt;: if you want to apply your theme to the entire page, add the theme class to the &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; element.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Using themes
&lt;/h2&gt;

&lt;p&gt;How you apply theming is entirely up to you. Whether you choose from a set of colours or change the theme based on the time of year, the choice is yours, so have fun and express yourself!&lt;/p&gt;

&lt;h2&gt;
  
  
  Light &amp;amp; dark modes
&lt;/h2&gt;

&lt;p&gt;Now you know the basics of theming, we take this a step further by leveraging light and dark modes. Of course, you could do this with scoped properties, but there is a better way...&lt;/p&gt;

&lt;p&gt;Most operating systems allow users to choose between a light and a dark mode as a system preference. We can make use of that by using a media query.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Target light mode */&lt;/span&gt;
&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prefers-color-scheme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;light&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#000000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;/* Target dark mode */&lt;/span&gt;
&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prefers-color-scheme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;dark&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#ffffff&lt;/span&gt;&lt;span class="p"&gt;;&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;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TIP&lt;/strong&gt;: pick either light or dark as a starting point and use a single media query to override. This means the theme will always work.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This way, when a user visits your website, they see your website based on their preference.&lt;/p&gt;

&lt;p&gt;By combining these techniques, you can create an experience that feels personal to everyone—and that is where the true magic lies!&lt;/p&gt;




&lt;p&gt;Pretty interesting, right? Even if you don’t use it directly, understanding how things work can really shape our perspective. If you ever have any questions, don't hesitate to ask—I’m always happy to help!&lt;/p&gt;

</description>
      <category>css</category>
      <category>theming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Hi, I'm Nathaniel Blackburn</title>
      <dc:creator>Nathaniel Blackburn</dc:creator>
      <pubDate>Tue, 03 Jan 2017 13:16:12 +0000</pubDate>
      <link>https://dev.to/nblackburn/hi-im-nathaniel-blackburn</link>
      <guid>https://dev.to/nblackburn/hi-im-nathaniel-blackburn</guid>
      <description>&lt;p&gt;Hey, my name is Nathaniel. I am a developer and designer from the United Kingdom. I have been coding for around a decade half of which is in the industry. I currently work for &lt;a href="http://relativeinsight.com" rel="noopener noreferrer"&gt;Relative Insight&lt;/a&gt; where i have created their new dashboard and continue to improve on it each day.&lt;/p&gt;

&lt;p&gt;I am active on GitHub &lt;a href="https://github.com/nblackburn" rel="noopener noreferrer"&gt;nblackburn&lt;/a&gt;&lt;br&gt;
I am also on Twitter as &lt;a href="https://twitter.com/itsnblackburn" rel="noopener noreferrer"&gt;@itsnblackburn&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Great to meet you all.&lt;/p&gt;

</description>
      <category>introduction</category>
    </item>
  </channel>
</rss>
