<?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: Chisom Uma</title>
    <description>The latest articles on DEV Community by Chisom Uma (@chisom642).</description>
    <link>https://dev.to/chisom642</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%2F812599%2Fd3272fb4-522d-41ac-8675-251c4ac35723.png</url>
      <title>DEV Community: Chisom Uma</title>
      <link>https://dev.to/chisom642</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/chisom642"/>
    <language>en</language>
    <item>
      <title>Custom Ecommerce Platform vs. Off-the-Shelf: 5 Factors to Help You Make the Best Choice</title>
      <dc:creator>Chisom Uma</dc:creator>
      <pubDate>Mon, 03 Jul 2023 10:48:40 +0000</pubDate>
      <link>https://dev.to/chisom642/custom-ecommerce-platform-vs-off-the-shelf-5-factors-to-help-you-make-the-best-choice-46c0</link>
      <guid>https://dev.to/chisom642/custom-ecommerce-platform-vs-off-the-shelf-5-factors-to-help-you-make-the-best-choice-46c0</guid>
      <description>&lt;p&gt;A custom ecommerce platform is a unique and tailored solution for selling products or services online built to meet a business's specific needs and requirements. This platform provides greater control and customization options compared to off-the-shelf ecommerce solutions. Custom ecommerce platforms are designed from scratch, allowing for greater flexibility and security.&lt;/p&gt;

&lt;p&gt;Off-the-shelf ecommerce platforms are prebuilt software that can be installed almost immediately after they are acquired. The platform provides all the essential features ready in one platform. It makes it easier and faster for stores to get up and running. Using an off-the-shelf platform requires minimal development work to set up as-is, putting aside customizations.&lt;/p&gt;

&lt;p&gt;Companies like Sephora and Netflix merch shops have used off-the-shelf ecommerce platforms such as Shopify. On the other hand, companies such as Amazon and Tesla use custom ecommerce platforms.&lt;/p&gt;

&lt;p&gt;This article examines the differences between a custom ecommerce and an off-the-shelf platform and provides readers with a better understanding of the advantages and disadvantages of each option. This article aims to help you decide which is the best fit for your ecommerce business.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What are Off-the-Shelf Ecommerce Platforms?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Off-the-Shelf ecommerce platforms are pre-built software solutions for building and managing an online store. These platforms provide a wide range of features and functionalities to online businesses set up and run quickly without requiring extensive technical knowledge. Examples of off-the-shelf ecommerce platforms include Shopify, Magento, WooCommerce, and BigCommerce.&lt;/p&gt;

&lt;p&gt;Off-the-shelf platforms can be installed and deployed immediately, allowing businesses to start selling online quickly.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Pros of Off-the-shelf Ecommerce Platforms&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Time-Saving&lt;/strong&gt; : it provides the basic ecommerce features out-of-the-box, allowing businesses to go live quickly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Plugins:&lt;/strong&gt; There is an availability of plugins that can add various features with minimal additional technical work.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Regular Updates:&lt;/strong&gt; Off-the-shelf ecommerce platforms are designed to be updated regularly to ensure they remain secure and compliant with the latest technologies and standards.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Cons of Off-the-Shelf Ecommerce Platforms&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Despite the benefits of off-the-shelf platforms, its worth noting that some large companies, including Amazon, Nike, and Tesla, prefer not to use them. There are several reasons behind this decision, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Slow Site Speed:&lt;/strong&gt; Customization most times include plugins. Plugins are one of the advantages of an off-the-shelf platform, but they can slow down your site. Too many plugins could risk slowing down your site or even causing it to crash.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Integration Problems:&lt;/strong&gt; Integrations are hard to add because most off-the-shelf platforms either don't allow you to own your tech stack completely or dont provide the necessary architecture for seamless integrations. This often leads to unanticipated bugs or leaves the platform at risk of breaking.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fewer Customization Options:&lt;/strong&gt; A challenge of customizing an off-the-shelf ecommerce platform is the platform's architecture. These platforms are often built with a specific architecture that may not be flexible enough to accommodate changes easily. Customizing the platform's architecture can lead to the accumulation of technical debt, making it harder to update or test the platform in the future.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Control limitations:&lt;/strong&gt; An off-the-shelf platform can limit the businesss control and customization options as the platform may have strict limitations on what can be modified or altered. This can impact the ability of the business to differentiate itself from competitors and meet specific customer needs effectively.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Lack of Tech Ownership:&lt;/strong&gt; An off-the-shelf platform does not allow businesses to choose the architecture or the components of their ecommerce store, including what integrations they want to use or features they want to add.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;High Costs Risks:&lt;/strong&gt; Businesses may also be at the mercy of the provider's pricing and licensing models, which can change without notice and potentially increase operating costs. Additionally, if the provider goes out of business or discontinues the platform, the business may be forced to switch to a different solution, leading to significant disruption and additional costs.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What are Custom Ecommerce Platforms?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Custom ecommerce platforms are online shopping systems created for a specific business use case. Unlike off-the-shelf ecommerce solutions, these platforms are tailored to fit the unique features that the business wants to offer. This includes custom payment and shipping options, personalized branding design, and integrations with specific business tools and systems.&lt;/p&gt;

&lt;p&gt;These platforms give businesses greater control and flexibility over their online sales processes than pre-built solutions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medusajs.com/" rel="noopener noreferrer"&gt;Medusa&lt;/a&gt; is an excellent example of a custom commerce infrastructure.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Pros of Custom Ecommerce Platforms&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Full Control and Ownership:&lt;/strong&gt; A custom ecommerce platform gives businesses full control and ownership over their online store by allowing them to tailor the platform to their specific needs and requirements. It is designed to meet the business's unique requirements from the ground up. This means the business has complete control over its online store's functionality, design, and user experience, allowing it to create a truly personalized shopping experience for its customers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scalability:&lt;/strong&gt; A custom ecommerce platform offers scalability to businesses by being designed and built specifically to meet their unique needs and requirements. With a platform tailored to a company's specific business needs, businesses can easily scale their operations as they grow without worrying about limitations or constraints imposed by generic off-the-shelf solutions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Improved Performance:&lt;/strong&gt; The platform provides businesses with a tailored solution optimized for their unique processes, customer base, and goals. This means the platform is designed to function efficiently and effectively without unnecessary features or excess resources. The result is faster load times, better user experience, and increased sales, as customers can find what they are looking for and complete their purchases quickly and smoothly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Customization:&lt;/strong&gt; Custom ecommerce platforms have the abstract architecture and tooling that allows businesses to easily customize any essential ecommerce features to match their use case without needing hacky workarounds.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Creating Custom Ecommerce Platforms Approaches
&lt;/h2&gt;

&lt;p&gt;Developing a custom ecommerce platform can be a daunting task for any business. However, there are several approaches available to make it easier. The following are some of the most popular ways to create a custom ecommerce platform.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Custom Development from Scratch&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Hire a professional developer. A business would work with a development team to create the platform from scratch.&lt;/p&gt;

&lt;p&gt;This approach gives you more control over the platform's features, design, and functionality.&lt;/p&gt;

&lt;p&gt;However, it takes more time to re-invent the wheel on basic ecommerce features, which leads to less focus on new and custom features and takes the platform longer to be ready to go live&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Open Source Custom Ecommerce Platform&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Open-source custom ecommerce platforms are cost-effective. They are free to use and allow you to make customizations easily. They also come with a range of community support, so you can get help if needed. Medusa is a leading open source commerce infrastructure for Node.js developers. It provides a flexible and modular architecture that can be easily customized to fit your business needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Trade-offs Between Custom Ecommerce Platforms Vs. Off-the-shelf Platforms&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Need for Solution Flexibility&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Custom ecommerce platforms are built specifically for your business so that they can be tailored to your specifications. This level of customization allows for greater flexibility and control over the functionality and design of your ecommerce store. You can add or remove features as you see fit and ensure your store is unique and stands out.&lt;/p&gt;

&lt;p&gt;On the other hand, off-the-shelf ecommerce platforms offer a more standardized solution that may not be as flexible. While these platforms typically come with a wide range of features and integrations, they may not be able to accommodate all of your business needs.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Development Speed&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Custom solutions are great when it comes to the development of custom features. Although, It requires more time to design and build the platform from scratch or use an open-source solution to fit the specific business needs.&lt;/p&gt;

&lt;p&gt;Off-the-shelf platforms are set up quickly because they are pre-built and only need configuring to meet the business's requirements. It makes it faster to set up and deploy your store.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Scalability&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Custom ecommerce platforms are designed and developed specifically for the needs of a particular business. They are highly scalable and flexible, allowing businesses to add new features and functionality as they grow. Custom ecommerce platforms can also be optimized for performance and speed, ensuring they can handle increased traffic without slowing down.&lt;/p&gt;

&lt;p&gt;Off-the-shelf platforms lack the flexibility and scalability to grow with a business's evolving needs. These platforms do not have the specific features or customization options individual businesses require.&lt;/p&gt;

&lt;p&gt;As a business grows, it may require more advanced features or integrations unavailable on the off-the-shelf platform. Also, the platform may become slow or unreliable as the number of users or data increases. Upgrades or changes to the platform can be expensive and may not always be compatible with existing systems or workflows.&lt;/p&gt;

&lt;p&gt;Off-the-shelf platforms are pre-built solutions that offer a range of features and functionality out of the box. They are also designed to be scalable and can handle increased traffic and transactions as businesses grow.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Upfront Cost vs. Cost Over Time&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Custom ecommerce platforms are typically expensive upfront but offer more flexibility, scalability, and customization options. Upfront costs can be high, requiring specialized development, design, and testing to ensure a seamless user experience. However, custom eCommerce solutions often cost less over time than pre-built solutions.&lt;/p&gt;

&lt;p&gt;On an off-the-shelf platform, developing new features becomes costly and time-consuming. More time is spent resolving unanticipated bugs from third-party libraries or plugins, which can introduce compatibility issues or complex codebases. Off-the-shelf platforms may have specific upfront and long-term costs for using the platform, but more costs come with adding new features, maintaining the platform, and so on.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Developer Resources&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Custom ecommerce platforms typically require more developer resources and agency support as they need to be built from scratch. This includes time and effort in designing, coding, testing, and maintaining the platform.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Build Custom Ecommerce Platforms with Medusa&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://medusajs.com/" rel="noopener noreferrer"&gt;Medusa&lt;/a&gt; is an open source composable digital commerce infrastructure that makes it effortless for businesses, developers, and merchants to build fully customizable commerce applications easily, providing an incredible developer experience.&lt;/p&gt;

&lt;p&gt;Medusa is an optimal option for building custom ecommerce stores due to the following reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Developer-Friendly: Medusa provides a great developer experience due to its modular architecture.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open Source: Most ecommerce platforms will not allow you complete ownership of your existing tech stacks. This isn't the case with Medusa; it is open source and lets you control your tech stacks completely.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Flexibility: You can integrate it with third-party tools, including customer relationship management (CRM) and enterprise resource planning (ERP) systems, as well as external services like social media and marketing automation. This allows businesses to streamline their operations and get the most out of their ecommerce platform.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Customization: Medusa is composed of an abstraction-based architecture built for seamless customization. This allows you to set up your store according to your preferred business needs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Community Support: With over 4000 developers on its Discord channel, Medusa has a strong community that is always willing to help. By participating in GitHub discussions with other ecommerce builders, open-source developers, and the Medusa core team, developers can also contribute to Medusa's growth.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This article explores the differences and trade-offs between custom ecommerce solutions and off-the-shelf solutions. The first offers distinct advantages over off-the-shelf solutions, especially for larger organizations. With custom ecommerce, businesses can tailor their stores to fit the specific needs of their customers.&lt;/p&gt;

&lt;p&gt;With Medusa, you can easily customize and maintain your ecommerce store. Maintaining your products on the platform, offering discounts and gift cards, supporting multiple currencies, and much more. This is possible with Medusa's headless architecture, which separates the admin dashboard from the storefront and back-end server.&lt;/p&gt;

&lt;p&gt;To learn more about Medusa and how to get started, check out &lt;a href="https://docs.medusajs.com/" rel="noopener noreferrer"&gt;Medusa's Documentation&lt;/a&gt; and &lt;a href="https://docs.medusajs.com/user-guide/" rel="noopener noreferrer"&gt;User Guide&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>A Complete Guide To API Calls With React And Axios</title>
      <dc:creator>Chisom Uma</dc:creator>
      <pubDate>Mon, 21 Mar 2022 16:11:11 +0000</pubDate>
      <link>https://dev.to/chisom642/a-guide-to-api-calls-with-react-and-axios-520i</link>
      <guid>https://dev.to/chisom642/a-guide-to-api-calls-with-react-and-axios-520i</guid>
      <description>&lt;p&gt;In this post, we are to be looking at how to use Axios in fetching data, manipulating it, and displaying it on your page with filtering functionality. We are also going to learn how to use the map, filter, and include method. In addition to that, you will learn how to create a simple loader to handle the loading state of the fetched data from the API endpoint.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up the project
&lt;/h2&gt;

&lt;p&gt;The first thing we need to do is set up the project with the &lt;code&gt;create-react-app&lt;/code&gt; command terminal:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-app project-name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Next thing is to open up the project directory through the terminal window, then input  &lt;code&gt;npm install axios&lt;/code&gt; to install Axios for the project locally. &lt;/p&gt;

&lt;h2&gt;
  
  
  Choose Target API
&lt;/h2&gt;

&lt;p&gt;To do this, we are going to be using the &lt;a href="https://www.randomuser.me/" rel="noopener noreferrer"&gt;Random User Generator API&lt;/a&gt; to fetch random user information, which we are going to use in our application. The next step is to add the Axios module to the application by importing it into our &lt;code&gt;App.js&lt;/code&gt; file. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import axios from 'axios'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The next thing we are going to do is to fetch ten different users, and we are going to need only the name, last name, and a unique ID, which is required for React when creating lists of elements. This will also make the call more specific, for example, the nationality option.&lt;/p&gt;

&lt;p&gt;Check out the API URL that we will make the call  for below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://randomuser.me/api/?results=10&amp;amp;inc=name,registered&amp;amp;nat=fr 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; i did not use the  &lt;code&gt;id&lt;/code&gt; option that was provided in the API because sometimes it returns &lt;code&gt;null&lt;/code&gt; for some users. I made sure that there will be a unique value for each user, by including the &lt;code&gt;registered&lt;/code&gt; option in  the API. &lt;/p&gt;

&lt;p&gt;Copy and paste it on your browser, you will  see the returned data in JSON format.&lt;/p&gt;

&lt;p&gt;The next thing is to make an API call through Axios.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating the App States
&lt;/h2&gt;

&lt;p&gt;The first thing we are going to do is create the states using the &lt;code&gt;useState&lt;/code&gt; hook from the React, so that we can be able to store the fetched data. &lt;/p&gt;

&lt;p&gt;Inside our &lt;code&gt;App&lt;/code&gt; component, next thing is to import the &lt;code&gt;useState&lt;/code&gt; hook from React and then create the states as seen below.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState } from "react";
import axios from "axios";

const App = () =&amp;gt; {
  const [users, setUsers] = useState([]);
  const [store, setStore] = useState([]);

  return (
    &amp;lt;div&amp;gt;

    &amp;lt;/div&amp;gt;
  );
};

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can see the &lt;code&gt;users&lt;/code&gt; and &lt;code&gt;store&lt;/code&gt; states. One will be used for the purpose of filtering, and won’t be edited, while the other one will hold the filter results that will hold the filter results that will be shown in the DOM.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fetch Data With Axios
&lt;/h2&gt;

&lt;p&gt;Next thing is to create a &lt;code&gt;getUsers&lt;/code&gt; function that will handle the fetching of data. In this function, we are going to use &lt;code&gt;axios&lt;/code&gt; to fetch our data from the API using &lt;code&gt;get&lt;/code&gt; method. &lt;/p&gt;

&lt;p&gt;For us to display our fetched data when the page loads, we will have to import a React hook called &lt;code&gt;useEffect&lt;/code&gt; and call the &lt;code&gt;getUsers&lt;/code&gt;  function inside it. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;useEffect&lt;/code&gt;  is responsible for managing the side effects in functional components, and it is similar to the &lt;code&gt;componentDidMount()&lt;/code&gt; lifecycle hook that is usually used in React class-based components. This hook accepts an empty array as a second argument for the purpose of side-effects cleanups. What you  should do now is update the code in the &lt;code&gt;App&lt;/code&gt; component, so that we check for the response data in the console, as shown below.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState, useEffect } from "react";

const App = () =&amp;gt; {
  const [users, setUsers] = useState([]);
  const [store, setStore] = useState([]);

  const getUsers = () =&amp;gt; {
    axios.get("https://randomuser.me/api/?results=10&amp;amp;inc=name,registered&amp;amp;nat=fr")
      .then(response =&amp;gt; console.log(response))
  };

  useEffect(() =&amp;gt; {
    getUsers();
  }, []);

  return (
    &amp;lt;div&amp;gt;

    &amp;lt;/div&amp;gt;
  );
};

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Check the console, you will see an object output. Open the object, and you will see another object inside named &lt;code&gt;data&lt;/code&gt; , inside the data, you will see an array known as &lt;code&gt;results&lt;/code&gt;. If you want to return a specific value from the results, you can update the &lt;code&gt;axios.get&lt;/code&gt; call as seen below.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;axios.get("https://randomuser.me/api/?results=10&amp;amp;inc=name,registered&amp;amp;nat=fr")
  .then(response =&amp;gt; console.log(response.data.results[0].name.first))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;What we did here is to log the name of the first value inside the results array.&lt;/p&gt;

&lt;h2&gt;
  
  
  Process the Result Data
&lt;/h2&gt;

&lt;p&gt;What we are going to do next is to use the built-in &lt;code&gt;map&lt;/code&gt; method for JavaScript in order to iterate through each element inside the array and create a new array of JavaScript Objects with a new structure. &lt;/p&gt;

&lt;p&gt;As shown below, update your`&lt;code&gt;getUsers&lt;/code&gt; function:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const getUsers = () =&amp;gt; {
  axios
    .get("https://randomuser.me/api/?results=10&amp;amp;inc=name,registered&amp;amp;nat=fr")
    .then((response) =&amp;gt; {
      const newData = response.data.results.map((result) =&amp;gt; ({
        name: `${result.name.first} ${result.name.last}`,
        id: result.registered
      }));
      setUsers(newData);
      setStore(newData);
    })
    .catch((error) =&amp;gt; {
      console.log(error);
    });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;What we did in the code above is that we created a variable called &lt;code&gt;newData&lt;/code&gt;. It stores the results by looking through the &lt;code&gt;response.data.results&lt;/code&gt; array with the &lt;code&gt;map&lt;/code&gt; method. Between the &lt;code&gt;map&lt;/code&gt; callback, we are going to reference each element of the array as &lt;code&gt;result&lt;/code&gt; (notice the singular/plural difference). Also, when we use the key-value pair of each object inside the array, we create another object with &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;id&lt;/code&gt; key-value pairs.&lt;/p&gt;

&lt;p&gt;Normally, if you go and check the result of the API call in your browser, you will notice that there are &lt;code&gt;first&lt;/code&gt; and &lt;code&gt;last&lt;/code&gt; key-value pairs inside the &lt;code&gt;name&lt;/code&gt; object, but there is no no key-value pair for full name. From the code is showed you above, i was able to combine the &lt;code&gt;first&lt;/code&gt; and &lt;code&gt;last&lt;/code&gt; names to create a full name inside the JavaScript object. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; the JSON and JavaScript objects are different things, even though they work pretty much the same way.&lt;/p&gt;

&lt;h2&gt;
  
  
  Populate Data Stores With Filtering
&lt;/h2&gt;

&lt;p&gt;The idea of filtering is not difficult at all. We have our &lt;code&gt;store&lt;/code&gt; state, which keeps the original data always without changing. By using the &lt;code&gt;filter&lt;/code&gt; function on this state, we only get the matching elements, then we assign them to the &lt;code&gt;users&lt;/code&gt; state.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const filteredData = store.filter((item) =&amp;gt; (
    item.name.toLowerCase().includes(event.target.value.toLowerCase()))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;filter&lt;/code&gt; method requires a function as an argument, a function that will run  for each element in the array. Here, we are going to be referring to each element inside the array as &lt;code&gt;item&lt;/code&gt;. Then, the next thing is to take the &lt;code&gt;name&lt;/code&gt; key of each item and convert it to lower case so that we can make our filtering functionality case insensitive.&lt;/p&gt;

&lt;p&gt;In the end, the &lt;code&gt;filter&lt;/code&gt; method returns the matching elements. So, we just simply take these elements and store them in the &lt;code&gt;setUsers&lt;/code&gt; state.&lt;/p&gt;

&lt;p&gt;Next is to update the &lt;code&gt;App&lt;/code&gt; component with the final version of the function we created.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const filterNames = (event) =&amp;gt; {
   const filteredData = store.filter((item) =&amp;gt;
     item.name.toLowerCase().includes(event.target.value.toLowerCase())
   );
   setUsers(filteredData);
 };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Creating the Components
&lt;/h2&gt;

&lt;p&gt;We can actually put everything inside the &lt;code&gt;App&lt;/code&gt; component for this small example, but let’s take advantage of React and make small functional components.&lt;/p&gt;

&lt;p&gt;Let us add some components to the app. The first thing is to import the components from separate JavaScript files, which we will define soon.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Lists from "./components/Lists";
import SearchBar from "./components/SearchBar";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Next thing is to update our &lt;code&gt;App&lt;/code&gt; components return statement to make use of these components.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return (
  &amp;lt;div className="Card"&amp;gt;
      &amp;lt;div className="header"&amp;gt;NAME LIST&amp;lt;/div&amp;gt;
      &amp;lt;SearchBar searchFunction={filterNames} /&amp;gt;
      &amp;lt;Lists usernames={users} /&amp;gt;
  &amp;lt;/div&amp;gt;
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If you notice, there is the &lt;code&gt;searchFunction&lt;/code&gt;  prop for the &lt;code&gt;SearchBar&lt;/code&gt; component and the &lt;code&gt;usernames&lt;/code&gt; prop for the &lt;code&gt;Lists&lt;/code&gt; component.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; we are going to be using &lt;code&gt;users&lt;/code&gt; state instead of the &lt;code&gt;store&lt;/code&gt; state to show the data. This is because the &lt;code&gt;users&lt;/code&gt; state contains the filtered results.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;**SearchBar**&lt;/code&gt; &lt;strong&gt;Component&lt;/strong&gt;&lt;br&gt;
This component only takes the &lt;code&gt;filterNames&lt;/code&gt; function as a prop and calls this function when the input field changes. Put the code below on &lt;strong&gt;components/SearchBar.Js:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';

const SearchBar = ({ searchFunction}) =&amp;gt; {
  return (
    &amp;lt;div&amp;gt;
        &amp;lt;input className="searchBar" type='search' onChange={searchFunction} /&amp;gt;
    &amp;lt;/div&amp;gt;
  )
};

export default SearchBar;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;List  Component&lt;/strong&gt;&lt;br&gt;
This List Component lists the names of the users. Put it into the &lt;strong&gt;components/List.js&lt;/strong&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';

const Lists = ({ usernames }) =&amp;gt; {
  return (
      &amp;lt;div&amp;gt;
          &amp;lt;ul&amp;gt;
              {usernames.map(username =&amp;gt; (
                  &amp;lt;li key={username.id}&amp;gt;{username.name}&amp;lt;/li&amp;gt;
              ))}
          &amp;lt;/ul&amp;gt;
      &amp;lt;/div&amp;gt;
  )
};

export default Lists;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Again, we used the map method to get each item in the array and  create a &lt;code&gt;&amp;lt;li&amp;gt;&lt;/code&gt; item out of it. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; when ****you use &lt;code&gt;map&lt;/code&gt; to create a list of items, you should use a &lt;code&gt;key&lt;/code&gt; so that React will keep track of each list item.&lt;/p&gt;

&lt;h2&gt;
  
  
  Track Loading State
&lt;/h2&gt;

&lt;p&gt;To create a loading state, we have to use &lt;code&gt;useState&lt;/code&gt; hook to show when the data is yet to  be fetched.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [loading, setLoading] = useState(false);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The next step is to update the loading state in our data fetch  method.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const getUsers = () =&amp;gt; {
  axios.get("https://randomuser.me/api/?results=10&amp;amp;inc=name,registered&amp;amp;nat=fr")
    .then((response) =&amp;gt; {
      const newData = response.data.results.map((result) =&amp;gt; ({
        name: `${result.name.first} ${result.name.first}`,
        id: result.registered,
      }));
      setLoading(true);
      setUsers(newData);
      setStore(newData);
    })
    .catch((error) =&amp;gt; {
      console.log(error);
    });
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;What we did here is create a loading state and set it to false initially. We then set this  state to true while fetching the data with the &lt;code&gt;setLoading&lt;/code&gt; state. Finally, we are going to return statement to render the loading state as shown below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return (
  &amp;lt;&amp;gt;
    {loading ? (
      &amp;lt;div className="Card"&amp;gt;
        &amp;lt;div className="header"&amp;gt;NAME LIST&amp;lt;/div&amp;gt;
        &amp;lt;SearchBar searchFunction={filterNames} /&amp;gt;
        &amp;lt;Lists users={users} /&amp;gt;
      &amp;lt;/div&amp;gt;
    ) : (
      &amp;lt;div className="loader"&amp;gt;&amp;lt;/div&amp;gt;
    )}
  &amp;lt;/&amp;gt;
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We used the JavaScript ternary operator to render the &lt;code&gt;SearchBar&lt;/code&gt; and &lt;code&gt;Lists&lt;/code&gt; components when the loading state is false and then rendered a loader when the loading state is true. We also created a simple loader to display to display the loading state in the interface. &lt;/p&gt;

&lt;h2&gt;
  
  
  Style With CSS
&lt;/h2&gt;

&lt;p&gt;This is the CSS file specific to this example:&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body,&lt;br&gt;
html {&lt;br&gt;
  -webkit-font-smoothing: antialiased;&lt;br&gt;
  margin: 0;&lt;br&gt;
  padding: 0;&lt;br&gt;
  font-family: "Raleway", sans-serif;&lt;br&gt;
  -webkit-text-size-adjust: 100%;&lt;br&gt;
}

&lt;p&gt;body {&lt;br&gt;
  display: flex;&lt;br&gt;
  justify-content: center;&lt;br&gt;
  font-size: 1rem/16;&lt;br&gt;
  margin-top: 50px;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;li,&lt;br&gt;
ul {&lt;br&gt;
  list-style: none;&lt;br&gt;
  margin: 0;&lt;br&gt;
  padding: 0;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;ul {&lt;br&gt;
  margin-top: 10px;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;li {&lt;br&gt;
  font-size: 0.8rem;&lt;br&gt;
  margin-bottom: 8px;&lt;br&gt;
  text-align: center;&lt;br&gt;
  color: #959595;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;li:last-of-type {&lt;br&gt;
  margin-bottom: 50px;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.Card {&lt;br&gt;
  font-size: 1.5rem;&lt;br&gt;
  font-weight: bold;&lt;br&gt;
  display: flex;&lt;br&gt;
  flex-direction: column;&lt;br&gt;
  align-items: center;&lt;br&gt;
  width: 200px;&lt;br&gt;
  border-radius: 10px;&lt;br&gt;
  background-color: white;&lt;br&gt;
  box-shadow: 0 5px 3px 0 #ebebeb;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.header {&lt;br&gt;
  position: relative;&lt;br&gt;
  font-size: 20px;&lt;br&gt;
  margin: 12px 0;&lt;br&gt;
  color: #575757;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.header::after {&lt;br&gt;
  content: "";&lt;br&gt;
  position: absolute;&lt;br&gt;
  left: -50%;&lt;br&gt;
  bottom: -10px;&lt;br&gt;
  width: 200%;&lt;br&gt;
  height: 1px;&lt;br&gt;
  background-color: #f1f1f1;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.searchBar {&lt;br&gt;
  text-align: center;&lt;br&gt;
  margin: 5px 0;&lt;br&gt;
  border: 1px solid add8e6;&lt;br&gt;
  height: 20px;&lt;br&gt;
  color: #575757;&lt;br&gt;
  border-radius: 3px;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.searchBar:focus {&lt;br&gt;
  outline-width: 0;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.searchBar::placeholder {&lt;br&gt;
  color: #dadada;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.loader {&lt;br&gt;
  border: 15px solid #ccc;&lt;br&gt;
  border-top: 15px solid #add8e6; &lt;br&gt;
  border-bottom: 15px solid #add8e6;&lt;br&gt;
  border-radius: 50%;&lt;br&gt;
  width: 80px;&lt;br&gt;
  height: 80px;&lt;br&gt;
  animation: rotate 2s linear infinite;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;@keyframes rotate {&lt;br&gt;
  0% { transform: rotate(0deg); }&lt;br&gt;
  100% { transform: rotate(360deg); }&lt;br&gt;
}&lt;br&gt;
&lt;/p&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  Conclusion&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;In this tutorial, we used the &lt;a href="https://www.randomuser.me/" rel="noopener noreferrer"&gt;Random User Generator API&lt;/a&gt; as the source of random user data. We then fetched the data from an API endpoint and restructured the results inside a new JavaScript object with the &lt;code&gt;map&lt;/code&gt; method. &lt;/p&gt;

&lt;p&gt;The next thing we did was to create a filtering function with the &lt;code&gt;filter&lt;/code&gt;  and &lt;code&gt;includes&lt;/code&gt; methods. Then finally, we created two different components and conditionally rendered our components with a loading state when the data is not fetched  yet.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Simple ‘Mixin’ Alternative To Standard CSS Grids</title>
      <dc:creator>Chisom Uma</dc:creator>
      <pubDate>Sat, 12 Mar 2022 13:22:05 +0000</pubDate>
      <link>https://dev.to/chisom642/simple-mixin-alternative-to-standard-css-grids-3m4l</link>
      <guid>https://dev.to/chisom642/simple-mixin-alternative-to-standard-css-grids-3m4l</guid>
      <description>&lt;p&gt;Using CSS grid to generate layouts in a design provides developers with value, and makes things a lot easier for developers, but there are still some problems or downsides of using the CSS grid systems. &lt;/p&gt;

&lt;p&gt;The main reason designers and web developers use &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout" rel="noopener noreferrer"&gt;CSS grid&lt;/a&gt; systems is to make the generation of layouts easier and faster. But the question is “can the generation of layouts be made easier and faster, and still overcome these problems?”. &lt;/p&gt;

&lt;p&gt;Fortunately for us, the answer is “Yes!’, all thanks to CSS preprocessors such as &lt;a href="https://lesscss.org/" rel="noopener noreferrer"&gt;LESS&lt;/a&gt; and &lt;a href="https://sass-lang.com/" rel="noopener noreferrer"&gt;SASS/SCSS&lt;/a&gt; that can work with CSS variables, and perform calculations and output CSS via ‘mixins’.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Outline&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;How CSS Grid System Works&lt;/li&gt;
&lt;li&gt;Some Downsides Of Using CSS Grids

&lt;ul&gt;
&lt;li&gt;High amounts of unused code&lt;/li&gt;
&lt;li&gt;Restrictions on layout&lt;/li&gt;
&lt;li&gt;set number of  overall columns&lt;/li&gt;
&lt;li&gt;Non semantic markup&lt;/li&gt;
&lt;li&gt;Restrictions on nesting&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;An Alternative Solution&lt;/li&gt;

&lt;li&gt;Tackling The Classic Layout

&lt;ul&gt;
&lt;li&gt;Easy px to em/rem conversion&lt;/li&gt;
&lt;li&gt;.Row() mixin&lt;/li&gt;
&lt;li&gt;.Cols() mixin&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Adding Padding And Margins

&lt;ul&gt;
&lt;li&gt;Adding padding&lt;/li&gt;
&lt;li&gt;Adding wrapping padding&lt;/li&gt;
&lt;li&gt;Adding column gutters&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Nesting And Increasing Layout Complexity&lt;/li&gt;

&lt;li&gt;Conclusion&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Prerequisite
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Basic knowledge of CSS and CSS grids&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;How CSS Grid Systems Work&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;A grid system is usually made up of a specific number of columns, normally 12 or 16 columns, and the ability to set an element, like the &lt;code&gt;div&lt;/code&gt; or &lt;code&gt;class&lt;/code&gt; element, to a width of X columns. &lt;/p&gt;

&lt;p&gt;Using CSS grid systems to create layouts on a website can be really easy, and of course, there are many values you can get from using CSS grid systems, but there are also downsides to using the CSS grid system. &lt;/p&gt;

&lt;p&gt;You should not think that using the CSS grid is bad because it isn’t. But as a tool you will be using consistently in your codes, you should be able to know the pros and cons, to determine if it is right for a specific project.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Some Downsides Of Using CSS Grids&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Some of the downsides of using CSS Grids include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;High amounts of unused code&lt;/strong&gt;: Grid classes could be anywhere from 200 to 700 lines of code, but even in a  simple design,             most of the codes may never be used.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Restrictions on layout&lt;/strong&gt;: Grids are already calculated, they tend to have set widths that are difficult to change, e.g.                 column widths, gutter widths. The design becomes restricted to working only those widths.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Set number of overall columns&lt;/strong&gt;: Already calculated grid classes normally uses 12 or 16 columns. Let’s say you wanted a                     different number of columns, well, that won’t be possible.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Non Semantic markup&lt;/strong&gt;: The use of grid classes tends to bring about the placement of numerous non-semantic class           names all through a document, such as a “row” or  “column”.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Restrictions on nesting&lt;/strong&gt;: Most times, grid systems can only have columns that are nested inside one another.               This restricts the complexity and flexibility of layout generation.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;An Alternative Solution&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;‘Mixins’ are available in both &lt;a href="https://lesscss.org/" rel="noopener noreferrer"&gt;LESS&lt;/a&gt; and &lt;a href="https://sass-lang.com/" rel="noopener noreferrer"&gt;SASS/SCSS&lt;/a&gt;. Mixins are reusable packages of rules that outputs different CSS depending on the information that  is passed through them for processing. &lt;/p&gt;

&lt;p&gt;If you are not yet familiar with the understanding of what preprocessors are, and how they work with mixins and variables, you can read about it from &lt;a href="http://lesscss.org/" rel="noopener noreferrer"&gt;http://lesscss.org/&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;Before we get started, you should know that there are already some existing libraries of LESS and SASS  mixins that are already solving the problems if CSS grids, but we are going to be taking a different approach. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;br&gt;
I am going to be writing these mixins in LESS, because it is harder to make LESS perform sophisticated operations than SASS, so it is easier for SASS users to adapt LESS mixins.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Tackling The Classic Layout&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Let’s create a layout via LESS mixins, keeping the amount of CSS required to a minimum, with no pixel values, and maintaining a semantic markup. Let’s look at the HTML below:&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 lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;title&amp;gt;Classic Layout&amp;lt;/title&amp;gt;
    &amp;lt;script type='text/javascript' src='js/modernizr.js'&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;link rel="stylesheet" href="css/normalize.css"&amp;gt;
    &amp;lt;link rel="stylesheet" href="css/classiclayout.css"&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;header&amp;gt;

&amp;lt;/header&amp;gt;
&amp;lt;main&amp;gt;
    &amp;lt;article&amp;gt;

    &amp;lt;/article&amp;gt;
    &amp;lt;aside&amp;gt;

    &amp;lt;/aside&amp;gt;
&amp;lt;/main&amp;gt;
&amp;lt;footer&amp;gt;

&amp;lt;/footer&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 you notice, there are no classes used here, only semantic HTML5 tags. I am going to be adding the following LESS code, using mixins and variables:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;header, main, footer {
    .Row;
    background-color: #ccc;
    min-height: 200 * @toRems;
}

article {
    .Cols( 3 );
    min-height: 500 * @toRems;
    background-color: #ddd;
}

aside {
    .Cols( 1 );
    min-height: 500 * @toRems;
    background-color: #eee;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;it will then generate the following lines of CSS:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;header,
main,
footer {
  max-width: 75rem;
  width: 100%;
  margin: 0 auto;
  background-color: #ccc;
  min-height: 12.5rem;
}
header:before,
main:before,
footer:before,
header:after,
main:after,
footer:after {
  content: "";
  display: table;
}
header:after,
main:after,
footer:after {
  clear: both;
}
article {
  width: 75%;
  float: left;
  min-height: 31.25rem;
  background-color: #ddd;
}
aside {
  width: 25%;
  float: left;
  min-height: 31.25rem;
  background-color: #eee;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Check out the result on your browser, you will see a nice layout. Let’s check out the LESS mixins and variables that were used to create the layout you will be seeing in your browser:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//
// Variables for em / rem use
//

@base_px: 16; //set to the most common base px size used in browsers, should generally be left at default

@toRems: (1 / @base_px) + 0rem; //allows you to set values as the default px size to target, which is then converted into scalable rem values.

@toEms: (1 / @base_px) + 0em; //same as above, but with em values

//
// Grid mixins
//

@default-width: 1200 * @toRems;

@default-colspan: 1;

@default-total_cols: 4;

.Row ( @width : @default-width ) {
    max-width: @width;
    width: 100%;
    margin: 0 auto;
    // clear at the end of container
    &amp;amp;:before,
    &amp;amp;:after {
        content:"";
        display:table;
    }
    &amp;amp;:after {
        clear:both;
    }
}

.Cols ( @colspan : @default-colspan; @total_cols : @default-total_cols ) {
    width: ( @colspan * (100 / @total_cols) ) + 0%;
    float: left;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, let’s check out  each elements one by one, as you can see above:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Easy px to em/rem conversion&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//
// Variables for em / rem use
//

@base_px: 16; //set to the most common base px size used in browsers, should generally be left at default

@toRems: (1 / @base_px) + 0rem; //allows you to set values as the default px size to target, which is then converted into scalable rem values.

@toEms: (1 / @base_px) + 0em; //same as above, but with em values
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The variables that are in the top section of the code set us up for easily scalable &lt;code&gt;em&lt;/code&gt; or &lt;code&gt;rem&lt;/code&gt; values all through the stylesheet, instead of a &lt;code&gt;px&lt;/code&gt; value. However, when we use these  values, it allows us to conceptualize our design in pixels. For example, we do not want the header, main or footer elements to be wider than  &lt;code&gt;1200px&lt;/code&gt;, so instead of specifying &lt;code&gt;1200px&lt;/code&gt; as the  &lt;code&gt;max-width&lt;/code&gt;, we have to covert that &lt;code&gt;1200px&lt;/code&gt; to rems by multiplying it with the &lt;code&gt;@toREms&lt;/code&gt; variable, for example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1200 * @toRems;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The output value will be &lt;code&gt;75rem&lt;/code&gt;, which means that if a browser or user sets the default font-size to something different from the default size of &lt;code&gt;16px&lt;/code&gt;, then the entire site will scale proportionally. You can also do the same  to generate &lt;code&gt;em&lt;/code&gt; values, instead of using the &lt;code&gt;@toEms&lt;/code&gt; variables.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;.Row() mixin&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@default-width: 1200 * @toRems;

.Row ( @width : @default-width ) {
    max-width: @width;
    width: 100%;
    margin: 0 auto;
    // clear at the end of container
    &amp;amp;:before,
    &amp;amp;:after {
        content:"";
        display:table;
    }
    &amp;amp;:after {
        clear:both;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;As you can see, the first mixin being used  is the &lt;code&gt;.Row()&lt;/code&gt; mixin. Instead of using the “.container” classes, you can call this mixin wherever you want an element to  be centered with a maximum width. For our  classic layout, we call this mixin on the &lt;code&gt;header&lt;/code&gt;, &lt;code&gt;main&lt;/code&gt;, and &lt;code&gt;footer&lt;/code&gt; elements. &lt;/p&gt;

&lt;p&gt;The mixin sets a &lt;code&gt;max-width&lt;/code&gt; with a &lt;code&gt;width&lt;/code&gt; of 100%. This will give us basic responsiveness by making the element automatically adjust to fill the available  space when the viewport gets smaller than the &lt;code&gt;max-width&lt;/code&gt; value.  It also sets the &lt;code&gt;margin&lt;/code&gt; to &lt;code&gt;0 auto&lt;/code&gt; making the elements to be automatically centered. &lt;/p&gt;

&lt;p&gt;Lastly, it adds the pseudo-elements &lt;code&gt;:before&lt;/code&gt; and &lt;code&gt;:after&lt;/code&gt; and  also uses them to automatically clear at the end of an element. This is required so that when adding columns inside  the element, their float settings will be cleared.&lt;/p&gt;

&lt;p&gt;The mixin accepts one parameter, a &lt;code&gt;@width&lt;/code&gt; value:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.Row (@width : @default-width ) {
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The value now gets passed to the &lt;code&gt;max-width&lt;/code&gt; property:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;max-width: @width;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If the mixin has a width parameter passed, e.g. &lt;code&gt;.Row(40rem)&lt;/code&gt;, the value will then be applied to the  &lt;code&gt;max-width&lt;/code&gt; property. &lt;/p&gt;

&lt;p&gt;However, if the mixin is called without passing a parameter, i.e. &lt;code&gt;.Row&lt;/code&gt;, then, the default value will be used. That default value is stored in the &lt;code&gt;@default-width&lt;/code&gt;  variable, which is set where you see:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@default-width: 1200 * @toRems;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;All this means that the default maximum width of any element this mixin is used on will be &lt;code&gt;1200px&lt;/code&gt;, converted into &lt;code&gt;1200rem&lt;/code&gt;. Using this mixin allows you to set any element to be centered at your default &lt;code&gt;max-width&lt;/code&gt;, or any other &lt;code&gt;max-width&lt;/code&gt; you may want to apply.  What this means is that you can change the width of the entire site by  changing the value of the &lt;code&gt;@default-width&lt;/code&gt; variable. Let’s say for example: &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@default-width: 800 * @toRems;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;.Cols() mixin&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@default-colspan: 1;

@default-total_cols: 4;

.Cols ( @colspan : @default-colspan; @total_cols : @default-total_cols ) {
    width: ( @colspan * (100 / @total_cols) ) + 0%;
    float: left;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Because we are not using fixed pixels, all our column widths will have to be percentage-based, because we want our layout to remain completely flexible. To calculate these percentages, we use &lt;code&gt;.cols()&lt;/code&gt; mixin. According to the values you put into the mixin, a simple formula is used to determine the percentage width value that should  be applied to the element. The element’s &lt;code&gt;float&lt;/code&gt; value is set to &lt;code&gt;left&lt;/code&gt;, so that columns will sit side by side (remember that we automatically clear floats that are applied to the columns via the &lt;code&gt;.Row()&lt;/code&gt; mixin).&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;.cols()&lt;/code&gt; mixin allows you to specify how many columns  wide you want your element to be, the same thing you could if you were using the standard CSS grid  system. This is normally done by passing a &lt;code&gt;@colspan&lt;/code&gt; parameter through the mixin, or you can set the default for the mixin via the &lt;code&gt;@default-colspan&lt;/code&gt; variable.&lt;/p&gt;

&lt;p&gt;But, unlike most CSS grid systems, you have complete control over how many total that value is relative to, rather than having access to only 12 or 16 columns. You can set the total columns by passing a &lt;code&gt;@total_cols&lt;/code&gt; parameter through the mixin, or you can just the mixin default via the  &lt;code&gt;@default-total_cols&lt;/code&gt;  variable. Sounds cool right?&lt;/p&gt;

&lt;p&gt;In the earlier example of a “classic” layout which I gave above, using CSS grid, the content area was set to  9 out of 12 available columns,(3/4), while the sidebar was set to 3 out of 12 columns(1/4).  Well, we do not need all 12 columns, and we do not need to break  the layout into twelve,  all we need is quarters, because we are trying to set the content area to 3/4  width, and the sidebar to 1/4 of the width. So, all we have to do now is set the value of the &lt;code&gt;@default-total_cols&lt;/code&gt; to a variable of 4. For example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@default-total_cols: 4;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then, we are going to use the mixins as we did in our “classic” layout above. The mixins assume that you want your columns to have a possibility of  4 total columns. So, for us  to set our article element to 3/4 width, you can do this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;article {
    .Cols( 3 );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;then, if you want to set the sidebar to 1/4 width, you can do this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aside {
    .Cols( 1 );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Let’s say you want to use a different number of total columns, we can do this by passing different values through the &lt;code&gt;.cols()&lt;/code&gt; mixin. This will allow us to change the widths of the article and aside elements to any we want. Example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;article {
    .Cols( 7, 11 ); // sets this element to span 7 of a total 11 columns
    min-height: 500 * @toRems;
    background-color: #ddd;
}

aside {
    .Cols( 4, 11 ); // sets this element to span 4 of a total 11 columns
    min-height: 500 * @toRems;
    background-color: #eee;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Awesome right?&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Adding Padding And Margins&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;When you begin adding content inside your container, you definitely would want to have the ability to control the spacing around it. There are ways you can control your spacing, and the best to use depends on what you are trying to achieve with the specific design you are trying to create.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adding Padding&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One of the easiest ways you can control your spacing is by using the simple addition of  padding parameters to both &lt;code&gt;.Row()&lt;/code&gt; and &lt;code&gt;.Cols()&lt;/code&gt; mixins. We are going to adjust our mixin code as shown below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@default-padding: 0;

.Row ( @width : @default-width; @padding: @default-padding; ) {
    max-width: @width;
    width: 100%;
    margin: 0 auto;
    padding: @padding;
    // clear at the end of container
    &amp;amp;:before,
    &amp;amp;:after {
        content:"";
        display:table;
    }
    &amp;amp;:after {
        clear:both;
    }
}

.Cols ( @colspan : @default-colspan; @total_cols : @default-total_cols; @padding: @default-padding; ) {
    width: ( @colspan * (100 / @total_cols) ) + 0%;
    float: left;
    padding: @padding;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We can now add padding to our header, article, aside, and footer elements. Note, we are also going to be setting the default &lt;code&gt;box-sizing&lt;/code&gt; property all through the design to &lt;code&gt;border-box&lt;/code&gt; so, padding does not get included in any browser calculation of the width of elements:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* {
    box-sizing:border-box;
    -moz-box-sizing:border-box;
}

header, footer {
    .Row ( 
        @padding: 20 * @toRems;
    );
    background-color: #ccc;
    min-height: 200 * @toRems;
}

main {
    .Row;
    background-color: #ccc;
}

article {
    .Cols (
        @colspan: 3;
        @padding: 10 * @toRems 20 * @toRems;
    );
    min-height: 500 * @toRems;
    background-color: #ddd;
}

aside {
    .Cols (
        @colspan: 1;
        @padding: 10 * @toRems 20 * @toRems;
    );
    min-height: 500 * @toRems;
    background-color: #eee;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This will give us  padding around each of our pieces of content, as shown below:&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%2Fq0y08bnvt52g8xu2yww2.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%2Fq0y08bnvt52g8xu2yww2.png" width="600" height="295"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adding Wrapper Margins&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In some cases, the spacing that is intended to be added to a design is   on the outside of an element, instead of the inside, for example, when you want a site’s background to show through between the elements. For this  to happen, we have to make further additions to bot the  &lt;code&gt;.Row()&lt;/code&gt; and &lt;code&gt;.Cols()&lt;/code&gt; mixins. &lt;/p&gt;

&lt;p&gt;To get started, let’s allow spacing to be added above and below the elements that have our &lt;code&gt;.Row()&lt;/code&gt; mixin applied to them. This can be done by simply replacing the existing &lt;code&gt;margin&lt;/code&gt;  property value with a variable that can be sent as a parameter all through the mixin.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@default-row_margin: 0 auto;

.Row ( @width : @default-width; @padding: @default-padding; @margin: @default-row_margin; ) {
    max-width: @width;
    width: 100%;
    margin: @margin;
    padding: @padding;
    // clear at the end of container
    &amp;amp;:before,
    &amp;amp;:after {
        content:"";
        display:table;
    }
    &amp;amp;:after {
        clear:both;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;As you can see, the default value for the row margin is still set to &lt;code&gt;0 auto&lt;/code&gt;, therefore, if no parameter is passed, the mixin will still center the element automatically.&lt;/p&gt;

&lt;p&gt;If we pass an &lt;code&gt;@margin&lt;/code&gt; value through the  mixin:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;header, footer {
    .Row ( 
        @padding: 20 * @toRems;
        @margin: 10 * @toRems auto;
    );
    background-color: #ccc;
    min-height: 200 * @toRems;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;…we  are going to be able to add vertical spacing as see below:&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%2Fb7xdw101o45qaiehw7ti.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%2Fb7xdw101o45qaiehw7ti.png" width="600" height="295"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also, if you do not want your element to center anymore, all you have to do is pass a &lt;code&gt;@margin&lt;/code&gt; value of &lt;code&gt;0 auto 0 0&lt;/code&gt; to left align an element, or you can do &lt;code&gt;0 0 0 auto&lt;/code&gt; to right align.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Adding Column Gutters&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;One of the common features of CSS grid systems is its  ability to add gutters between the columns, i.e. margins that apply between each columns but not to the outside of the outermost columns. Once again we can add this functionality with some additions to the &lt;code&gt;Cols()&lt;/code&gt; mixin:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@default-gutter: 0;

.Cols ( @colspan : @default-colspan; @total_cols : @default-total_cols; @padding: @default-padding; @gutter: @default-gutter; @edge: false; ){
    @total_gutter: (@total_cols - 1) * @gutter;
    @spanned_gutters: (@colspan - 1) * @gutter;
    width: ( @colspan * ( (100 - @total_gutter) / @total_cols) ) + @spanned_gutters + 0%;
    float: left;
    padding: @padding;
    .IfEdge (@edge; @gutter);
}

.IfEdge ( @edge; @gutter; ) when (@edge = false) {
    margin-right: @gutter + 0%;
}

.IfEdge ( @edge; @gutter; ) when (@edge = true) {
    margin-right: 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, the mixin does two extra things;&lt;/p&gt;

&lt;p&gt;First, it checks for a value via the new &lt;code&gt;@gutter&lt;/code&gt; parameter and goes on to factor it into the width calculation for the column. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; the &lt;code&gt;@gutter&lt;/code&gt;  ****value should be a number used as a percentage value. For example 2 for a 2% gutter.&lt;/p&gt;

&lt;p&gt;Secondly, it goes on to check the new &lt;code&gt;@edge&lt;/code&gt; variable to see is set to &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;. If it is set to false, the value of the &lt;code&gt;@guttter&lt;/code&gt; parameter is added to the right margin as a percentage. IF it is set to true, the right  margin is set to &lt;code&gt;0&lt;/code&gt;. This will allow you to specify where a column is at the edge of your layout and therefore, should not have an applied gutter.&lt;/p&gt;

&lt;p&gt;In the example I will be showing you below, I will be showing you the effect of this change on the mixin. I have added two extra &lt;code&gt;article&lt;/code&gt; element to our HTML. Also, I have adjusted the LESS for the &lt;code&gt;article&lt;/code&gt; and &lt;code&gt;aside&lt;/code&gt; elements, as shown below;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;article {
    .Cols (
        @colspan: 1;
        @padding: 10 * @toRems 20 * @toRems;
        @gutter: 1; //include a gutter of 1%
    );
    min-height: 500 * @toRems;
    background-color: #ddd;
}

aside {
    .Cols (
        @colspan: 1;
        @padding: 10 * @toRems 20 * @toRems;
        @gutter: 1; //include a gutter of 1%
        @edge: true; //this is the column on the edge so don't set a right margin
    );
    min-height: 500 * @toRems;
    background-color: #eee;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;the result is 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%2Fk49l4f7mhm1c8zrihlmb.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%2Fk49l4f7mhm1c8zrihlmb.png" width="600" height="295"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To allow for control over vertical margins on columns, all we have to do is include some additional parameters in the mixin as shown below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@default-margin_top: 0;

@default-margin_bottom: 0;

.Cols ( @colspan : @default-colspan; @total_cols : @default-total_cols; @padding: @default-padding; @gutter: @default-gutter; @edge: false; @margin_top : @default-margin_top; @margin_bottom : @default-margin_bottom; ){
    @total_gutter: (@total_cols - 1) * @gutter;
    @spanned_gutters: (@colspan - 1) * @gutter;
    width: ( @colspan * ( (100 - @total_gutter) / @total_cols) ) + @spanned_gutters + 0%;
    float: left;
    padding: @padding;
    .IfEdge (@edge; @gutter; @margin_top; @margin_bottom; );
}

.IfEdge ( @edge; @gutter; @margin_top; @margin_bottom;  ) when (@edge = false) {
    margin: @margin_top @gutter + 0% @margin_bottom 0;
}

.IfEdge ( @edge; @gutter; @margin_top; @margin_bottom;  ) when (@edge = true) {
    margin: @margin_top 0 @margin_bottom 0;
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The top and bottom margin settings can now be included when we use the &lt;code&gt;.Cols()&lt;/code&gt; mixin, as shown below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;article {
    .Cols (
        @colspan: 1;
        @padding: 10 * @toRems 20 * @toRems;
        @gutter: 1;
        @margin_top: 20 * @toRems;
        @margin_bottom: 30 * @toRems;
    );
    min-height: 500 * @toRems;
    background-color: #ddd;
}

aside {
    .Cols (
        @colspan: 1;
        @padding: 10 * @toRems 20 * @toRems;
        @gutter: 1;
        @edge: true;
        @margin_top: 20 * @toRems;
        @margin_bottom: 30 * @toRems;
    );
    min-height: 500 * @toRems;
    background-color: #eee;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;…this would add vertical margins to the columns, as shown in the example below:&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%2Fjfl76vst2cqkcwr8kq6j.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%2Fjfl76vst2cqkcwr8kq6j.png" width="600" height="295"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Nesting And Increasing Layout Complexity&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To add another level of complexity to our example layout, we  have to increase the number of  &lt;code&gt;article&lt;/code&gt; elements to 6 and place them inside a &lt;code&gt;section&lt;/code&gt; element  wrapper, then we can apply our mixins to create  the layout in the example below:&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%2F06w9k9wtbadf96yichr7.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%2F06w9k9wtbadf96yichr7.png" width="600" height="295"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have made changes  to the HTML to get the layout above, as you can see below:&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 lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;title&amp;gt;Classic Layout&amp;lt;/title&amp;gt;
    &amp;lt;script type='text/javascript' src='js/modernizr.js'&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;link rel="stylesheet" href="css/normalize.css"&amp;gt;
    &amp;lt;link rel="stylesheet" href="css/classiclayout.css"&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;header&amp;gt;
    &amp;lt;h1&amp;gt;Site Title&amp;lt;/h1&amp;gt;
&amp;lt;/header&amp;gt;
&amp;lt;main&amp;gt;
    &amp;lt;section&amp;gt;
        &amp;lt;h1&amp;gt;Latest Articles&amp;lt;/h1&amp;gt;
        &amp;lt;article&amp;gt;
            &amp;lt;h1&amp;gt;Article Title&amp;lt;/h1&amp;gt;
            &amp;lt;p&amp;gt;...&amp;lt;/p&amp;gt;
        &amp;lt;/article&amp;gt;
        &amp;lt;article&amp;gt;
            &amp;lt;h1&amp;gt;Article Title&amp;lt;/h1&amp;gt;
            &amp;lt;p&amp;gt;...&amp;lt;/p&amp;gt;
        &amp;lt;/article&amp;gt;
        &amp;lt;article&amp;gt;
            &amp;lt;h1&amp;gt;Article Title&amp;lt;/h1&amp;gt;
            &amp;lt;p&amp;gt;...&amp;lt;/p&amp;gt;
        &amp;lt;/article&amp;gt;
        &amp;lt;article&amp;gt;
            &amp;lt;h1&amp;gt;Article Title&amp;lt;/h1&amp;gt;
            &amp;lt;p&amp;gt;...&amp;lt;/p&amp;gt;
        &amp;lt;/article&amp;gt;
        &amp;lt;article&amp;gt;
            &amp;lt;h1&amp;gt;Article Title&amp;lt;/h1&amp;gt;
            &amp;lt;p&amp;gt;...&amp;lt;/p&amp;gt;
        &amp;lt;/article&amp;gt;
        &amp;lt;article&amp;gt;
            &amp;lt;h1&amp;gt;Article Title&amp;lt;/h1&amp;gt;
            &amp;lt;p&amp;gt;...&amp;lt;/p&amp;gt;
        &amp;lt;/article&amp;gt;
    &amp;lt;/section&amp;gt;
    &amp;lt;aside&amp;gt;
        &amp;lt;p&amp;gt;...&amp;lt;/p&amp;gt;
    &amp;lt;/aside&amp;gt;
&amp;lt;/main&amp;gt;
&amp;lt;footer&amp;gt;
    &amp;lt;p&amp;gt;Example Footer&amp;lt;/p&amp;gt;
&amp;lt;/footer&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We are also  going to change  the LESS code we are using to control the layouts as  shown below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;header, footer {
    .Row ( @padding: 20 * @toRems; @margin: 10 * @toRems auto; );
    background-color: #ccc;
    min-height: 100 * @toRems;
}

main {
    .Row;
}

section {
    .Cols ( @colspan: 3; @padding: 10 * @toRems 20 * @toRems; @gutter: 1; );
    background-color: #ddd;
}

aside {
    .Cols ( @colspan: 1; @padding: 10 * @toRems 20 * @toRems; @gutter: 1; @edge: true; );
    min-height: 500 * @toRems;
    background-color: #eee;
}

article {
    .Cols ( @colspan: 1; @total_cols: 3; @padding: 0 20 * @toRems 20 * @toRems 20 * @toRems; @margin_bottom: 20 * @toRems;  @gutter: 2; );
    background-color: #eee;
    &amp;amp;:nth-of-type(3n) {
        margin-right: 0;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;As you can  see above, the &lt;code&gt;section&lt;/code&gt; element has been set to take up 3 columns of the default of 4 total columns(3/4). Next to the &lt;code&gt;section&lt;/code&gt;  is the &lt;code&gt;aside&lt;/code&gt; element, which is set to 1 column of 4(1/4). The &lt;code&gt;section&lt;/code&gt; element acts as a wrapper  for the article. Since the article elements are now  nested, they can have all the new column width applied to them, and they will now each take up a percentage of their parent element’s interior. Therefore, each is set to 1 column out of  3, with a gutter of 2%.&lt;/p&gt;

&lt;p&gt;All third article is identified by using the &lt;code&gt;:nth-of-type(3n)&lt;/code&gt; selector and set to  have no right margin/gutter.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;We have gone through so many details in this article on how the &lt;code&gt;.Row&lt;/code&gt; and &lt;code&gt;.Cols&lt;/code&gt;  mixins work so that you can have an understanding, for you to be able to make further additions and modifications if you want. The result of all we have covered is actually a simple and easy-to-use layout system.&lt;/p&gt;

&lt;p&gt;By using just two mixins, you can now create highly complex, but scalable and flexible layouts, without restrictions. You can also use any total number of columns you feel like, width of gutters, and you can nest your grids as much as needed, etc.&lt;/p&gt;




</description>
      <category>css</category>
      <category>grids</category>
    </item>
    <item>
      <title>A Complete Guide To Using CSS Custom Variables</title>
      <dc:creator>Chisom Uma</dc:creator>
      <pubDate>Mon, 28 Feb 2022 07:00:58 +0000</pubDate>
      <link>https://dev.to/chisom642/a-complete-guide-to-using-css-custom-variables-3ohi</link>
      <guid>https://dev.to/chisom642/a-complete-guide-to-using-css-custom-variables-3ohi</guid>
      <description>&lt;p&gt;Sometimes in CSS, values tend to show up multiple times or repeat themselves throughout your code. Imagine if you have a much bigger style sheet file, you will have to keep reusing these values again and again. That’s pretty stressful right?. Well, at some point, you might want to change every occurrence of a particular value. I know you may be asking “can’t i just do a find and replace?”. Doing a find and replace will work, but there is a much easier way you can change these values, and that is where CSS variables come in.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Outline&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Basics Of CSS Variables

&lt;ul&gt;
&lt;li&gt;What Are CSS Variables&lt;/li&gt;
&lt;li&gt;Inheritance &lt;/li&gt;
&lt;li&gt;Working with Invalid Variables and Fallback Values&lt;/li&gt;
&lt;li&gt;Using CSS Variables With Inline Styles&lt;/li&gt;
&lt;li&gt;Storing Single and Multiple Values &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;What You Should Know About CSS Variables

&lt;ul&gt;
&lt;li&gt;Using Variables With Media Queries&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Conclusion&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Basics Of CSS Variables
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What Are CSS Variables&lt;/strong&gt;&lt;br&gt;
CSS custom variables, also known as CSS variables or cascading variables,  are entities that contain specific values that can be reused throughout a document. It is usually set using a custom property notion.&lt;/p&gt;

&lt;p&gt;for example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;--main-color: black;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;and can be accessed using the &lt;code&gt;var()&lt;/code&gt; function.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;color: var(--main-color);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;When looking at the style sheet below, you notice that there are some values  of some elements that keep repeating themselves. For example, the border-radius, the color &lt;code&gt;#0176b8&lt;/code&gt; (which we have on the border of the button, background color, main color for our anchor tags, and down on the inverse button), and for the images we also use the width and height of 2.5rem. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.btn{
  text-decoration: none
  color: white
  background-color: #0176b8
  display:inline-block
  padding: 1px
  border-radius: 5px
  border: 1px solid #00176b8
}

.btn.inverse{
  background-color: white;
  border-color:#0176b8
  color: #0176b8
}

.table img{
  width: 2.5rem
  height: 2.5rem
  border-radius:50%
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, if you notice, these values show up, multiple times.  &lt;/p&gt;

&lt;p&gt;To get started, you have to define your variables inside the root pseudo-class, and this applies to the entire HTML document.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:root{

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

&lt;/div&gt;

&lt;p&gt;To define a variable, you will have to start with a double hyphen, and then you input the name of the variable next. For instance color -primary; then put in the value. Lets say the &lt;code&gt;#0176b8&lt;/code&gt; color.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:root{
  --color-primary; #0176b8
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You have now justified the variable by doing this. The next thing is to use the variable in your CSS code, by replacing that value with var, open parenthesis and then you put the name of your variable inside.  &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a{
  color: var(--color-primary);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This will make all the anchor links, for example, to be defined by the variable. Remember that color &lt;code&gt;#0176b8&lt;/code&gt; is also the main color for the anchor tags. The awesome thing about this is that you can easily replace the value with another value. For instance, you can replace the color &lt;code&gt;#0176b8&lt;/code&gt; with let’s say Yellow, and all the elements that use that variable will get updated. Now instead of find and replace, you can just replace all the &lt;code&gt;#0176b8&lt;/code&gt; or colors in your CSS codes with your variable &lt;code&gt;var(--color-primary);&lt;/code&gt;. Now if you change the color value, to let’s say yellow, every thing else changes to yellow. That’s  pretty awesome, right?&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;Let’s transform something else into a variable, like a border-radius for example. You can define another variable, by imputing borer-radius with 5pixels&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:root{
  --color-primary; #0176b8
  --global-radius 5px;
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;All you have to do now is replace the border-radius with &lt;code&gt;var()&lt;/code&gt;, global radius&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.btn{
  text-decoration: none
  color: white
  background-color: #0176b8
  display:inline-block
  padding: 1px
  border-radius: var(global-radius);
  border: 1px solid #00176b8
}

.card {
    max-width: 50rem;
    background-color: white;
    padding: 2rem;
    border-radius: var(--global-radius);
    box-shadow: 1px 1px 15px 0 rgba(0, 0, 0, .25);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If you go to &lt;code&gt;- - border-radius&lt;/code&gt; and change the value from 5px to maybe 20px you will notice the cards and buttons updating automatically.&lt;/p&gt;

&lt;p&gt;As for the case  of browser compatibility, if you open &lt;a href="https://caniuse.com/" rel="noopener noreferrer"&gt;caniuse&lt;/a&gt;, you can check the browsers that are compatible with the CSS variables, as shown in the image below:&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%2Fta9x33l182qnpxgqemyc.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%2Fta9x33l182qnpxgqemyc.png" alt="CSS variables browser support" width="800" height="422"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this image, you can see that it is supported  in most of the browsers, well except in internet explorer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Inheritance&lt;/strong&gt;&lt;br&gt;
 Inheritance controls what happens when there is no value specified for a property on an element;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;body&amp;gt;
  &amp;lt;div&amp;gt;
   &amp;lt;p&amp;gt;Hello&amp;lt;/p&amp;gt;
  &amp;lt;h1&amp;gt;Text&amp;lt;/h1&amp;gt; 
&amp;lt;/body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, if you apply styles to the body tag, then everything within the body tag will inherit those styles. Let’s assume we want everything under the body tag to have a font color of blue, all you have to do is;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.body{
  color: blue;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;and everything under the body tag turns blue. Pretty cool right? well, that’s because everything  within the body are inheriting that style. Let’s now say we want everything under the &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; tag to be yellow, you can do this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.body{
  color: blue;
}
.div{
  color: yellow;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;and everything in the &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; tags overrides the inherited styles of the &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt;tag, and turns yellow, while the rest remains blue. So! what if you want only the &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; tag to be green even though they already have the &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; tag of yellow. Well, you can just do this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.body{
  color: blue;
}
.div{
  color: yellow;
}
.p{
  color: green;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Working With Invalid Variables and Fallback Values&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We are going to be learning what happens when certain CSS variables are invalid, and how the browser is going to deal with this, coupled with how to provide fallback values for CSS variables. Let’s get started!&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;P&amp;gt; learning css variables&amp;lt;p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;then inside the CSS, you can write this;&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;As you can see, this is invalid, and we  are going to see how the browser deals with it;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:root{
  --color: 1rem;
}
.body{
  display: flex;
  height: 100vh 
  align-items:center;
  justify-content: center:
}
.p{
  max-width: 50%
  color: var(--color);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;at this point, nothing happens because the color variable is invalid, i.e. it has  an invalid value for the color property. Now, the browser checks if the color property can be inherited. So it looks at its parents to see if there is  a color defined there. If you notice, the body, which is the parent element of the &lt;code&gt;&amp;lt;P&amp;gt;&lt;/code&gt; tag does not have  a color defined. In this case, the browser will go back to the initial value of the  color, which is black, so the text still appears black. Even if you were to  set a color of green in the &lt;/p&gt;
&lt;p&gt; tag it still won’t work, because of the cascading nature of CSS. However, let’s say we defined  color of blue in the body;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:root{
  --color: 1rem;
}
.body{
  display: flex;
  height: 100vh 
  align-items:center;
  justify-content: center;
  color: blue;
}
.p{
  max-width: 50%
  color: var(--color);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, the text changes to blue, because we have defined the color off the body. If you remove the blue, the browser will automatically revert to the initial color, which is black. Hopefully, you understood this. &lt;/p&gt;

&lt;p&gt;I am now going to show you how to define some fallback values for CSS variables. This is a simple mark up below;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;ul class="menu"&amp;gt;
  &amp;lt;li&amp;gt;&amp;lt;i class="far fa-bell"&amp;gt;&amp;lt;/i&amp;gt;&amp;lt;/li&amp;gt;
  &amp;lt;li&amp;gt;&amp;lt;i class="far fa-bookmark"&amp;gt;&amp;lt;/i&amp;gt;&amp;lt;/li&amp;gt;
  &amp;lt;li&amp;gt;&amp;lt;i class="far fa-calendar"&amp;gt;&amp;lt;/i&amp;gt;&amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;then for the CSS, i added some demo styles for the body;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.body{
  display: flex;
  height: 100vh;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
  justify-content: center;
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;the next thing is to define our menu by defining some variables ;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.body{
  display: flex;
  height: 100vh;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
  justify-content: center;
} 

.menu{
  --item-size: 3rem;
  --font-size: 18px
  --item-color-1: black;
  --item-color-1: green;

  list-style:none
  padding: 0
  margin: 0
  display: flex;
  gap: calc(var(--item-size)/4);
  font-size: var(--font-size);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;trust me! it gets interesting from here. Now I am going to do this;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.body{
  display: flex;
  height: 100vh;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
  justify-content: center;
} 

.menu{
  --item-size: 3rem;
  --font-size: 18px
  --item-color-1: black;
  --item-color-2: green;

  list-style:none
  padding: 0
  margin: 0
  display: flex;
  gap: calc(var(--item-size)/4);
  font-size: var(--font-size);
}

.menu li{
  background-color:var(--item-color-1,red);
  color: white;
  width: var(--item-size);
  height: var(--item--size);
  text-align: center;
  line-height: var(--item-size);
  border-radius: 5px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, if you are going to use the var function like this, by adding a second parameter, what you are saying is,  use item color 1 if it is defined, otherwise use the color red. So, if item color 1 was not defined, (--item-color-1, red); does not exist. You can even do;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.menu li{
  background-color:var(--item-color-2, blue));
  color: white;
  width: var(--item-size);
  height: var(--item--size);
  text-align: center;
  line-height: var(--item-size);
  border-radius: 5px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;what this means is that, you can say &lt;code&gt;var()&lt;/code&gt;, and inside the &lt;code&gt;var()&lt;/code&gt; you are saying, if item color 1 does not exist, then use   item color 2 and if that does not exist, use another color, e.g. blue; if item color 1 was not defined, it uses item color 2. If item color 2 was not defined, it uses the fallback which is blue. &lt;/p&gt;

&lt;p&gt;Note that this is not a solution for invalid variables. Therefore, you cannot use this fallback to fix invalid variables.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using CSS  Variables With Inline Styles&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Using inline styles in production is not recommended in the final stages of your code, but it can break the CSS specificity that you defined in your style sheet. Although, you can use inline styles  during development or testing. So, I will be showing you how variables can help you. Lets’ check out the simple grid i designed below in HTML;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div  class= "grid"&amp;gt;
  &amp;lt;div class= "grid-item"&amp;gt;
    &amp;lt;img src="https://media.istockphoto.com/photos/advertising-concept-confident-and-smiling-young-african-american-picture-id1290599844?b=1&amp;amp;k=20&amp;amp;m=1290599844&amp;amp;s=170667a&amp;amp;w=0&amp;amp;h=mKM_VHxQK1N0l5ojPiG9mcIRERgt4RqMqfP5Z9hnKN8= "&amp;gt; 
    &amp;lt;/div&amp;gt;


    &amp;lt;div class= "grid-item"&amp;gt;
      &amp;lt;img src="https://media.istockphoto.com/photos/advertising-concept-confident-and-smiling-young-african-american-picture-id1290599844?b=1&amp;amp;k=20&amp;amp;m=1290599844&amp;amp;s=170667a&amp;amp;w=0&amp;amp;h=mKM_VHxQK1N0l5ojPiG9mcIRERgt4RqMqfP5Z9hnKN8= "&amp;gt; 
      &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then i have the  CSS;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.grid{
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--column-width), 1fr));
  grid-gap:var(--gap);
  margin-button 2rem;
}

.grid-item{
  background-color: #705ae3;
  color: white;
  display:flex;
  align-item: center;
  justify-content:center;
  padding: 2rem;
}

.img{
  width: var(--avatar-size);
  height: var(--avatar-size);
  border-radius: 50%
  border: 2px solid white;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;all you have to do here is define the actual variables, and we are going to define them in the root;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:root{
  --avatar-size: 3rem;
  --column-width: 20rem
  --gap: calc(var(--column-width)/ 10);

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

&lt;/div&gt;

&lt;p&gt;Now, let’s say during development or during testing, you can play around with different values for the grid, without opening up the CSS file again. You can do this from your browser or HTML using inline styles, as seen in the example below;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div  class= "grid" style="--column-width: 12rem"&amp;gt;
  &amp;lt;div class= "grid-item"&amp;gt;
    &amp;lt;img src="https://media.istockphoto.com/photos/advertising-concept-confident-and-smiling-young-african-american-picture-id1290599844?b=1&amp;amp;k=20&amp;amp;m=1290599844&amp;amp;s=170667a&amp;amp;w=0&amp;amp;h=mKM_VHxQK1N0l5ojPiG9mcIRERgt4RqMqfP5Z9hnKN8= "&amp;gt; 
    &amp;lt;/div&amp;gt;


    &amp;lt;div class= "grid-item"&amp;gt;
      &amp;lt;img src="https://media.istockphoto.com/photos/advertising-concept-confident-and-smiling-young-african-american-picture-id1290599844?b=1&amp;amp;k=20&amp;amp;m=1290599844&amp;amp;s=170667a&amp;amp;w=0&amp;amp;h=mKM_VHxQK1N0l5ojPiG9mcIRERgt4RqMqfP5Z9hnKN8= "&amp;gt; 
      &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can now play around with the size here. For instance, you can change the size from 12rem to 15rem, depending on which one you want to work with. Why  this is cool is because you don’t have to change anything in your CSS file. Note,  please do not use this in your final  code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Storing Single and Multiple Values&lt;/strong&gt;&lt;br&gt;
 In this  lesson, you will learn about what values you can store inside a CSS  variable. You will see  that you can store multiple values in the same variable. Let’s start with this simple HTML, which is a card with a paragraph and a button inside;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="card"&amp;gt;
  &amp;lt;h1&amp;gt; How are you today&amp;lt;/h1&amp;gt;
  &amp;lt;p&amp;gt; i am fine thank you&amp;lt;/p&amp;gt;

  &amp;lt;a href="a" class="btn"&amp;gt;close window&amp;lt;/a&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;let’s write the CSS;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.body{
   display:flex;
   height: 100vh
   align-items: center;
   justify-content: center:
   background-color: #ececec;
   line-height: 1.35;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;CSS variables are not just for holding numbers, pixel values, or colors. They are also capable of holding gradients  for example;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:root{
  --body-bg: linear-gradient(120deg, #705ae3 0%, #8ec5fc 100%);
}

.body{
   display:flex;
   height: 100vh
   align-items: center;
   justify-content: center:
   background-color: #ececec;
   line-height: 1.35;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;now you can go into your body  and say;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:root{
  --body-bg: linear-gradient(120deg, #705ae3 0%, #8ec5fc 100%);
}

.body{
   background-image: var(--body-bg);
   display:flex;
   height: 100vh
   align-items: center;
   justify-content: center:
   background-color: #ececec;
   line-height: 1.35;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;as i stated above, variables are capable of holding multiple values, i will be demonstrating with another example using button color;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:root{
  --body-bg: linear-gradient(120deg, #705ae3 0%, #8ec5fc 100%);
  --button-color: 107, 93, 227;
}

.body{
   background-image: var(--body-bg);
   display:flex;
   height: 100vh
   align-items: center;
   justify-content: center:
   background-color: #ececec;
   line-height: 1.35;
}

.btn{
  background-color: rgb(var(--button-color));
  display: inline-block;
  color: white;
  padding: 1rem 2.5rem;
  text-decoration:none;
  border-radius: 100px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;as you can see, you can use the &lt;code&gt;107, 93, 227&lt;/code&gt;; and define the color as &lt;code&gt;rgb&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What You Should Know About CSS variables
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Using CSS Variables With Media Queries and JavaScript&lt;/strong&gt;&lt;br&gt;
In this lesson, you are going to learn how to use CSS variables inside media queries, and  how to change their value with JavaScript. For the HTML, we are going to use a simple grid;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="grid"&amp;gt;
  &amp;lt;div class="grid-item"&amp;gt;1&amp;lt;/div&amp;gt;
  &amp;lt;div class="grid-item"&amp;gt;2&amp;lt;/div&amp;gt;
  &amp;lt;div class="grid-item"&amp;gt;3&amp;lt;/div&amp;gt;
  &amp;lt;div class="grid-item"&amp;gt;4&amp;lt;/div&amp;gt;
  &amp;lt;div class="grid-item"&amp;gt;5&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;for the CSS;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.body{
  padding: 2rem;  
}

.grid{
  --grid-item-color: #8ec5fc
  --column-width: 100%;
  --gap: 1rem;

  display: grid;
  grid-template-column: repeat(auto-fill, minmax(var(--column-width),1fr));
  grid-gap: var(--gap);
}

.grid-item{
  background-color: var(--grid-item-color);
  color: white;
  display: fle;
  align-items: center;
  padding: 2rem;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, this version of the grid will work on all screen sizes, but what if you want to split up into multiple columns  when it reaches or surpasses a certain screen width, all you have to do is use media query, as shown in the example below;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.body{
  padding: 2rem;  
}

.grid{
  --grid-item-color: #8ec5fc
  --column-width: 100%;
  --gap: 1rem;

  display: grid;
  grid-template-column: repeat(auto-fill, minmax(var(--column-width),1fr));
  grid-gap: var(--gap);
}

.grid-item{
  background-color: var(--grid-item-color);
  color: white;
  display: fle;
  align-items: center;
  padding: 2rem;
}

@media screen and (min-width: 720px) {
  .grid{
     --column-width: 10rem;
     --gap: calc(var(--column-width)/ 10);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, when we go past 720 pixels, you see the  changes in the grid from the stacked version to  using actual columns, all thanks to the media query. Now, what about JavaScript, you can read CSS variables from JavaScript, and you can change the color. Let me show you in the example below;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let targetElem = document.querySelector('.grid');
targetElem.style.setProperty('--grid-item-color', 'purple');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now,  you can see that when we go back to the original code, i.e. the one outside the media query, it actually changes the color to whatever color you want, you can change the ‘purple’ color to ‘yellow’. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
What I have done in this article, is to explain what CSS variables mean, and how to use them in your style sheet file. In the aspect of web development, speed and flexibility is very important, and CSS variables helps with these. &lt;/p&gt;

&lt;p&gt;If you implement your CSS variables properly, it will make your code more readable and accessible, and still provide a semantic meaning to your values.&lt;/p&gt;

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