<?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>Forem: Dualite Technology Private Limited</title>
    <description>The latest articles on Forem by Dualite Technology Private Limited (@dualitedev).</description>
    <link>https://forem.com/dualitedev</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%2Forganization%2Fprofile_image%2F9636%2F65149f0d-1687-4dca-a190-310887c77a86.png</url>
      <title>Forem: Dualite Technology Private Limited</title>
      <link>https://forem.com/dualitedev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/dualitedev"/>
    <language>en</language>
    <item>
      <title>Introduction to Web Components: Creating Reusable UI Elements</title>
      <dc:creator>Ayush Thakur</dc:creator>
      <pubDate>Thu, 24 Oct 2024 15:51:15 +0000</pubDate>
      <link>https://forem.com/dualitedev/introduction-to-web-components-creating-reusable-ui-elements-27a8</link>
      <guid>https://forem.com/dualitedev/introduction-to-web-components-creating-reusable-ui-elements-27a8</guid>
      <description>&lt;p&gt;In modern web development, reusability and modularity have become important factors in building scalable and maintainable applications. As the complexity of web applications is growing, developers look for ways to efficiently manage their code, particularly the user interface (UI). This is where Web Components come into the picture. &lt;/p&gt;

&lt;p&gt;Web Components allow developers to build reusable, encapsulated UI elements that can be used across various web applications, regardless of the framework or library. In this blog, we'll dive into what Web Components are, how they work, and why they can be a game-changer in web development.&lt;/p&gt;

&lt;p&gt;So, let’s get started!&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Web Components?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvgzmc32a04hzjfvikrra.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvgzmc32a04hzjfvikrra.gif" alt="Image description" width="500" height="278"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Web Components are a set of web platform APIs that allow developers to create custom, reusable HTML elements with their own behavior and style. These elements are independent and encapsulated, which means they won’t be affected by the styling or behavior of other components on the page. &lt;/p&gt;

&lt;p&gt;At their core, Web Components are built using three main technologies:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Custom Elements&lt;/strong&gt;: These allow you to define your own HTML tags and associated behavior.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Shadow DOM&lt;/strong&gt;: This helps in encapsulating the styles and markup, ensuring that the component’s internal structure remains hidden and unaffected by external styles.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;HTML Templates&lt;/strong&gt;: Templates provide reusable chunks of HTML that can be stamped into the DOM when needed, offering a way to define reusable UI without rendering it immediately.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Together, these technologies allow you to create components that are self-contained and reusable across different parts of your application, or even different projects.&lt;br&gt;
Why Use Web Components?&lt;/p&gt;

&lt;p&gt;Web Components come with several benefits that make them a compelling choice for developers:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reusability&lt;/strong&gt;: You can create components once and use them anywhere, which speeds up the development process.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Encapsulation&lt;/strong&gt;: With Shadow DOM, you can ensure that the styles and logic inside the component don’t interfere with the rest of your application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Framework-Agnostic&lt;/strong&gt;: Web Components work across any framework, making them highly versatile. Whether you're using React, Angular, Vue, or plain HTML, you can integrate Web Components effortlessly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Interoperability&lt;/strong&gt;: Web Components can be easily shared between projects, teams, and even across organizations, promoting collaboration and standardization.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  How to Create a Basic Web Component
&lt;/h2&gt;

&lt;p&gt;Now that we understand what Web Components are, let’s look at how to create one. We'll start by building a simple custom button component using native JavaScript.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1.0"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;My Button Component&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;my-button&amp;gt;&lt;/span&gt;Click Me!&lt;span class="nt"&gt;&amp;lt;/my-button&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
    &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyButton&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;HTMLElement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="c1"&gt;// Attach Shadow DOM&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;attachShadow&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;open&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

        &lt;span class="c1"&gt;// Create button element&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;button&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Add styles&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;style&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`
          button {
            background-color: blue;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
          }
          button:hover {
            background-color: darkblue;
          }
        `&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Append the button and style to the Shadow DOM&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;shadowRoot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Define the new element&lt;/span&gt;
    &lt;span class="nx"&gt;customElements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my-button&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;MyButton&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;We create a class &lt;code&gt;MyButton&lt;/code&gt; that extends &lt;code&gt;HTMLElement&lt;/code&gt;, allowing us to define a new HTML tag &lt;code&gt;&amp;lt;my-button&amp;gt;&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Inside the constructor, we attach a &lt;strong&gt;Shadow DOM&lt;/strong&gt; to encapsulate the component’s internal structure.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We define the button’s styling using the &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; tag and append it to the Shadow DOM along with the button element.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally, we register the component using &lt;code&gt;customElements.define()&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With this, we've created a custom button component that can be reused throughout your application by simply using the &lt;code&gt;&amp;lt;my-button&amp;gt;&lt;/code&gt; tag.&lt;/p&gt;

&lt;h2&gt;
  
  
  Best Practices for Web Components
&lt;/h2&gt;

&lt;p&gt;Here are some best practices you should follow when building Web Components:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use Shadow DOM Wisely&lt;/strong&gt;: It’s great for encapsulating styles, but remember that it also means you’ll need to manage your own accessibility (e.g., making sure ARIA attributes are properly added).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Name Custom Elements Appropriately&lt;/strong&gt;: Always use a dash (&lt;code&gt;-&lt;/code&gt;) in custom element names (e.g., &lt;code&gt;&amp;lt;my-button&amp;gt;&lt;/code&gt;). This is required by the specification to differentiate custom elements from standard HTML tags.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Keep Components Small and Focused&lt;/strong&gt;: Like any good UI component, your Web Component should have a single responsibility and be easily testable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use Slots for Flexibility&lt;/strong&gt;: Slots allow you to create placeholders inside your component where content can be dynamically injected. This is especially useful when building more complex components that require customization.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  When to Use Web Components
&lt;/h2&gt;

&lt;p&gt;While Web Components are powerful, they aren’t a one-size-fits-all solution. Here are some cases where they shine:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Design Systems&lt;/strong&gt;: If your team is building a design system, Web Components can help ensure consistency across multiple applications and frameworks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cross-Framework Projects&lt;/strong&gt;: Since Web Components are framework-agnostic, they are perfect for projects where multiple frameworks are used, or when you need to switch frameworks without rewriting the entire UI.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reusability Across Teams&lt;/strong&gt;: If your company has different teams working on various projects, Web Components provide a standardized way to share UI elements across projects.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Web Components provide a modern, standardized approach to building reusable and encapsulated UI elements. By leveraging Custom Elements, Shadow DOM, and HTML Templates, you can create powerful, framework-independent components that enhance both code maintainability and UI consistency. Whether you're working on a design system, or simply trying to make your UI more modular, Web Components offer an elegant solution.&lt;/p&gt;

&lt;p&gt;This is another advantage of using Dualite. &lt;a href="https://bit.ly/DualiteDevToArindam" rel="noopener noreferrer"&gt;Dualite&lt;/a&gt; can also be used to create reusable web components that can form the entire layout of a webpage.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to Optimize Your React App for Performance</title>
      <dc:creator>Ayush Thakur</dc:creator>
      <pubDate>Wed, 16 Oct 2024 15:37:24 +0000</pubDate>
      <link>https://forem.com/dualitedev/how-to-optimize-your-react-app-for-performance-39ic</link>
      <guid>https://forem.com/dualitedev/how-to-optimize-your-react-app-for-performance-39ic</guid>
      <description>&lt;p&gt;In today’s fast digital world, having a web application with optimized performance is crucial for maintaining user satisfaction and engagement. When it comes to React apps, optimizing performance not only improves the user experience but also helps in reducing load times, minimizing resource usage, and boosting overall responsiveness. &lt;/p&gt;

&lt;p&gt;Given that React apps can range from small-scale to highly complex, knowing the right strategies for performance optimization is key.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fcn5amnip6iiscsaam23b.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fcn5amnip6iiscsaam23b.gif" alt="Image description" width="450" height="253"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this blog, we’ll cover practical techniques to optimize your React app and ensure it runs smoothly, regardless of the complexity. &lt;/p&gt;

&lt;p&gt;Let's dive in!&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Avoid Unnecessary Renders
&lt;/h2&gt;

&lt;p&gt;React is efficient when it comes to rendering, but unnecessary re-renders can still slow down your app. A common reason for unnecessary renders is passing down new props to child components, even if the data hasn’t changed.&lt;/p&gt;

&lt;p&gt;To prevent this, you can use &lt;code&gt;React.memo&lt;/code&gt; for functional components and PureComponent for class components. These tools help by memoizing the component, ensuring that it only re-renders when its props or state actually changes.&lt;/p&gt;

&lt;p&gt;Here’s an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;memo&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, &lt;code&gt;MyComponent&lt;/code&gt; will only re-render if the value prop changes, preventing unnecessary updates and boosting performance.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Use Code-Splitting and Lazy Loading
&lt;/h2&gt;

&lt;p&gt;For large React apps, loading everything at once can result in slow initial load times. Code-splitting allows you to split your code into smaller chunks, loading only what’s needed when it’s needed. This reduces the bundle size and improves loading times.&lt;/p&gt;

&lt;p&gt;React’s &lt;code&gt;React.lazy&lt;/code&gt; and Suspense are great tools for implementing code-splitting and lazy loading.&lt;/p&gt;

&lt;p&gt;Here’s an example of how you can implement lazy loading:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MyLazyComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lazy&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./MyComponent&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Suspense&lt;/span&gt; &lt;span class="nx"&gt;fallback&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Loading&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;}&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;MyLazyComponent&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Suspense&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this approach, &lt;code&gt;MyComponent&lt;/code&gt; is only loaded when it’s actually needed, improving initial load time.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Optimize Component Size
&lt;/h2&gt;

&lt;p&gt;React developers often use third-party libraries to speed up development. However, some of these libraries can be bulky and add to your app’s overall size, affecting performance.&lt;/p&gt;

&lt;p&gt;You can minimize your bundle size by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Only importing the specific parts of libraries that you need (tree-shaking).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Avoiding heavy libraries when lightweight alternatives are available.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Monitoring your bundle size using tools like Webpack Bundle Analyzer to see which parts of your app are taking up the most space.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, instead of importing the entire &lt;code&gt;lodash&lt;/code&gt; library, you can import only the functions you need:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;debounce&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;lodash/debounce&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Use useCallback and useMemo Hooks
&lt;/h2&gt;

&lt;p&gt;In React, the &lt;code&gt;useCallback&lt;/code&gt; and &lt;code&gt;useMemo&lt;/code&gt; hooks help in preventing unnecessary re-calculations or re-creations of functions and values.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;useCallback&lt;/code&gt; is used to memoize functions so they don’t get recreated on every render.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;useMemo&lt;/code&gt; is used to memoize expensive calculations and avoid recalculating values unnecessarily.&lt;/p&gt;

&lt;p&gt;Here’s an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;memoizedValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useMemo&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;expensiveCalculation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;memoizedCallback&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useCallback&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;doSomething&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By using these hooks, you can prevent your app from wasting resources on recalculations, which enhances performance.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Optimize Images and Static Resources
&lt;/h2&gt;

&lt;p&gt;Large image files can dramatically increase load times and slow down your app. Here’s how you can optimize images and other static resources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Compress images using tools like ImageOptim or TinyPNG.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use modern formats like WebP to reduce file size without compromising quality.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Lazy-load images so that they are only loaded when they come into view, improving initial page load time.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"image.webp"&lt;/span&gt; &lt;span class="na"&gt;loading=&lt;/span&gt;&lt;span class="s"&gt;"lazy"&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"example image"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. Minimize Reconciliation and Re-renders
&lt;/h2&gt;

&lt;p&gt;React’s reconciliation process ensures that only the parts of the DOM that need to be updated are changed. However, if your components frequently re-render unnecessarily, this can impact performance.&lt;/p&gt;

&lt;p&gt;To minimize this, avoid directly mutating the state or props, and make sure to structure your component hierarchy in a way that limits how much of your app needs to re-render when the state changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Use Efficient State Management
&lt;/h2&gt;

&lt;p&gt;Managing state in large React apps can be complex and lead to performance bottlenecks if not handled efficiently. While React’s built-in &lt;code&gt;useState&lt;/code&gt; and &lt;code&gt;useReducer&lt;/code&gt; hooks work well for small to medium apps, consider using libraries like Redux or MobX for more complex applications.&lt;/p&gt;

&lt;p&gt;However, when using state management libraries, make sure to:&lt;br&gt;
Keep your state minimal.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Avoid storing unnecessary data in the global state.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use selectors to ensure that components only re-render when necessary data changes.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  8. Keep the Virtual DOM Light
&lt;/h2&gt;

&lt;p&gt;React’s Virtual DOM diffing algorithm is optimized for performance, but it’s still important to keep your component tree shallow and efficient. Avoid deeply nested components that result in excessive DOM nodes.&lt;/p&gt;

&lt;p&gt;Try to break down complex components into smaller, reusable pieces and minimize the number of elements rendered at once.&lt;/p&gt;

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

&lt;p&gt;Optimizing a React app for performance is an ongoing process. By reducing unnecessary re-renders, leveraging code-splitting, and optimizing state management, you can ensure that your app runs smoothly, even as it scales. Remember that a fast, responsive app not only improves user experience but also enhances the app’s SEO performance.&lt;/p&gt;

&lt;p&gt;With &lt;a href="https://bit.ly/DualiteDevToArindam" rel="noopener noreferrer"&gt;Dualite&lt;/a&gt;, you get optimized ReactJS code that's not only conversion-ready but also ensures faster load times and seamless performance for your web applications.&lt;/p&gt;

</description>
      <category>react</category>
      <category>ui</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Using CSS Variables for Theme Customisation</title>
      <dc:creator>Ayush Thakur</dc:creator>
      <pubDate>Sat, 12 Oct 2024 13:14:19 +0000</pubDate>
      <link>https://forem.com/dualitedev/using-css-variables-for-theme-customisation-5aoj</link>
      <guid>https://forem.com/dualitedev/using-css-variables-for-theme-customisation-5aoj</guid>
      <description>&lt;p&gt;CSS variables, also known as custom properties, offer a flexible and efficient way to implement theme customisation across web applications. By defining reusable values in a single place, you can easily manage and apply themes throughout your site without repeating yourself in the code.&lt;/p&gt;

&lt;p&gt;In this blog, we’ll explore how to use CSS variables for theme customisation, and why this approach is beneficial for modern web design.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are CSS Variables?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.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%2F27zikgs1m4l7w566xncs.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F27zikgs1m4l7w566xncs.gif" alt="Image description" width="450" height="253"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;CSS variables allow you to store values for reuse across your stylesheets. You can think of them as placeholders that can be updated in one spot but reflected throughout your entire CSS file.&lt;/p&gt;

&lt;p&gt;Here’s a simple example of defining and using a CSS variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--primary-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#3498db&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--primary-color&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, &lt;code&gt;--primary-color&lt;/code&gt; is the variable, and you can access it using the &lt;code&gt;var()&lt;/code&gt; function wherever you need it. The &lt;code&gt;:root&lt;/code&gt; selector defines the variable at the global level, meaning it can be accessed anywhere in your stylesheet.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Use CSS Variables for Themes?
&lt;/h2&gt;

&lt;p&gt;When building applications that require multiple themes (like light and dark modes), CSS variables shine. Instead of hardcoding colors or font sizes throughout your stylesheet, you can store these values in variables and switch themes by changing the values dynamically.&lt;/p&gt;

&lt;p&gt;Let’s dive into some key reasons why CSS variables make theme &lt;br&gt;
customisation more manageable:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Consistency Across Components&lt;/strong&gt;: By using variables, your UI components will remain consistent. When you need to update a theme color or font size, you only need to adjust it at a single place.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dynamic Theme Switching&lt;/strong&gt;: You can easily switch themes with JavaScript by updating the CSS variable values on the fly, allowing for real-time theme changes without the need for page reloads.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Easier Maintenance&lt;/strong&gt;: Updating a design system is much easier when variables are used. For example, if you need to tweak the primary color, you only change it in one place, and the change will propagate throughout the entire site.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Implementing Theme Customisation with CSS Variables
&lt;/h2&gt;

&lt;p&gt;Let’s say we want to build a simple dark mode and light mode theme switcher using CSS variables. We start by defining our theme variables in the &lt;code&gt;:root&lt;/code&gt; selector for the default (light) theme:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#ffffff&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--text-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#000000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Next, we define the dark theme by updating the variable values in a custom class. This class will be toggled when switching between themes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.dark-mode&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#2c3e50&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--text-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#ecf0f1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this setup, all that’s left is to toggle the dark-mode class on the body element using JavaScript when the user switches themes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;toggleTheme&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toggle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dark-mode&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Advanced Theme Customisation
&lt;/h2&gt;

&lt;p&gt;CSS variables aren’t limited to just colors. You can use them for any CSS property, such as fonts, spacing, or even animations. Here’s an example of customising font sizes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--base-font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--heading-font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--base-font-size&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--heading-font-size&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This level of control allows you to adjust not only colors but also the overall look and feel of your themes dynamically.&lt;/p&gt;

&lt;h2&gt;
  
  
  Accessibility Considerations
&lt;/h2&gt;

&lt;p&gt;When implementing theme customisation, it’s important to consider accessibility. Ensure that your themes offer sufficient contrast between background and text colors to accommodate users with visual impairments. Tools like WebAIM’s contrast checker can help you ensure that your themes meet accessibility standards.&lt;/p&gt;

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

&lt;p&gt;CSS variables offer a powerful way to customise themes, ensuring consistency across your design while making updates and theme switches simple. Whether you’re building a simple website or a complex web app, integrating CSS variables into your workflow can streamline your development process and improve maintainability.&lt;/p&gt;

&lt;p&gt;By leveraging this technique, you’ll provide users with a seamless, dynamic experience that can adapt to their preferences—all with minimal code changes.&lt;/p&gt;

&lt;p&gt;No matter which approach you take for theme customization, Dualite can support your workflow. &lt;a href="https://bit.ly/DualiteDevToArindam" rel="noopener noreferrer"&gt;Dualite&lt;/a&gt; seamlessly integrates with CSS variables, offering optimized code generation that helps keep your site performing at its best.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>ui</category>
      <category>css</category>
    </item>
    <item>
      <title>Tailwind vs Custom CSS: What Should You Choose?</title>
      <dc:creator>Ayush Thakur</dc:creator>
      <pubDate>Mon, 07 Oct 2024 16:12:53 +0000</pubDate>
      <link>https://forem.com/dualitedev/tailwind-vs-custom-css-what-should-you-choose-bmi</link>
      <guid>https://forem.com/dualitedev/tailwind-vs-custom-css-what-should-you-choose-bmi</guid>
      <description>&lt;p&gt;When building a website, one of the fundamental decisions you’ll face is how to handle your CSS. Should you rely on a utility-first framework like Tailwind CSS, or write custom CSS from scratch? Each approach has its strengths and trade-offs, and the right choice depends on your project’s requirements, developer preferences, and future scalability.&lt;/p&gt;

&lt;p&gt;In this blog, we will explore both Tailwind and custom CSS, diving into what makes them unique, their benefits, and when to choose one over the other. By the end, you'll have a clearer understanding of which method best suits your next project.&lt;/p&gt;

&lt;p&gt;Let’s get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Tailwind CSS?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fplwsmz6ua91ymy48puo4.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fplwsmz6ua91ymy48puo4.gif" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://tailwindcss.com/" rel="noopener noreferrer"&gt;Tailwind&lt;/a&gt; is a utility-first CSS framework that provides low-level utility classes to help you style your elements directly in your HTML. Unlike traditional CSS frameworks that come with predefined components (like Bootstrap), Tailwind allows you to build custom designs by combining utility classes without writing any actual CSS.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"bg-blue-500 text-white p-4 rounded-lg"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  This is a Tailwind-styled div
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of creating custom class names and writing CSS rules for them, you use pre-built utility classes like &lt;code&gt;bg-blue-500&lt;/code&gt; for background color, &lt;code&gt;text-white&lt;/code&gt; for text color, &lt;code&gt;p-4&lt;/code&gt; for padding, and so on.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Custom CSS?
&lt;/h2&gt;

&lt;p&gt;Custom CSS refers to writing your own styles from scratch. This involves defining your class names and assigning CSS properties and values to control the appearance of elements. You have complete freedom over how you write your styles, including organizing them into reusable components or creating a design system tailored to your needs.&lt;/p&gt;

&lt;p&gt;Here’s an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"custom-div"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  This is a custom CSS styled div
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
  &lt;span class="nc"&gt;.custom-div&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#3490dc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, you define a custom class (custom-div) and manually apply your CSS properties in a &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; block or an external stylesheet.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tailwind CSS: Pros and Cons
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Pros:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Rapid Development&lt;/strong&gt;: Tailwind speeds up the development process by allowing you to apply styles directly in your HTML. No need to switch between your CSS and HTML files constantly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Responsive by Design&lt;/strong&gt;: With built-in responsive utilities like &lt;code&gt;sm:&lt;/code&gt;, &lt;code&gt;md:&lt;/code&gt;, and &lt;code&gt;lg:&lt;/code&gt;, Tailwind makes it easier to apply breakpoints and design for different devices.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;No Naming Conflicts&lt;/strong&gt;: Since Tailwind relies on utility classes, you don't have to worry about creating conflicting class names, which is a common issue when working with custom CSS.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Consistency&lt;/strong&gt;: The use of predefined utility classes enforces a consistent design system throughout your project, making it easier to maintain the codebase.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Cons:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;HTML Bloat&lt;/strong&gt;: Styling everything in your HTML can lead to a bloated codebase, with long class strings that may reduce readability.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Learning Curve&lt;/strong&gt;: While Tailwind is powerful, there’s a learning curve involved, especially if you’re used to traditional CSS methods.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Customization Limits&lt;/strong&gt;: Although Tailwind offers great flexibility, some developers find that it limits creativity, as you're constrained by its pre-built utilities unless you extend the framework.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Custom CSS: Pros and Cons
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Pros:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Full Control&lt;/strong&gt;: With custom CSS, you have complete control over your styles, making it easier to implement highly specific designs that may not be achievable with a utility-first framework.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cleaner HTML&lt;/strong&gt;: Custom CSS allows you to keep your HTML clean and uncluttered, focusing purely on structure while your styles are defined separately.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scalability&lt;/strong&gt;: If organized well, custom CSS can scale efficiently with large projects. By building reusable classes and components, you can create a robust design system that adapts to future needs.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Cons:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Slower Development&lt;/strong&gt;: Writing custom CSS can take longer than using a utility-first framework, especially for common styling patterns that Tailwind handles out of the box.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Potential for Inconsistency&lt;/strong&gt;: Without a predefined design system, it's easy for custom CSS to become inconsistent across pages, especially when working in a team or on a large project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Maintenance&lt;/strong&gt;: Over time, managing a growing custom CSS codebase can become challenging, especially if not well-organized. Naming conflicts and specificity issues may arise.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Tailwind or Custom CSS: Which Should You Choose?
&lt;/h2&gt;

&lt;p&gt;Both Tailwind and custom CSS have their advantages, but your choice will depend on a few factors:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Project Size&lt;/strong&gt;:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you're building a smaller project and need to move fast, Tailwind CSS might be the better option. Its utility-first approach allows for rapid development without the need to set up a comprehensive design system.&lt;/p&gt;

&lt;p&gt;For larger projects where scalability and long-term maintainability are key, custom CSS provides more control and can be tailored to the project's needs.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Developer Experience&lt;/strong&gt;:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Developers who prefer working with pre-built systems and want to focus on functionality rather than design details may find Tailwind CSS more convenient.&lt;/p&gt;

&lt;p&gt;On the other hand, if you enjoy fine-tuning every aspect of your design, custom CSS gives you the freedom to do so without being constrained by a framework.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Consistency vs. Flexibility&lt;/strong&gt;:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tailwind CSS excels at enforcing a consistent design system across your project, which can be a huge advantage for teams.&lt;/p&gt;

&lt;p&gt;Custom CSS offers greater flexibility, which is ideal if your design needs deviate significantly from typical patterns or if you want a highly unique look.&lt;/p&gt;

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

&lt;p&gt;Ultimately, the choice between Tailwind and custom CSS depends on your project’s needs and your personal workflow preferences. Tailwind CSS is perfect for developers who want to speed up their development process and maintain a consistent design system, while custom CSS is ideal for those who want more control over their design and are willing to spend extra time fine-tuning their styles.&lt;/p&gt;

&lt;p&gt;Also, no matter what you choose, Dualite is here to help in both scenarios. &lt;a href="https://bit.ly/DualiteDevToArindam" rel="noopener noreferrer"&gt;Dualite&lt;/a&gt; supports both Tailwind CSS and custom CSS, allowing you to choose whichever fits your needs best.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
      <category>ui</category>
    </item>
    <item>
      <title>How to make your Web Page Responsive</title>
      <dc:creator>Ayush Thakur</dc:creator>
      <pubDate>Wed, 02 Oct 2024 05:16:24 +0000</pubDate>
      <link>https://forem.com/dualitedev/how-to-make-your-web-page-responsive-1fo2</link>
      <guid>https://forem.com/dualitedev/how-to-make-your-web-page-responsive-1fo2</guid>
      <description>&lt;p&gt;Nowadays, the majority of internet users browse websites on their mobile phones or smartphones. As technology is evolving, more and more devices are making their way into the technology market, be it tablets, foldable smartphones, smart watches, etc. Therefore designing web pages that adapt themselves seamlessly to different viewports has become necessary now. &lt;/p&gt;

&lt;p&gt;As per the &lt;a href="https://www.statista.com/statistics/558610/number-of-mobile-internet-user-in-india/#:~:text=India's%20digital%20journey%20is%20one,over%201.2%20billion%20by%202050." rel="noopener noreferrer"&gt;Statisa&lt;/a&gt;, over 1.05 billion people uses the internet in India, and this number is going to increase to 1.20 billion by 2050. These huge numbers show how much important it is to build a web page that is responsive enough.&lt;/p&gt;

&lt;p&gt;A good well-designed responsive web page makes sure that the user has an optimal view experience and a uniform user experience irrespective of the device the user is using. Responsiveness not only enhances the user experience but also plays a major role in the SEO ranking of the website.&lt;/p&gt;

&lt;p&gt;And when it comes to adding responsiveness, the first thing that comes in mind is the media queries. In this blog, we will go through what are media queries, and how you can use them to make your web page responsive.&lt;/p&gt;

&lt;p&gt;So, let’s get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Media Queries?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.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%2Frdzosvscoyti0o57nqej.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Frdzosvscoyti0o57nqej.gif" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Media queries are a CSS technique that enables developers to define styling for different viewports, optimizing the layout and design across various devices. In essence, media queries allow the application of CSS rules based on the characteristics of the device or browser window the user is working with.&lt;/p&gt;

&lt;p&gt;By leveraging the width, orientation, and other features of the viewport, media queries ensure that the specified styles are dynamically applied, allowing the webpage to adapt seamlessly to a range of screen sizes. This results in a consistent and optimized user experience, regardless of the device.&lt;/p&gt;

&lt;p&gt;To effectively use media queries, you must specify the target viewport characteristics, such as width, and then define the corresponding styles. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;768px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;lightgray&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we have specified the width of the viewport as 768px in the &lt;a class="mentioned-user" href="https://dev.to/media"&gt;@media&lt;/a&gt; query. Furthermore, we have set the background-color property of the body element to lightgray. Therefore, when the width of the viewport is equal to or less than 768px, the background color of the body will change to lightgray.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Media Query works?
&lt;/h2&gt;

&lt;p&gt;As we have discussed earlier in the blog, Media queries demand two things - the width of the viewport and CSS styling, to show its magic. Let’s break this example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;768px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;lightgray&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a class="mentioned-user" href="https://dev.to/media"&gt;@media&lt;/a&gt; - a defined keyword used to initiate media query&lt;/li&gt;
&lt;li&gt;max-width - property of media query to define width of viewport&lt;/li&gt;
&lt;li&gt;body - element whose styling you want to target&lt;/li&gt;
&lt;li&gt;background-color - styling you want to change in that viewport&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here’s another example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1024px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we are targeting a div element and changing it’s multiple styling properties under the viewport of width 1024 px.&lt;/p&gt;

&lt;p&gt;Along with the max-width property, media queries also use the min-width property. As their names suggest, they work in opposite ways. The min-width property in a media query is used to apply CSS styles when the width of the viewport is equal to or greater than the specified width.&lt;/p&gt;

&lt;p&gt;Here’s an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt; &lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;720px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nt"&gt;span&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Media queries also give us the flexibility to use a combination of both min-width and max-width to target a specific viewport width range. Let’s see an example of it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="n"&gt;screen&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;600px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1200px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;lightblue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we are using a combination of both max-width and min-width to target a viewport width ranging from 600px to 1200px.&lt;/p&gt;

&lt;p&gt;Each type of device, such as smartphones, tablets, desktops, and even larger monitors, has a specific viewport width. We can use these viewport widths (breakpoints) to style our web components accordingly.&lt;/p&gt;

&lt;p&gt;Checkout this table for the breakpoints:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;BREAKPOINT&lt;/th&gt;
&lt;th&gt;KEYWORD&lt;/th&gt;
&lt;th&gt;DIMENSION&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Small&lt;/td&gt;
&lt;td&gt;sm&lt;/td&gt;
&lt;td&gt;≥576px&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Medium&lt;/td&gt;
&lt;td&gt;md&lt;/td&gt;
&lt;td&gt;≥768px&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Large&lt;/td&gt;
&lt;td&gt;lg&lt;/td&gt;
&lt;td&gt;≥992px&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Extra large&lt;/td&gt;
&lt;td&gt;xl&lt;/td&gt;
&lt;td&gt;≥1200px&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Extra extra large&lt;/td&gt;
&lt;td&gt;xxl&lt;/td&gt;
&lt;td&gt;≥1400px&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fhb77agld1p2kww7kteot.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fhb77agld1p2kww7kteot.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Until now, we've used pixel units to define width, but media queries also support other length units such as vw, vh, percentages, em, rem, and calc().&lt;/p&gt;

&lt;h2&gt;
  
  
  Best Practices for Using Media Queries
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Mobile-First Approach&lt;/strong&gt;: Start with the styles for the smallest screens first, then add media queries for larger screens. This approach often results in cleaner and more efficient CSS.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Limit Breakpoints&lt;/strong&gt;: Use a limited number of breakpoints to keep your styles manageable. Focus on the most common device sizes instead of trying to cover every possible device.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use Relative Units&lt;/strong&gt;: Whenever possible, use relative units like percentages, em, or rem instead of fixed units like pixels. This can improve accessibility and responsiveness.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Group Media Queries&lt;/strong&gt;: Keep all media queries at the end of your CSS file or group them together for better readability. This way, it’s easier to see how styles change across different viewports.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Test on Real Devices&lt;/strong&gt;: Always test your responsive design on actual devices or using device emulators to ensure that your media queries work as expected.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Avoid Overlapping Queries&lt;/strong&gt;: Be careful when defining overlapping media queries, as they can lead to unexpected results. Ensure that each query has a distinct range.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;Responsive web design is essential in today's multi-device world, and media queries help ensure your site adapts seamlessly to various screen sizes. By using them effectively, you can enhance both user experience and SEO performance. Prioritize responsiveness to future-proof your site and ensure it looks great across all devices.&lt;/p&gt;

&lt;p&gt;Also, make sure to checkout &lt;a href="https://bit.ly/DualiteDevToArindam" rel="noopener noreferrer"&gt;Dualite&lt;/a&gt; to convert your complex Figma designs into code in a few seconds.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>mobile</category>
      <category>ui</category>
    </item>
    <item>
      <title>Convert your Figma design to code using Dualite</title>
      <dc:creator>Ayush Thakur</dc:creator>
      <pubDate>Sat, 28 Sep 2024 06:46:23 +0000</pubDate>
      <link>https://forem.com/dualitedev/convert-your-figma-design-to-code-using-dualite-4leh</link>
      <guid>https://forem.com/dualitedev/convert-your-figma-design-to-code-using-dualite-4leh</guid>
      <description>&lt;p&gt;Creating a User Interface is the first and foremost step that takes place while building a website. Multiple factors like responsiveness, easy navigation, color contrast, pleasing to the eyes, etc, are kept in mind while designing the user interface.&lt;/p&gt;

&lt;p&gt;When it comes to designing a UI, Figma is the first and most popular tool that comes to mind. Figma comes with tons of customization that helps to build endless UI designs following the designer's creativity.&lt;/p&gt;

&lt;p&gt;After the design is ready, a developer's role comes into play. The developers convert the whole Figma design frontend code. But the problem is it literally takes hours to even convert a simple basic design into code. It’s a very hectic task for a developer to generate code that gives the same result as of created design.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdrwhvyxqxy5fhzy6ud7z.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdrwhvyxqxy5fhzy6ud7z.gif" alt="Image description" width="500" height="289"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thus reducing the developer's productivity and that's where Dualite comes to rescue us.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.dualite.dev/" rel="noopener noreferrer"&gt;Dualite&lt;/a&gt; is an AI-powered designed-to-code tool that allows us to convert the whole Figma design into frontend code within a few seconds. With Dualite, all it takes is a few clicks and a few seconds to convert a complex UI into frontend code.&lt;/p&gt;

&lt;p&gt;In this blog, we will walk through the procedure on how you can convert a Figma design into a React code using Dualite. You can simply use the Dualite plugin in Figma and generate the code in a few clicks.&lt;/p&gt;

&lt;p&gt;Let's get started&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Select the Figma Design
&lt;/h2&gt;

&lt;p&gt;Open &lt;a href="https://www.figma.com/" rel="noopener noreferrer"&gt;Figma&lt;/a&gt;, and design the UI for your webpage. Once the design is fully created, select the design.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo9dgx19azxiljo0bl3kw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo9dgx19azxiljo0bl3kw.png" alt="Image description" width="725" height="452"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can select the entire design or any particular section/frame in the design depending upon your choice. The frame you will select will be the one that the Dualite will convert to code.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Run the Dualite plugin
&lt;/h2&gt;

&lt;p&gt;In order to use Dualite, we need to run its plugin.&lt;/p&gt;

&lt;p&gt;Go to &lt;strong&gt;Resources&lt;/strong&gt; (Shift + I) present on the tools bar, and navigate to the &lt;strong&gt;Plugins&lt;/strong&gt; section.&lt;/p&gt;

&lt;p&gt;Search for the Dualite plugin and run it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmojjybwn5mhfsc8whfgt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmojjybwn5mhfsc8whfgt.png" alt="Image description" width="726" height="451"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Login to Dualite
&lt;/h2&gt;

&lt;p&gt;After running the plugin, you need to login to the Dualite plugin using your desired credentials. You can use your Figma account credentials to login to the Dualite plugin.&lt;/p&gt;

&lt;p&gt;After successfully logging in, you will see this screen&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3xnvswy9p1yb2f8g0lxu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3xnvswy9p1yb2f8g0lxu.png" alt="Image description" width="722" height="442"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Select the desired mode
&lt;/h2&gt;

&lt;p&gt;Dualite offers us two different modes to convert Figma design into code-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.dualite.dev/page-mode" rel="noopener noreferrer"&gt;Page Mode&lt;/a&gt;: Built for designers to convert the designs into code super fast. It converts the whole design into a single page code. If you don’t want the hassle to tweak the code and understand it, then Page Mode will be an ideal choice for you.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.dualite.dev/component-mode" rel="noopener noreferrer"&gt;Component Mode&lt;/a&gt;: Built for developers to generate interactive and static Reusable components. It scans each element present in the design and creates reusable components for each individual element making it an ideal choice for developers.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For this tutorial, we will select the Component Mode.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwvly3w97bcst6v425eoz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwvly3w97bcst6v425eoz.png" alt="Image description" width="726" height="451"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Currently, Dualite supports only the React JS library in converting designs into reusable components code. Stay tuned for more JS Frameworks/Library support.&lt;/p&gt;

&lt;p&gt;Now, click on the &lt;strong&gt;Convert To Code&lt;/strong&gt; button to start conversion and Dualite will show its magic.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Get the Output
&lt;/h2&gt;

&lt;p&gt;Within a few seconds, Dualite will scan the component and generate the code. After the Dualite has successfully generated the code, you will see this screen:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8sqh0aqw4yn2ymsun5o3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8sqh0aqw4yn2ymsun5o3.png" alt="Image description" width="722" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can download the Zip file of your code and run it locally. Also, you can try and run the code on CodeSandbox by clicking on the &lt;strong&gt;Preview Code&lt;/strong&gt; button.&lt;/p&gt;

&lt;p&gt;You can tweak or manipulate the generated code to get the desired results. &lt;/p&gt;

&lt;p&gt;Every conversion that you make using Dualite will get saved to your Dualite Dashboard allowing you to access the code anytime in the future.&lt;/p&gt;

&lt;p&gt;Checkout the video tutorial&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/H8phHvBdF3c"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In this tutorial, we took an example of a static webpage for the demo purpose. But websites like eCommerce, Blogging, Portfolio, etc comes with multiple animations and interactions. Dualite also comes with the capability to convert these animations and interactions into code. &lt;/p&gt;

&lt;p&gt;Checkout the docs to learn more about it, &lt;a href="https://docs.dualite.dev/" rel="noopener noreferrer"&gt;click here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Got stuck anywhere? Join our Slack Community&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;a href="https://dualite-workspace.slack.com/join/shared_invite/zt-2rhcsjqs5-Xeep1KWd2u_cJgGX9Tco6g" rel="noopener noreferrer"&gt;
      dualite-workspace.slack.com
    &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>webdev</category>
      <category>design</category>
      <category>react</category>
      <category>ui</category>
    </item>
  </channel>
</rss>
