<?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: AlexDunia</title>
    <description>The latest articles on DEV Community by AlexDunia (@dunia).</description>
    <link>https://dev.to/dunia</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%2F1249086%2F6e6e145a-047c-46e1-8a03-e71a5d139cd0.jpeg</url>
      <title>DEV Community: AlexDunia</title>
      <link>https://dev.to/dunia</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dunia"/>
    <language>en</language>
    <item>
      <title>Using Vue.js Directives to build a Cryptocurrency (web3, DEfi) Interface.</title>
      <dc:creator>AlexDunia</dc:creator>
      <pubDate>Sun, 07 Sep 2025 17:07:43 +0000</pubDate>
      <link>https://dev.to/dunia/using-vuejs-directives-to-build-a-cryptocurrency-web3-defi-interface-552m</link>
      <guid>https://dev.to/dunia/using-vuejs-directives-to-build-a-cryptocurrency-web3-defi-interface-552m</guid>
      <description>&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;p&gt;In this article, you'll discover the power of Vue.js bind directives and its use cases in a cryptocurrency app. It is perfectly suited for all Vue Js and Javascript developers at every level. &lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;To fully understand this tutorial, you need to have at minimum:&lt;br&gt;
A very basic knowledge of Vue.js.&lt;br&gt;
A good understanding of Css and Descendant Selectors in Css.&lt;br&gt;
If you have these, then by the end of this article, you will be able to write simple, interactive, and functional conditions using the Vue.js bind directive; and most importantly, how to use Vue.js bind directive for reactivity on application.&lt;/p&gt;
&lt;h2&gt;
  
  
  Introduction to Vue.Js Directives
&lt;/h2&gt;

&lt;p&gt;In Vue.Js, directives are shortcuts used to add functionality to DOM elements. They specifically target, change, and make elements do more within the DOM.&lt;br&gt;
While several directives improve the general functionality of a Vue web application, this tutorial will focus on a type of directive called the v-bind directive.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is the Vue Bind directive?
&lt;/h2&gt;

&lt;p&gt;When building web applications, certain HTML attributes (like src, href, class, etc.) can load by default, or they could be as a result of the conditions set by the developer. &lt;/p&gt;

&lt;p&gt;Little user interactions, like clicking, can dynamically change some parts of the HTML to show different content, and these are crucial for improving User Experience(UX)  in web and mobile applications, whether in a Social networking application, Web3 application, AI powered application, and many others.&lt;/p&gt;

&lt;p&gt;For more context on these little interactions, let’s consider two instances using a man we’ll call "Dan":&lt;/p&gt;

&lt;p&gt;The first is Dan getting into a social app and searching for a profile. If the profile is online, he sees a green dot next to the name to show the profile is “active”; otherwise, he sees a red one(inactive).&lt;/p&gt;

&lt;p&gt;The second is Dan in the process of ordering a shoe online. On the product description page, he finds two available sizes for the shoes he's interested in. If sizes 14 and 18 are available, and he clicks on one, there would be an indication on the website that the size was selected, for this, by changing the button color to green (or another noticeable color).&lt;/p&gt;

&lt;p&gt;Actions like these during development, would require a large chunk of code mostly composed of several CSS styles and traditional vanilla JavaScript or other framework conditions. This already seems like a stretch, especially considering how simple the functionality sounds. &lt;/p&gt;

&lt;p&gt;Luckily, when building this reactivity, developers can use Vue.js to make the code easier to read, write, and understand with the v-bind directive.&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%2Fuploads%2Farticles%2Fixvrbf25h6qlr057pgvf.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%2Fixvrbf25h6qlr057pgvf.png" alt="Vue.js developer salary" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To ‘bind’ in general terms, means to connect or attach two things together. This is a solid foundation to understanding what the V-bind directive does. It is a type of Vue.js directive that is attached to our HTML via a special token for the purpose of adding styling and functionality to DOM elements. &lt;/p&gt;

&lt;p&gt;Its goal is not to change how the code works but to simplify the expression, and make it more readable and easier to manage, especially for larger projects.&lt;/p&gt;

&lt;p&gt;They are specifically used for binding styles, classes, attributes, props etc.  &lt;/p&gt;

&lt;p&gt;There are two commonly used v-bind directives. They Include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The v-bind:style directive, and &lt;/li&gt;
&lt;li&gt;The v-bind:class directive.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since this is the first part of a two-part article, our only focus here will be breaking down the v-bind:style directive. &lt;/p&gt;

&lt;p&gt;We will take it step by step, from very basic and static syntax to more complex syntax and in every example of this first part article, we will be using iterations of the cryptocurrency application I’ve prebuilt as a reference. &lt;/p&gt;

&lt;p&gt;This approach is intended to make it easier for you to understand, no matter what level you are. &lt;/p&gt;

&lt;p&gt;If you happen to be more interested in the codes, then you can head to my github repository here:&lt;br&gt;
&lt;a href="https://github.com/AlexDunia/spendcryptai" rel="noopener noreferrer"&gt;Alex Dunia's github repository&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What is the V-bind:style directive ?
&lt;/h2&gt;

&lt;p&gt;V-bind:style directives are special tokens that are used to add styles directly on the html.&lt;br&gt;
It’s as easy as it sounds, they are simply written directly on our HTML, and can be done in three ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The String Syntax&lt;/li&gt;
&lt;li&gt;The Object Syntax&lt;/li&gt;
&lt;li&gt;The Array Syntax.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  The String Syntax
&lt;/h4&gt;

&lt;p&gt;If you’ve written CSS, then you should be used to this syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;span style="color: #00ff00"&amp;gt; +$400 &amp;lt;/span&amp;gt;
// The outcome of the code would be a red color on our page.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This pattern of CSS is known as inline css styles, and they allow us to create styles directly within the HTML tag. &lt;/p&gt;

&lt;p&gt;As simple as it is, It is not far off from the work the string syntax does.&lt;/p&gt;

&lt;p&gt;The v-bind:style string syntax allows you to apply styles as a single string, just like inline CSS.&lt;/p&gt;

&lt;p&gt;Here is the app we will be working with, along with a link to view the project live: &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%2Fuploads%2Farticles%2F8oojm0yzhv60apl7hbm2.jpg" 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%2F8oojm0yzhv60apl7hbm2.jpg" alt="what crypto app uses vue.js?" width="800" height="358"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(&lt;a href="https://alexdunia.github.io/spendcryptai/" rel="noopener noreferrer"&gt;https://alexdunia.github.io/spendcryptai/&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;There are two key things to note here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Balance&lt;/li&gt;
&lt;li&gt;The Transaction History. &lt;/li&gt;
&lt;/ul&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%2Fuploads%2Farticles%2Fseuvwjc84u1f1nknl5dt.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%2Fseuvwjc84u1f1nknl5dt.png" alt="crypto app with vue.js" width="800" height="357"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The balance is $400, and it’s colored green. We can write this with the v-bind:style string syntax.&lt;/p&gt;

&lt;p&gt;But first, we will start by declaring a ref that contains the actual value of the account balance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script setup&amp;gt;
import { ref } from 'vue';
const accountBalance = ref(400)
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we will add the style using the v-bind:style string syntax.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;p class="income-amount"&amp;gt;
 &amp;lt;span v-bind:style=""&amp;gt; ${{ accountBalance }}
           &amp;lt;/span&amp;gt;
              &amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code above, we have a span where our directive sits. &lt;/p&gt;

&lt;p&gt;&lt;span&gt; syntax allows us to bind a dynamic value to an HTML attribute. In simpler terms, it allows us to change the CSS styles of an HTML element based on data inside our Vue component (in our case, the accountBalance). We are attaching (binding) dynamic styles (CSS) to the element, and after the connection is made, we can then manipulate the HTML styling however we choose.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;Since we are using the string syntax, we will add a string inside our quotes, and write our styling inside it, just like we did with the inline css:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;p class="income-amount"&amp;gt;
 &amp;lt;span v-bind:style="'color: green'"&amp;gt; ${{ accountBalance }}
           &amp;lt;/span&amp;gt;
              &amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this, our application is set, and our $400 balance is now coloured Green. &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%2Fuploads%2Farticles%2Fb15tihldslh760xs0x9o.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%2Fb15tihldslh760xs0x9o.png" alt="web3 vue.js" width="800" height="358"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This look great, but we want some styling reactivity based on the wallet balance,&lt;/p&gt;

&lt;p&gt;That is:&lt;/p&gt;

&lt;p&gt;If the wallet balance is $1, or more than $1, the text will be Green (Sufficient Balance).&lt;/p&gt;

&lt;p&gt;If the wallet balance is less than $1, then the text will be Red (Insufficient Balance): &lt;/p&gt;

&lt;p&gt;These will serve as clear visual cues that will help users (Like Dan from earlier) be more intuitive about the status of their account. Hence, if Dan is the owner of the wallet, he can easily know if his balance is sufficient or insufficient without necessarily paying too much attention to the actual figures.&lt;/p&gt;

&lt;p&gt;Traditionally, to achieve this with Vue.JS, it has to be written in an if-else statement in the script section of our Vue Js code, followed by a mount, for when the app is loaded. &lt;/p&gt;

&lt;p&gt;This already seems hectic, and would lead to a chunk of code.&lt;br&gt;
The string syntax will serve as the syntactic sugar that will allow us to achieve this with fewer lines of code. &lt;/p&gt;

&lt;p&gt;The first step is to not make any changes to the accountBalance.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const accountBalance = ref(400)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: This balance can either be Positive values (e.g., 400) or negative values (e.g., -400).&lt;/p&gt;

&lt;p&gt;Next, we want to be able to monitor the number. &lt;br&gt;
At the moment, it is $400, but if it drops below $0, we need the app to change the color accordingly. This can be achieved with a condition created using a &lt;a href="https://www.linkedin.com/pulse/ternary-operator-ben-braunstein#:~:text=A%20ternary%20operator%20is%20a,readable%20than%20if%2Delse%20blocks" rel="noopener noreferrer"&gt;ternary operator&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;The Vue.JS bind directive allows us to write a ternary operator inside our v-bind:style directive so we can set our conditions inside the string in our markup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;p class="income-amount"&amp;gt;
                &amp;lt;span v-bind:style="accountBalance &amp;gt; 0 ? 'color: #00ff00' : 'color: #ff0000'"&amp;gt; ${{ accountBalance }} &amp;lt;/span&amp;gt;
              &amp;lt;/p&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note:  If it was the array syntax, we would have an array replacing the strings and If it was the Object syntax, we would have an object.&lt;/p&gt;

&lt;p&gt;As seen inside the string:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;accountBalance &amp;gt; 0 ? 'color: #00ff00' : 'color: #ff0000'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What this condition set with a ternary operator means is If the accountBalance is greater than zero (&lt;strong&gt;written in the code as accountBalance &amp;gt; 0&lt;/strong&gt;), then (&lt;strong&gt;written on the code as a question mark ‘?’&lt;/strong&gt;),  we set the CSS styling to green*&lt;em&gt;(&lt;/em&gt;&lt;em&gt;with the color code of ‘#00ff00’&lt;/em&gt;&lt;em&gt;); otherwise (&lt;/em&gt;&lt;em&gt;on the code as a colon  ‘:’&lt;/em&gt;&lt;em&gt;), we set the color to red(&lt;/em&gt;&lt;em&gt;with the color code of ‘#ff0000’&lt;/em&gt;*).&lt;/p&gt;

&lt;p&gt;With this implementation, the account balance will be displayed in green. However, if the balance is manually changed to a value below zero, the text will automatically update to red.&lt;/p&gt;

&lt;p&gt;It’s important to note that any CSS style properties (such as background-color, font-size, font-weight, etc.) can be applied directly using Vue.js’s v-bind:style directive, Not just the color property used in our example. The same way we added one style property, we can also update multiple styles in response to data changes. &lt;br&gt;
In situations like this where you need to add multiple CSS styles at once, you write them in a single string inside the v-bind:style directive and separate each styling with a semicolon.&lt;br&gt;
Like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;span
                  v-bind:style="accountBalance &amp;gt; 0 ? 'color: #00ff00; background-color: #e0ffe0; font-size: 20px; padding: 5px; border-radius: 5px; font-weight: bold; border: 1px solid #00ff00' : 'color: #ff0000; background-color: #ffe0e0; font-size: 20px; padding: 5px; border-radius: 5px; font-weight: bold; border: 1px solid #ff0000'"&amp;gt;
                  ${{ accountBalance }}
                &amp;lt;/span&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Note: The Object syntax and Array Syntax for the style directives are better alternatives to go around situations like this, and the v-bind:class directive can be used to make the aforementioned more readable.&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;Next, we want to build the transaction history section of our web application. &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%2Fuploads%2Farticles%2F32ys9z1cjkpfuh1udvrv.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%2F32ys9z1cjkpfuh1udvrv.png" alt="crypto app with vue.js" width="800" height="237"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our credit notification features a green line on the left side, while our debit notification has a red line on the left side.&lt;br&gt;
In order to achieve this we must first store the  transactions in an array. ]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script setup&amp;gt;
const transactions = ref([
  { id: "xy8723ougihk8o7ii", amount: 10 },
  { id: "ww9732ougihk8wdvk", amount: -10 },
  { id: "xy8723ougihk8o7ii", amount: 10 },
]);
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Note: In a real-life scenario, we would fetch transactions from the backend using a GET request. If you intend to do this, simply add a GET request and store the response in the transactions array to achieve the same results.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In the amount field of the transactions array, we have positive and negative values. &lt;br&gt;
Positive amount values (e.g., 10) represent credits.&lt;br&gt;
Negative amount values (e.g., -10) represent debits.&lt;br&gt;
This is how we would be able to monitor our application to tell if a transaction is debit or credit, and in the same way, give us the needed color.&lt;br&gt;
Following this, we will add some lines of code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        &amp;lt;div v-for="transaction in transactions" :key="transaction.id"&amp;gt;
            &amp;lt;div class="tracker-item"
              v-bind:style="transaction.amount &amp;gt; 0 ? 'border-left: 4px solid #00ff00' : 'border-left: 4px solid #ff0000'"&amp;gt;
              &amp;lt;p&amp;gt;{{ transaction.amount &amp;gt; 0 ? 'Account Credited from ' : 'Account Debited for ' }} {{ transaction.id }}
              &amp;lt;/p&amp;gt;
          &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we first make a class and a transaction history heading, then, we loop through the transactions array to display all transaction values on our web page.&lt;/p&gt;

&lt;p&gt;Then for our class called ‘tracker-item’, we access the transaction amount using transaction.amount, check if it is greater than zero, and use the  style directive to apply the styling directly on our markup. &lt;br&gt;
Based on the same condition, we also add the text "&lt;strong&gt;Account credited from&lt;/strong&gt;" or "&lt;strong&gt;Account debited from&lt;/strong&gt;." on our P tag.&lt;br&gt;
Now, you should get the appropriate colors that indicate the credit and debit section.&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%2Fuploads%2Farticles%2Fe3t7jqlrvbxvd6vutujf.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%2Fe3t7jqlrvbxvd6vutujf.png" alt="crypto app with vue.js" width="800" height="237"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It only gets better from here because Vue.JS makes the code cleaner and easier to write with their shorthand.&lt;br&gt;
Rather than writing v-bind:style, you just write :style, and it performs the same function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;div class="tracker-item"
     :style="transaction.amount &amp;gt; 0 ? 'border-left: 4px solid #00ff00' : 'border-left: 4px solid #ff0000'"&amp;gt;
    &amp;lt;p&amp;gt;{{ '{{' }} transaction.amount &amp;gt; 0 ? 'Account Credited from ' : 'Account Debited for ' {{ '}}' }} {{ '{{' }} transaction.id {{ '}}' }}&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With simple and very little code, we have been able to achieve a lot compared to vanilla Javascript and other Javascript frameworks.&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%2Fuploads%2Farticles%2Fhdtbedu2bibgfwocslg9.jpg" 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%2Fhdtbedu2bibgfwocslg9.jpg" alt="vue js vs react" width="800" height="404"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As mentioned earlier, the v-bind:style also supports Object Syntax and the Array Syntax. &lt;/p&gt;

&lt;h3&gt;
  
  
  V-bind:style Object Syntax
&lt;/h3&gt;

&lt;p&gt;The v-bind:style Object Syntax allows you to apply styles as Javascript objects.&lt;br&gt;
It serves the same purpose of styling, but compared to the string syntax, is better for cases where we add multiple style properties dynamically.&lt;br&gt;
Like every object in traditional programming, it is wrapped in curly braces, and contains key-value pairs.&lt;br&gt;
For instance, in Javascript, an object will look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;family&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;father&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;David&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;mother&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Esther&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;fathersAge&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;father, mother, and fathersAge are keys&lt;/strong&gt;.&lt;br&gt;
&lt;strong&gt;"David", "Esther"&lt;/strong&gt;, and 40 are the values associated with each key.&lt;br&gt;
The object syntax follows this template, especially in terms of key-value pairs. The major difference however, is the keys are CSS properties and the values will be the value associated with the CSS property.&lt;br&gt;
Here’s a very basic example of the v-bind:Style Object Syntax that gives more context to our explanation: &lt;br&gt;
&lt;em&gt;Note: To properly follow along, you will have to indent the previous string syntax and copy or write this on your code editor.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;span :style="{ color: '#00ff00' }"&amp;gt;
  ${{ accountBalance }}
&amp;lt;/span&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside the curly braces {}, we define a JavaScript object where the key value pairs follow CSS rules; &lt;br&gt;
The key is the CSS property called ‘color’.&lt;br&gt;
The value is the value of the associated CSS property. The value could either be the hex value, RGB values, or named colors. &lt;br&gt;
We should see a green balance now.&lt;/p&gt;

&lt;p&gt;Next, we want the styles to change depending on the wallet balance, so, our object syntax would look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;span :style="{ color: accountBalance &amp;gt; 0 ? '#00ff00' : '#ff0000'}"&amp;gt;
  ${{ accountBalance }}
&amp;lt;/span&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The major difference between setting conditions here, and with the string syntax, is how we set our conditions. &lt;br&gt;
In the object syntax, conditions are defined directly within the key-value pairs, where the key represents the CSS property (such as color), and the value is dynamically assigned based on the condition.&lt;br&gt;
If the accountBalance is greater than 0, the color will be green (#00ff00). Otherwise, it will be red (#ff0000).&lt;br&gt;
For cases where we want to add multiple styling, we would easily separate it via a comma:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;span
  :style="{ color: accountBalance &amp;gt; 0 ? '#00ff00' : '#ff0000', fontSize: accountBalance &amp;gt; 0 ? '20px' : '15px' }"&amp;gt;
  ${{ accountBalance }}
&amp;lt;/span&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where the newly added style is the font size, and it’s set on the same condition. &lt;/p&gt;

&lt;h1&gt;
  
  
  $# V-bind Array Syntax.
&lt;/h1&gt;

&lt;p&gt;In the V-bind Array Syntax, we can pass in arrays directly on our markup, and inside the arrays would have the styles we need for our web application. &lt;br&gt;
Let's go back to our application, and assume we do not want to place a condition on the account balance. We just want a green color; this is how we would achieve that using the array syntax, &lt;br&gt;
We would declare a &lt;strong&gt;REF&lt;/strong&gt;, and inside it an object, where we want some static colors:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const accountBalanceColor = ref({
  color: '#00ff00',
  fontSize: '20px',
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: To follow along with this, you would again need to remove all styles for the account balance, along with the conditions previously set.&lt;br&gt;
Next, we want to add this to our markup, and It’s as simple as writing the array directly inside the style directive:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;span :style="[accountBalanceColor]"&amp;gt;
  ${{ accountBalance}}
&amp;lt;/span&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With that, we have a green color. &lt;/p&gt;

&lt;p&gt;In cases where we need to have a condition, then we place the ternary operator inside the array, and create a ref that houses the color of the insufficient balance.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;span :style="[accountBalance &amp;gt; 0 ? accountBalanceColor : insufficientBalance]"&amp;gt;
  ${{ accountBalance }}
&amp;lt;/span&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code follows the same logic as previous examples, where we conditionally apply styles based on the accountBalance. The difference here is that we are using an array syntax to apply styles, and the outcome of our condition (accountBalance &amp;gt; 0) determines which style object (either accountBalanceColor or insufficientBalance) is used. These style objects are defined in the  block.&amp;lt;br&amp;gt;
&amp;lt;/p&amp;gt;
&amp;lt;div class="highlight"&amp;gt;&amp;lt;pre class="highlight plaintext"&amp;gt;&amp;lt;code&amp;gt;const insufficientBalance = ref({
  color: '#ff0000',
  fontSize: '20px',
})
&amp;lt;/code&amp;gt;&amp;lt;/pre&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;Then, if we need to add another condition, we simply add a comma after the first like this:&amp;lt;br&amp;gt;
&amp;lt;/p&amp;gt;
&amp;lt;div class="highlight"&amp;gt;&amp;lt;pre class="highlight plaintext"&amp;gt;&amp;lt;code&amp;gt;&amp;amp;lt;span :style="[
  accountBalance &amp;amp;gt; 0 ? accountBalanceColor : insufficientBalance,
  accountBalance &amp;amp;gt; 1000 ? highBalanceColor : {}
]"&amp;amp;gt;
  ${{ accountBalance }}
&amp;amp;lt;/span&amp;amp;gt;
&amp;lt;/code&amp;gt;&amp;lt;/pre&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;p&amp;gt;&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;And that’s all it takes. &amp;lt;/p&amp;gt;
&amp;lt;h2&amp;gt;
  &amp;lt;a name="conclusion" href="#conclusion" class="anchor"&amp;gt;
  &amp;lt;/a&amp;gt;
  Conclusion
&amp;lt;/h2&amp;gt;

&amp;lt;p&amp;gt;In this guide, we have walked through the steps of using Vue.js Directives to add functionality to DOM elements, and how faster it is. &amp;lt;br&amp;gt;
While we’ve explored a couple of features, we have barely scratched the surface of the countless use cases for using Vue.Js Directives, ranging from building interactive AI interfaces, to building interfaces across other niches. &amp;lt;br&amp;gt;
Hopefully, this guide gives you a general overview of the possibilities of the bind directives.&amp;lt;/p&amp;gt;
&lt;/p&gt;

</description>
      <category>web3</category>
      <category>cryptocurrency</category>
      <category>blockchain</category>
      <category>ai</category>
    </item>
    <item>
      <title>Implement a Light and Dark Mode Toggle with JavaScript and Local Storage.</title>
      <dc:creator>AlexDunia</dc:creator>
      <pubDate>Sat, 10 Feb 2024 11:26:12 +0000</pubDate>
      <link>https://dev.to/dunia/implement-a-light-and-dark-mode-toggle-with-javascript-and-local-storage-19ce</link>
      <guid>https://dev.to/dunia/implement-a-light-and-dark-mode-toggle-with-javascript-and-local-storage-19ce</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;If you want to learn how to toggle between light and dark modes on HTML, CSS, and JAVASCRIPT, then this practical tutorial is for you.&lt;/p&gt;

&lt;p&gt;Live project: &lt;a href="https://jstogglemode.netlify.app/" rel="noopener noreferrer"&gt;https://jstogglemode.netlify.app/&lt;/a&gt;&lt;br&gt;
Source code: &lt;a href="https://github.com/AlexDunia/Js-Toggle-Tech-Writing-source-code-" rel="noopener noreferrer"&gt;https://github.com/AlexDunia/Js-Toggle-Tech-Writing-source-code-&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What is a Toggle/Switcher in this context?
&lt;/h2&gt;

&lt;p&gt;A toggle is a button or icon on a website or app that lets you switch between two options, like showing or hiding a menu, selecting filters, or changing between light and dark mode (Like in our case).&lt;/p&gt;
&lt;h2&gt;
  
  
  Setting up our Font Awesome Icons to toggle.
&lt;/h2&gt;

&lt;p&gt;To set up this toggle, we need to get the icons for the buttons we want to use.&lt;/p&gt;

&lt;p&gt;Here's how the toggle button looks on our website.&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%2Fuploads%2Farticles%2Frraow8eii9xi3w5woib2.gif" 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%2Frraow8eii9xi3w5woib2.gif" alt="Toggle light and dark mode on javascript" width="1348" height="599"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Clicking the icons circled red toggles between light and dark modes. We'll import two icons accordingly.&lt;/p&gt;

&lt;p&gt;For this project, we will be using &lt;a href="https://fontawesome.com/" rel="noopener noreferrer"&gt;Font Awesome&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Sign up to open a new account or log in to continue with the old account. &lt;/p&gt;

&lt;p&gt;Once this is done, we will visit our profile.&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%2Fuploads%2Farticles%2Fe454ugwpd6htcdv8p8vu.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%2Fuploads%2Farticles%2Fe454ugwpd6htcdv8p8vu.jpeg" alt="Toggle light and dark mode on javascript" width="800" height="109"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We want to make use of our kits, so we click on 'Your kits'.&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%2Fuploads%2Farticles%2Fmnq3nnvvozzny9au4j1d.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%2Fuploads%2Farticles%2Fmnq3nnvvozzny9au4j1d.jpeg" alt="Toggle light and dark mode on javascript" width="689" height="161"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and we click on the alphanumeric string on our profile:&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%2Fuploads%2Farticles%2Fz2bpgy9jcecm06k7d4fi.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%2Fuploads%2Farticles%2Fz2bpgy9jcecm06k7d4fi.jpeg" alt="Toggle light and dark mode on Html and css" width="800" height="389"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will then see the code we need to copy and paste for the icons we will use to toggle to be displayed.&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%2Fuploads%2Farticles%2F2svfbsjoyuoaoi7tygqn.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%2Fuploads%2Farticles%2F2svfbsjoyuoaoi7tygqn.jpeg" alt="Toggle light and dark mode on javascript" width="800" height="241"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy on our HTML&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%2Fuploads%2Farticles%2F3q0cqcw22dwy4ca4lkbv.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%2F3q0cqcw22dwy4ca4lkbv.png" alt=" " width="795" height="117"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After this, we go back to the Font Awesome website to search for "Toggle".&lt;/p&gt;

&lt;p&gt;We need two icons, toggle on and toggle off.&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%2Fuploads%2Farticles%2Ffcn3qfq9tm3zps1zw6yf.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%2Fuploads%2Farticles%2Ffcn3qfq9tm3zps1zw6yf.jpeg" alt=" " width="800" height="412"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy and paste that into your HTML too.&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%2Fuploads%2Farticles%2Fickvvmakkdh689hc34as.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%2Fuploads%2Farticles%2Fickvvmakkdh689hc34as.jpeg" alt="Toggle light and dark mode on javascript" width="615" height="295"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Take note of the IDhere, we would be storing them in separate variables and using them as event listeners.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is Local Storage?
&lt;/h2&gt;

&lt;p&gt;Local Storage is a global object in the browser that lets websites store key/value pairs on a user's device. &lt;/p&gt;

&lt;p&gt;What this means on a basic level is that a user can do something on a website, leave that website, restart their computer and that particular thing would remain the same when they get back to it. That's the power of the local storage.&lt;/p&gt;

&lt;p&gt;In doing its work, it provides a set of methods (getItem, setItem, removeItem, clear, etc.) to interact with the stored data. You can find out more about local storage &lt;a href="https://blog.logrocket.com/localstorage-javascript-complete-guide/#:~:text=storage%20in%20JavaScript.-,What%20is%20localStorage%20in%20JavaScript%3F,browser%20or%20restarts%20the%20computer." rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In our use case, local storage will be useful in toggling dark and light mode and we begin by storing it inside a variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`let mode = localStorage.getItem("mode");`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We're creating a variable to hold our local storage value, ensuring we have a default when the page loads.&lt;/p&gt;

&lt;p&gt;We are using let so that its value can be reassigned later in the code.&lt;/p&gt;

&lt;p&gt;This &lt;strong&gt;'mode'&lt;/strong&gt; variable will also help us track the current mode, making it easy to switch between light and dark modes.&lt;/p&gt;

&lt;p&gt;If you knew how local storage works before this moment, then the question pops up: why are we using getItem, not setItem? aren't we supposed to initialize it first?&lt;/p&gt;

&lt;p&gt;Yes. Either way is right, but in our use case, the trick here is that we are using &lt;strong&gt;let mode = localStorage.getItem("mode")&lt;/strong&gt; to retrieve the value of "mode" from local storage when the page loads.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up our variables
&lt;/h2&gt;

&lt;p&gt;For this project, we need four more variables, making the total 5.&lt;/p&gt;

&lt;p&gt;Remember, &lt;strong&gt;mode&lt;/strong&gt; was a variable itself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  let toggleoff = document.querySelector("#toggleoff");
  let toggleon = document.querySelector("#toggleon");
  let herolarge = document.querySelector("#htx");
  let herosub = document.querySelector("#htxtwo");
  let mode = localStorage.getItem("mode");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now when we need a function.&lt;/p&gt;

&lt;p&gt;I assume you already have the basics of function covered, however, &lt;a href="https://freecodecamp.org/news/understanding-functions-in-javascript/" rel="noopener noreferrer"&gt;here is a link that explains functions in JavaScript&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up our function.
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;_Note: For now, we don't have an event listener to listen to the click, and this is intentional.&lt;br&gt;
_&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Moving forward, we will create a function called updateMode and pass in a parameter of "mode". &lt;/p&gt;

&lt;p&gt;'Mode' is the same name we gave to the first variable we created.&lt;/p&gt;

&lt;p&gt;Copy and paste this code into your editor. I will explain each line now.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; function updateMode(mode) {
  if (mode === 'darkmode') {
    localStorage.setItem('mode', 'darkmode');
    toggle.style.display = 'none';
    toggleon.style.display = 'block';
    herolarge.style.color = "white";
    herosub.style.color = "white";
    document.body.classList.add("darkmode");
    document.body.classList.remove('lightmode');
  } else {
    localStorage.setItem('mode', 'lightmode');
    toggle.style.display = 'block';
    toggleon.style.display = 'none';
    herolarge.style.color = "#000039";
    herosub.style.color = "black";
    document.body.classList.remove("darkmode");
    document.body.classList.add('lightmode');
    console.log('light mode');
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Breaking down our Function.
&lt;/h2&gt;

&lt;p&gt;First, we have a function with a parameter of mode.&lt;/p&gt;

&lt;p&gt;This function is used to monitor and change the state of our toggle.&lt;/p&gt;

&lt;p&gt;The 'mode' parameter corresponds to the name of our variable that gets the value of the local storage (the first variable we created) because we use the variable as an argument when calling the function.&lt;/p&gt;

&lt;p&gt;What you need to understand here is that with the "mode" parameter, the function is aware of the current state stored in local storage.&lt;/p&gt;

&lt;p&gt;Then, we have a condition:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (mode === 'darkmode')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we check if (mode === 'darkmode'), it means we are verifying whether our variable (mode), which is getting its value from local storage, is equal to 'darkmode'.&lt;/p&gt;

&lt;p&gt;So what happens if it is equal to darkmode? &lt;/p&gt;

&lt;p&gt;Remember, in the first instance we haven't explicitly set any local storage values yet, we used a getItem instead.&lt;/p&gt;

&lt;p&gt;Now, Inside this condition, we'll be setting up our local storage for the first time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; localStorage.setItem('mode', 'darkmode');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This sets our value to "darkmode".&lt;/p&gt;

&lt;p&gt;Our function has a condition that if our mode is darkmode, then we set a local storage called 'darkmode'.&lt;/p&gt;

&lt;p&gt;After that, we move to these lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;toggle.style.display = 'none';
toggleon.style.display = 'block';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are the variables that control our Font Awesome icons.&lt;/p&gt;

&lt;p&gt;When it is dark mode, our toggle button or toggle icon activates and needs to be 'on'.&lt;/p&gt;

&lt;p&gt;Let's take a step back to properly understand.&lt;/p&gt;

&lt;p&gt;Note: We are trying to control the dark mode here.&lt;/p&gt;

&lt;p&gt;By default, our toggle is 'off.'&lt;/p&gt;

&lt;p&gt;It is 'off' because our dark mode is off.&lt;/p&gt;

&lt;p&gt;The toggle controls our dark mode.&lt;/p&gt;

&lt;p&gt;When we click the button, the dark mode comes 'on', and so does our button.&lt;/p&gt;

&lt;p&gt;This works vice versa because when the toggle is off, then our dark mode also goes off.&lt;/p&gt;

&lt;p&gt;Turning on the night mode means showing the Font Awesome icon that displays the toggle "on."&lt;/p&gt;

&lt;p&gt;In essence, the objective is to set the default state of the button as 'OFF.' When clicked, it toggles to 'ON,' activating the night mode and displaying the corresponding Font Awesome icon for the 'ON' state&lt;/p&gt;

&lt;p&gt;If that is clear then we move to the next two lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; document.body.classList.add("darkmode");
 document.body.classList.remove('lightmode');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we refer back to our CSS, specifically lines 38-44, we have two classes: one sets the background color to light mode (white), and the other sets it to dark mode (ash).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.lightmode{
    background-color: white;
}

.darkmode{
    background:#1b1b1b;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On our CSS, we also have the body:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body{
    font-family:Montserrat;
    overflow-x: hidden;
    position: relative;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the hero text and subtext, we have default colors(lines 49 and 54 specifically), this shows we can do it however we want to, provided there is a color.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; #htx {
        animation: fadeIn 1s ease-in-out 1.5s forwards;
        line-height:1.1em;
        color:#000039;
    }

    #htxtwo {
        animation: fadeIn 1s ease-in-out 2.5s forwards;
        color: black;
        margin-top:15px;
        font-weight:500;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The JavaScript code adds the appropriate background color and text color based on the selected mode.&lt;/p&gt;

&lt;p&gt;The first half of our updateMode condition checks if the mode set in our local storage is darkmode.&lt;/p&gt;

&lt;p&gt;If our stored mode is set to darkmode, we do the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Save dark mode in the storage,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Switch the icon from 'off' to 'on'.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make the page dark.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Remove any light styles.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The terms 'dark mode' and 'light mode' here correspond to the CSS classes we have defined. The function updates the styles and adds them to the body of our website based on the selected mode.&lt;/p&gt;

&lt;p&gt;Note: darkmode and lightmode are not prefixed names. You can name them anything you choose.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; function updateMode(mode) {
  if (mode === 'darkmode') {
    localStorage.setItem('mode', 'darkmode');
    toggleoff.style.display = 'none';
    toggleon.style.display = 'block';
    document.body.classList.add("darkmode");
    herolarge.style.color = "white";
    herosub.style.color = "white";
    document.body.classList.remove('lightmode');
    console.log('dark mode');
  } else {
    localStorage.setItem('mode', 'lightmode');
    toggleoff.style.display = 'block';
    toggleon.style.display = 'none';
    herolarge.style.color = "#000039";
    herosub.style.color = "black";
    document.body.classList.remove("darkmode");
    document.body.classList.add('lightmode');
    console.log('light mode');
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the else condition, we reverse everything.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;else{ 
    localStorage.setItem('mode', 'lightmode');
    toggleoff.style.display = 'block';
    toggleon.style.display = 'none';
    herolarge.style.color = "#000039";
    herosub.style.color = "black";
    document.body.classList.remove("darkmode");
    document.body.classList.add('lightmode');
    console.log('light mode');
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the mode is not darkmode, then we do the opposite: show the 'off' icon, hide the 'on' icon, switch the page to light mode, and remove any darkmode styles.&lt;/p&gt;

&lt;p&gt;Now our function is ready to go, but it's not done yet.&lt;/p&gt;

&lt;p&gt;We need two event listeners that listen for a click event outside the function.&lt;/p&gt;

&lt;p&gt;This will be the toggle on and toggle off event.&lt;/p&gt;

&lt;p&gt;Without these, our well-written function won't do anything.&lt;/p&gt;

&lt;p&gt;That listener calls the function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;toggleon.addEventListener('click', function () {
  updateMode('lightmode');
});

toggleoff.addEventListener('click', function () {
  updateMode('darkmode');
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we click on the toggleon, it triggers the updateMode function with a parameter of lightmode.&lt;/p&gt;

&lt;p&gt;This implies that whenever we click on either the 'toggleon' or 'toggleoff' icon, we invoke the function to perform different actions.&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%2Fuploads%2Farticles%2Fmt03cg2vvos92o6dvpmx.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%2Fuploads%2Farticles%2Fmt03cg2vvos92o6dvpmx.jpeg" alt="Toggle light and dark mode on HTML, CSS and JAVASCRIPT" width="800" height="311"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and for the final piece of the puzzle:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (mode === 'darkmode') {
  updateMode('darkmode');
} else if (mode === 'lightmode'){
  updateMode('lightmode');
} else {
  updateMode('lightmode');
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the local storage mode is 'darkmode,' update to dark mode.&lt;/p&gt;

&lt;p&gt;If the mode is 'lightmode,' update to light mode.&lt;/p&gt;

&lt;p&gt;The additional condition is our DEFAULT STATE, and it handles situations where no mode is stored in local storage, which often occurs on page load. In such cases, the default action is to set the mode to 'lightmode,' ensuring the page loads in light mode by default.&lt;/p&gt;

&lt;p&gt;This code helps maintain the user's preferred mode across page loads.&lt;/p&gt;

&lt;h2&gt;
  
  
  CONCLUSION
&lt;/h2&gt;

&lt;p&gt;Adding beauty to the user interface (UI) via interaction is crucial because users find it visually appealing.  Also, it is a good trick to learn as it gives beginners a friendly approach to logic in JavaScript and DOM manipulation.&lt;/p&gt;

&lt;p&gt;Thanks for stopping by! If you found this helpful, consider giving it a like, dropping a comment, and hitting that follow button.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>css</category>
    </item>
    <item>
      <title>Mastering CSS Custom Properties: The Senior Developer's Approach to CSS Custom Properties.</title>
      <dc:creator>AlexDunia</dc:creator>
      <pubDate>Sun, 21 Jan 2024 20:54:42 +0000</pubDate>
      <link>https://dev.to/dunia/mastering-css-custom-properties-the-senior-developers-approach-to-css-custom-properties-4088</link>
      <guid>https://dev.to/dunia/mastering-css-custom-properties-the-senior-developers-approach-to-css-custom-properties-4088</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Working with CSS (Cascading Style Sheets) is a very important part of our application as it allows us to change the colors, fonts, and layouts of all our HTML elements.&lt;/p&gt;

&lt;p&gt;It usually involves &lt;a href="https://www.freecodecamp.org/news/css-selectors-cheat-sheet-for-beginners/" rel="noopener noreferrer"&gt;_Class selectors _&lt;/a&gt; that Target elements with a specific class, &lt;a href="https://www.w3schools.com/css/css_selectors.asp" rel="noopener noreferrer"&gt;&lt;code&gt;ID Selectors&lt;/code&gt;&lt;/a&gt; that target elements with a specific ID, and &lt;a href="https://www.w3schools.com/css/css_selectors.asp" rel="noopener noreferrer"&gt;Element Selectors&lt;/a&gt; that target specific HTML elements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Note: I'll assume you already have basic knowledge of CSS before delving into this project.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Also, I made sure that the words colored blue on this article are links. You can click on it to learn more.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now back to our work 👇 :&lt;/p&gt;

&lt;p&gt;For our project, we will be making use of this code with &lt;a href="https://www.geeksforgeeks.org/internal-css/" rel="noopener noreferrer"&gt;Internal CSS&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
&amp;lt;title&amp;gt;Page Title&amp;lt;/title&amp;gt;
&amp;lt;link rel="preconnect" href="https://fonts.googleapis.com"&amp;gt;
&amp;lt;link rel="preconnect" href="https://fonts.gstatic.com" crossorigin&amp;gt;
&amp;lt;link href="https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,100;0,300;0,400;0,700;0,900;1,100;1,300;1,400;1,700;1,900&amp;amp;family=Montserrat:ital,wght@0,100;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100&amp;amp;family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&amp;amp;display=swap" rel="stylesheet"&amp;gt;
&amp;lt;style&amp;gt;

    body {
      font-family: "Poppins", sans-serif;
      background-color: #e8d300;
      color: #333;
      margin: 20px;
    }

    h1 {
      color: white;
      text-align:center;
      padding-top:30px;
      font-size:80px;
      line-height:1.1em;
    }

    p {
      font-size: 25px;
      font-weight:600;
      text-align:center;
      color:rgb(53, 53, 53);
    }

    .custprop{
        color:rgb(61, 61, 61);
    }
  &amp;lt;/style&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;

&amp;lt;h1&amp;gt;CSS &amp;lt;br/&amp;gt; &amp;lt;span class="custprop"&amp;gt; Custom Properties &amp;lt;/span&amp;gt;
 &amp;lt;/br/&amp;gt; Project&amp;lt;/h1&amp;gt;
&amp;lt;p&amp;gt; If you have reached here, then you got it right&amp;lt;/p&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we copy and paste this into our code editor and then save it, we'll end up with a page that looks like this:&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%2Fuploads%2Farticles%2Fk39f60gztngsbei24r5q.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%2Fk39f60gztngsbei24r5q.png" alt="Css custom properties" width="800" height="354"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice I wrote &lt;strong&gt;"CSS CUSTOM PROPERTIES"&lt;/strong&gt;. Good! thats what we will be learning today. Let us start with a definition.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Css properties?
&lt;/h2&gt;

&lt;p&gt;CSS properties are key-value pairs that define a specific styling applied to an HTML element.&lt;/p&gt;

&lt;p&gt;Here is what I mean 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; p {
      font-size: 25px;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, &lt;strong&gt;"font-size"&lt;/strong&gt; is a property, and its value is set to &lt;strong&gt;"25px."&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;While this approach works, it has some limitations.&lt;/p&gt;

&lt;p&gt;For instance,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;If there is another &lt;strong&gt;font-size&lt;/strong&gt; somewhere in the application and it's consistent with &lt;strong&gt;25px&lt;/strong&gt;, when we want to make changes to one, we have to find the other to make changes all over again. If there are 10 of these, we have to make changes in all 10 places it appears on the website. We cannot effortlessly update it across entire codebases.&lt;/li&gt;
&lt;li&gt;We cannot create User-defined variable names. We are limited to &lt;a href="https://www.w3schools.com/cssref/index.php" rel="noopener noreferrer"&gt;built-in properties&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;I know you have seen something that may sound strange to you "User defined variables". We will get to that shortly.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So it has been established that doing iot the traditional way comes with limitations. Because of this, in cases where our websites have a lot of content that will also mean a lot of styling, we can employ a better approach called &lt;strong&gt;CSS Custom properties or Custom variables&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The term "Custom" is used because these &lt;strong&gt;properties are defined by the developer rather than being built-in or predefined by the browser&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;CSS custom properties, or CSS variables, are user-defined values in CSS that hold specific values.&lt;/p&gt;

&lt;p&gt;Take note of these &lt;strong&gt;key statements&lt;/strong&gt; in its definition:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;User-defined values.&lt;/li&gt;
&lt;li&gt;Custom variables.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's try to progressively break them down.&lt;/p&gt;

&lt;h2&gt;
  
  
  User-defined Values
&lt;/h2&gt;

&lt;p&gt;In our previous code, &lt;strong&gt;font-size&lt;/strong&gt; cannot be altered by the developer, because it is built-in. If it is altered, then the code won't run. 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;p {
      myfontsize: 25px;
      front-size:10px;
      fontsize:10px;
      front-size:10px;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;None of the codes defined above will run.&lt;/p&gt;

&lt;p&gt;What Custom Properties allows us to do is to break these rules.&lt;/p&gt;

&lt;p&gt;With Custom properties, we can give it any name we want. If a color is yellow, we can name the property &lt;strong&gt;Spongebob&lt;/strong&gt; and give it a &lt;strong&gt;yellow color&lt;/strong&gt;, and it will run.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Giving it any name we want is the feature that makes it a User-defined value.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If the user (you and I as developers) can customise it to any type of name we want, then it is a user-defined value.&lt;/p&gt;

&lt;h2&gt;
  
  
  CUSTOMISED VARIABLE
&lt;/h2&gt;

&lt;p&gt;Surprisingly, that same control you and I have is also what makes it a &lt;strong&gt;Customised Variable&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;We store information inside, and in the context of programming, a &lt;strong&gt;variable&lt;/strong&gt; is a way to store and use to data in a program.&lt;/p&gt;

&lt;p&gt;The custom properties are the user-defined variables.&lt;/p&gt;

&lt;p&gt;If that has been understood, then we need to now understand &lt;strong&gt;CSS pseudo-class selector&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Pseudo-Class Selector?
&lt;/h2&gt;

&lt;p&gt;A pseudo-class is a keyword added to a selector to indicate a special state or condition of the selected elements.&lt;/p&gt;

&lt;p&gt;For instance, we have the &lt;strong&gt;:hover&lt;/strong&gt;, &lt;strong&gt;:roots&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If this is gibberish to you, then you must &lt;a href="https://www.w3schools.com/css/css_pseudo_classes.asp" rel="noopener noreferrer"&gt;read this to know more about the &lt;strong&gt;pseudo-class&lt;/strong&gt;.&lt;br&gt;
&lt;/a&gt;&lt;br&gt;
In our case, we'll be making use of the &lt;strong&gt;:root&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;:root&lt;/strong&gt; is the highest-level parent element in an HTML document. In simple terms, it is the styling with the most authority.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:root{
background-color:red;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you apply the code above, it overshadows the rest of the stying because it the highest level parent element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;html {
  background-color: red;
  color: white;
}

body{
background-color:red;

:root{
background-color:red;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code above, The styles defined for &lt;strong&gt;:root&lt;/strong&gt; would apply globally to the entire HTML document. Yes, it is &lt;strong&gt;more powerful and global&lt;/strong&gt; than the &lt;strong&gt;html&lt;/strong&gt; and the &lt;strong&gt;body selector&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How can the Custom Variables be used?
&lt;/h2&gt;

&lt;p&gt;To declare a CSS custom variable, use the &lt;strong&gt;-- prefix followed by your preferred name for the variable&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; :root{
        --yellow-background:#e8d300;
        --dark-color:#333;
        --white-color:white;
        --heading-font-size:80px;
        --paragraph-font-size:25px;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;strong&gt;--&lt;/strong&gt; is our &lt;strong&gt;prefix&lt;/strong&gt;, and &lt;strong&gt;--yellow-background --dark-color --white-color --heading-font --paragraph-font-size&lt;/strong&gt; are our custom variables/properties defined within the*&lt;em&gt;:root&lt;/em&gt;* pseudo-class, which represents the highest-level parent element in the document.&lt;/p&gt;

&lt;p&gt;If you noticed all the names of the properties are user-defined.&lt;/p&gt;

&lt;p&gt;We can name it anything we want and use them globally.&lt;/p&gt;

&lt;p&gt;The only condition in which we are allowed to break the rule of &lt;a href="https://www.w3schools.com/cssref/index.php" rel="noopener noreferrer"&gt;built-in or predefined by the browser&lt;/a&gt; is when we use the &lt;strong&gt;-- prefix&lt;/strong&gt; &lt;strong&gt;followed by our preferred name for the variable&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Note: Just to see if it works, you can name it whatever you wish.&lt;/p&gt;

&lt;p&gt;Now that we have declared it, how do we use it?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; :root{
        --yellow-background:#e8d300;
        --dark-color:#333;
        --white-color:white;
        --heading-font-size:80px;
        --paragraph-font-size:25px;
    }

    body {
      font-family: "Poppins", sans-serif;
      background-color: var(--yellow-background);
      color: var(--dark-color);
    }

    h1 {
      color: var(--white-color);
      text-align:center;
      padding-top:50px;
      font-size:var(--heading-font-size);
      line-height:1.1em;
    }

    p {
      font-size: var(--paragraph-font-size);
      font-weight:600;
      text-align:center;
      color:var(--dark-color);
    }

    .custprop{
        color:var(--dark-color);
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you notice, anytime we want to use what we declared in the &lt;strong&gt;: root&lt;/strong&gt;, we have to include a &lt;strong&gt;var()&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;var()&lt;/strong&gt; function in CSS is used to insert the value of a custom property/variable wherever it is called. That is exactly what we did above.&lt;/p&gt;

&lt;p&gt;With this, our styling should work on your browser, and you should be getting the same result as the original code. 👇&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%2Fuploads%2Farticles%2Fvaljgbrx3l9t2adh45n9.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%2Fvaljgbrx3l9t2adh45n9.png" alt="Css for beginners" width="800" height="354"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;CSS custom properties/variables make it simple to change values globally. If we want to change the heading font size, we only need to update it in one place:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:root{
        --heading-font-size:40px;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Notice it was 80px earlier.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With that single adjustment, it changes to 👇&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%2Fuploads%2Farticles%2Fba57zz62wj4n551efen2.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%2Fba57zz62wj4n551efen2.png" alt="css custom properties" width="800" height="355"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we had more classes with more headings, we only need to change the &lt;strong&gt;--heading -font-size&lt;/strong&gt; value once and it updates the rest of the application.&lt;/p&gt;

&lt;p&gt;I hope this is clear.&lt;/p&gt;

&lt;p&gt;Now we can effortlessly update our website across our entire codebases, Provide enhanced readability through user-defined variable names, and ensure reusable style components.&lt;/p&gt;

</description>
      <category>css</category>
      <category>html</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Understanding the Basics: Data Engineering, Data Analytics, and Data Science.</title>
      <dc:creator>AlexDunia</dc:creator>
      <pubDate>Thu, 04 Jan 2024 23:52:16 +0000</pubDate>
      <link>https://dev.to/dunia/understanding-the-basics-data-engineering-data-analytics-and-data-science-39ek</link>
      <guid>https://dev.to/dunia/understanding-the-basics-data-engineering-data-analytics-and-data-science-39ek</guid>
      <description>&lt;p&gt;Artificial Intelligence has had more buzz than ever since Open AI released chat GTP to the public, Alexander Wang, Ceo of Scale AI called it a “Four year overnight success”. This gives an overview of the difficulties involved in building it.&lt;/p&gt;

&lt;p&gt;ChatGPT and other AI tools reveal a fundamental truth: they heavily rely on data. This reliance explains the sudden popularity of fields such as data engineering, data science, and data analysis. It can be said that the influence and popularity of ChatGPT has extended to these domains.&lt;/p&gt;

&lt;p&gt;However, this newfound fame has raised questions about the roles of individuals in related fields. While they all contribute to world-class technologies through their work with data, understanding their individual roles is crucial—especially for people with the desire to get into the fields. This article aims to discuss these roles in concise terms.&lt;/p&gt;

&lt;p&gt;Firstly, let's define data—it's the collection of facts and statistics used for reference or analysis. Not clear enough? Well, let's simplify: Data is the collection of activities, engagements, or actions taken and studied to aid future actions.&lt;/p&gt;

&lt;p&gt;In the business realm, data is a powerful tool. The top players in business recognize that delving deep into data gives them a competitive edge. This awareness further drives the demand for roles we'll explore in this article. Now, let's dive into understanding these crucial roles.&lt;/p&gt;

&lt;p&gt;Data engineering is a field that focuses on designing and building data infrastructure. It involves building and optimizing systems for data analysis.&lt;/p&gt;

&lt;p&gt;If this does not make sense to you, then think of it like this: before anything can be done with data, the data actually needs to exist, and it needs to exist in a way that can be used in the most expandable way possible. Data engineers are responsible for building the foundational infrastructure of data.&lt;/p&gt;

&lt;p&gt;Consider them the architects of data—after constructing the data pipelines, they ensure it is collected, stored, and positioned for future analysis.&lt;/p&gt;

&lt;p&gt;They use tools like SQL (for databases like MySQL, PostgreSQL) and NoSQL databases (like MongoDB, Cassandra) to get and work with data. They also use tools like Hadoop, Oracle Data Integrator, and IBM DataStage to organize, clean, and change data. These tools help them manage and change data for different purposes. The Data engineer ensures that data is available in a structured and usable format for analysis.&lt;/p&gt;

&lt;p&gt;Data engineering is about creating data systems, which can include the development of software systems and applications. Therefore, if you're a software engineer with a good background and strong programming skills, you're in a great position to move into data engineering roles.&lt;/p&gt;

&lt;p&gt;Now, let's shift our focus. We've talked about data engineering, the foundation builders.&lt;/p&gt;

&lt;p&gt;The infrastructure is established, and data is at our fingertips. This is where data analysts step into the scene.&lt;/p&gt;

&lt;p&gt;From the infrastructure built and the data obtained, data analysts can then take the reins by building dashboards, understandable reports, and visuals to provide insights for informed decision-making.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Notice the distinction now? While the former builds the foundation, the latter builds on the foundation.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Once the data infrastructure is in place, the data analysts work with the available data to generate reports, visualizations, and meaningful conclusions. They clean and organize data, analyze it to find important patterns, and explore the data to understand its main characteristics. Afterward, they create easy-to-understand reports and dashboards to help with future work and decision-making.&lt;/p&gt;

&lt;p&gt;Data engineers set up the data infrastructure, and data analysts use it to create reports and visualizations. Engineers build the foundation, and analysts build on it by cleaning and organizing data, finding patterns, and creating easy-to-understand reports and dashboards for decision-making.&lt;/p&gt;

&lt;p&gt;Data analysts employ various tools like Excel for data cleaning, filtering, and charting. They also use advanced visualization tools such as Power BI and Tableau to present data in a clear manner accessible to everyone. This is important because data analysts often engage in soft skills, including presentation in fields like sales, marketing, and finance, requiring effective communication and ensuring understanding to both technical and non-technical audiences.&lt;/p&gt;

&lt;p&gt;If all this doesn't make sense, then let me tell you a story...&lt;/p&gt;

&lt;p&gt;_**Steve Nutjobs sells fashion items online. He's been doing it for a year now and has good data on what he sold. Enter his cousin, Bill, who knows a thing or two about being a data analyst. While helping out, Bill dives into the year's data using tools like Excel.&lt;/p&gt;

&lt;p&gt;As he works, Bill discovers that certain products sell better during specific times or with promotions on social media. Armed with this info, Bill plans targeted promotions and tweaks Steve's inventory to match what customers like. He also analyzes customer feedback and reviews, learning what features and styles shoppers prefer.&lt;/p&gt;

&lt;p&gt;Using these insights, Bill brings in more of the popular products, making customers happier and boosting sales. Steve's online store thrives, all thanks to Bill's data analytics skills.&lt;/p&gt;

&lt;p&gt;Bill has just played his role as a Data Analyst in Steve's eCommerce venture. I hope this story has given you a better understanding, especially in the context of differentiating between the role of a Data Engineer. Although, he would have a more rigorous experience executing his role in bigger organizations, but you get this gist.**_&lt;/p&gt;

&lt;p&gt;Beyond these fundamental tasks, Data Analysts delve into more sophisticated and analytical roles. They use languages like Python and R, write database queries—essentially, guiding instructions for data—and apply math concepts like statistics and probability. Understanding algebra and calculus helps them stand out.&lt;/p&gt;

&lt;p&gt;So, data analysts do all these? Shouldn’t this be everything? What else could possibly exist? I'm glad you have these in mind. This is where the data scientist comes in.&lt;/p&gt;

&lt;p&gt;While data analysts focus on organizing and presenting data, data scientists take it a step further. They delve deep into data mines, utilizing advanced algorithms to shape the future of data. Data scientists develop models that predict outcomes and optimize decision-making processes.&lt;/p&gt;

&lt;p&gt;Take note of a keyword here: 'Model.' This is new, and we haven't seen this before.&lt;/p&gt;

&lt;p&gt;So, what then is a model?&lt;/p&gt;

&lt;p&gt;A 'Model' refers to a mathematical representation or framework created using algorithms and trained on data. The purpose of a model is to make predictions or decisions based on new, unseen data.&lt;/p&gt;

&lt;p&gt;Now, let's utilize the data we already have, we can term them as historical data (training data). We can teach the model patterns and relationships within the data. Why is this useful? Simply because the model learns from this data to make predictions or classifications when exposed to new, unseen data. This officially brings into light the concept of automation and less human input, although in a preliminary way.&lt;/p&gt;

&lt;p&gt;Once trained, the model can be applied to new data to make predictions, classifications, or decisions. And that is what differentiates the Data Analyst from the Data Scientist. Data Science is the extension of Data Analytics. It revolves around more math (a computational degree would be more plausible for job titles around Data Science, although not mandatory if you have enough fieldwork), more analytical thinking, and more programming.&lt;/p&gt;

&lt;p&gt;We can now say that Data science extends beyond descriptive analytics, incorporating more advanced mathematical concepts, analytical thinking, and programming skills.&lt;/p&gt;

&lt;p&gt;The integration of data science with data analytics amplifies the impact of insights gained from data.&lt;/p&gt;

&lt;p&gt;A data scientist utilizes a range of tools and skills, including Python, Power BI, machine learning algorithms, SQL, and mathematical concepts such as statistics and probability.&lt;/p&gt;

&lt;p&gt;Once a model is trained, it can be then deployed in various real-world scenarios to make predictions, classifications, or decisions on their own. Yes, now we are talking about Artificial Intelligence. I'm sure you have heard about this already. :)&lt;/p&gt;

&lt;p&gt;Data scientists may come from fields such as computer science, statistics, physics, and engineering as some mathematical concepts are commonly used in data science (e.g., linear algebra, calculus) and programming languages (e.g., Python, R).&lt;/p&gt;

&lt;p&gt;It's essential to note that, theoretically, the roles of a data scientist, engineer, and analyst differ. In practice, though, these roles often overlap, with blurry lines between them in many organizations, Team members may find themselves wearing multiple hats.&lt;/p&gt;

&lt;p&gt;This situation is particularly common in small companies or startups aiming to minimize spending to meet their goals. At this stage, these organizations carefully manage their resources, leading to a blending of roles. So, Despite officially designating the position as a 'Data Scientist,' in practice, it extends to encompass the day-to-day or occasional implementation of both data engineers and analysts.&lt;/p&gt;

&lt;p&gt;In Big companies, however, the division of labor tends to be more specialized, and roles may be more clearly defined, that is, the data scientist will do the job of the Data Scientist, the Data Analyst will do the job of the analyst, etc. This is most likely because, unlike a startup, their number one priority may not be to manage their resources and use fewer people.&lt;/p&gt;

&lt;p&gt;Now you know the difference between a Data Engineer, Data Analyst, and Data Scientist, And if there's any part you do not fully comprehend, you can always go back to read as it has been written in an easy and digestible way.&lt;/p&gt;

&lt;p&gt;And for the people wanting to get into any of these spaces, its very important to consider the things that interest you.&lt;/p&gt;

&lt;p&gt;If you are good at advanced mathematical concepts, analytical thinking, and programming, then pursuing a career in data science is the right move for you.&lt;/p&gt;

&lt;p&gt;If you prefer storytelling, analyzing businesses, or Maths (Average level but the higher the better), Data Analytics is the right choice for you.&lt;/p&gt;

&lt;p&gt;And lastly, if you enjoy building infrastructures or have a background in software engineering already, then pushing it further in a way that compliments your already existing skills is you opting for Data Engineering.&lt;/p&gt;

&lt;p&gt;Ultimately, your success depends on picking what works for you and becoming a consistent doer.&lt;/p&gt;

&lt;p&gt;If you like this content, kindly give it a like and share, it would go a long way :).&lt;/p&gt;

&lt;p&gt;See you soon.&lt;/p&gt;

&lt;p&gt;Good luck :)&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
