<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Sass - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Sass - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Mon, 25 May 2026 22:38:27 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/sass/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Customize Bootstrap with Sass ]]>
                </title>
                <description>
                    <![CDATA[ Bootstrap is an awesome CSS framework that can help you create stylish and sleek websites. Some developers and teams find that code written in Bootstrap is easier to maintain than regular CSS, so they prefer Bootstrap to vanilla CSS. But if everyone ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-customize-bootstrap-with-sass/</link>
                <guid isPermaLink="false">66d461734bc8f441cb6df831</guid>
                
                    <category>
                        <![CDATA[ Bootstrap ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Sass ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Vinod Mathew Sebastian ]]>
                </dc:creator>
                <pubDate>Tue, 21 Jun 2022 20:59:02 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/06/How_to_customize_Boostrap_with_Sass.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Bootstrap is an awesome CSS framework that can help you create stylish and sleek websites.</p>
<p>Some developers and teams find that code written in Bootstrap is easier to maintain than regular CSS, so they prefer Bootstrap to vanilla CSS.</p>
<p>But if everyone used Bootstrap with its default styles, then every site would look the same – and quickly, the internet would become pretty bland. Fortunately, Bootstrap is also highly customizable.</p>
<h2 id="heading-how-to-customize-bootstrap">How to Customize Bootstrap</h2>
<p>If you're a beginner, you can customize Bootstrap with a custom CSS stylesheet. CSS specificity is important here. You write custom CSS, with the same or higher specificity, and link to it in the head section of your index.html <em>after</em> the line which links to the original Bootstrap CSS.</p>
<pre><code class="lang-typescript">&lt;!-- index.html --&gt;
&lt;head&gt;

    &lt;link rel=<span class="hljs-string">"stylesheet"</span> href=<span class="hljs-string">"./node_modules/bootstrap/dist/css/bootstrap.min.css"</span>&gt;
    &lt;!-- custom CSS should come after Bootstrap CSS --&gt;
    &lt;link rel=<span class="hljs-string">"stylesheet"</span> href=<span class="hljs-string">"./custom.css"</span>

&lt;/head&gt;
</code></pre>
<p>For small tweaks this is OK. But for larger projects, this can be time-consuming and there may be a lot of redundant style declarations. So there has to be another, cleaner, way.</p>
<h3 id="heading-how-to-use-sass-with-bootstrap">How to Use Sass with Bootstrap</h3>
<p>The solution is to use Sass – a CSS preprocessor. Sass is compiled down to CSS before it's used on web pages.</p>
<p>Until Bootstrap version 3.x, you had a choice between CSS preprocessors: Less or Sass. But since version 4, Bootstrap uses only Sass. The source code for the Bootstrap 4 and 5 frameworks is written entirely in Sass, which is a testimony to how mature Sass has become.</p>
<p>You may have heard the tagline, "Sass is CSS with superpowers". If you want to learn Sass, the <a target="_blank" href="https://sass-lang.com">official</a> website is an excellent resource. You can also refer to other tutorials on freeCodeCamp, like this one on <a target="_blank" href="https://www.freecodecamp.org/news/how-to-use-sass-with-css/">how to use Sass with CSS</a>, or this video course on <a target="_blank" href="https://www.freecodecamp.org/news/learn-bootstrap-5-and-sass-by-building-a-portfolio-website/">how to use Sass with Bootstrap 5</a>.</p>
<p>Sass comes with two syntaxes. The older one uses indentation and the newer SCSS syntax (SCSS for Sassy CSS) uses CSS-like curly braces.</p>
<p>SCSS is a superset of CSS. So CSS code saved with a .scss extension (or SCSS interspersed with CSS) is also valid Sass code.</p>
<p>In this tutorial, we are going to use the SCSS version. Whatever the style is, indented Sass or CSS-like SCSS, the Sass compiler will transpile it to vanilla CSS to be used on the browser.</p>
<h3 id="heading-what-we-are-going-to-do-in-this-tutorial">What we are going to do in this tutorial</h3>
<ol>
<li><p>We will change the primary and secondary theme colors Bootstrap ships with.</p>
</li>
<li><p>We will also change the default media breakpoints Bootstrap uses.</p>
</li>
</ol>
<p>Once we can do these, it will become easy to do other customizations.</p>
<h3 id="heading-the-prerequisites">The Prerequisites</h3>
<ol>
<li><p>Node.js with npm or yarn</p>
</li>
<li><p>A code editor, preferably VS Code.</p>
</li>
<li><p>A basic understanding of Sass</p>
</li>
</ol>
<p>Download Bootstrap from the official website: <a target="_blank" href="https://getbootstrap.com">https://getbootstrap.com</a></p>
<p>Since we have Node.js installed, I'm going to use the npm version.</p>
<p><code>npm i bootstrap</code></p>
<p>We also need to install the Sass compiler. We can get the official dart-sass version from <a target="_blank" href="https://sass-lang.com">their website</a>. Whether you're on Windows, Mac, or Linux you just need to download the dart-sass package, unzip it, and add it to the path (environment variables).</p>
<p>There is a npm sass package. Also, there is a <em>Live Sass Compiler</em> VS Code extension with over 2 million installs. Feel free to use whatever Sass compiler you're comfortable with.</p>
<p>Here, we are going to use the npm package: sass.</p>
<p>After downloading Bootstrap, and the Sass compiler, in the <code>node-modules</code> directory, there is a folder named <code>bootstrap</code>.</p>
<p>There are also three folders inside it: <code>dist</code>, <code>js</code>, and <code>scss</code>.</p>
<p>All the compiled CSS is in <code>dist</code>, the Bootstrap JavaScript code in <code>js</code>, and all the Sass files are in the <code>scss</code> folder.</p>
<h3 id="heading-how-to-change-the-primary-and-secondary-theme-colors">How to change the primary and secondary theme colors</h3>
<p>For customization, our idea is to override the .scss files and recompile them.</p>
<p>The official Bootstrap documentation advises against changing the core bootstrap files whenever possible. So we are going to create a custom.scss stylesheet.</p>
<p>And we are going to import all of Bootstrap in the custom.scss file.</p>
<pre><code class="lang-typescript"><span class="hljs-comment">//custom.scss</span>

<span class="hljs-meta">@import</span> <span class="hljs-string">"../node_modules/bootstrap/scss/bootstrap"</span>;
</code></pre>
<p>Variables are suffixed with a <code>!default</code> (a Sass flag) in Bootstrap. The <code>!default</code> flag tells the compiler to set the value only if the value is not defined.</p>
<p>So, we set the variables before the @import directive so that, later, the compiler sets our value instead of the default ones.</p>
<pre><code class="lang-typescript"><span class="hljs-comment">//custom.scss</span>

$primary: teal;
$secondary: green;

<span class="hljs-meta">@import</span> <span class="hljs-string">"../node_modules/bootstrap/scss/bootstrap"</span>;
</code></pre>
<p>We also need an HTML file to preview the results.</p>
<pre><code class="lang-typescript">&lt;!-- index.html --&gt;
&lt;!DOCTYPE html&gt;
&lt;html lang=<span class="hljs-string">"en"</span>&gt;
&lt;head&gt;
    &lt;meta charset=<span class="hljs-string">"UTF-8"</span>&gt;
    &lt;meta http-equiv=<span class="hljs-string">"X-UA-Compatible"</span> content=<span class="hljs-string">"IE=edge"</span>&gt;
    &lt;meta name=<span class="hljs-string">"viewport"</span> content=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;
    &lt;title&gt;Welcome! Customize Bootstrap <span class="hljs-keyword">with</span> Sass&lt;/title&gt;
    &lt;link rel=<span class="hljs-string">"stylesheet"</span> href=<span class="hljs-string">"./node_modules/bootstrap/dist/css/bootstrap.min.css"</span>
&lt;/head&gt;
&lt;body&gt;
 &lt;div <span class="hljs-keyword">class</span>=<span class="hljs-string">"container"</span> &gt;
 &lt;div <span class="hljs-keyword">class</span>=<span class="hljs-string">"row"</span>&gt;
    &lt;nav <span class="hljs-keyword">class</span>=<span class="hljs-string">"navbar navbar-expand-lg navbar-light bg-primary"</span>&gt;
        &lt;div <span class="hljs-keyword">class</span>=<span class="hljs-string">"container-fluid"</span>&gt;
          &lt;a <span class="hljs-keyword">class</span>=<span class="hljs-string">"navbar-brand"</span> href=<span class="hljs-string">"#"</span>&gt;Customize Bootstrap&lt;/a&gt;
          &lt;button <span class="hljs-keyword">class</span>=<span class="hljs-string">"navbar-toggler"</span> <span class="hljs-keyword">type</span>=<span class="hljs-string">"button"</span> data-bs-toggle=<span class="hljs-string">"collapse"</span> data-bs-target=<span class="hljs-string">"#navbarSupportedContent"</span> aria-controls=<span class="hljs-string">"navbarSupportedContent"</span> aria-expanded=<span class="hljs-string">"false"</span> aria-label=<span class="hljs-string">"Toggle navigation"</span>&gt;
            &lt;span <span class="hljs-keyword">class</span>=<span class="hljs-string">"navbar-toggler-icon"</span>&gt;&lt;/span&gt;
          &lt;/button&gt;
          &lt;div <span class="hljs-keyword">class</span>=<span class="hljs-string">"collapse navbar-collapse"</span> id=<span class="hljs-string">"navbarSupportedContent"</span>&gt;
            &lt;ul <span class="hljs-keyword">class</span>=<span class="hljs-string">"navbar-nav me-auto mb-2 mb-lg-0"</span>&gt;
              &lt;li <span class="hljs-keyword">class</span>=<span class="hljs-string">"nav-item"</span>&gt;
                &lt;a <span class="hljs-keyword">class</span>=<span class="hljs-string">"nav-link active"</span> aria-current=<span class="hljs-string">"page"</span> href=<span class="hljs-string">"#"</span>&gt;Home&lt;/a&gt;
              &lt;/li&gt;
              &lt;li <span class="hljs-keyword">class</span>=<span class="hljs-string">"nav-item"</span>&gt;
                &lt;a <span class="hljs-keyword">class</span>=<span class="hljs-string">"nav-link"</span> href=<span class="hljs-string">"#"</span>&gt;Link&lt;/a&gt;
              &lt;/li&gt;
              &lt;li <span class="hljs-keyword">class</span>=<span class="hljs-string">"nav-item dropdown"</span>&gt;
                &lt;a <span class="hljs-keyword">class</span>=<span class="hljs-string">"nav-link dropdown-toggle"</span> href=<span class="hljs-string">"#"</span> id=<span class="hljs-string">"navbarDropdown"</span> role=<span class="hljs-string">"button"</span> data-bs-toggle=<span class="hljs-string">"dropdown"</span> aria-expanded=<span class="hljs-string">"false"</span>&gt;
                  Dropdown
                &lt;/a&gt;
                &lt;ul <span class="hljs-keyword">class</span>=<span class="hljs-string">"dropdown-menu"</span> aria-labelledby=<span class="hljs-string">"navbarDropdown"</span>&gt;
                  &lt;li&gt;&lt;a <span class="hljs-keyword">class</span>=<span class="hljs-string">"dropdown-item"</span> href=<span class="hljs-string">"#"</span>&gt;Action&lt;<span class="hljs-regexp">/a&gt;&lt;/</span>li&gt;
                  &lt;li&gt;&lt;a <span class="hljs-keyword">class</span>=<span class="hljs-string">"dropdown-item"</span> href=<span class="hljs-string">"#"</span>&gt;Another action&lt;<span class="hljs-regexp">/a&gt;&lt;/</span>li&gt;
                  &lt;li&gt;&lt;hr <span class="hljs-keyword">class</span>=<span class="hljs-string">"dropdown-divider"</span>&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a <span class="hljs-keyword">class</span>=<span class="hljs-string">"dropdown-item"</span> href=<span class="hljs-string">"#"</span>&gt;Something <span class="hljs-keyword">else</span> here&lt;<span class="hljs-regexp">/a&gt;&lt;/</span>li&gt;
                &lt;/ul&gt;
              &lt;/li&gt;
              &lt;li <span class="hljs-keyword">class</span>=<span class="hljs-string">"nav-item"</span>&gt;
                &lt;a <span class="hljs-keyword">class</span>=<span class="hljs-string">"nav-link disabled"</span> href=<span class="hljs-string">"#"</span> tabindex=<span class="hljs-string">"-1"</span> aria-disabled=<span class="hljs-string">"true"</span>&gt;Disabled&lt;/a&gt;
              &lt;/li&gt;
            &lt;/ul&gt;
            &lt;form <span class="hljs-keyword">class</span>=<span class="hljs-string">"d-flex"</span>&gt;
              &lt;input <span class="hljs-keyword">class</span>=<span class="hljs-string">"form-control me-2"</span> <span class="hljs-keyword">type</span>=<span class="hljs-string">"search"</span> placeholder=<span class="hljs-string">"Search"</span> aria-label=<span class="hljs-string">"Search"</span>&gt;
              &lt;button <span class="hljs-keyword">class</span>=<span class="hljs-string">"btn btn-outline-success"</span> <span class="hljs-keyword">type</span>=<span class="hljs-string">"submit"</span>&gt;Search&lt;/button&gt;
            &lt;/form&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/nav&gt;
&lt;div <span class="hljs-keyword">class</span>=<span class="hljs-string">"container"</span>&gt;
&lt;div <span class="hljs-keyword">class</span>=<span class="hljs-string">"row"</span>&gt;

  &lt;div <span class="hljs-keyword">class</span>=<span class="hljs-string">"col-xl pt-3"</span>&gt;
    Lorem ipsum dolor sit amet consectetur adipisicing elit. Vero, laborum hic, quia maiores animi nobis eligendi est eos saepe architecto reiciendis! Aliquam inventore distinctio reprehenderit corporis amet assumenda officiis dolorem, animi delectus sunt dolor commodi. Adipisci nam nemo labore eligendi quas, rem ipsum iusto eveniet itaque vero necessitatibus! Quas, cupiditate tempora unde nam exercitationem libero aut labore deserunt nesciunt voluptate dignissimos quis porro reprehenderit maiores excepturi, esse, nisi dolores sit tenetur voluptatum corrupti alias provident pariatur? Quam illo unde autem, fugit numquam dolores, odio sed rem saepe exercitationem fuga, nisi soluta sunt officiis! Similique, vero repudiandae quae dignissimos fuga natus!
    &lt;/div&gt;

  &lt;div <span class="hljs-keyword">class</span>=<span class="hljs-string">"col-xl pt-3 "</span>&gt;
    Lorem ipsum dolor sit, amet consectetur adipisicing elit. Numquam, aliquid, cumque nisi tenetur similique labore repudiandae voluptas qui hic blanditiis beatae sapiente autem dolore! Quam, cupiditate nostrum laboriosam blanditiis vel ratione, repellat, incidunt modi tempore soluta ab nesciunt? Ab similique illum suscipit exercitationem et, aut quisquam neque atque recusandae rem delectus facilis. Magnam rerum fugit minus explicabo vel! Hic quibusdam laudantium dolorum, pariatur ipsam veritatis voluptate animi, nesciunt dolorem autem dicta. Debitis quae nam dicta autem ipsum mollitia! Ipsum ipsa, molestias fugiat officiis aut illum ullam architecto maxime labore vitae. Ipsum quos neque rerum, esse iste quo explicabo eos ipsa?
    &lt;/div&gt;

&lt;/div&gt;
&lt;/div&gt;

&lt;div <span class="hljs-keyword">class</span>=<span class="hljs-string">"mt-5 pt-5 mb-5 text-center"</span>&gt;
  &lt;button <span class="hljs-keyword">type</span>=<span class="hljs-string">"button"</span> <span class="hljs-keyword">class</span>=<span class="hljs-string">"btn btn-primary"</span>&gt;Primary&lt;/button&gt;
  &lt;button <span class="hljs-keyword">type</span>=<span class="hljs-string">"button"</span> <span class="hljs-keyword">class</span>=<span class="hljs-string">"btn btn-secondary"</span>&gt;Secondary&lt;/button&gt;
  &lt;button <span class="hljs-keyword">type</span>=<span class="hljs-string">"button"</span> <span class="hljs-keyword">class</span>=<span class="hljs-string">"btn btn-success"</span>&gt;Success&lt;/button&gt;
  &lt;button <span class="hljs-keyword">type</span>=<span class="hljs-string">"button"</span> <span class="hljs-keyword">class</span>=<span class="hljs-string">"btn btn-danger"</span>&gt;Danger&lt;/button&gt;
  &lt;button <span class="hljs-keyword">type</span>=<span class="hljs-string">"button"</span> <span class="hljs-keyword">class</span>=<span class="hljs-string">"btn btn-warning"</span>&gt;Warning&lt;/button&gt;
  &lt;button <span class="hljs-keyword">type</span>=<span class="hljs-string">"button"</span> <span class="hljs-keyword">class</span>=<span class="hljs-string">"btn btn-info"</span>&gt;Info&lt;/button&gt;
  &lt;button <span class="hljs-keyword">type</span>=<span class="hljs-string">"button"</span> <span class="hljs-keyword">class</span>=<span class="hljs-string">"btn btn-light"</span>&gt;Light&lt;/button&gt;
  &lt;button <span class="hljs-keyword">type</span>=<span class="hljs-string">"button"</span> <span class="hljs-keyword">class</span>=<span class="hljs-string">"btn btn-dark"</span>&gt;Dark&lt;/button&gt;
  &lt;button <span class="hljs-keyword">type</span>=<span class="hljs-string">"button"</span> <span class="hljs-keyword">class</span>=<span class="hljs-string">"btn btn-link"</span>&gt;Link&lt;/button&gt;
&lt;/div&gt;

 &lt;/div&gt;

 &lt;/div&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>We have not compiled Sass yet. To see the default styles, run <em>Live Server</em>.</p>
<p>If <em>Live Server</em> is not installed, you can download the free extension from the VS Code extensions marketplace.</p>
<p>This is what we see:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/default_theme-3.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>It is time to compile our custom Sass file.</p>
<p>Compilation syntax is simple: Specify the source and destination folders separated with a colon.</p>
<p>I have my custom.scss file in a folder called <code>custom_scss</code>.</p>
<p><code>sass custom_scss/custom.scss:assets/css/custom_bootstrap.css</code></p>
<p>After recompiling, we have the customized bootstrap in the <code>assets/css/custom_bootstrap.css</code> file.</p>
<p>Instead of the default bootstrap file, we are going to use this customized bootstrap stylesheet.</p>
<pre><code class="lang-typescript">&lt;!-- index.html --&gt;
&lt;head&gt;

&lt;link rel=<span class="hljs-string">"stylesheet"</span> href=<span class="hljs-string">"./assets/css/custom_bootstrap.css"</span>&gt; <span class="hljs-string">`

&lt;/head&gt;</span>
</code></pre>
<p>Then run the <em>Live Server</em> again.</p>
<p>We get the webpage customized with our new styles.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/custom_theme..png" alt="Image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-how-to-change-the-grid-breakpoints">How to change the grid breakpoints</h3>
<p>We'll now customize the media breakpoints. Alongside, we have to redefine container-max-widths also.</p>
<p>The easiest way is to simply override the variables:</p>
<pre><code class="lang-typescript">$primary: teal;
$secondary:green;

$grid-breakpoints: (
  xs: <span class="hljs-number">0</span>,
  sm: <span class="hljs-number">576</span>px,
  md: <span class="hljs-number">768</span>px,
  lg: <span class="hljs-number">992</span>px,
  xl: <span class="hljs-number">1280</span>px,
  xxl: <span class="hljs-number">1600</span>px
);

$container-max-widths: (
  sm: <span class="hljs-number">540</span>px,
  md: <span class="hljs-number">720</span>px,
  lg: <span class="hljs-number">960</span>px,
  xl: <span class="hljs-number">1220</span>px,
  xxl: <span class="hljs-number">1520</span>px
);

<span class="hljs-meta">@import</span> <span class="hljs-string">'../node_modules/bootstrap/scss/bootstrap'</span>
</code></pre>
<p>Since this would violate DRY principles (Don't Repeat Yourself), using the <code>map-merge()</code> function is a better option.</p>
<p>We have to import functions first in the custom.scss file to make <code>map.merge()</code> available.</p>
<p>We have to import variables also because $grid-breakpoints (to be used inside the function) is defined there.</p>
<pre><code class="lang-typescript"><span class="hljs-comment">//custom.scss</span>

$primary: teal;
$secondary: green;

<span class="hljs-meta">@import</span> <span class="hljs-string">'../node_modules/bootstrap/scss/functions'</span>;
<span class="hljs-meta">@import</span> <span class="hljs-string">'../node_modules/bootstrap/scss/variables'</span>;
</code></pre>
<p>This is the code:</p>
<pre><code class="lang-typescript"><span class="hljs-comment">//custom.scss</span>

$primary: teal;
$secondary: green;

<span class="hljs-comment">//We have to import the functions first to use map.merge()</span>

<span class="hljs-meta">@import</span> <span class="hljs-string">'../node_modules/bootstrap/scss/functions'</span>;

<span class="hljs-comment">// We have to import the variables beforehand to </span>
<span class="hljs-comment">//use the variable $grid-breakpoints.</span>
<span class="hljs-comment">// Otherwise, compiler will show error - '$grid-breakpoints </span>
<span class="hljs-comment">//undefined.'</span>

<span class="hljs-meta">@import</span> <span class="hljs-string">'../node_modules/bootstrap/scss/variables'</span>;

$new-breakpoints: (
    xl: <span class="hljs-number">1280</span>px,
    xxl:<span class="hljs-number">1600</span>px
);

$grid-breakpoints: map-merge($grid-breakpoints, $new-breakpoints);

$new-container-max-widths: (
  xl: <span class="hljs-number">1220</span>px,
  xxl:<span class="hljs-number">1520</span>px
);

$container-max-widths: map-merge($container-max-widths, $new-container-max-widths);

<span class="hljs-meta">@import</span> <span class="hljs-string">"../node_modules/bootstrap/scss/bootstrap"</span>;
</code></pre>
<p>We compile again and use the newest file in place of the older one.</p>
<p><code>&lt;link rel="stylesheet" href="./assets/css/custom_bootstrap.css"&gt;</code></p>
<p>This is the final result:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/06/custom_theme_with_custom_breakpoints-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>It is not just theme colors and media breakpoints. Borders, spacing, box-shadow, fonts, icons...you can customize anything.</p>
<p>I have put up all the above code in this GitHub <a target="_blank" href="https://github.com/vinod-vms/Customize_Bootstrap_with_Sass">repo</a>.</p>
<p>For exploring further, the official Bootstrap <a target="_blank" href="https://getbootstrap.com/docs/5.0/getting-started/introduction/">documentation</a> is an excellent resource in this regard.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this tutorial, I've shown you how we can use Sass to customize Bootstrap.</p>
<p>Even if we are in a project that uses React with Bootstrap, the idea is the same. Create a custom .scss file, make customizations, import bootstrap, recompile, and then link to the customized file in place of the original bootstrap file.</p>
<p>Happy Learning!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Use Sass with CSS ]]>
                </title>
                <description>
                    <![CDATA[ Hi there! If you are reading this article, you're probably trying to understand what Sass is and how it works. Sass is a CSS preprocessor that helps you manage tasks in large projects where the style sheets get larger, you have a number of lines of C... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-use-sass-with-css/</link>
                <guid isPermaLink="false">66d84c8cf6f7ca5a6046249d</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Sass ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Design ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Adalbert Pungu ]]>
                </dc:creator>
                <pubDate>Mon, 25 Apr 2022 22:32:38 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/04/sass-image.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Hi there! If you are reading this article, you're probably trying to understand what Sass is and how it works.</p>
<p>Sass is a CSS preprocessor that helps you manage tasks in large projects where the style sheets get larger, you have a number of lines of CSS code, and it becomes difficult to maintain your CSS codes.</p>
<p>This is where Sass becomes useful, as it has features that don't yet exist in CSS like nesting, creating functions with mixins, inheritance, and more. These features will help you write maintainable CSS code.</p>
<p>Sass lets you reuse your code, split it into files, and it also helps you create functions, variables, nest your CSS selectors, and other shortcuts.</p>
<h2 id="heading-how-sass-works">How Sass Works</h2>
<p>The web browser does not understand Sass code, though – it only understands CSS code. This means that you have to transform the Sass code into CSS code.</p>
<p>To do this, the compiler will generate a file with the CSS code. This transformation is called compilation. When you write Sass code in a .scss file, it is compiled into a regular CSS file that the browser will use to display it on the web page.</p>
<h2 id="heading-why-use-sass">Why Use Sass?</h2>
<p>There are many advantages to using Sass, so let's look at some of them now:</p>
<p>First, Sass is easy to understand if you know CSS. Since it's a CSS preprocessor its syntax is similar.</p>
<p>Also, if you use Sass, your CSS code will be compatible with all versions of browsers.</p>
<p>Sass also makes it possible to reuse your code by creating variables and functions with mixins (cutting up pieces of code) that can be reused over and over again. This helps you save time and allows you to code faster.</p>
<p>Speaking of saving time, Sass reduces the repetition of writing CSS code. This is thanks to its features like functions, variables, inheritance, and so on.</p>
<p>Finally, Sass is compiled to CSS and adds all the necessary vendor prefixes so you don't have to worry about writing them manually.</p>
<h2 id="heading-how-to-install-and-configure-sass">How to Install and Configure Sass</h2>
<p>In this article, I'll show you two ways to install Sass.</p>
<h3 id="heading-how-to-install-sass-with-nodejs">How to Install Sass with Node.js</h3>
<p>First, we'll download and install Node. Then we'll use the JavaScript package manager npm to install Sass and configure it in your project.</p>
<p>We are going to do a global installation, because this will save you from installing it every time you plan to work in your projects with Sass.</p>
<p>Here are the steps to follow to install and set up Sass in a project:</p>
<p>First, open your terminal and type:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">npm</span> <span class="hljs-selector-tag">install</span> <span class="hljs-selector-tag">-g</span> <span class="hljs-selector-tag">scss</span>
</code></pre>
<p>Again, this is global installation. If you do this, you avoid installing it every time you plan to work with Sass in your projects.</p>
<p>Then, in the project folder, create a Sass file in the one you are going to work on:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">style</span><span class="hljs-selector-class">.scss</span>
</code></pre>
<p><code>style</code> is the file name and <code>.scss</code> is the Sass extension name.</p>
<p>Then you will use the following command to generate a style.css file from the SASS file:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">sass</span> <span class="hljs-selector-tag">--watch</span> <span class="hljs-selector-tag">style</span><span class="hljs-selector-class">.scss</span> <span class="hljs-selector-tag">style</span><span class="hljs-selector-class">.css</span>
</code></pre>
<p><code>style.scss</code> is the source file and <code>style.css</code> is the destination file where Sass generates the CSS code.</p>
<p>Now installation and configuration are complete! You can use Sass in your projects.</p>
<p>But before we get into how to use Sass, I want to show you a second way of doing it. I recommend this way, as it is the simplest and easiest way to install and configure Sass.</p>
<h3 id="heading-how-to-install-sass-using-vs-code">How to Install Sass Using VS Code</h3>
<p>First, download and install Microsoft's VS Code editor if you haven't already. Then launch the editor so you can download the Live Sass Compiler extension.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/03/image-37.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>And that's all you have to do. Once the installation is done, you'll be able to use Sass in your projects. Easy, right?</p>
<h2 id="heading-how-to-use-sass-in-a-project">How to Use Sass in a Project</h2>
<p>To understand how to use Sass, we will work on an example project where we will create two grids. The idea here is not to learn everything about Sass but what you see is mostly what you need to know to start using Sass.</p>
<p>Here is an overview of what we will create to understand Sass.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot--12--1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>You might be wondering why I took the grid example? Well, because we often use grids in web pages and they're simple to understand.</p>
<p>First of all, you should know that we'll do all the coding in the Sass file (style.scss) and not in the style.css file. It is Sass that will generate a CSS file for us with the same code.</p>
<p>To start, create a folder with two folders inside, <strong>CSS</strong> and <strong>images</strong>. Then inside the CSS folder create a file with the Sass extension – in my case it's <strong>style.scss</strong>.</p>
<p>Then open it and the file will be detected right away. Below the editor a button will appear named <strong>Watch Sass</strong>. Just click on it to tell Sass to watch this file and start generating (compiling) code in the CSS file.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/capt.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/03/image-38.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Once SASS finishes compiling it will create three files in the project's CSS folder: <strong>style.css</strong>, <strong>style.scss</strong>, and <strong>style.css.map</strong>. It tracks all the changes and it is ready to generate CSS code.</p>
<p>If you come back soon to continue working, all you have to do is open the file which has the extension .scss. Then click on Watch Sass for Sass to start generating the modifications in the CSS file (otherwise nothing will be generated in the CSS file).</p>
<p>I hope it's going ok so far. You have just seen how to install, configure, and start using Sass in your project. So now let's continue with our example of the grids to understand the different functionalities Sass brings.</p>
<h2 id="heading-how-to-use-variables-in-sass">How to Use Variables in Sass</h2>
<p>Before seeing how to create Sass variables, create an <strong>index.html</strong> file copy and paste the code below in the file:</p>
<pre><code class="lang-html">
<span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">"X-UA-Compatible"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"IE=edge"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>card with sass<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>

            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"card"</span>&gt;</span>
                  <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://images.unsplash.com/photo-1524749292158-7540c2494485?ixlib=rb-1.2.1&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8MTd8fGRldmVsb3BlcnN8ZW58MHx8MHx8&amp;auto=format&amp;fit=crop&amp;w=500&amp;q=60"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">""</span>&gt;</span>
                  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"card_content"</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"card_title"</span>&gt;</span>Lorem<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"card_description"</span>&gt;</span>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Rerum porro dolores sapiente.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
                  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"card card_dark"</span>&gt;</span>
                  <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://media.istockphoto.com/photos/put-more-in-get-more-out-picture-id1291318636?b=1&amp;k=20&amp;m=1291318636&amp;s=170667a&amp;w=0&amp;h=UvVIk7wwkN3X9OFm8gBlWWviV5vAjfrq2ejYP30JmnA="</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">""</span>&gt;</span>
                  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"card_content"</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"card_title"</span>&gt;</span>Lorem<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
                        <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"card_description"</span>&gt;</span>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque amet obcaecati nihil.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
                  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

      <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>Run the file in your browser to see the result.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot--14--1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Sass lets you create variables, but I want to show you a difference between Sass and CSS.</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">body</span> {
    <span class="hljs-attribute">font-family</span>: <span class="hljs-string">'Poppins'</span>, Helvertica, sans-serif;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#ab99ca</span>;
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">2rem</span>;
    <span class="hljs-attribute">min-height</span>: <span class="hljs-number">100vh</span>;
    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">align-items</span>: center;
    <span class="hljs-attribute">justify-content</span>: center;
}
</code></pre>
<p>If you look at this example, it's CSS. But if in the project I want to reuse any color, padding, or font, I have to rewrite the same code (in CSS).</p>
<p>But with Sass I can create variables so I can reuse these features. To create a variable in Sass, we use the dollar sign <strong>$</strong> followed by the variable name and a colon for the value. Keep in mind that it's best to create a name that reflects the object you're going to use.</p>
<pre><code class="lang-css"><span class="hljs-comment">/* Creating and Using Variables */</span>

$<span class="hljs-selector-tag">fonts</span>: '<span class="hljs-selector-tag">Poppins</span>', <span class="hljs-selector-tag">Helvertica</span>, <span class="hljs-selector-tag">sans-serif</span>;
$<span class="hljs-selector-tag">primary-color</span>: <span class="hljs-selector-id">#ab99ca</span>;
$<span class="hljs-selector-tag">spacing</span>: 2<span class="hljs-selector-tag">rem</span>;

<span class="hljs-selector-tag">body</span> {
    <span class="hljs-attribute">font-family</span>: $fonts;
    <span class="hljs-attribute">background-color</span>: $primary-color;
    <span class="hljs-attribute">padding</span>: $spacing;
    <span class="hljs-attribute">min-height</span>: <span class="hljs-number">100vh</span>;
    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">align-items</span>: center;
    <span class="hljs-attribute">justify-content</span>: center;
}
</code></pre>
<p>Add the above code in the style.scss file. Since we are working with a Sass file and HTML does not recognize Sass, to see the results we'll specify the CSS file that has been generated in our file <strong>index.html</strong>.</p>
<h2 id="heading-how-to-link-the-css-file">How to Link the CSS File</h2>
<p>It's really important to link the CSS file to index.html, to allow the CSS file to apply the CSS styles to the HTML. Otherwise there will be no styling applied and you will only see the code produced by the HTML.</p>
<p>So we will link our CSS file in the index.html file. In my case:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"css/style.css"</span>&gt;</span>
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot--13--1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Run the file in your browser to see the result.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot--15--1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>We will now see how to organize the code thanks to IMPORTS. The code will be cut into files while we keep using our example.</p>
<p>When creating a file, the file name will be followed by an underscore(_) at the beginning to prevent it from being compiled by Sass.</p>
<p>Create three files:</p>
<ul>
<li><p><code>_variables.scss</code>: to add the variables</p>
</li>
<li><p><code>_mixins.scss</code>: to add the functions that we will reuse</p>
</li>
<li><p><code>_card.scss</code>: to add the styles of our cards</p>
</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/03/image-40.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Copy and paste the variables you created in the <strong>style.scss</strong> file and put them in the <code>_variables.scss</code> file:</p>
<pre><code class="lang-css">    $<span class="hljs-selector-tag">fonts</span>: '<span class="hljs-selector-tag">Poppins</span>', <span class="hljs-selector-tag">Helvetica</span>, <span class="hljs-selector-tag">sans-serif</span>;
    $<span class="hljs-selector-tag">primary-color</span>: <span class="hljs-selector-id">#ab99ca</span>;
    $<span class="hljs-selector-tag">spacing</span>: 2<span class="hljs-selector-tag">rem</span>;
    $<span class="hljs-selector-tag">dark-grey</span>: <span class="hljs-selector-id">#999</span>;
</code></pre>
<p>For the <code>_mixins.scss</code> file, this is where we'll create the reusable functions with mixins.</p>
<p>Mixins allow you to create reusable functions. To declare a function you must enter <code>@mixin name_fonction { content }</code> or if your function has a parameter, you must enter <code>@mixin name_fonction($name_variable) { content }</code>.</p>
<p>To use mixins, you have to import it by typing <code>@include namefunction();</code> which saves time in a large project.</p>
<p>Add this code to the <code>_mixins.scss</code> file:</p>
<pre><code class="lang-css">
<span class="hljs-keyword">@mixin</span> flex-center {
    <span class="hljs-selector-tag">display</span>: <span class="hljs-selector-tag">flex</span>;
    <span class="hljs-selector-tag">align-items</span>: <span class="hljs-selector-tag">center</span>;
    <span class="hljs-selector-tag">justify-content</span>: <span class="hljs-selector-tag">center</span>;
}

<span class="hljs-comment">/* $radius is the parameter of the function */</span>

<span class="hljs-keyword">@mixin</span> border-radius($radius) {
    <span class="hljs-selector-tag">-webkit-border-radius</span>: $<span class="hljs-selector-tag">radius</span>;
    <span class="hljs-selector-tag">-moz-border-radius</span>: $<span class="hljs-selector-tag">radius</span>;
    <span class="hljs-selector-tag">border-radius</span>: $<span class="hljs-selector-tag">radius</span>;
}
</code></pre>
<p>For the <code>_card.scss</code> file, add this code to it:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.card</span> {
    <span class="hljs-attribute">background-color</span>: white;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">20rem</span>;
    <span class="hljs-attribute">overflow</span>: hidden;
    <span class="hljs-attribute">margin</span>: <span class="hljs-number">2rem</span>;
    <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">5px</span> <span class="hljs-number">5px</span> <span class="hljs-number">5px</span> <span class="hljs-number">5px</span> <span class="hljs-number">#000</span>;
    @include border-radius(0.5rem); <span class="hljs-comment">/* using the mixins function */</span>

    img {
        <span class="hljs-attribute">height</span>: <span class="hljs-number">15rem</span>;
        <span class="hljs-attribute">background-size</span>: cover;
        <span class="hljs-attribute">background-position</span>: center center;
    }

    <span class="hljs-selector-class">.card_content</span> {
        <span class="hljs-attribute">padding</span>: $spacing;
    }

    <span class="hljs-selector-class">.card_title</span> {
        <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
        <span class="hljs-attribute">color</span>: black;
    }

    <span class="hljs-selector-class">.card_description</span> {
        <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
        <span class="hljs-attribute">color</span>: $dark-grey;
    }

    &amp;_<span class="hljs-selector-tag">dark</span> {

        <span class="hljs-attribute">background-color</span>: black;

        .card_title {
            <span class="hljs-attribute">color</span>: white;
        }
    }

}
</code></pre>
<p>In the code above we're using <strong>nesting</strong> and <strong>aliases</strong>. Nesting helps us simplify the way we write our CSS styles and allows us to nest CSS selectors.</p>
<p>For aliases you can use (<strong>&amp;</strong>) or (<strong>and</strong>) followed by the class name that will resume the parent selector's code.</p>
<p>To use an alias, you must import it by typing the alias followed by the name of the variable (&amp;_dark).</p>
<p>If you try to run the index.html file, nothing will change. It does not change because we have created files that are not related to index.html and our style.sass file only generates the code it has.</p>
<p>To fix this, we'll import all the files we've created into the style.sass file so that when SASS does the monitoring, it'll generate the code of those files.</p>
<pre><code class="lang-css"><span class="hljs-comment">/* file import */</span>
<span class="hljs-keyword">@import</span> <span class="hljs-string">'variables'</span>;
<span class="hljs-keyword">@import</span> <span class="hljs-string">'mixins'</span>;
<span class="hljs-keyword">@import</span> <span class="hljs-string">'card'</span>;
</code></pre>
<p>For the style.scss file, add the above code. The style.scss file should be like this:</p>
<pre><code class="lang-css">
<span class="hljs-comment">/* file import */</span>

<span class="hljs-keyword">@import</span> <span class="hljs-string">'variables'</span>;
<span class="hljs-keyword">@import</span> <span class="hljs-string">'mixins'</span>;
<span class="hljs-keyword">@import</span> <span class="hljs-string">'card'</span>;

<span class="hljs-selector-tag">body</span> {
    <span class="hljs-attribute">font-family</span>: $fonts; <span class="hljs-comment">/* variable usage */</span>
    <span class="hljs-attribute">background-color</span>: $primary-color;
    <span class="hljs-attribute">padding</span>: $spacing;
    <span class="hljs-attribute">min-height</span>: <span class="hljs-number">100vh</span>;
    @include flex-center(); <span class="hljs-comment">/* using the mixins function */</span>
}
</code></pre>
<p>In the previous code, I imported the files (<strong>SASS import</strong>) into style.css so that they can be tracked and generate code when there are changes.</p>
<p>Run the index.html file in your browser to see the result.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot--12--1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>If you get the same result as in the capture above, congratulations, you now understand how Sass works.</p>
<p>Here is the preview link for the project we built: <a target="_blank" href="https://adalbertpungu.github.io/card_with_sass/">https://adalbertpungu.github.io/card_with_sass/</a></p>
<p>And here's the GitHub repository link:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://github.com/AdalbertPungu/card_with_sass">https://github.com/AdalbertPungu/card_with_sass</a></div>
<p> </p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this article, you learned how Sass works by building a simple photo grid. In this small project, we've covered many core Sass features, but not all of them. So I hope you will start using it in your projects to learn more.</p>
<p>You can check the documentation if you want to dive deeper: <a target="_blank" href="https://sass-lang.com/documentation">https://sass-lang.com/documentation</a>.</p>
<p>That’s all for this article. Thank you for reading! I think you’re ready to try using Sass.</p>
<p>Happy coding.</p>
<p>Follow me on Twitter: <a target="_blank" href="https://twitter.com/adalbertpungu">twitter.com/AdalbertPungu</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ The Beginner's Guide to Sass ]]>
                </title>
                <description>
                    <![CDATA[ Have you ever wondered what SASS stands for? Or perhaps you already know what it is but haven't taken the time to study and use it. Whether you're learning about it for the first time, or want to brush up on your knowledge of the subject, this is the... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/the-beginners-guide-to-sass/</link>
                <guid isPermaLink="false">66d45f37264384a65d5a9544</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Sass ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Israel Oyetunji ]]>
                </dc:creator>
                <pubDate>Mon, 04 Apr 2022 23:39:31 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/04/The-Beginner-s-Guide-to-SASS.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Have you ever wondered what SASS stands for? Or perhaps you already know what it is but haven't taken the time to study and use it.</p>
<p>Whether you're learning about it for the first time, or want to brush up on your knowledge of the subject, this is the article for you.</p>
<p>In this post, you'll learn the fundamentals of Sass, what it is, and how to use Sass's awesome features to speed up the process of writing styles.</p>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>This article assumes that you have:</p>
<ul>
<li><p>Basic understanding of HTML &amp; CSS</p>
</li>
<li><p>A code editor (VS Code recommended). If you don't have it installed, download it <a target="_blank" href="http://code.visualstudio.com/">here</a>.</p>
</li>
<li><p>And a browser (Chrome or Firefox recommended)</p>
</li>
</ul>
<h2 id="heading-what-exactly-is-sass">What exactly is Sass?</h2>
<p>Sass (Syntactically Awesome Style Sheets) is a CSS preprocessor that gives your CSS superpowers.</p>
<p>Let's face it: writing CSS can be difficult at times, especially in today's world of increasingly complex user interfaces.</p>
<p>And many times, you'll find that you're repeating yourself often.</p>
<p>Sass comes to the rescue in this situation. It helps you stick to the DRY (Do Not Repeat Yourself) philosophy when writing CSS.</p>
<p>Sass provides a compiler that allows us to write stylesheets in two different syntaxes, indented and SCSS. Let's look at each now.</p>
<h3 id="heading-indented-syntax">Indented syntax</h3>
<p>This is the older syntax that is indented, and gets rid of the curly braces and semi-colons. It has a file extension of <code>.sass</code>.</p>
<pre><code class="lang-plaintext">nav
  ul
    margin: 0
    padding: 0
    list-style: none

  li
    display: inline-block

  a
    display: block
    text-decoration: none
</code></pre>
<h3 id="heading-scss-syntax">SCSS syntax</h3>
<p>This is the newer and more popular syntax. It is essentially a subset of the CSS3 syntax. This means that you can write regular CSS with some additional functionalities.</p>
<p>Due to its advanced features it is often termed as <em>Sassy CSS</em>. It has a file extension of <code>.scss</code>.</p>
<pre><code class="lang-scss"><span class="hljs-selector-tag">nav</span> {
  <span class="hljs-selector-tag">ul</span> {
    <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">list-style</span>: none;
  }
  <span class="hljs-selector-tag">li</span> {
    <span class="hljs-attribute">display</span>: inline-block;
  }

  <span class="hljs-selector-tag">a</span> {
    <span class="hljs-attribute">display</span>: block;
    <span class="hljs-attribute">text-decoration</span>: none;
  }
}
</code></pre>
<blockquote>
<p>Quick Disclaimer: This article uses the SCSS syntax because it's more widely used.</p>
</blockquote>
<h2 id="heading-how-does-sass-work">How Does Sass Work?</h2>
<p>Sass works in such a way that when you write your styles in a <code>.scss</code> file, it gets compiled into a regular CSS file. The CSS code is then loaded into the browser.</p>
<p>That is why it's called a Preprocessor.</p>
<h2 id="heading-why-should-you-use-sass">Why should you use Sass?</h2>
<ul>
<li><p><strong>Easy to learn</strong>: If you are familiar with CSS already, then you'll be glad to know that Sass actually has a similar syntax, and so you can start using it, even after this tutorial ;)</p>
</li>
<li><p><strong>Compatibility</strong>: It is compatible with all versions of CSS. So, you can use any available CSS libraries.</p>
</li>
<li><p><strong>Saves time</strong>: It helps reduce the repetition of CSS, because of its powerful features.</p>
</li>
<li><p><strong>Reusable code</strong>: Sass allows for variables and chunks of code (mixins) that can be reused over and over again. This helps you save time and makes you able to code faster.</p>
</li>
<li><p><strong>Organized Code</strong>: Sass helps keep your code organized by using partials.</p>
</li>
<li><p><strong>Cross Browser Compatibility</strong>: Sass gets compiled into CSS and adds all the necessary vendor prefixes so you don't have to worry about manually writing them out.</p>
</li>
</ul>
<h2 id="heading-features-of-sass">Features of Sass</h2>
<p>Here are some of the features that make Sass truly CSS with Superpowers:</p>
<h3 id="heading-variables-in-sass">Variables in Sass</h3>
<p>You can declare variables in Sass. This is one of Sass's strengths since we can define variables for various properties and use them in any file.</p>
<p>The benefit here is that if that value changes, you simply need to update a single line of code.</p>
<p>This is done by naming a variable with a dollar symbol <code>$</code> and then referencing it elsewhere in your code.</p>
<pre><code class="lang-scss"><span class="hljs-variable">$primary-color</span>: <span class="hljs-number">#24a0ed</span>;

<span class="hljs-selector-class">.text</span> {
  <span class="hljs-attribute">color</span>: <span class="hljs-variable">$primary-color</span>;
}
<span class="hljs-selector-tag">button</span> {
  <span class="hljs-attribute">color</span>: <span class="hljs-variable">$primary-color</span>;
  <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid <span class="hljs-variable">$primary-color</span>;
}
</code></pre>
<h3 id="heading-nesting-in-sass">Nesting in Sass</h3>
<p>Most of the time, while writing CSS, classes are often duplicated. We can avoid this duplication by nesting styles inside the parent element.</p>
<p>In CSS,</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">nav</span> {
  <span class="hljs-attribute">height</span>: <span class="hljs-number">10vh</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
  <span class="hljs-attribute">display</span>: flex;
}

<span class="hljs-selector-tag">nav</span> <span class="hljs-selector-tag">ul</span> {
  <span class="hljs-attribute">list-style</span>: none;
  <span class="hljs-attribute">display</span>: flex;
}

<span class="hljs-selector-tag">nav</span> <span class="hljs-selector-tag">li</span> {
  <span class="hljs-attribute">margin-right</span>: <span class="hljs-number">2.5rem</span>;
}

<span class="hljs-selector-tag">nav</span> <span class="hljs-selector-tag">li</span> <span class="hljs-selector-tag">a</span> {
  <span class="hljs-attribute">text-decoration</span>: none;
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#707070</span>;
}

<span class="hljs-selector-tag">nav</span> <span class="hljs-selector-tag">li</span> <span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:hover</span> {
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#069c54</span>;
}
</code></pre>
<p>With Sass, the above code can be written like this:</p>
<pre><code class="lang-scss"><span class="hljs-selector-tag">nav</span> {
  <span class="hljs-attribute">height</span>: <span class="hljs-number">10vh</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
  <span class="hljs-attribute">display</span>: flex;

  <span class="hljs-selector-tag">ul</span> {
    <span class="hljs-attribute">list-style</span>: none;
    <span class="hljs-attribute">display</span>: flex;
  }

  <span class="hljs-selector-tag">li</span> {
    <span class="hljs-attribute">margin-right</span>: <span class="hljs-number">2.5rem</span>;

    <span class="hljs-selector-tag">a</span> {
      <span class="hljs-attribute">text-decoration</span>: none;
      <span class="hljs-attribute">color</span>: <span class="hljs-number">#707070</span>;

      &amp;<span class="hljs-selector-pseudo">:hover</span> {
        <span class="hljs-attribute">color</span>: <span class="hljs-number">#069c54</span>;
      }
    }
  }
}
</code></pre>
<h3 id="heading-parent-selector">Parent Selector</h3>
<p>In the Sass code above, you might notice the ampersand symbol <code>&amp;</code> used with the hover pseudo-class. This is called a Parent Selector.</p>
<blockquote>
<p>The parent selector, <code>&amp;</code>, is a special selector invented by Sass that's used in nested selectors to refer to the outer selector. Source – <a target="_blank" href="https://sass-lang.com/documentation/style-rules/parent-selector">Sass Documentation</a></p>
</blockquote>
<p>So, in the case of the code above, <code>&amp;</code> will refer to the parent which is the anchor tag <code>a</code>.</p>
<blockquote>
<p>You can check out my <a target="_blank" href="https://israelmitolu.hashnode.dev/writing-cleaner-css-using-bem-methodology">article</a> on how to implement Sass using BEM methodology.</p>
</blockquote>
<h3 id="heading-partials-in-sass">Partials in Sass</h3>
<p>This is one of the many awesome features of Sass that gives you an advantage.</p>
<p>As stylesheets grow large over time, it gets difficult to maintain them. Because of this, it just makes sense to break your stylesheets into smaller chunks. In other words, Partials help you organize and structure your code.</p>
<p>To declare a partial, we will start the file name with an underscore <code>_</code>, and add it in another Sass file using the <code>@import</code> directive.</p>
<p>For example, if we have a <code>_globals.scss</code>, <code>_variables.scss</code>, and <code>_buttons.scss</code>, we could import them into the main SCSS file <code>main.scss</code>.</p>
<pre><code class="lang-scss"><span class="hljs-keyword">@import</span> <span class="hljs-string">"globals"</span>;
<span class="hljs-keyword">@import</span> <span class="hljs-string">"variables"</span>;
<span class="hljs-keyword">@import</span> <span class="hljs-string">"buttons"</span>;
</code></pre>
<p>You'll notice that the underscore and the <code>.scss</code> are not added. That is because Sass automatically assumes that you are referring to the <code>.sass</code> or <code>.scss</code> file.</p>
<h3 id="heading-mixins-in-sass">Mixins in Sass</h3>
<p>Another major issue with CSS is that you'll often use a similar group of styles. Mixins allow you to encapsulate a group of styles, and apply those styles anywhere in your code using the <code>@include</code> keyword.</p>
<p>An example of when you'd use mixins is when using Flexbox.</p>
<pre><code class="lang-scss"><span class="hljs-keyword">@mixin</span> flex-container {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">justify-content</span>: space-around;
  <span class="hljs-attribute">align-items</span>: center;
  <span class="hljs-attribute">flex-direction</span>: column;
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#ccc</span>;
}

<span class="hljs-selector-class">.card</span> {
  <span class="hljs-keyword">@include</span> flex-container;
}

<span class="hljs-selector-class">.aside</span> {
  <span class="hljs-keyword">@include</span> flex-container;
}
</code></pre>
<h3 id="heading-sass-functions-and-operators">Sass Functions and Operators</h3>
<p>Sass provides a suite of tools to help write more programmatic code.</p>
<p>Sass offers built-in functions that enable us to do calculations and operations that return a specific value.</p>
<p>They range from color calculations to math operations like getting random numbers and calculation of sizes, and even conditionals.</p>
<p>It also provides support for mathematical operators like <code>+</code>, <code>-</code>, <code>\</code>, <code>*</code>, <code>/</code>, and <code>%</code>, which we can use with the <code>calc</code> function.</p>
<p>Here is an example using a pixel to rem conversion function:</p>
<pre><code class="lang-scss"><span class="hljs-keyword">@function</span> pxToRem(<span class="hljs-variable">$pxValue</span>) {
  <span class="hljs-variable">$remValue</span>: (<span class="hljs-variable">$pxValue</span> / <span class="hljs-number">16</span>) + rem;
  <span class="hljs-keyword">@return</span> <span class="hljs-variable">$remValue</span>;
}

<span class="hljs-selector-tag">div</span> {
  <span class="hljs-attribute">width</span>: pxToRem(<span class="hljs-number">480</span>);
}
</code></pre>
<blockquote>
<p>However, it's important to note that the <code>/</code> operator for division is deprecated, and will be removed in Dart Sass 2.0.0. You can read about it in the <a target="_blank" href="https://sass-lang.com/documentation/breaking-changes/slash-div">Docs</a>.</p>
</blockquote>
<p>So, this is how it should be written:</p>
<pre><code class="lang-scss"><span class="hljs-keyword">@use</span> <span class="hljs-string">"sass:math"</span>;

<span class="hljs-keyword">@function</span> pxToRem(<span class="hljs-variable">$pxValue</span>) {
  <span class="hljs-keyword">@return</span> math.div(<span class="hljs-variable">$pxValue</span>, <span class="hljs-number">16px</span>) * <span class="hljs-number">1rem</span>;
}

<span class="hljs-selector-tag">div</span> {
  <span class="hljs-attribute">width</span>: pxToRem(<span class="hljs-number">480px</span>); <span class="hljs-comment">// gives 30rem</span>
}
</code></pre>
<p>Here is an example of conditional logic in a mixin:</p>
<pre><code class="lang-scss"><span class="hljs-keyword">@mixin</span> body-theme(<span class="hljs-variable">$theme</span>) {
  <span class="hljs-keyword">@if</span> <span class="hljs-variable">$theme</span> == <span class="hljs-string">"light"</span> {
    <span class="hljs-attribute">background-color</span>: <span class="hljs-variable">$light-bg</span>;
  } <span class="hljs-keyword">@else</span> {
    <span class="hljs-attribute">background-color</span>: <span class="hljs-variable">$dark-bg</span>;
  }
}
</code></pre>
<p>Sass also provides the <code>lighten</code> and <code>darken</code> functions to adjust a color by a certain percentage.</p>
<p>For example:</p>
<pre><code class="lang-scss"><span class="hljs-variable">$red</span>: <span class="hljs-number">#ff0000</span>;

<span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:visited</span> {
  <span class="hljs-attribute">color</span>: darken(<span class="hljs-variable">$red</span>, <span class="hljs-number">25%</span>);
}
</code></pre>
<h2 id="heading-how-to-set-up-sass-for-local-development">How to Set Up Sass for Local Development</h2>
<p>Great! Now that we have learned about the "theoretical" aspects of Sass, let's get into the code to better understand how it works.</p>
<p>In this section, you will learn how to set up a local development environment, and also go through a simple landing page I have prepared.</p>
<p>Check out the demo on <a target="_blank" href="https://codesandbox.io/s/currying-river-44d7zr?file=/index.html">Codesandbox</a> and code repository on <a target="_blank" href="https://github.com/israelmitolu/Getting-Started-with-SASS">GitHub</a>.</p>
<h3 id="heading-ways-to-compile-sass">Ways to compile Sass</h3>
<p>There are different ways of compiling Sass files which are:</p>
<ul>
<li><p>VS Code Extension</p>
</li>
<li><p>Install using NPM globally</p>
</li>
<li><p>Install using open source apps such as Compass.app, Live Reload, and Koala.</p>
</li>
<li><p>Install using Homebrew (for MacOS)</p>
</li>
</ul>
<p>In this tutorial, we will be using the VS code Extension option because it is the easiest to get started with.</p>
<h3 id="heading-how-to-set-up-sass-for-vs-code">How to Set Up Sass for VS Code</h3>
<h4 id="heading-step-1-install-live-sass-compiler">Step 1: Install Live Sass Compiler</h4>
<p>First, launch Visual Studio Code. Once it's loaded, go to the side panel on the left and select the extensions tab.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/1.PNG" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Extensions tab in VS Code</em></p>
<p>In the search bar, search for "Live Sass Compiler" and install it. This extension helps us to compile the Sass files — <code>.scss</code> (or <code>.sass</code>) – into <code>.css</code> files.</p>
<h4 id="heading-step-2-set-the-save-location">Step 2: Set the Save Location</h4>
<p>Now change the file path so that Sass gets compiled into the <code>styles</code> folder.</p>
<p>To do this, you will make changes to the <code>settings.json</code> file.</p>
<p>In VS Code, go to File &gt; Preferences &gt; Settings. Now search for <code>live sass compile</code> to change the global settings.</p>
<p>Click on <code>Edit settings.json</code>.</p>
<p>Now, on the first few lines, where you see this code:</p>
<pre><code class="lang-json">{
  <span class="hljs-attr">"liveSassCompile.settings.formats"</span>: [
    {
      <span class="hljs-attr">"format"</span>: <span class="hljs-string">"expanded"</span>,
      <span class="hljs-attr">"extensionName"</span>: <span class="hljs-string">".css"</span>,
      <span class="hljs-attr">"savePath"</span>: <span class="hljs-string">"/"</span>
    }
  ],
</code></pre>
<p>Change <code>"savePath": "/"</code> to <code>"savePath": "/styles"</code>, so it now looks like this:</p>
<pre><code class="lang-json">{
  <span class="hljs-attr">"liveSassCompile.settings.formats"</span>:[
    {
      <span class="hljs-attr">"format"</span>: <span class="hljs-string">"expanded"</span>,
      <span class="hljs-attr">"extensionName"</span>:<span class="hljs-string">".css"</span>,
      <span class="hljs-attr">"savePath"</span>:<span class="hljs-string">"/styles"</span>,
    },

    <span class="hljs-comment">// You can also use this minified extension for production, as it reduces the file size</span>

    {
      <span class="hljs-attr">"format"</span>: <span class="hljs-string">"compressed"</span>,
      <span class="hljs-attr">"extensionName"</span>:<span class="hljs-string">".min.css"</span>,
      <span class="hljs-attr">"savePath"</span>:<span class="hljs-string">"/styles"</span>,
    }
  ],
</code></pre>
<h4 id="heading-step-3-compile-sass">Step 3: Compile Sass</h4>
<p>Now, after saving the settings, go back to the Sass file, and click on the button that says "Watch Sass" at the very bottom of the window.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/2.PNG" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Click on "Watch Sass"</em></p>
<p>After you click the button, two files get created: <code>.css</code> and a <code>.css.map</code> in the <code>styles</code> folder.</p>
<p>You should not, however, change any of them. Because it already helps you compile the Sass into CSS every time you save new stylings.</p>
<h4 id="heading-step-4-link-the-css-file">Step 4: Link the CSS file</h4>
<p>Then, link the CSS file in your <code>index.html</code>. In our case:</p>
<pre><code class="lang-html">    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"/styles/main.css"</span> /&gt;</span>
</code></pre>
<p>Now run the file in your browser. This should be the resulting layout in CodeSandbox below:</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codesandbox.io/embed/currying-river-44d7zr?autoresize=1&amp;fontsize=14&amp;hidenavigation=1&amp;moduleview=1&amp;theme=dark&amp;view=preview" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodeSandbox embed" allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin" loading="lazy"></iframe></div>
<p> </p>
<h2 id="heading-walking-through-the-code">Walking through the code</h2>
<p>Here's an explanation of the code from the previous section:</p>
<ul>
<li><p>We have a basic markup in the <code>index.html</code> file which contains a header and home/hero section.</p>
<ul>
<li><p>It contains a link to the CSS file which the extension compiled for us.</p>
</li>
<li><p>And some JavaScript for the responsive menu toggle.</p>
</li>
</ul>
</li>
<li><p>The <code>main.scss</code> gets compiled, and the resulting CSS file <code>main.css</code> is what is imported in the <code>index.html</code>:</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"/styles/main.css"</span> /&gt;</span>
</code></pre>
</li>
<li><p>The Main Scss file <code>main.scss</code> imports all of the partials: <code>_base.scss</code>, <code>_components.scss</code>, <code>_home.scss</code>, <code>_layout.scss</code> <code>_responsive.scss</code>, <code>_variables.scss</code>.</p>
<pre><code class="lang-scss">  <span class="hljs-keyword">@import</span> <span class="hljs-string">"variables"</span>;
  <span class="hljs-keyword">@import</span> <span class="hljs-string">"base"</span>;
  <span class="hljs-keyword">@import</span> <span class="hljs-string">"layout"</span>;
  <span class="hljs-keyword">@import</span> <span class="hljs-string">"components"</span>;
  <span class="hljs-keyword">@import</span> <span class="hljs-string">"home"</span>;
  <span class="hljs-keyword">@import</span> <span class="hljs-string">"responsive"</span>;
</code></pre>
</li>
<li><p>The base partial contains the mixins of <code>flex</code> and <code>grid</code> which are included in the places where we need them.</p>
</li>
</ul>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Congrats! If you made it to the end, that means you have learned about how Sass works, its cool features, and hopefully you start using it soon.</p>
<p>If you want to learn more about Sass, I recommend checking out <a target="_blank" href="https://www.youtube.com/watch?v=aoQ6S1a32j8&amp;t=3323s">freeCodeCamp's course</a>.</p>
<p>If you found this article useful (which I'm sure you did 😉), do share it with your friends and network, and feel free to connect with me on <a target="_blank" href="https://twitter.com/israelmitolu">Twitter</a> and my <a target="_blank" href="https://israelmitolu.hashnode.dev">blog</a> where I share resources and articles to make you a better dev.</p>
<p>Thanks for reading, and happy coding!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Use Mixins in Sass and Pass Arguments – With Code Examples ]]>
                </title>
                <description>
                    <![CDATA[ Mixins are my favorite thing about Sass. They made my life so much easier, so I wanted to show you how they can do the same for you. Mixins can be a bit tricky to understand at first, but don't worry. You'll get the hang of it by practicing and ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-pass-arguments-to-mixins/</link>
                <guid isPermaLink="false">66d46040e39d8b5612bc0dc0</guid>
                
                    <category>
                        <![CDATA[ Sass ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Nazanin Ashrafi ]]>
                </dc:creator>
                <pubDate>Thu, 02 Dec 2021 18:45:59 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/11/sass-mixins.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Mixins are my favorite thing about Sass. They made my life so much easier, so I wanted to show you how they can do the same for you.</p>
<p>Mixins can be a bit tricky to understand at first, but don't worry. You'll get the hang of it by practicing and will fall in love with mixins like I have.</p>
<p>Before I get started, let me show you what you will read in this article:</p>
<ul>
<li><p>What mixins are</p>
</li>
<li><p>How to write mixins and include them in your code</p>
</li>
<li><p>How and when to pass arguments</p>
</li>
</ul>
<p>Now let's get to the point, shall we?</p>
<h2 id="heading-what-are-mixins-in-sass">What Are Mixins in Sass?</h2>
<p>First, let's take a quick look at what a mixin is:</p>
<blockquote>
<p>"<a target="_blank" href="https://sass-lang.com/documentation/at-rules/mixin">Mixins</a> allow you to define styles that can be re-used throughout your stylesheet. They make it easy to avoid using non-semantic classes like <code>.float-left</code>, and to distribute collections of styles in libraries." – Sass Docs</p>
</blockquote>
<p>To put it simply, a mixin is a code block which allows you to write your styles in it and use it throughout the whole project. You can also think of it as a <em>reusable</em> component. It also helps you to write cleaner code without having to repeat yourself.</p>
<h2 id="heading-how-to-write-a-mixin">How to Write a Mixin</h2>
<p>This is how you write a mixin in Sass:</p>
<pre><code class="lang-scss"><span class="hljs-keyword">@mixin</span> name {
    properties;
}
</code></pre>
<p>And here's how to include it in your code:</p>
<pre><code class="lang-scss"><span class="hljs-selector-tag">div</span> {
    <span class="hljs-keyword">@include</span> name;
}
</code></pre>
<p>Here's an example of using a mixin in your code:</p>
<pre><code class="lang-scss"><span class="hljs-keyword">@mixin</span> circle {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">background</span>: red;
    <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">50%</span>;
}

<span class="hljs-selector-tag">div</span> {
   <span class="hljs-keyword">@include</span> circle;
}
</code></pre>
<p>Now let's see what's happening in the above code:</p>
<ol>
<li><p>First we define a mixin using the <code>@mixin</code> at-rule.</p>
</li>
<li><p>Then we give it a name – choose whatever you think will fit what you're gonna be using it for.</p>
</li>
<li><p>Add your CSS properties.</p>
</li>
<li><p>By simply using <code>@include</code> you pass it to the mixin block.</p>
</li>
</ol>
<h2 id="heading-mixin-example">Mixin Example</h2>
<p>Now let's look at an example of a mixin in action.</p>
<p>Here's how to create a pink circle with a mixin:</p>
<pre><code class="lang-scss"><span class="hljs-keyword">@mixin</span> circle {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">50%</span>;
    <span class="hljs-attribute">background</span>: <span class="hljs-number">#ea0185</span> ;
}
</code></pre>
<pre><code class="lang-html">.circle {
    @include circle;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/Screenshot-from-2021-11-18-19-27-24--1-.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Now you might ask <em>"why should I use a mixin to create a pink circle? I could just give my element a class and style it."</em></p>
<p>Mixins are reusable, remember? We use them when we know we'll be repeating ourselves a lot. So the whole point is to <em>avoid</em> repetition and keep the code clean.</p>
<h2 id="heading-passing-arguments">Passing Arguments</h2>
<p>Now that we've seen how to write a mixin, let's move on to the next section. I want to divide this section into smaller parts:</p>
<ul>
<li><p>What are mixin arguments?</p>
</li>
<li><p>When to pass arguments?</p>
</li>
<li><p>How to pass arguments? + Examples.</p>
</li>
</ul>
<h3 id="heading-what-are-mixin-arguments">What Are Mixin Arguments?</h3>
<p>An argument is the name of a variable which is separated by a comma.</p>
<h3 id="heading-when-should-you-pass-arguments-to-a-mixin">When Should You Pass Arguments to a Mixin?</h3>
<p>I'll start this section with an example:</p>
<p>What if you were to create two different circles? Like a green circle and a pink circle?</p>
<p>You could create two separate mixins, one for the green one and one for the pink one:</p>
<pre><code class="lang-scss"><span class="hljs-comment">// a mixin for the green circle</span>
<span class="hljs-keyword">@mixin</span> green-circle {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">50%</span>;
    <span class="hljs-attribute">background</span>: green;
}

<span class="hljs-comment">// and another mixin for the pink circle</span>
<span class="hljs-keyword">@mixin</span> pink-circle {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">50%</span>;
    <span class="hljs-attribute">background</span>: pink;
}
</code></pre>
<p>But this isn't great because you're repeating your code. And we should stick to the DRY (Don't Repeat Yourself) principle, remember?</p>
<p>And that's where mixin arguments come in.</p>
<p>In a regular mixin (and by regular I mean a mixin when no argument is passed) you define some certain styles. But an argument allows you to define different styles by turning them into variables. It's like customizing each style for each element. Let's move on to the next section and see some examples.</p>
<h3 id="heading-how-to-pass-arguments-to-mixins">How to Pass Arguments to Mixins</h3>
<p>We've seen what an argument is and when to use it. And now it's time to see how to pass the arguments:</p>
<pre><code class="lang-scss"><span class="hljs-keyword">@mixin</span> name(<span class="hljs-variable">$argument</span>,<span class="hljs-variable">$argument</span>) {
    property: <span class="hljs-variable">$argument</span>;
    property: <span class="hljs-variable">$argument</span>;

}
</code></pre>
<p>Here's an example:</p>
<pre><code class="lang-scss"><span class="hljs-keyword">@mixin</span> circle2 (<span class="hljs-variable">$width</span>,<span class="hljs-variable">$height</span>,<span class="hljs-variable">$color</span>) {
    <span class="hljs-attribute">width</span>: <span class="hljs-variable">$width</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-variable">$height</span>;
    <span class="hljs-attribute">background</span>: <span class="hljs-variable">$color</span>;
}
</code></pre>
<p>You can think of arguments as customizable variables that you can use in different situations to create different things without repeating yourself.</p>
<p>Like when you pass <code>$width</code> to the width property, you can define it in different situations. Maybe you need the width to be 50px in one place and 500px somewhere else.</p>
<p>Does that make sense? Let me break it down for you with another example.</p>
<p>Okay, back to our circles.</p>
<p>I want to make one big red circle and one small green circle (two different things) with just one mixin.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/Screenshot-from-2021-11-22-21-25-44--1-.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Now what properties do I need to make a circle?</p>
<pre><code class="lang-python">width, height <span class="hljs-keyword">and</span> background-color, right?
</code></pre>
<p>Since we're building circles, the border-radius will be 50% in both situations. So I will leave it alone and won't pass any argument to it.</p>
<p>Now we're down to 3 properties:</p>
<ol>
<li><p>width</p>
</li>
<li><p>height</p>
</li>
<li><p>background-color</p>
</li>
</ol>
<p>That means we only need 3 arguments:</p>
<pre><code class="lang-scss"><span class="hljs-keyword">@mixin</span> circle(<span class="hljs-variable">$width</span>,<span class="hljs-variable">$height</span>,<span class="hljs-variable">$color</span>) {
    <span class="hljs-comment">// We passed $width to the width property</span>
    <span class="hljs-attribute">width</span>: <span class="hljs-variable">$width</span>;

    <span class="hljs-comment">// We passed $height to the height property</span>
    <span class="hljs-attribute">height</span>: <span class="hljs-variable">$height</span>;

    <span class="hljs-comment">// And we passed $color to width background-color</span>
    <span class="hljs-attribute">background</span>: <span class="hljs-variable">$color</span>;

    <span class="hljs-comment">// no argument for this property, beacuase it's gonna be the</span>
    <span class="hljs-comment">// same in both circles</span>
    <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">50%</span>;
}
</code></pre>
<p>So now let's see how we can pass arguments to our mixin:</p>
<h4 id="heading-for-the-big-red-circle">For the big red circle</h4>
<pre><code class="lang-scss"><span class="hljs-selector-class">.circle-red</span> {

    <span class="hljs-comment">// circle ($width,$height,$color);</span>
   <span class="hljs-keyword">@include</span> circle (<span class="hljs-number">350px</span>,<span class="hljs-number">350px</span>,red);
}
</code></pre>
<h4 id="heading-for-the-small-green-circle">For the small green circle</h4>
<pre><code class="lang-scss"><span class="hljs-selector-class">.circle-green</span> {

     <span class="hljs-comment">// circle ($width,$height,$color);</span>
    <span class="hljs-keyword">@include</span> circle (<span class="hljs-number">200px</span>,<span class="hljs-number">200px</span>,green);
}
</code></pre>
<p>And here's the result:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/Screenshot-from-2021-11-22-21-25-44--1--1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>If you want some more info about passing arguments to mixins, here's a little video to help you out:</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/0s-xjyXOtP4" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<p> </p>
<p>Alright, back to our tutorial. As I said earlier, I didn't pass any arguments to the border-radius property because it's always gonna be 50% (in <em>this</em> case).</p>
<p>But if I were to make one square and one circle, then I would need to pass an argument to <code>border-radius</code> too:</p>
<pre><code class="lang-scss"><span class="hljs-keyword">@mixin</span> circle(<span class="hljs-variable">$width</span>,<span class="hljs-variable">$height</span>,<span class="hljs-variable">$color</span>,<span class="hljs-variable">$radius</span>) {
    <span class="hljs-attribute">width</span>: <span class="hljs-variable">$width</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-variable">$height</span>;
    <span class="hljs-attribute">background</span>: <span class="hljs-variable">$color</span>;
    <span class="hljs-comment">// passed argument to border-radius to have control over it </span>
    <span class="hljs-attribute">border-radius</span>: <span class="hljs-variable">$radius</span>;
}

<span class="hljs-selector-class">.square</span> {
            <span class="hljs-comment">// ($width,$height,$color,$radius)</span>
    <span class="hljs-keyword">@include</span> circle (<span class="hljs-number">350px</span>,<span class="hljs-number">350px</span>,red, <span class="hljs-number">10px</span>);
}

<span class="hljs-selector-class">.circle</span> {
            <span class="hljs-comment">// ($width,$height,$color,$radius)</span>
    <span class="hljs-keyword">@include</span> circle (<span class="hljs-number">200px</span>,<span class="hljs-number">200px</span>,green, <span class="hljs-number">50%</span>);
}
</code></pre>
<p>Now we have a big red square and a small green circle:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/Screenshot-from-2021-11-22-22-17-12--1-.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Let's take a look at another example. This time let's try using a mixin on some text.</p>
<p>This is what I want to make, a green text with black background and red text with a transparent background:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/Screenshot-from-2021-11-25-19-26-49--1-.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>First I created two h2 elements:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text1"</span>&gt;</span>Text<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text2"</span>&gt;</span>Text<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
</code></pre>
<p>We need <code>font-size, color, and background</code> properties here. Now I should pass arguments by turning them into variables.</p>
<pre><code class="lang-scss"><span class="hljs-keyword">@mixin</span> text(<span class="hljs-variable">$font-size</span>,<span class="hljs-variable">$color</span>,<span class="hljs-variable">$bg-color</span>) {

     <span class="hljs-comment">// we pass the $font-size to font-size property</span>
    <span class="hljs-attribute">font-size</span>: <span class="hljs-variable">$font-size</span>;

    <span class="hljs-comment">// we pass the $color to color property</span>
    <span class="hljs-attribute">color</span>: <span class="hljs-variable">$color</span>;

    <span class="hljs-comment">// we pass the $bg-color to background property</span>
    <span class="hljs-attribute">background</span>: <span class="hljs-variable">$bg-color</span>;
}



<span class="hljs-selector-class">.text1</span> {
          <span class="hljs-comment">// ($font-size,$color,$bg-color)</span>
    <span class="hljs-keyword">@include</span> text(<span class="hljs-number">3rem</span>,green , black)
}

.text2 {
          <span class="hljs-comment">// ($font-size,$color,$bg-color)</span>
    <span class="hljs-keyword">@include</span> text(<span class="hljs-number">5em</span>,red , transparent)
}
</code></pre>
<p>And there you have it.</p>
<p><strong>Quick tip:</strong> Remember that <em>the order of arguments matters.</em></p>
<p>It matters because the only way to know what value you meant to pass for each parameter is by using the correct order.</p>
<p>For example, if your arguments order is <em>$width, $height, $color</em>, passing them should be in order as well:</p>
<pre><code class="lang-scss"><span class="hljs-keyword">@mixin</span> circle(<span class="hljs-variable">$width</span>,<span class="hljs-variable">$height</span>,<span class="hljs-variable">$color</span>) {
    <span class="hljs-attribute">width</span>: <span class="hljs-variable">$width</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-variable">$height</span>;
    <span class="hljs-attribute">background</span>: <span class="hljs-variable">$color</span>;
    <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">50%</span>;

}
</code></pre>
<pre><code class="lang-scss"><span class="hljs-selector-class">.circle-red</span> {
             <span class="hljs-comment">// ($width,$height,$color)</span>
    <span class="hljs-keyword">@include</span> circle (<span class="hljs-number">350px</span>,<span class="hljs-number">350px</span>,red);
}
</code></pre>
<p>You can't pass color first followed by the width and height:</p>
<pre><code class="lang-python">.circle-red {
<span class="hljs-meta">    @include circle (red,350px,350px);</span>
}
</code></pre>
<p>Regarding this wrong order, we passed <code>$width</code> to width property, therefore the first value needs to be a number. So if you pass <code>$color</code> first, the value won't be recognized. That's why we have to pass arguments in order.</p>
<h2 id="heading-heres-a-quick-review-of-what-weve-talked-about-in-this-article">Here's a quick review of what we've talked about in this article</h2>
<ul>
<li><p>Mixins are reusable code blocks.</p>
</li>
<li><p>We use them when we know we'll be repeating pieces of code a lot.</p>
</li>
<li><p>This is how to we write a mixin:</p>
</li>
</ul>
<pre><code class="lang-scss"><span class="hljs-keyword">@mixin</span> name {
    properties;
}
</code></pre>
<ul>
<li><p>An argument is a name of a variable which is separated by a comma.</p>
</li>
<li><p>Arguments allow you to define different styles.</p>
</li>
<li><p>The order of arguments matters.</p>
</li>
<li><p>This is how we pass arguments:</p>
</li>
</ul>
<pre><code class="lang-scss"><span class="hljs-keyword">@mixin</span> name(<span class="hljs-variable">$argument</span>,<span class="hljs-variable">$argument</span>) {
    property: <span class="hljs-variable">$argument</span>;
    property: <span class="hljs-variable">$argument</span>;

}
</code></pre>
<p>And that's a wrap for this article – I hope you liked it and found it useful. 😊</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/image-113.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>You can also connect with me on</em> <a target="_blank" href="https://twitter.com/nazanin_ashrafi"><strong><em>twitter-</em></strong></a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Use Sass with CSS Modules in Next.js ]]>
                </title>
                <description>
                    <![CDATA[ Next.js gives us CSS Modules by default, providing benefits like scoped styles and focused development in our app. How can we give our Next.js CSS superpowers with Sass? What are CSS Modules? What is Sass? What are we going to build? Step 0: Creatin... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-use-sass-with-css-modules-in-next-js/</link>
                <guid isPermaLink="false">66b8e3790a89d796f29a16f7</guid>
                
                    <category>
                        <![CDATA[ CSS Modules ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Next.js ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Sass ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Colby Fayock ]]>
                </dc:creator>
                <pubDate>Thu, 07 Jan 2021 17:31:14 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/01/Article.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Next.js gives us CSS Modules by default, providing benefits like scoped styles and focused development in our app. How can we give our Next.js CSS superpowers with Sass?</p>
<ul>
<li><a class="post-section-overview" href="#heading-what-are-css-modules">What are CSS Modules?</a></li>
<li><a class="post-section-overview" href="#heading-what-is-sass">What is Sass?</a></li>
<li><a class="post-section-overview" href="#heading-what-are-we-going-to-build">What are we going to build?</a></li>
<li><a class="post-section-overview" href="#heading-step-0-creating-a-new-nextjs-app">Step 0: Creating a new Next.js app</a></li>
<li><a class="post-section-overview" href="#heading-step-1-installing-sass-in-a-nextjs-app">Step 1: Installing Sass in a Next.js app</a></li>
<li><a class="post-section-overview" href="#heading-step-2-importing-sass-files-into-a-nextjs-app">Step 2: Importing Sass files into a Next.js app</a></li>
<li><a class="post-section-overview" href="#heading-step-3-using-sass-variables-in-a-nextjs-app">Step 3: Using Sass variables in a Next.js app</a></li>
<li><a class="post-section-overview" href="#heading-step-4-using-sass-mixins-with-global-imports-in-nextjs">Step 4: Using Sass mixins with global imports in Next.js</a></li>
</ul>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/C1-hmauMht0" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<h2 id="heading-what-are-css-modules">What are CSS Modules?</h2>
<p><a target="_blank" href="https://github.com/css-modules/css-modules">CSS Modules</a> are essentially CSS files that, when imported into JavaScript projects, provide styles that are scoped to that particular part of the project by default.</p>
<p>When importing your module, the classes are represented by an object mapped with each class name, allowing you to apply that class right to your project.</p>
<p>For instance, if I had a CSS module for the title of my page:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.title</span> {
  <span class="hljs-attribute">color</span>: blueviolet;
}
</code></pre>
<p>And I import that into my React project:</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> styles <span class="hljs-keyword">from</span> <span class="hljs-string">'./my-styles.css'</span>
</code></pre>
<p>I can then apply that title right to an element as if it were a string:</p>
<pre><code class="lang-jsx">&lt;h1 className={styles.title}&gt;My Title&lt;/h1&gt;
</code></pre>
<p>By scoping styles, you no longer have to worry about breaking other parts of the application with cascading styles. It’s also easier to manage smaller chunks of code that pertain to a specific piece of the application.</p>
<h2 id="heading-what-is-sass">What is Sass?</h2>
<p><a target="_blank" href="https://sass-lang.com/">Sass</a> is an extension of the CSS language that provides powerful features like variables, functions, and other operations that allow you to more easily build complex features into your project.</p>
<p>As an example, if I wanted to store my color above in a variable so I can easily change it later, I can add:</p>
<pre><code class="lang-scss"><span class="hljs-variable">$color-primary</span>: blueviolet;

<span class="hljs-selector-class">.title</span> {
  <span class="hljs-attribute">color</span>: <span class="hljs-variable">$color-primary</span>;
}
</code></pre>
<p>If I wanted to change that color but only in one spot, I can use built-in color functions to change the shade:</p>
<pre><code class="lang-scss"><span class="hljs-variable">$color-primary</span>: blueviolet;

<span class="hljs-selector-class">.title</span> {
  <span class="hljs-attribute">color</span>: <span class="hljs-variable">$color-primary</span>;
  <span class="hljs-attribute">border-bottom</span>: solid <span class="hljs-number">2px</span> darken(<span class="hljs-variable">$color-primary</span>, <span class="hljs-number">10</span>);
}
</code></pre>
<p>One additional benefit is the ability to nest styles. This allows for easier, more logical organization of your CSS.</p>
<p>For instance, if I wanted to change only a <code>&lt;strong&gt;</code> element nested in a title, I can add:</p>
<pre><code>$color-primary: blueviolet;
$color-secondary: cyan;

.title {

  <span class="hljs-attr">color</span>: $color-primary;
  border-bottom: solid <span class="hljs-number">2</span>px darken($color-primary, <span class="hljs-number">10</span>);

  strong {
    <span class="hljs-attr">color</span>: $color-secondary;
  }

}
</code></pre><h2 id="heading-what-are-we-going-to-build">What are we going to build?</h2>
<p>We're going to create a new <a target="_blank" href="https://reactjs.org/">React</a> app using <a target="_blank" href="https://nextjs.org/">Next.js</a>.</p>
<p>With our new app, we'll learn how to install and configure Sass so that we can take advantage its features inside of Next.js.</p>
<p>Once set up Sass, we'll walk through how to use Sass <a target="_blank" href="https://sass-lang.com/documentation/variables">variables</a> and <a target="_blank" href="https://sass-lang.com/documentation/at-rules/mixin">mixins</a> to recreate some of the default elements of the Next.js UI.</p>
<blockquote>
<p>Want to skip the tutorial and dive into the code? Check out <a target="_blank" href="https://github.com/colbyfayock/next-sass-starter">Next.js Sass Starter on GitHub</a>: <a target="_blank" href="https://github.com/colbyfayock/next-sass-starter"><em>https://github.com/colbyfayock/next-sass-starter</em></a></p>
</blockquote>
<h2 id="heading-step-0-creating-a-new-nextjs-app">Step 0: Creating a new Next.js app</h2>
<p>To get started with a new Next.js app, we can use <a target="_blank" href="https://nextjs.org/docs/api-reference/create-next-app">Create Next App</a>.</p>
<p>In your terminal, navigate to where you want to create the new project and run:</p>
<pre><code>yarn create next-app my-next-sass-app
</code></pre><p><em>Note: you can use npm instead of yarn for any examples with installation and package management.</em></p>
<p>Once the installation finishes, you can navigate into the directory, and start your development server:</p>
<pre><code>yarn dev
</code></pre><p>Which should start your new Next.js project at <a target="_blank" href="http://localhost:3000">http://localhost:3000</a>!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/01/nextjs-app.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>New Next.js app</em></p>
<p>If this is your first time creating a new Next.js app, have a look around! It comes with a basic homepage as well as two CSS files:</p>
<ul>
<li><code>/styles/globals.css</code></li>
<li><code>/styles/Home.module.css</code></li>
</ul>
<p>Here we’ll be focusing on the home file. If you look inside <code>pages/index.js,</code> there, you’ll see that we’re importing the home file, making those styles available.</p>
<p>Next.js has CSS Modules built in by default. This means that when we import our home styles file, the CSS classes are added to the styles object, and we apply each of those class names to the React elements from that object, such as:</p>
<pre><code class="lang-jsx">&lt;h1 className={styles.title}&gt;
</code></pre>
<p>That means that our styles are scoped to that single page.</p>
<p>To learn more about CSS Modules or the built-in support in Next.js, you can check out the following resources:</p>
<ul>
<li><a target="_blank" href="https://github.com/css-modules/css-modules">https://github.com/css-modules/css-modules</a></li>
<li><a target="_blank" href="https://nextjs.org/docs/basic-features/built-in-css-support">https://nextjs.org/docs/basic-features/built-in-css-support</a></li>
</ul>
<h2 id="heading-step-1-installing-sass-in-a-nextjs-app">Step 1: Installing Sass in a Next.js app</h2>
<p>While Next.js comes with some good built-in CSS support, it doesn’t come with Sass completely built in.</p>
<p>Luckily, to get Sass up and running inside of our Next.js app, all we need to do is install the <a target="_blank" href="https://www.npmjs.com/package/sass">Sass package</a> from npm, which will let Next.js include those files in its pipeline.</p>
<p>To install Sass, run the following inside of your project:</p>
<pre><code>yarn add sass
</code></pre><p>And if we start back up our development server and reload the page, we’ll actually notice that nothing has happened yet, which is a good thing!</p>
<p>But next we’ll learn how to take advantage of our CSS superpowers.</p>
<p><a target="_blank" href="https://github.com/colbyfayock/my-next-sass-app/commit/053b07ccaa1eb30a7d0eff15e2e24470564092f6">Follow along with the commit!</a></p>
<h2 id="heading-step-2-importing-sass-files-into-a-nextjs-app">Step 2: Importing Sass files into a Next.js app</h2>
<p>Now that Sass is installed, we’re ready to use it.</p>
<p>In order you use any Sass-specific features though, we’ll need to use Sass files with either the <code>.sass</code> or <code>.scss</code> extension. For this walkthrough, we’re going to use the SCSS syntax and the <code>.scss</code> extension.</p>
<p>To get started, inside of <code>pages/index.js</code>, change the import of the styles object at the top of the page to:</p>
<pre><code class="lang-jsx"><span class="hljs-keyword">import</span> styles <span class="hljs-keyword">from</span> <span class="hljs-string">'../styles/Home.module.scss'</span>
</code></pre>
<p>And once the page reloads, as we probably expect, the page is actually broken.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/01/nextjs-error-import.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Next.js failed to compile</em></p>
<p>To fix this, rename the file:</p>
<pre><code>/styles/Home.module.css
</code></pre><p>to</p>
<pre><code>/styles/Home.module.scss
</code></pre><p>The difference is we’re changing the file extension from <code>.css</code> to <code>.scss</code>.</p>
<p>Once the page reloads, we’ll see that our Next.js site is loading and is back ready for action!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/01/nextjs-app-title.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>New.js app loading</em></p>
<p>_Note: We’re not going to cover the global styles file here – you can do the same thing by renaming the global styles file and updating the import inside of <code>/pages/_app.js</code>_</p>
<p>Next, we’ll learn how to use Sass features for our Next.js app.</p>
<p><a target="_blank" href="https://github.com/colbyfayock/my-next-sass-app/commit/cf2a3f56688a728163f2e2d3229565c4efdd6661">Follow along with the commit!</a></p>
<h2 id="heading-step-3-using-sass-variables-in-a-nextjs-app">Step 3: Using Sass variables in a Next.js app</h2>
<p>Now that we’re using Sass in our project, we can start using some of the basic features like variables.</p>
<p>To show how this works, we’re going to update the blue inside of our app to my favorite color, purple!</p>
<p>At the top of <code>/styles/Home.module.css</code>, add the following:</p>
<pre><code class="lang-scss"><span class="hljs-variable">$color-primary</span>: <span class="hljs-number">#0070f3</span>;
</code></pre>
<p>The color <code>#0070f3</code> is what Next.js uses by default in the app.</p>
<p>Next, update each location that uses that color in our home CSS file to our new variables, such as changing:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.title</span> <span class="hljs-selector-tag">a</span> {
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#0070f3</span>;
</code></pre>
<p>to</p>
<pre><code class="lang-scss"><span class="hljs-selector-class">.title</span> <span class="hljs-selector-tag">a</span> {
  <span class="hljs-attribute">color</span>: <span class="hljs-variable">$color-primary</span>;
</code></pre>
<p>If we refresh the page, nothing should change.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/01/nextjs-app-1.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Unchanged Next.js app</em></p>
<p>But now because we’re using a variable to define that color, we can easily change it.</p>
<p>At the top of the page, change the <code>$color-primary</code> variable to purple or whatever your favorite color is:</p>
<pre><code class="lang-scss"><span class="hljs-variable">$color-primary</span>: blueviolet;
</code></pre>
<p>And when the page reloads, we can see that our colors are now purple!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/01/nextjs-app-purple.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Next.js app with purple color</em></p>
<p>Variables are just the start to the superpowers Sass gives our CSS, but we can see that they allow us to easily manage our colors or other values throughout our application.</p>
<p><a target="_blank" href="https://github.com/colbyfayock/my-next-sass-app/commit/0a9e72485957154cfc6a9dbe68f2d9d0d056daed">Follow along with the commit!</a></p>
<h2 id="heading-step-4-using-sass-mixins-with-global-imports-in-nextjs">Step 4: Using Sass mixins with global imports in Next.js</h2>
<p>One of the other many features of Sass is mixins. They give us the ability to create function-like definitions, allowing us to configure rules that we can repeat and use throughout our app.</p>
<p>In our example, we’re going to create a new mixin that allows us to create responsive styles using a media query throughout our app. While we can already do that with a media query alone, using a mixin allows us to use a single definition, keeping that consistent and allowing us to manage that responsive definition from one place.</p>
<p>Because this mixin is something we want to use throughout our entire application, we can also use another feature of Sass, which is the ability to import files.</p>
<p>To get started, create a new file under the <code>/styles</code> directory:</p>
<pre><code>/styles/_mixins.scss
</code></pre><p>We’re using an underscore in front of our filename to denote that it’s a partial.</p>
<p>Next, inside of our <code>/styles/Home.module.scss</code> file, let’s import that new file:</p>
<pre><code class="lang-scss"><span class="hljs-keyword">@import</span> <span class="hljs-string">"mixins"</span>;
</code></pre>
<p>Once the page reloads, we’ll notice nothing changed.</p>
<p>If we lookout the bottom of <code>Home.module.scss</code>, we’ll see that we’re using a media query to make the <code>.grid</code> class responsive. We’re going to use that as a basis for our mixin.</p>
<p>Inside of <code>_mixins.scss</code>, add the following:</p>
<pre><code>@mixin desktop() {
  @media (max-width: <span class="hljs-number">600</span>px) {
    @content;
  }
}
</code></pre><p><em>Note: while we probably can come up with a better name for this mixin than desktop, we’ll use that as the basis of our example.</em></p>
<p>The <code>@content</code> means that any time we use our desktop mixin, it will include the nested content in that location.</p>
<p>To test this out, back in our <code>Home.module.css</code> file, let’s update our <code>.grid</code> snippet:</p>
<pre><code class="lang-scss"><span class="hljs-keyword">@include</span> desktop() {
  <span class="hljs-selector-class">.grid</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
    <span class="hljs-attribute">flex-direction</span>: column;
  }
}
</code></pre>
<p>If we open our app back up and shrink the browser window, we can see that we still have our responsive styles!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/01/nextjs-responsive-styles.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Responsive styles in Next.js</em></p>
<p>We can even take this a step further. Sass allows you to nest styles. For instance, instead of writing:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.footer</span> {
  // Styles
}

<span class="hljs-selector-class">.footer</span> <span class="hljs-selector-tag">img</span> {
  <span class="hljs-attribute">margin-left</span>: <span class="hljs-number">0.5rem</span>;
}
</code></pre>
<p>We can include that <code>img</code> definition right inside of the original <code>.footer</code> definition:</p>
<pre><code class="lang-scss"><span class="hljs-selector-class">.footer</span> {

  <span class="hljs-comment">// Styles</span>

  <span class="hljs-selector-tag">img</span> {
    <span class="hljs-attribute">margin-left</span>: <span class="hljs-number">0.5rem</span>;
  }

}
</code></pre>
<p>That img definition will compile to <code>.footer img</code>, just the same as if it was written in standard CSS.</p>
<p>So with that in mind, we can use the same concept and move our desktop mixin into our original <code>.grid</code> class:</p>
<pre><code class="lang-scss"><span class="hljs-selector-class">.grid</span> {

  <span class="hljs-keyword">@include</span> desktop() {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
    <span class="hljs-attribute">flex-direction</span>: column;
  }

}
</code></pre>
<p>And if you notice, because we’re inside of the <code>.grid</code> class already, we can remove that from inside of the mixin, as it will already be applied.</p>
<p>This allows for much easier organization of our responsive styles.</p>
<p>Finally, if we look back at our app, we’ll notice that still, nothing has changed, which means we’re successfully using our Sass mixin.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/01/nextjs-responsive-styles-1.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>No change in our Next.js app</em></p>
<p><a target="_blank" href="https://github.com/colbyfayock/my-next-sass-app/commit/6781916d8c12225c85dfde96bdab59bfaa14e22b">Follow along with the commit!</a>  </p>
<h2 id="heading-what-else-can-we-do-with-sass-and-nextjs">What else can we do with Sass and Next.js?</h2>
<p>We’re only scratching the surface here with Sass. Because our CSS modules now have the power of Sass, we have a ton of capabilities that don’t come by default with CSS.</p>
<h3 id="heading-color-functions">Color Functions</h3>
<p>Sass has a ton of functions built in that allow us to manipulate colors, mixing and matching shades much more easily.</p>
<p>Two that I use often are <a target="_blank" href="https://sass-lang.com/documentation/modules/color#darken">darken</a> and <a target="_blank" href="https://sass-lang.com/documentation/modules/color#lighten">lighten</a>, that allow you to take a color and change the shade.</p>
<p><a target="_blank" href="https://sass-lang.com/documentation/modules/color">Learn more about all of the available color functions in Sass.</a></p>
<h3 id="heading-custom-functions">Custom Functions</h3>
<p>While mixins seem like functions, we can define true functions in Sass that allow us to perform complex operations and produce values based on an input.</p>
<p><a target="_blank" href="https://sass-lang.com/documentation/values/functions">Learn more about custom functions in Sass.</a></p>
<h3 id="heading-other-value-types">Other Value Types</h3>
<p>While most of the time with CSS we’re using strings or numbers, we saw that a simple extension of that is the ability to use variables.</p>
<p>In addition to variables, Sass gives us more value types like <a target="_blank" href="https://sass-lang.com/documentation/values/maps">Maps</a>, which function sort of like an object, and <a target="_blank" href="https://sass-lang.com/documentation/values/lists">Lists</a>, which are kind of like arrays.</p>
<p><a target="_blank" href="https://sass-lang.com/documentation/values">Learn more about the value types in Sass.</a></p>
<h3 id="heading-more">More</h3>
<p>There are a ton of features available in Sass and lots of articles that cover the most used features. Take some time to explore the documentation and find what’s out there!</p>
<div id="colbyfayock-author-card">
  <p>
    <a href="https://twitter.com/colbyfayock">
      <img src="https://res.cloudinary.com/fay/image/upload/w_2000,h_400,c_fill,q_auto,f_auto/w_1020,c_fit,co_rgb:007079,g_north_west,x_635,y_70,l_text:Source%20Sans%20Pro_64_line_spacing_-10_bold:Colby%20Fayock/w_1020,c_fit,co_rgb:383f43,g_west,x_635,y_6,l_text:Source%20Sans%20Pro_44_line_spacing_0_normal:Follow%20me%20for%20more%20JavaScript%252c%20UX%252c%20and%20other%20interesting%20things!/w_1020,c_fit,co_rgb:007079,g_south_west,x_635,y_70,l_text:Source%20Sans%20Pro_40_line_spacing_-10_semibold:colbyfayock.com/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_68,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_145,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_222,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_295,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/v1/social-footer-card" alt="Follow me for more Javascript, UX, and other interesting things!" width="2000" height="400" loading="lazy">
    </a>
  </p>
  <ul>
    <li>
      <a href="https://twitter.com/colbyfayock">🐦 Follow Me On Twitter</a>
    </li>
    <li>
      <a href="https://youtube.com/colbyfayock">📺 Subscribe To My Youtube</a>
    </li>
    <li>
      <a href="https://www.colbyfayock.com/newsletter/">📫 Sign Up For My Newsletter</a>
    </li>
    <li>
      <a href="https://github.com/sponsors/colbyfayock">💝 Sponsor Me</a>
    </li>
  </ul>
</div>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Create a Next.js Starter to Easily Bootstrap a New React App ]]>
                </title>
                <description>
                    <![CDATA[ Getting started with a new React app is easier than ever with frameworks like Next.js. But those frameworks don’t always include all of the tools you want to use.  How can we use Starters to become super productive when starting a new project with ou... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-create-a-nextjs-starter-to-easily-bootstrap-a-new-react-app/</link>
                <guid isPermaLink="false">66b8e35389963e292346f67d</guid>
                
                    <category>
                        <![CDATA[ Next.js ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Sass ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Colby Fayock ]]>
                </dc:creator>
                <pubDate>Tue, 18 Aug 2020 15:33:48 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/08/nextjs-starter.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Getting started with a new React app is easier than ever with frameworks like Next.js. But those frameworks don’t always include all of the tools you want to use. </p>
<p>How can we use Starters to become super productive when starting a new project with our favorite tools?</p>
<ul>
<li><a class="post-section-overview" href="#heading-what-is-nextjs">What is Next.js?</a></li>
<li><a class="post-section-overview" href="#heading-what-is-a-starter">What is a Starter?</a></li>
<li><a class="post-section-overview" href="#heading-what-are-we-going-to-build">What are we going to build?</a></li>
<li><a class="post-section-overview" href="#heading-adding-sass-to-a-nextjs-starter">Adding Sass to a Next.js Starter</a></li>
<li><a class="post-section-overview" href="#heading-setting-up-nextjs-starter-documentation-for-easy-setup">Setting up Next.js Starter documentation for easy setup</a></li>
<li><a class="post-section-overview" href="#heading-some-other-things-to-consider">Some other things to consider</a></li>
</ul>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/oFGs_x7kxZg" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<h2 id="heading-what-is-nextjs">What is Next.js?</h2>
<p><a target="_blank" href="https://nextjs.org/">Next.js</a> is an application framework from <a target="_blank" href="https://vercel.com/">Vercel</a> that allows you to very quickly bootstrap a new <a target="_blank" href="http://reactjs.org/">React</a> application.</p>
<p>Some basic features include creating <a target="_blank" href="https://nextjs.org/docs/basic-features/pages">pages</a> and <a target="_blank" href="https://nextjs.org/docs/basic-features/data-fetching">data fetching</a>, and they allow you to generate a static site or use server side rendering to dynamically load your app. </p>
<p>On top of that, you can take advantage of its advanced features like <a target="_blank" href="https://nextjs.org/docs/routing/introduction">Routing</a> or creating an <a target="_blank" href="https://nextjs.org/docs/api-routes/introduction">API</a> right next to your UI.</p>
<h2 id="heading-what-is-a-starter">What is a Starter?</h2>
<p>Starters are basically a git repository in the form of a template that allows you to easily create a preconfigured app.</p>
<p>There’s nothing necessarily special about a Starter. At it’s core, it’s a Next.js app that’s already been set up a specific way and typically generalized so that anyone can use it.</p>
<p>For example, if you tend to build lots of apps the same way each time, you might have to repeat those same configuration steps every time you create a new app. </p>
<p>Instead, you can create a Starter from where you'll start your projects – and it'll eliminate the need to repeat those first steps each time.</p>
<h2 id="heading-what-are-we-going-to-build">What are we going to build?</h2>
<p>We’re going to build a basic Next.js Starter that will let you or anyone else quickly and easily create a new project with that Starter as a starting point.</p>
<p>While we won’t go too heavy into features, as the goal here is to learn about Starters, we’ll test this out by adding <a target="_blank" href="https://sass-lang.com/">Sass</a> to Next.js so someone can easily get started with CSS superpowers.</p>
<p>You can check out the <a target="_blank" href="https://github.com/colbyfayock/next-sass-starter">Starter</a> on GitHub: <a target="_blank" href="https://github.com/colbyfayock/next-sass-starter">github.com/colbyfayock/next-sass-starter</a>.</p>
<h2 id="heading-creating-a-new-nextjs-starter">Creating a new Next.js Starter</h2>
<p>To get started with creating a Starter, we need to start with a Next.js app.</p>
<p>We can do this by running the following command in whatever directory you want to create this in:</p>
<pre><code>yarn create next-app
# or
npx create-next-app
</code></pre><p>Once you run that, Next.js will ask you for a project name. While you can use whatever you like, Next.js Starters typically have a name pattern of <code>next-[name]-starter</code>.</p>
<p>So because we’re creating a Sass Starter, I might call it <code>next-sass-starter</code>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/08/command-line-new-nextjs-app.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>New Next.js app in the terminal</em></p>
<p>Once Next.js has installed all of our dependencies, you’ll be ready to navigate to that folder and run the command to start your development server.</p>
<pre><code>yarn dev
# or
npm run dev
</code></pre><p>And once the development server starts up, we should be ready to go!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/08/new-nextjs-app-browser.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>New Next.js app in the browser</em></p>
<p>At this point, we pretty much have a basic Starter. As mentioned before, there really isn’t much that’s actually special with a Next.js Starter. So if we pushed this up to Github, we could immediately start using it “as is”.</p>
<p>You can test this out by running the following:</p>
<pre><code>yarn create next-app [project-name] -e [GitHub URL]
# or
npx create-next-app [project-name] -e [GitHub URL]
</code></pre><p>After running that, you should be set up with a new directory that has a project created from your Starter with all of the dependencies installed.</p>
<p>But we want to do more than that. Our goal is to add features that help get an app started with more than the default, so let’s add Sass.</p>
<p><a target="_blank" href="https://github.com/colbyfayock/next-colbyfayock-starter/commit/ed87ce9d6585b2b642adf7e6878d0fc01bba05ef">Follow along with the commit!</a></p>
<h2 id="heading-adding-sass-to-a-nextjs-starter">Adding Sass to a Next.js Starter</h2>
<p>Note: For our example, we’re going to create a Sass starter as the name above might have implied. Feel free to add any features you want at this point, whether it includes Sass or not. </p>
<p>Remember – the goal here will be to provide something that we’ll be able to use when creating a new project with this Starter.</p>
<p>Next, we want to actually add Sass to our project. To get started, we want to install sass as a dependency:</p>
<pre><code>yarn add sass
# or
npm install sass
</code></pre><p>Next, because Next.js already looks for <code>.scss</code> as a file extension, we can simply update out two CSS files under the <code>styles</code> directory to <code>.scss</code>.</p>
<p>So change the following files:</p>
<pre><code>styles/globals.css =&gt; styles/globals.scss
styles/Home.module.css =&gt; styles/Home.module.scss
</code></pre><p>Next, we need to set up our import statements to recognize our new file extensions.</p>
<p>In <code>pages/_app.js</code>, update the styles import at the top to:</p>
<pre><code class="lang-scss">import '../styles/globals<span class="hljs-selector-class">.scss</span>'
</code></pre>
<p>And in <code>pages/index.js</code>, update the styles import to:</p>
<pre><code class="lang-scss">import styles from '../styles/Home<span class="hljs-selector-class">.module</span><span class="hljs-selector-class">.scss</span>'
</code></pre>
<p>At this point, you can start your development server and we should still see the default Next.js page.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/08/new-nextjs-app-browser.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Next.js app should look the same</em></p>
<p>To see our Sass in action, we can update some of our classes to use nested styles instead of individual selectors.</p>
<p>Update all of the <code>.footer</code> selectors inside of <code>styles/Home.module.scss</code> to the following:</p>
<pre><code class="lang-scss"><span class="hljs-selector-class">.footer</span> {

  <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">100px</span>;
  <span class="hljs-attribute">border-top</span>: <span class="hljs-number">1px</span> solid <span class="hljs-number">#eaeaea</span>;
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">justify-content</span>: center;
  <span class="hljs-attribute">align-items</span>: center;

  <span class="hljs-selector-tag">img</span> {
    <span class="hljs-attribute">margin-left</span>: <span class="hljs-number">0.5rem</span>;
  }

  <span class="hljs-selector-tag">a</span> {
    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">justify-content</span>: center;
    <span class="hljs-attribute">align-items</span>: center;
  }

}
</code></pre>
<p>You can use the same nesting structure to update <code>.title</code> and <code>.card</code>.</p>
<p>We can also add the following to the top of our <code>styles/Home.module.css</code> file:</p>
<pre><code class="lang-scss"><span class="hljs-variable">$color-primary</span>: <span class="hljs-number">#0070f3</span>;
</code></pre>
<p>And update all instances of the color in that file from <code>#0070f3</code> to <code>$color-primary</code>:</p>
<pre><code class="lang-scss"><span class="hljs-selector-class">.title</span> {
  ...
  <span class="hljs-selector-tag">a</span> {
    <span class="hljs-attribute">color</span>: <span class="hljs-variable">$color-primary</span>;
</code></pre>
<p>If you reload the page, nothing will change. But update that variable to your favorite color like:</p>
<pre><code class="lang-scss"><span class="hljs-variable">$color-primary</span>: blueviolet;
</code></pre>
<p>And now all of the colors change.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/08/nextjs-app-updated-colors.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Updated colors in the Next.js app</em></p>
<p>Finally, since we now have a Sass starter, let’s update the title of the page. Replace “Welcome to Next.js!” In <code>pages/index.js</code> to:</p>
<pre><code class="lang-jsx">&lt;h1 className={styles.title}&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://nextjs.org"</span>&gt;</span>Next.js<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span></span> Sass Starter
&lt;/h1&gt;
</code></pre>
<p>And now we have a Sass starting point!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/08/nextjs-app-updated-title.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Updated title in the Next.js app</em></p>
<p>Similar to before, you can test this out by creating a new project with your starter once all of the changes are on GitHub.</p>
<pre><code>yarn create next-app [project-name] -e [GitHub URL]
# or
npx create-next-app [project-name] -e [GitHub URL]
</code></pre><p><a target="_blank" href="https://github.com/colbyfayock/next-sass-starter/commit/56c5b67e8a383d8dc89c72d88cbe86adbac3edb8">Follow along with the commit!</a></p>
<h2 id="heading-setting-up-nextjs-starter-documentation-for-easy-setup">Setting up Next.js Starter documentation for easy setup</h2>
<p>Arguably one of the most important things about a Starter is documentation. </p>
<p>It might not be as important if you’re only using this yourself. But if you want other people to use it, you want them to know how to use it or else they’ll get stuck and become frustrated.</p>
<p>The most important part is getting the Starter set up. Setting up your Starter in a GitHub repo is a great first step. But if someone wants to use that Starter, they would have to clone or download that repo and then remove the git history.</p>
<p>Instead, you can add the command we used above in your <code>README.me</code> file to give people instructions on how to quickly get started, such as:</p>
<pre><code class="lang-mdx">## Getting Started

Run the following command to create a new project with this Starter:
</code></pre>
<p>yarn create next-app [project-name] -e https://github.com...</p>
<h1 id="heading-or">or</h1>
<p>npx create-next-app [project-name] -e https://github.com...</p>
<pre><code>
</code></pre><p>This will prevent people who might not understand how to do some of those things manually from getting stuck.</p>
<p>It’s also important to add any documentation of configuration options you’ve added.</p>
<p>If you’re adding some variables that allow you to change some site-wide features, make sure to add notes about those. </p>
<p>You ultimately want people to understand how to use the features you added to make their lives easier. If they don’t understand it, they may just rip that code out and do it manually.</p>
<p>Ultimately, creating and publishing a Starter is about making people’s lives easier. Whether it’s you coming back to your Starter a few months later or a swarm of new people looking to get productive, you’re giving them a better developer experience by adding good documentation.</p>
<h2 id="heading-some-other-things-to-consider">Some other things to consider</h2>
<h3 id="heading-generalizing-features-and-adding-configuration-for-a-nextjs-starter">Generalizing features and adding configuration for a Next.js Starter</h3>
<p>Adding features is a great way to make a Starter more likely to be used. If I used a Starter to create a new blog, I would love if that Starter included my name as an author and maybe even an About Me page.</p>
<p>But what I wouldn’t want is to have to replace someone else’s name 100 times throughout the code to update my own project. Not to mention, seeing that name on the Starter might make me feel more like it’s their blog rather than a template I can use for my project.</p>
<p>Consider starting off by using a generalized name throughout the project. Instead of using Colby Fayock’s Blog throughout the Starter, make it My Blog, which will make it feel less personal to the creator for the person using the Starter.</p>
<p>Also add some configuration options. It’s much easier to be able to update a single variable that would make my project include Colby Fayock instead of My Blog than it is to search all files to make that change manually.</p>
<h3 id="heading-choose-carefully-where-to-be-opinionated">Choose carefully where to be opinionated</h3>
<p>When using a tool like Sass, there is more than one way to use that tool. If you set up an incredibly specific and opinionated project structure, you’re alienating people using your Starter. </p>
<p>It'll either force them to rework the entire project or make them want to delete a bunch of code which might make them avoid wanting to use it in the future.</p>
<p>You can create opinionated Starters, but choose wisely where you inject those opinions. This will make your work usable by a larger group of people who want to be productive.</p>
<p>If you want to create something very opinionated, consider naming it something different and using the tool as part of the name. For example, I could create an opinionated Sass Starter called Colby’s Sassy Next.js Starter.</p>
<h2 id="heading-did-you-create-a-new-starter">Did you create a new Starter?</h2>
<p><a target="_blank" href="https://twitter.com/colbyfayock">Share with me on Twitter!</a></p>
<div id="colbyfayock-author-card">
  <p>
    <a href="https://twitter.com/colbyfayock">
      <img src="https://res.cloudinary.com/fay/image/upload/w_2000,h_400,c_fill,q_auto,f_auto/w_1020,c_fit,co_rgb:007079,g_north_west,x_635,y_70,l_text:Source%20Sans%20Pro_64_line_spacing_-10_bold:Colby%20Fayock/w_1020,c_fit,co_rgb:383f43,g_west,x_635,y_6,l_text:Source%20Sans%20Pro_44_line_spacing_0_normal:Follow%20me%20for%20more%20JavaScript%252c%20UX%252c%20and%20other%20interesting%20things!/w_1020,c_fit,co_rgb:007079,g_south_west,x_635,y_70,l_text:Source%20Sans%20Pro_40_line_spacing_-10_semibold:colbyfayock.com/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_68,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_145,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_222,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_295,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/v1/social-footer-card" alt="Follow me for more Javascript, UX, and other interesting things!" width="2000" height="400" loading="lazy">
    </a>
  </p>
  <ul>
    <li>
      <a href="https://twitter.com/colbyfayock">? Follow Me On Twitter</a>
    </li>
    <li>
      <a href="https://youtube.com/colbyfayock">? Subscribe To My Youtube</a>
    </li>
    <li>
      <a href="https://www.colbyfayock.com/newsletter/">✉️ Sign Up For My Newsletter</a>
    </li>
    <li>
      <a href="https://github.com/sponsors/colbyfayock">? Sponsor Me</a>
    </li>
  </ul>
</div>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ CSS Preprocessors Explained ]]>
                </title>
                <description>
                    <![CDATA[ CSS Preprocessors are increasingly becoming a mainstay in the workflow of front end web developers. CSS is an incredibly complicated and nuanced language, and in an effort to make it’s usage easier, developers often turn to using preprocessors such a... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/css-preprocessors/</link>
                <guid isPermaLink="false">66c3485bd48c8b932b406b3e</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Sass ]]>
                    </category>
                
                    <category>
                        <![CDATA[ toothbrush ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 17 Jan 2020 20:55:00 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9c9dce740569d1a4ca39bd.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>CSS Preprocessors are increasingly becoming a mainstay in the workflow of front end web developers. CSS is an incredibly complicated and nuanced language, and in an effort to make it’s usage easier, developers often turn to using preprocessors such as SASS or LESS.</p>
<p>CSS Preprocessors compile the code which is written using a special compiler. They then use that to create a CSS file, which can then be referenced by the main HTML document. </p>
<p>When using any CSS Preprocessor, you will be able to program in normal CSS just as you would if the preprocessor were not in place. The good thing is you also have more options available to you. Some, such as SASS, has specific style standards which are meant make the writing of the document even easier, such as the freedom to omit braces if you want.</p>
<p>Of course, CSS Preprocessors also offer other features as well. Many of the features offered are incredibly similar across preprocessors, with only slight variances in syntax. Thus, you can choose pretty much any one you wish, and you will be able to achieve the same things. Some of the more useful features are:</p>
<h3 id="heading-variables"><strong>Variables</strong></h3>
<p>One of the most commonly used item in any programming language is the variable, something which CSS notably lacks. By having variables at your disposal, you may define a value once, and reuse if throughout the entire program. An example of this in SASS would be:</p>
<pre><code class="lang-sass">$yourcolor: #000056
.yourDiv {
  color: $yourcolor;
 }
</code></pre>
<p>By declaring the <code>SASS yourcolor</code> variable once, it is now possible to reuse this same exact color throughout the entire document without ever having to retype the definition.</p>
<h3 id="heading-loops"><strong>Loops</strong></h3>
<p>Another common item in languages are loops, something else CSS lacks. Loops can be used to repeat the same instructions multiple times without having to be reentered multiple times. An example with SASS would be:</p>
<pre><code class="lang-sass">@for $vfoo 35px to 85px {
  .margin-#{vfoo} {
    margin: $vfoo 10px;
   }
 }
</code></pre>
<p>This loop saves us from having the to write the same code multiple times to change the margin size.</p>
<h3 id="heading-ifelse-statements"><strong>If/Else Statements</strong></h3>
<p>Yet another feature which CSS lacks are If/Else statements. These will run a set of instructions only if a given condition is true. An example of this in SASS would be:</p>
<pre><code class="lang-sass">@if width(body) &gt; 500px {
  background color: blue;
 } else {
  background color: white;
 }
</code></pre>
<p>Here, the background color will change color depending on the width of the page’s body.</p>
<p>These are but a few of the major functions of CSS Preprocessors. As you can see, CSS Preprocessors are incredibly useful and versitile tools. Many web developers use them, and it is highly recommended to learn at least one of them.</p>
<h4 id="heading-more-information"><strong>More Information:</strong></h4>
<ul>
<li><a target="_blank" href="https://www.freecodecamp.org/news/best-css-and-css3-tutorial/">The best CSS tutorials</a></li>
<li>SASS docs: <a target="_blank" href="http://sass-lang.com/">http://sass-lang.com/</a></li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/give-more-oompf-to-your-web-garnishes-with-preprocessors-in-sass-bd379226a114/">SASS, a preprocessor for your web garnishes</a></li>
<li>LESS docs: <a target="_blank" href="http://lesscss.org/">http://lesscss.org/</a></li>
<li>Stylus docs: <a target="_blank" href="http://stylus-lang.com/">http://stylus-lang.com/</a></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Give your CSS superpowers by learning Sass ]]>
                </title>
                <description>
                    <![CDATA[ Learn the basics of Sass in this free 2-hour video course from codeSTACKr. The course starts with a brief overview of what Sass is along with what is required to incorporate Sass into your environment.  Then it covers how to set up a Sass compiler in... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/give-your-css-superpowers-by-learning-sass/</link>
                <guid isPermaLink="false">66b202a0297cd6de0bd5463d</guid>
                
                    <category>
                        <![CDATA[ Sass ]]>
                    </category>
                
                    <category>
                        <![CDATA[ youtube ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Beau Carnes ]]>
                </dc:creator>
                <pubDate>Mon, 09 Sep 2019 14:08:01 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2019/09/sass.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Learn the basics of Sass in this free 2-hour video course from codeSTACKr.</p>
<p>The course starts with a brief overview of what Sass is along with what is required to incorporate Sass into your environment. </p>
<p>Then it covers how to set up a Sass compiler in Visual Studio Code.</p>
<p>You will learn all about: </p>
<ul>
<li>Sass variables</li>
<li>maps</li>
<li>nesting</li>
<li>functions</li>
<li>mixins</li>
<li>extending</li>
<li>and operations.</li>
</ul>
<p>After learning the basics, you'll see how to build a real-world project using Sass. </p>
<p>The course goes step-by-step through each part, including deploying the site.</p>
<p>You can watch the <a target="_blank" href="https://www.youtube.com/watch?v=_a5j7KoflTs">full video on the freeCodeCamp.org YouTube channel</a> (2 hour watch).</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ You Don't Need CSS-in-JS: Why (and When) I Use Stylesheets Instead ]]>
                </title>
                <description>
                    <![CDATA[ CSS-in-JS is all the rage. But is it really the best option? Solving problems you don’t need to solve Don’t get me wrong, CSS-in-JS is a great solution, but it’s for a problem most people don’t have. Maintaining your components in a very siloed appro... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/you-dont-need-css-in-js-why-i-use-stylesheets/</link>
                <guid isPermaLink="false">66b8e3a668c5b9f37d1d1af3</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CSS in JS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Sass ]]>
                    </category>
                
                    <category>
                        <![CDATA[ styled-components ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Colby Fayock ]]>
                </dc:creator>
                <pubDate>Tue, 13 Aug 2019 14:30:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2019/08/you-dont-need-css-in-js.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>CSS-in-JS is all the rage. But is it really the best option?</p>
<h2 id="heading-solving-problems-you-dont-need-to-solve">Solving problems you don’t need to solve</h2>
<p>Don’t get me wrong, CSS-in-JS is a great solution, but it’s for a problem most people don’t have. Maintaining your components in a very siloed approach absolutely helps things like:</p>
<ul>
<li>Unintentional side effects of cascading styles</li>
<li>Helping teams organize their rules</li>
<li>Avoiding stepping on each other’s toes while developing</li>
</ul>
<p>But those really only become problems with large teams with many developers and a vast library of components.</p>
<h2 id="heading-so-what-do-you-want-me-to-use">So what do you want me to use?</h2>
<p>To start from a slightly higher point of view, you can get in the habit of a few basic ideas:</p>
<ul>
<li>Set and follow some basic rules for writing</li>
<li>Use tooling or set standards for organization</li>
<li>Developing with methodologies like <a target="_blank" href="http://getbem.com/">BEM</a></li>
</ul>
<p>This will eliminate any of those concerns on a smaller project (or large) and can actually make life easier.</p>
<h2 id="heading-what-css-in-js-is-good-at">What CSS-in-JS is good at…</h2>
<h3 id="heading-helping-large-teams-preserve-sanity">Helping large teams preserve sanity</h3>
<p>Part of why this solution exists is because very large teams have a hard time avoiding conflicts when they have a huge library to deal with. Being able to have your component and anything that impacts it in one compartmentalized area helps people avoid stepping on each other’s feet and potentially rolling out tweaks that unintentionally cascade throughout the app. This is great but more likely than not, you’re 1 of a few (or alone) working on a small app. If you and your team aren’t communicating about some basic rules and standards, I’d argue you have bigger problems.</p>
<h3 id="heading-kind-of-eliminates-the-need-to-learn-css-kind-of">Kind of eliminates the need to learn CSS (kind of)</h3>
<p>Some developers mock CSS saying it’s not real code, others are scared about it’s magic (don’t be, embrace it). Only having to worry about a few rules in one component helps put people’s mind at ease knowing it’s just a little more JS that changes how it looks a bit.</p>
<h2 id="heading-what-can-both-do">What can both do?</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/08/1_VRkx9H7RikKZg4pl6EP5rw.png" alt="Image" width="600" height="400" loading="lazy">
<em>CSS pointing at CSS</em></p>
<h3 id="heading-hot-module-reloading-hmr">Hot Module Reloading (HMR)</h3>
<p>Though some say an advantage to CSS-in-JS is HMR, you’ll find this works fine with stylesheets. Sometimes it actually works a little nicer if you’re working on a component that requires a rerender such as those with a network request as a dependency, where the CSS changes won’t force that rerender.</p>
<h3 id="heading-variables-global-settings">Variables, Global Settings</h3>
<p>If someone is making an argument that CSS can’t do that, it’s because they haven’t been paying attention for a while. Not only does Sass provide this, <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties">it's native to modern browsers</a>.</p>
<h3 id="heading-encapsulation">Encapsulation</h3>
<p>Yes, you don’t need JS to do this. Add a class name to the top-level element of the component or page, nest all styles inside, and you have your encapsulation.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.page-about</span> {
  .header {
    <span class="hljs-attribute">background-color</span>: red;
  }
}

<span class="hljs-selector-class">.navigation</span> {
  .button {
    <span class="hljs-attribute">background-color</span>: blue;
  }
}
</code></pre>
<h3 id="heading-linting">Linting</h3>
<p><a target="_blank" href="https://stylelint.io/">https://stylelint.io/</a></p>
<h3 id="heading-a-lot-more">A lot more</h3>
<p>Honestly, there’s probably a lot more that both do similarly that you just don’t realize.</p>
<h2 id="heading-what-stylesheets-and-sass-do-better">What stylesheets and SASS do better…</h2>
<h3 id="heading-rule-sharing-and-configuration">Rule sharing and configuration</h3>
<p>SASS allows you to configure variables, custom functions, and mixins that take your CSS development to the next level.</p>
<p>Ignoring the bad selector names:</p>
<pre><code class="lang-css">// <span class="hljs-selector-tag">settings</span><span class="hljs-selector-class">.scss</span>

$<span class="hljs-selector-tag">color-ultraviolet</span>: <span class="hljs-selector-id">#5F4B8B</span>;

// <span class="hljs-selector-tag">colbys-styles</span><span class="hljs-selector-class">.scss</span>

<span class="hljs-keyword">@import</span> <span class="hljs-string">"settings"</span>;

<span class="hljs-selector-class">.colbys-text-color</span> {
  <span class="hljs-attribute">color</span>: $color-ultraviolet
}

<span class="hljs-selector-class">.colbys-background-color</span> {
  <span class="hljs-attribute">background-color</span>: $color-ultraviolet
}
</code></pre>
<p>While the syntax and configuration of this are arguably easier than setting up a bunch of object configurations in JS, this greatly allows you to provide consistent visual experiences and DRY up your code.</p>
<h3 id="heading-responsive-design">Responsive design</h3>
<p>One of the many things that add to the role of a good front end engineer is paying attention to how the project will look across multiple devices and sizes. Overall, UX is everyone’s job. Developing with a responsive-first mindset not only makes that process easier, it helps build a better product.</p>
<p>Trying to make your components responsive in JS means more Javascript and more event listeners. Not only does this add complexity, it hits performance. We can do this much easier with media queries baked right into CSS.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.colbys-sidebar</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
}

// <span class="hljs-selector-tag">NO</span> <span class="hljs-selector-tag">EVENT</span> <span class="hljs-selector-tag">LISTENERS</span>

<span class="hljs-keyword">@media</span> (<span class="hljs-attribute">min-width:</span> <span class="hljs-number">1024px</span>) {
  <span class="hljs-selector-class">.colbys-sidebar</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">25%</span>;
  }
}
</code></pre>
<p>Instead of having to throttle the event listeners, making sure your event listeners unregister on unmount, and just dealing with organizing that all in “the react way”, media queries trigger on-demand and will flip your styles as needed in a more consistent manner.</p>
<h3 id="heading-less-complexity-of-your-components">Less complexity of your components</h3>
<p>Being able to focus on the functionality and the rendered output allows you to avoid pulling in libraries or complex methods to essentially patch CSS into your JS, not to mention the JS hack or two or three that you’re using to get it working in the first place.</p>
<pre><code class="lang-jsx"><span class="hljs-comment">// This is an exaggeration</span>

<span class="hljs-keyword">const</span> styles = {
  <span class="hljs-attr">color</span>: blue;
}

<span class="hljs-keyword">if</span> ( whos_favorite === <span class="hljs-string">'Colby'</span> || whos_favorite === <span class="hljs-string">'Lord Commander'</span> ) {
  styles.color = <span class="hljs-string">'ultraviolet'</span>;
} <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> ( whos_favorite === <span class="hljs-string">'The Gary'</span> ) {
  styles.color = <span class="hljs-string">'red'</span>;
} <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> ( whos_favorite === <span class="hljs-string">'Mooncake'</span> ) {
  styles.color = <span class="hljs-string">'green'</span>;
} <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> ( whos_favorite === <span class="hljs-string">'HUE'</span> ) {
  styles.color = <span class="hljs-string">'blue'</span>;
} <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> ( whos_favorite === <span class="hljs-string">'KVN'</span> ) {
  styles.color = <span class="hljs-string">'yellow'</span>;
}

&lt;MyCompnent styles={styles} /&gt;
</code></pre>
<h3 id="heading-performance">Performance</h3>
<p><a target="_blank" href="https://medium.com/@addyosmani/the-cost-of-javascript-in-2018-7d8950fbb5d4">Less Javascript is always a win</a>. It’s less your browser has to load, less your browser has to compile, which will ultimately translate to quicker page speed. When the browser loads a page, it tries to optimize the HTML and CSS as much as possible. Yes, you probably are loading more CSS upfront, but more JS is very costly and also is more likely to <a target="_blank" href="https://developers.google.com/web/fundamentals/performance/rendering/">force a full rerender</a>;</p>
<p>A lot of the little magic bits you do with Javascript can be done with some pretty powerful CSS animation methods, just browse Codepen a bit or check out something like <a target="_blank" href="http://animista.net/">Animista</a>.</p>
<p>I don’t actually have any numbers on this aside <a target="_blank" href="https://blog.primehammer.com/the-performance-of-styled-react-components/">from a few good notes</a> and some <a target="_blank" href="https://github.com/A-gambit/CSS-IN-JS-Benchmarks">CSS-in-JS benchmarks</a>. <em>Has anyone done the legwork on this?</em></p>
<h2 id="heading-at-the-end-of-the-day-do-whats-effective">At the end of the day, do what’s effective</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/08/1_rHuLBikidh3kSQ5M4JXjQQ.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><strong>Everyone has a personal preference, everyone is productive in a different way.</strong> Do what’s best for you, do what’s best for your team, and avoid treating what other developers say as dogmatic rights and wrongs.</p>
<p>If you’re a lone developer on a project and want to practice CSS-in-JS to get used to it for when you’re on a big team, go for it! If you’re on a huge, huge team at Facebook and want to use stylesheets, well you might run into issues if everyone’s not following the same guidelines, but do what’s best for you and your team.</p>
<p>The only way you can figure that out is with experience and experimentation. Play with both solutions and figure out why YOU think one is better than the other. You never know where you’ll end up after landing that gig at Google or your new startup in your garage.</p>
<div id="colbyfayock-author-card">
  <p>
    <a href="https://twitter.com/colbyfayock">
      <img src="https://res.cloudinary.com/fay/image/upload/w_2000,h_400,c_fill,q_auto,f_auto/w_1020,c_fit,co_rgb:007079,g_north_west,x_635,y_70,l_text:Source%20Sans%20Pro_64_line_spacing_-10_bold:Colby%20Fayock/w_1020,c_fit,co_rgb:383f43,g_west,x_635,y_6,l_text:Source%20Sans%20Pro_44_line_spacing_0_normal:Follow%20me%20for%20more%20JavaScript%252c%20UX%252c%20and%20other%20interesting%20things!/w_1020,c_fit,co_rgb:007079,g_south_west,x_635,y_70,l_text:Source%20Sans%20Pro_40_line_spacing_-10_semibold:colbyfayock.com/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_68,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_145,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_222,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_295,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/v1/social-footer-card" alt="Follow me for more Javascript, UX, and other interesting things!" width="2000" height="400" loading="lazy">
    </a>
  </p>
  <ul>
    <li>
      <a href="https://twitter.com/colbyfayock">? Follow Me On Twitter</a>
    </li>
    <li>
      <a href="https://youtube.com/colbyfayock">?️ Subscribe To My Youtube</a>
    </li>
    <li>
      <a href="https://www.colbyfayock.com/newsletter/">✉️ Sign Up For My Newsletter</a>
    </li>
  </ul>
</div>

<p><em>Originally published at <a target="_blank" href="https://www.colbyfayock.com/2019/07/you-dont-need-css-in-js-why-i-use-stylesheets">https://www.colbyfayock.com/2019/07/you-dont-need-css-in-js-why-i-use-stylesheets</a>.</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Up & Going with Nuxt.js, Bulma and  Sass ]]>
                </title>
                <description>
                    <![CDATA[ By Eduardo Vedes TL;DR: Overcome Nuxt.js, Bulma and Sass shenanigans with this quick article to help you start developing your next App in less than 10 minutes. Hi everyone ❤️! Few days ago I found myself struggling a bit to put Nuxt.js, Bulma and Sa... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/up-goind-with-nuxt-js-bulma-and-sass/</link>
                <guid isPermaLink="false">66d45f0b3a8352b6c5a2aa5b</guid>
                
                    <category>
                        <![CDATA[ 100DaysOfCode ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Bulma ]]>
                    </category>
                
                    <category>
                        <![CDATA[ freeCodeCamp.org ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Nuxt.js ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Sass ]]>
                    </category>
                
                    <category>
                        <![CDATA[ vue ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sat, 15 Jun 2019 11:09:27 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9ca202740569d1a4ca51f3.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Eduardo Vedes</p>
<p><strong>TL;DR: Overcome Nuxt.js, Bulma and Sass shenanigans with this quick article to help you start developing your next App in less than 10 minutes.</strong></p>
<p>Hi everyone ❤️! Few days ago I found myself struggling a bit to put <strong>Nuxt.js</strong>, <strong>Bulma</strong> and <strong>Sass</strong> to work correctly and the info I found on google didn't help too much. </p>
<p>Most of the configurations I found were not working, because they were outdated or didn't explain quite well how to do it. So I deep dived a little bit on this subject and decided to write an article to help you do the same in less than 10 minutes.</p>
<p>Let's have some fun and get our hands dirty while grokking a few concepts needed to do this.</p>
<h2 id="heading-1-scaffolding-nuxtjs">1. Scaffolding Nuxt.js</h2>
<p>Nowadays, to get started quickly with Nuxt.js we use a scaffolding tool called <strong><a target="_blank" href="https://github.com/nuxt/create-nuxt-app">create-nuxt-app</a></strong>. Please make sure you have <strong><a target="_blank" href="https://www.npmjs.com/package/npx">npx</a></strong> installed on your machine.</p>
<p>Let's open a terminal and do: <code>npx create-nuxt-app nuxt-bulma-sass</code>, where <code>nuxt-bulma-sass</code> is the name of the project we're scaffolding for the purpose of this article.</p>
<p><strong>create-nuxt-app</strong> will ask you some questions before creating the scaffold. For the purpose of this article I've chosen the following setup:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/bulma2.png" alt="Image" width="600" height="400" loading="lazy">
<em>create-nuxt-app init questions</em></p>
<p>So, the next step will be to change directory into our project folder:</p>
<p><code>cd nuxt-bulma-sass</code></p>
<p>and launch the project with: <code>yarn run dev</code>. (you can also use npm if you like it)</p>
<p>At this point we have our project running:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/bulma3.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>And if we open our browser on localhost:3000 we'll be getting this screen:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/Screen-Shot-2019-06-14-at-09.29.05.png" alt="Image" width="600" height="400" loading="lazy">
<em>localhost:3000 pages/index.vue</em></p>
<p>So at this point we have the pages/index.vue on the screen, which is the first page to be rendered in your project by default.</p>
<p>Let's replace the content of this file by the following one:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/carbon1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>If we inspect our page in the browser we see we got <strong>bulma</strong> installed because section is formatted according to it.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/Screen-Shot-2019-06-14-at-09.45.03.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Easy peasy lemon squeezy.</p>
<p>Let's add a class and choose some colors:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/carbon-2.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/Screen-Shot-2019-06-14-at-09.47.55.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>What if we want to nest .<em>hello-nuxt</em> inside .<em>edo-theme</em>? We're going to need SASS to be able to do it.</p>
<h2 id="heading-2-adding-sass">2. Adding Sass</h2>
<p>So, to add Sass to our project we'll need to stop our running app (Ctrl+c) and do the following:</p>
<p><code>yarn add node-sass sass-loader --dev</code></p>
<p>These are the two packages needed as dev-dependencies to be able to have Sass in our boilerplate.</p>
<p>Note that we're adding it as a dev dependency because we only need it while developing and at build time. After that <strong>Sass</strong> is transformed into <strong>CSS</strong> and we don't need it anymore.</p>
<p>Let's sneak peek my package.json for you to check it:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/Screen-Shot-2019-06-14-at-09.57.38.png" alt="Image" width="600" height="400" loading="lazy">
<em>package.json with sass added to the project</em></p>
<p>Okay everyone ❤️, at this point we're able to nest the classes we wanted to.</p>
<p>Let's run our boilerplate again: <code>yarn run dev</code> and do the tweaks needed ?</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/carbon--1-.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/Screen-Shot-2019-06-14-at-10.05.23.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Noice! We already did a lot today! Go grab a coffee ☕, I'll wait for you here ?</p>
<p>Okay, let's abstract things a bit and create this file <em>~/assets/scss/main.scss</em> and put there some classes and variables:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/carbon-1.png" alt="Image" width="600" height="400" loading="lazy">
<em>new ~/assets/scss/main.scss</em></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/06/carbon--1--1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Nice! It's working!</p>
<p>Now we have two problems: </p>
<ol>
<li>We need to import main.scss into each one of our pages/components, which is not nice. We want to import it only once and have it available in all our </li></ol> ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Ember QuickTips: How to breakup and import SASS/CSS files separately ]]>
                </title>
                <description>
                    <![CDATA[ By Michael Xavier There are times when it’s desirable to break up your stylesheets into multiple files and import them into your project separately. This came up in a side project I started recently, and I thought y’all might benefit from what I came... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/ember-quicktips-how-to-breakup-and-import-sass-css-files-separately-b0759459027d/</link>
                <guid isPermaLink="false">66d46042f855545810e934a5</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ ember ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Sass ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 11 Jan 2019 17:50:43 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*ZVmLA6aPZFWbG6UDK5nEfw.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Michael Xavier</p>
<p>There are times when it’s desirable to <strong>break up your stylesheets into multiple files and import them into your project separately</strong>. This came up in a side project I started recently, and I thought y’all might benefit from what I came up with as a solution. It’s a quick and easy method, so let’s get started ?</p>
<p>When you begin a new EmberJS app you’ll notice that the <code>index.html</code> file imports the main stylesheet into the app like so:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
 ...
 <span class="hljs-tag">&lt;<span class="hljs-name">link</span>
  <span class="hljs-attr">integrity</span>=<span class="hljs-string">""</span>
  <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span>
  <span class="hljs-attr">href</span>=<span class="hljs-string">"{{rootURL}}assets/test-app.css"</span>
 &gt;</span>
 ...
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
</code></pre>
<p><code>test-app.css</code> is compiled directly from your project. When we write our custom styles in <code>app/styles/app.css</code> they get put into this file.</p>
<p>Now, what if we don’t want to import all of our styles into the app as a single stylesheet? <strong>How can we breakup our styles and import multiple stylesheets into the app?</strong> Something like this:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
 ...
 <span class="hljs-tag">&lt;<span class="hljs-name">link</span>
  <span class="hljs-attr">integrity</span>=<span class="hljs-string">""</span>
  <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span>
  <span class="hljs-attr">href</span>=<span class="hljs-string">"{{rootURL}}assets/test-app.css"</span>
 &gt;</span>
 <span class="hljs-tag">&lt;<span class="hljs-name">link</span>
  <span class="hljs-attr">integrity</span>=<span class="hljs-string">""</span>
  <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span>
  <span class="hljs-attr">href</span>=<span class="hljs-string">"{{rootURL}}assets/second-stylesheet.css"</span>
 &gt;</span>
...
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
</code></pre>
<p>It may be easier than you think ?</p>
<h3 id="heading-step-one-write-styles-in-scsssass-and-compile-to-css">Step One: Write styles in SCSS/SASS and compile to CSS</h3>
<p>First, install a SASS preprocessor to compile SCSS/SASS stylesheets into CSS stylesheets. For this example I’ll use <code>ember-cli-sass</code>:</p>
<pre><code>ember install ember-cli-sass
</code></pre><p>Now rename <code>app/styles/app.css</code> to <code>app/styles/app.scss</code>. The preprocessor will take care of processing and compiling your stylesheet automatically.</p>
<p>If you run the app the Ember welcome page should display as usual:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/aYuzVPXdJ4BtKQenSZFHhS-C-GDrL2LS7Ryf" alt="Image" width="800" height="579" loading="lazy">
<em>Nothing has changed. That’s good.</em></p>
<p>Comment out <code>{{welcome-page}}</code> in <code>app/templates/application.hbs</code> before you continue. We now have a blank DOM to work with.</p>
<h3 id="heading-step-two-create-a-new-stylesheet">Step Two: Create a new stylesheet</h3>
<p>Let’s create a new stylesheet called <code>app/styles/second-stylesheet.scss</code> and add the following styles:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">body</span> {
 <span class="hljs-attribute">width</span>: <span class="hljs-number">100vw</span>;
 <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;
 <span class="hljs-attribute">background-color</span>: red;
}
</code></pre>
<p>A glaring red background would be very obvious, yet when you run the server you see nothing but a sea of white. Why is this?</p>
<p>If your instinct was to import it into the project as specified above, you would be correct:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
 ...
 <span class="hljs-tag">&lt;<span class="hljs-name">link</span>
  <span class="hljs-attr">integrity</span>=<span class="hljs-string">""</span>
  <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span>
  <span class="hljs-attr">href</span>=<span class="hljs-string">"{{rootURL}}assets/second-stylesheet.css"</span>
 &gt;</span>
...
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
</code></pre>
<p>Yet, it still doesn’t show up. Why? ? That’s because the build pipeline hasn’t been configured to build this file in the correct folder just yet.</p>
<h3 id="heading-step-three-configure-ember-cli-build">Step Three: Configure Ember-CLI-Build</h3>
<p>The final step is to tell the Ember app that you have a <code>css</code> file to include in its build pipeline.</p>
<p>In <code>ember-cli-build.js</code> add the following:</p>
<pre><code class="lang-js">...
module.exports = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">defaults</span>) </span>{
  <span class="hljs-keyword">let</span> app = <span class="hljs-keyword">new</span> EmberApp(defaults, {
    <span class="hljs-comment">// Add options here</span>
    <span class="hljs-attr">outputPaths</span>: {
      <span class="hljs-attr">app</span>: {
        <span class="hljs-attr">css</span>: {
          <span class="hljs-string">'second-stylesheet'</span>: <span class="hljs-string">'/assets/second-stylesheet.css'</span>
        }
      }
    }

  });
  ...
};
</code></pre>
<p><strong>That’s it!</strong> ? This tells Ember where to output your new stylesheet so that it can be properly accessed in your i<code>ndex.html</code> ?</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/EY9F7DHJAzzfJqcwOS9Ft-TyL78cFd5nYfuE" alt="Image" width="800" height="517" loading="lazy">
<em>A Sea of Red. Remember to restart the server when you make configuration changes or you may not see the changes.</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ A Learning Path for Newbies in WordPress Development ]]>
                </title>
                <description>
                    <![CDATA[ By Ihtisham Zahoor In this information age, one obstacle in learning something new is not where to find the resources. It’s from where to start and make sense of all the resources available online these days. This holds especially true in web develop... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/learning-path-for-newbies-in-wordpress-development-a283981adf53/</link>
                <guid isPermaLink="false">66d45f32b6b7f664236cbdcc</guid>
                
                    <category>
                        <![CDATA[ Bootstrap ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CSS3 ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML5 ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ jQuery ]]>
                    </category>
                
                    <category>
                        <![CDATA[ js ]]>
                    </category>
                
                    <category>
                        <![CDATA[ learning ]]>
                    </category>
                
                    <category>
                        <![CDATA[ PHP ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Sass ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ WordPress ]]>
                    </category>
                
                    <category>
                        <![CDATA[ wordpress plugins ]]>
                    </category>
                
                    <category>
                        <![CDATA[ WordPress Theme ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 12 Sep 2018 18:46:58 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/0*RlFuY9MLjBJDt1U5" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Ihtisham Zahoor</p>
<p>In this information age, one obstacle in learning something new is not where to find the resources. It’s from where to start and make sense of all the resources available online these days. This holds especially true in web development when new tools are popping up overnight.</p>
<p>Back in 2015, since I first decided to learn web development, I have faced challenges of self-doubt and lack of motivation. But the one challenge which drained my energies was not knowing what path to follow.</p>
<p>Considering the initial challenges in this path I have written this piece for technology enthusiasts who want to get their hands dirty in web development. Especially WordPress development. All in the hope you are going to spend your time building something cool than getting into this never-ending vicious cycle of learning one tool to another.</p>
<h1 id="heading-caution-a-lot-of-learning-in-this-path"><strong>Caution! A lot of learning in this path</strong></h1>
<p>I am a WordPress developer (although my impostor syndrome tells me otherwise). I can share my experience only related to WordPress. But before diving into details, let’s examine a Q/A session first.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/NXiCcxwi7e3plLZMWr3KAfpSuCMA1KA5ODNe" alt="Image" width="700" height="418" loading="lazy"></p>
<p>Now, is the answer mean? Maybe. Is it true? Absolutely! WordPress and Web Development, in general, are as serious and demanding as any profession. So be ready for…</p>
<ul>
<li>Lifetime of Learning</li>
<li>Pulling all-nighters occasionally</li>
</ul>
<p>All right, have you read and understood the above points? Great. Now relax as it is not to discourage you or anything. It’s just how the life of a developer is as the ever-changing nature of this field requires.</p>
<p>The good news is there are not many web technologies you have to learn to master the craft of WordPress Development. That being said, give your time to this amazing piece of software, and WordPress will adore you in return.</p>
<p>WordPress will change your life if you let it — Chris Lema</p>
<p>It’s all inspiring and cute, right? It is one of the reasons <a target="_blank" href="https://topher1kenobe.com/">Topher DeRosia</a> (huge props) has provided the <a target="_blank" href="https://heropress.com/">HeroPress</a> platform for WordPressers (yes, this is what we proudly call ourselves). Here WordPressers share regularly their WordPress origin stories with the <a target="_blank" href="https://opensource.org/community">community</a>. Rest assured while reading through the stories you are going to feel adrenaline rush through your body as many of you are going to find yourself related to those stories.</p>
<h1 id="heading-wordpress-for-everyone">WordPress for Everyone!</h1>
<p>WordPress is super easy to use. In fact, anyone without any technical knowledge, can set up and start using WordPress in no time. However, WordPress has a vast ecosystem. I, for one, would categorize WordPress development being carried out in two different domains. I’ll first list those domains below and then I will discuss each one separately.</p>
<ul>
<li>WordPress Site Customization</li>
<li>WordPress Themes/Plugins Development</li>
</ul>
<h1 id="heading-wordpress-site-customization">WordPress Site Customization</h1>
<p>WordPress Site Customization is where all the buzz is about, as it amounts for most of the work done with respect to WordPress usage. Site Customization is that domain where no prior coding knowledge is required.</p>
<p>That is to say, a WordPress power user can easily perform tasks like Theme/Plugin setup and customization using page builders, site debugging, and site maintenance, etc. Moreover, Theme customization is all about customizing or modifying a pre-made theme as per the requirements of your client.</p>
<p>Considering that, and to give you a perspective about the process, you can watch the following short tutorial by Tyler Moore. In his tutorial, he builds a new website by customizing a pre-made theme using the Elementor page builder.</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/8AZ8GqW5iak" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<h1 id="heading-wordpress-themesplugins-development">WordPress Themes/Plugins Development</h1>
<p>It is where all the fun is for WordPress geeks. We can call it the <em>actual</em> WordPress development, as this domain is all about knowing and getting into the nitty-gritty technical details of programming. It can be as simple as using a few WordPress hooks to modify responses or as complex as building a full-fledge product on WordPress.</p>
<p>So, in case you want to start into this domain, you have to invest more time learning about web technologies involved in WordPress development. Considering that, the rest of this article will discuss all the technologies and a few tips and tricks to get you started in <em>actual</em> WordPress development.</p>
<h1 id="heading-learning-path"><strong>Learning Path</strong></h1>
<p>To get started in your WordPress Development journey, these tools and technologies are what you are going to be working with.</p>
<ol>
<li><p>Say hello and embrace g̵o̵o̵d̵ ̵o̵̵̵l̵̵̵’ HTML5 modules with Semantics and Accessibility concepts. HTML is what gives structure to the site contents.</p>
</li>
<li><p>This quote says it all:</p>
</li>
</ol>
<p>You are the CSS to my HTML — Some Genius</p>
<p>CSS is how HTML is presented in the web browser. Make sure to learn SASS preprocessor as your savior in writing modular CSS once you get a grasp of the basics.</p>
<ol start="3">
<li>The organization behind WordPress has big plans for making JavaScript part of the WordPress Front-end. This officially came from the original author of WordPress.</li>
</ol>
<p>Learn JavaScript, Deeply — Matt Mullenweg</p>
<p>Yes, I know that might be far-fetched for a newbie who is starting out to follow this advice, but keep an eye out for development in this area. Now, this doesn’t mean you have to master JavaScript to work with WordPress. Start with the basics including its hugely popular library jQuery.</p>
<ol start="4">
<li><p>Wouldn’t it be nice if you could get a 1000-step head-start with these three technologies to speed up your development process? Well, that is where front-end frameworks like <a target="_blank" href="http://getbootstrap.com/">Twitter Bootstrap</a> come into play. Explore it and get amazed. Don’t confuse front-end frameworks with JavaScript frameworks. Front-end is used interchangeably with JavaScript libraries and frameworks, which is a whole different path.</p>
</li>
<li><p>PHP is the scripting language that powers WordPress. If you want to dive deep in WordPress, learn PHP head-first with its OOP concepts including MySQL as its back-end database.</p>
</li>
<li><p>In general, when people talk about WordPress Development, it usually means only two segments of WordPress.</p>
</li>
<li><p>WordPress Theme Development, which is developing a presentation (layout) of sites (hence the name “Theme”).</p>
</li>
<li>WordPress Plugin Development, which is to add functionality to WordPress sites</li>
</ol>
<p>For a developer, it is of utmost importance to understand and be comfortable working with both these segments. And to add a tad bit more in your learning journey, get familiar with Internationalization and Localization. You also need to know WordPress Hooks and APIs to name a few.</p>
<p>While developing sites, most of your time is going to be spent in a local development environment and in a code editor. For the sake of complete information in this article, let me point you to an easy-to-setup yet powerful local development environment (<a target="_blank" href="https://local.getflywheel.com/">Local by Flywheel</a>) and lightning-fast code editor (<a target="_blank" href="https://code.visualstudio.com/">Visual Studio Code</a> by Microsoft). Yes, they are both free of cost like WordPress.</p>
<h2 id="heading-workflow"><strong>Workflow</strong></h2>
<p>As your workflow becomes more advanced and complex, it’s important for you to stay sane and keep enjoying life. In that case, you are going to need to streamline your workflow. Try task automation tools like <a target="_blank" href="https://gruntjs.com/">Grunt</a>/<a target="_blank" href="https://gulpjs.com/">Gulp</a> and use a version control system like <a target="_blank" href="https://git-scm.com/">git</a> to keep you from making blunders.</p>
<h2 id="heading-illustration-of-learning-path-guide-published-on-github"><strong>Illustration of Learning Path Guide Published on GitHub</strong></h2>
<p>To make things more clear for you, I have published an illustration of the Learning Path as a step-by-step guide on <a target="_blank" href="https://github.com/ihtishamzahoor/wordpress-learning-path">GitHub</a> which I have provided below.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/BglSkXSPbis8Tkk86z5kuf3VVx4Pt2KNkdfx" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Learn from it, give feedback, improve it to make it better for newbies, and by that means feel free to send PR requests.</p>
<h1 id="heading-resources"><strong>Resources</strong></h1>
<p>In case you are still worried that you are going to need more than a bunch of motivational words to actually start doing meaningful work, maybe you need like a step by step guide — well, worry no more. Follow the <a target="_blank" href="https://developer.wordpress.org/"><strong><em>WordPress WordPress Developer Handbook</em></strong></a> and <a target="_blank" href="https://codex.wordpress.org/"><strong><em>WordPress Developer Codex</em></strong></a> like religion and consider yourself in safe hands.</p>
<p>Moreover, you can receive great help from the <a target="_blank" href="https://wordpress.org/support/"><strong><em>WordPress Support</em></strong></a> forum as well as digging your answers from the Q&amp;A site <a target="_blank" href="https://stackoverflow.com/"><strong><em>Stack Overflow</em></strong></a>, which is immensely popular among the developer community.</p>
<p>Apart, from the official WordPress resources, support forum, and developer-centric Q&amp;A sites. There are a plethora of sites like <a target="_blank" href="https://wpbeginner.com/"><strong><em>WPBeginner</em></strong></a><strong><em>,</em></strong> made possible by the awesome WordPress community, offering WordPress centric free tutorials and guides.</p>
<p><a target="_blank" href="https://www.codexspot.com/category/tutorials/"><strong><em>CodexSpot</em></strong></a> is one such attempt by a bunch of <a target="_blank" href="https://www.codexspot.com/about-us/"><em>WordPress geeks</em></a> including yours truly to give back to the community. <em>CodexSpot</em> is an online platform, focused solely on providing web solutions. Our aim is to provide quality tutorials, DIY guides, and keep you up-to-date with web industry news and trend reports.</p>
<p>We are a huge supporter of free and open-source software initiative and don’t miss any opportunity to evangelize FOSS practices to promote this movement. Besides that, we also offer free web development generators and tools to speed up your development time.</p>
<p>Now, there is one other type of learning resource, which is premium courses. By comparison with free resources, the main benefit of premium ones is the timely support offered by the course instructors for their students. That is to say, the ability to get your queries answered by the very instructors from whom you are learning, hugely benefits you during your learning journey. Furthermore, they stay on top of the latest industry trends.</p>
<p>I have personally learned a great deal from the <a target="_blank" href="https://www.lynda.com/learning-paths/Web/become-a-junior-wordpress-developer"><strong><em>Lynda.com</em></strong></a> (now <em>LinkedIn Learning</em>) courses, highly recommended. I have also found <a target="_blank" href="https://onemonth.com/courses/wordpress"><strong><em>Learn WordPress</em></strong></a> course by <em>Chris Castiglione, a nice beginner-friendly course to start with. So, if you are looking for a premium course on WordPress, you will find any of these courses worth your buck</em>.</p>
<p>At this point, you have the dedication and tons of resources readily available for you to learn everything about WordPress. However, it is equally important that you understand the job market and what the companies seek in candidates applying for the WordPress developer position.</p>
<p><a target="_blank" href="https://www.toptal.com/">Toptal</a>, an exclusive network of the top freelancers in the world, has published a guide for hiring a “<a target="_blank" href="https://www.toptal.com/wordpress#hiring-guide">Great WordPress Developer</a>” which you can read to better align yourself with the most in-demand WordPress skills.</p>
<h1 id="heading-conclusion">Conclusion</h1>
<p>Don’t try to learn everything at once. Start with the basics. Implement what you’ve learned and then build from there. Take note of these following two not hard-and-fast rules for guidance, as these rules will come in handy in your journey.</p>
<ul>
<li><em>Just in Time (JIT) learning</em> is you learn the tool when you need it.</li>
<li><em>80/20 rule of learning</em> is you give 20% of your time to learning and 80% of your time implementing what you have learned already.</li>
</ul>
<p>Now repeat after me:</p>
<p>I learn.<br>I code!<br>I code again!!<br>I code some more!!!<br>I keep coding!!!!!</p>
<p>…and that is how you start in WordPress. Good Luck WordPresser and welcome to the WordPress family!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to compile Sass files in Visual Studio and Webpack ]]>
                </title>
                <description>
                    <![CDATA[ By Esau Silva Sass is a very popular CSS pre-processor. The intent of this tutorial is to show you how to compile Sass files within Visual Studio using Webpack. Our discussion will include minification and autoprefixing for production. Visual Studio... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-compile-sass-files-in-visual-studio-and-webpack-6e45cdc1c14c/</link>
                <guid isPermaLink="false">66d45e3c9208fb118cc6cf8f</guid>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Sass ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ visual studio ]]>
                    </category>
                
                    <category>
                        <![CDATA[ webpack ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 07 Sep 2018 16:38:25 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*-rQU7AOJC3p-ZbiEQnYYlw.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Esau Silva</p>
<p>Sass is a very popular CSS pre-processor. The intent of this tutorial is to show you how to compile Sass files within Visual Studio using Webpack. Our discussion will include minification and autoprefixing for production.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/3k12b5dvlT4iN20sLPdB9W064Z6R7tSYIuX7" alt="Image" width="800" height="197" loading="lazy">
<em>Visual Studio meets Sass</em></p>
<p>Sure, there are some plug-ins in the Visual Studio Marketplace, and it can be nice to just install a plug-in and forget about configuration. But what happens if the plug-in is not supported anymore and stops working with newer Visual Studio versions? Well, too bad. This is the case with one of the most popular compiler plug-ins on the market.</p>
<p>By configuring the compilation yourself, you will have total control over the output. Also, vendor prefixes will be added automatically to your CSS rules. How cool is that?</p>
<h4 id="heading-prerequisites">Prerequisites</h4>
<p>You will need to have Node installed, and you can grab it <a target="_blank" href="https://nodejs.org/en/">here</a>. That’s it really. You’ll also need npm, but it will also be installed with Node.</p>
<h3 id="heading-creating-the-project">Creating the Project</h3>
<p><strong>Note:</strong> We will be creating a .NET Core MVC app, but the same principles apply to any ASP.NET MVC app. You would just need to modify the Webpack configuration a little bit to output the CSS file to the <code>Content</code> directory.</p>
<p>Open Visual Studio and create a new <strong>ASP.NET Core Web Application</strong>, then select <strong>Web Application (Model-View-Controller)</strong>. I’m naming my project <em>netcore-sass-webpack</em>.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/aiZk0QmUZvH0pLbYz4NJQDjsubLYGjSu3D7S" alt="Image" width="800" height="555" loading="lazy">
<em>Creating the project</em></p>
<p>Create a <code>Styles</code> folder within the root of the project. Inside it, create a Sass file and name it <code>site.scss</code>. Open this new Sass file and copy the following:</p>
<pre><code class="lang-css"><span class="hljs-comment">/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification\ 
for details on configuring this project to bundle and minify static web assets. */</span>
<span class="hljs-selector-tag">body</span> {
    <span class="hljs-attribute">padding-top</span>: <span class="hljs-number">50px</span>;
    <span class="hljs-attribute">padding-bottom</span>: <span class="hljs-number">20px</span>;
    <span class="hljs-attribute">background</span>: <span class="hljs-number">#D69655</span> <span class="hljs-built_in">url</span>(<span class="hljs-string">'../wwwroot/images/pattern.png'</span>) repeat;
}

<span class="hljs-comment">/* Wrapping element */</span>
<span class="hljs-comment">/* Set some basic padding to keep content from hitting the edges */</span>
<span class="hljs-selector-class">.body-content</span> {
    <span class="hljs-attribute">padding-left</span>: <span class="hljs-number">15px</span>;
    <span class="hljs-attribute">padding-right</span>: <span class="hljs-number">15px</span>;
}

<span class="hljs-comment">/* Carousel */</span>
<span class="hljs-selector-class">.carousel-caption</span> <span class="hljs-selector-tag">p</span> {
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">20px</span>;
    <span class="hljs-attribute">line-height</span>: <span class="hljs-number">1.4</span>;
}

<span class="hljs-comment">/* Make .svg files in the carousel display properly in older browsers */</span>
<span class="hljs-selector-class">.carousel-inner</span> <span class="hljs-selector-class">.item</span> <span class="hljs-selector-tag">img</span><span class="hljs-selector-attr">[src$=<span class="hljs-string">".svg"</span>]</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
}

<span class="hljs-comment">/* QR code generator */</span>
<span class="hljs-selector-id">#qrCode</span> {
    <span class="hljs-attribute">margin</span>: <span class="hljs-number">15px</span>;
}

<span class="hljs-comment">/* Hide/rearrange for smaller screens */</span>
<span class="hljs-keyword">@media</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">767px</span>) {
    <span class="hljs-comment">/* Hide captions */</span>
    <span class="hljs-selector-class">.carousel-caption</span> {
        <span class="hljs-attribute">display</span>: none;
    }
}
</code></pre>
<p>You will notice that this is the same CSS provided by Visual Studio when we created the project, with the exception of the <code>background</code> rule in the <code>body</code> tag. Now delete the provided CSS located under <code>wwwroot/css</code> (both files: <code>site.css</code> and <code>site.min.css</code>). Don’t worry, we will auto-generate these with Webpack.</p>
<p>Now, download <a target="_blank" href="https://github.com/esausilva/netcore-sass-webpack/tree/master/netcore-sass-webpack/wwwroot/images">pattern.png</a> and place it under <code>wwwroot/images</code>.</p>
<p>Create an empty JavaScript file under the root of the application and name it <code>webpack.config.js</code>. We will take care of this later. You should end up with the following project structure:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/jLrFCNq5AeHVD47jJDIveoOzJgDw6zkryxt3" alt="Image" width="305" height="567" loading="lazy">
<em>Project Structure</em></p>
<p><strong>Note:</strong> You don’t need to do the following two steps for every project, just once (unless you un-install and re-install Visual Studio).</p>
<p>You will need to provide Visual Studio with the Node installation path. Go back to your project and select <strong>Tools -&gt; Optio</strong>ns on the left pa<strong>ne Projects and Solutions -&gt; Web Package Mana</strong>gement and add the path to Node installation at the top of the l<code>ist ( C:\Program Files\</code>node<code>js or C:\Program Files (x86)\</code>nodejs, depending if you installed the x64 or x86 version).</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/J8sJYylsXyYm2gZ2V3Nma4bvABRfJdefnldJ" alt="Image" width="800" height="233" loading="lazy">
<em>Node path</em></p>
<p>Finally download <a target="_blank" href="https://marketplace.visualstudio.com/items?itemName=MadsKristensen.NPMTaskRunner">NPM Task Runner</a> and install it — but you will need to close Visual Studio first.</p>
<h3 id="heading-webpack-and-npm-dependencies">Webpack and NPM Dependencies</h3>
<p>Open <strong>Command Prompt</strong> and navigate to the root of the project and install the needed dependencies:</p>
<pre><code>cd netcore-sass-webpack\netcore-sass-webpack
npm init -y
npm i -D webpack webpack-cli node-sass postcss-loader postcss-preset-env sass-loader css-loader cssnano mini-css-extract-plugin cross-env file-loader
</code></pre><p>The first <code>npm</code> command initializes your <code>package.json</code> and the second installs your dependencies.</p>
<ul>
<li><strong>webpack, webpack-cli</strong> — Module bundler</li>
<li><strong>node-sass</strong> — Bindings for Node to LibSass; provides support for Sass</li>
<li><strong>postcss-loader, postcss-preset-env</strong> — PostCSS loader for Webpack to process autoprefixing and minification</li>
<li><strong>sass-loader, css-loader</strong> — Webpack needs specific loaders to support Sass and CSS</li>
<li><strong>cssnano</strong> — CSS minifier</li>
<li><strong>mini-css-extract-plugin</strong> — Extracts the CSS to a separate file</li>
<li><strong>cross-env</strong> — Provides support to Windows users for environment variables. We will use NODE_ENVenvironment variable</li>
<li><strong>file-loader</strong> — Provides support for files (images) in our CSS rules</li>
</ul>
<p>At this point you can re-open the project in Visual Studio. After the project finishes loading, open <code>package.json</code> and add the following scripts:</p>
<pre><code class="lang-js"><span class="hljs-string">"scripts"</span>: {
    <span class="hljs-string">"dev"</span>: <span class="hljs-string">"webpack --watch"</span>,
    <span class="hljs-string">"build"</span>: <span class="hljs-string">"cross-env NODE_ENV=production webpack"</span>
  },
</code></pre>
<ul>
<li><strong>dev</strong> — We will bind this script whenever the project opens, and Webpack will continually watch for changes to the source Sass files, compile them, and output the separate CSS file</li>
<li><strong>build</strong> — We will bind this script before each project build and will produce the production CSS file, including minification and autoprefixing</li>
</ul>
<p><strong>Note:</strong> The NPM scripts will run automatically using the <strong>Task Runner</strong> window. More on that later.</p>
<p>It is time to work on our Webpack configuration. Open <code>webpack.config.js</code> and copy the following:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> path = <span class="hljs-built_in">require</span>(<span class="hljs-string">"path"</span>);
<span class="hljs-keyword">const</span> MiniCssExtractPlugin = <span class="hljs-built_in">require</span>(<span class="hljs-string">"mini-css-extract-plugin"</span>);
<span class="hljs-keyword">const</span> postcssPresetEnv = <span class="hljs-built_in">require</span>(<span class="hljs-string">"postcss-preset-env"</span>);
<span class="hljs-comment">// We are getting 'process.env.NODE_ENV' from the NPM scripts</span>
<span class="hljs-comment">// Remember the 'dev' script?</span>
<span class="hljs-keyword">const</span> devMode = process.env.NODE_ENV !== <span class="hljs-string">"production"</span>;
<span class="hljs-built_in">module</span>.exports = {
  <span class="hljs-comment">// Tells Webpack which built-in optimizations to use</span>
  <span class="hljs-comment">// If you leave this out, Webpack will default to 'production'</span>
  <span class="hljs-attr">mode</span>: devMode ? <span class="hljs-string">"development"</span> : <span class="hljs-string">"production"</span>,
<span class="hljs-comment">// Webpack needs to know where to start the bundling process,</span>
  <span class="hljs-comment">// so we define the Sass file under './Styles' directory</span>
  <span class="hljs-attr">entry</span>: [<span class="hljs-string">"./Styles/site.scss"</span>],
<span class="hljs-comment">// This is where we define the path where Webpack will place</span>
  <span class="hljs-comment">// a bundled JS file. Webpack needs to produce this file,</span>
  <span class="hljs-comment">// but for our purposes you can ignore it</span>
  <span class="hljs-attr">output</span>: {
    <span class="hljs-attr">path</span>: path.resolve(__dirname, <span class="hljs-string">"wwwroot"</span>),
<span class="hljs-comment">// Specify the base path for all the styles within your</span>
    <span class="hljs-comment">// application. This is relative to the output path, so in</span>
    <span class="hljs-comment">// our case it will be './wwwroot/css'</span>
    <span class="hljs-attr">publicPath</span>: <span class="hljs-string">"/css"</span>,
<span class="hljs-comment">// The name of the output bundle. Path is also relative</span>
    <span class="hljs-comment">// to the output path, so './wwwroot/js'</span>
    <span class="hljs-attr">filename</span>: <span class="hljs-string">"js/sass.js"</span>
  },
  <span class="hljs-attr">module</span>: {
    <span class="hljs-comment">// Array of rules that tells Webpack how the modules (output)</span>
    <span class="hljs-comment">// will be created</span>
    <span class="hljs-attr">rules</span>: [
      {
        <span class="hljs-comment">// Look for Sass files and process them according to the</span>
        <span class="hljs-comment">// rules specified in the different loaders</span>
        <span class="hljs-attr">test</span>: <span class="hljs-regexp">/\.(sa|sc)ss$/</span>,
<span class="hljs-comment">// Use the following loaders from right-to-left, so it will</span>
        <span class="hljs-comment">// use sass-loader first and ending with MiniCssExtractPlugin</span>
        use: [
          {
            <span class="hljs-comment">// Extracts the CSS into a separate file and uses the</span>
            <span class="hljs-comment">// defined configurations in the 'plugins' section</span>
            <span class="hljs-attr">loader</span>: MiniCssExtractPlugin.loader
          },
          {
            <span class="hljs-comment">// Interprets CSS</span>
            <span class="hljs-attr">loader</span>: <span class="hljs-string">"css-loader"</span>,
            <span class="hljs-attr">options</span>: {
              <span class="hljs-attr">importLoaders</span>: <span class="hljs-number">2</span>
            }
          },
          {
            <span class="hljs-comment">// Use PostCSS to minify and autoprefix with vendor rules</span>
            <span class="hljs-comment">// for older browser compatibility</span>
            <span class="hljs-attr">loader</span>: <span class="hljs-string">"postcss-loader"</span>,
            <span class="hljs-attr">options</span>: {
              <span class="hljs-attr">ident</span>: <span class="hljs-string">"postcss"</span>,
<span class="hljs-comment">// We instruct PostCSS to autoprefix and minimize our</span>
              <span class="hljs-comment">// CSS when in production mode, otherwise don't do</span>
              <span class="hljs-comment">// anything.</span>
              <span class="hljs-attr">plugins</span>: devMode
                ? <span class="hljs-function">() =&gt;</span> []
                : <span class="hljs-function">() =&gt;</span> [
                    postcssPresetEnv({
                      <span class="hljs-comment">// Compile our CSS code to support browsers</span>
                      <span class="hljs-comment">// that are used in more than 1% of the</span>
                      <span class="hljs-comment">// global market browser share. You can modify</span>
                      <span class="hljs-comment">// the target browsers according to your needs</span>
                      <span class="hljs-comment">// by using supported queries.</span>
                      <span class="hljs-comment">// https://github.com/browserslist/browserslist#queries</span>
                      <span class="hljs-attr">browsers</span>: [<span class="hljs-string">"&gt;1%"</span>]
                    }),
                    <span class="hljs-built_in">require</span>(<span class="hljs-string">"cssnano"</span>)()
                  ]
            }
          },
          {
            <span class="hljs-comment">// Adds support for Sass files, if using Less, then</span>
            <span class="hljs-comment">// use the less-loader</span>
            <span class="hljs-attr">loader</span>: <span class="hljs-string">"sass-loader"</span>
          }
        ]
      },
      {
        <span class="hljs-comment">// Adds support to load images in your CSS rules. It looks for</span>
        <span class="hljs-comment">// .png, .jpg, .jpeg and .gif</span>
        <span class="hljs-attr">test</span>: <span class="hljs-regexp">/\.(png|jpe?g|gif)$/</span>,
        use: [
          {
            <span class="hljs-attr">loader</span>: <span class="hljs-string">"file-loader"</span>,
            <span class="hljs-attr">options</span>: {
              <span class="hljs-comment">// The image will be named with the original name and</span>
              <span class="hljs-comment">// extension</span>
              <span class="hljs-attr">name</span>: <span class="hljs-string">"[name].[ext]"</span>,
<span class="hljs-comment">// Indicates where the images are stored and will use</span>
              <span class="hljs-comment">// this path when generating the CSS files.</span>
              <span class="hljs-comment">// Example, in site.scss I have</span>
              <span class="hljs-comment">// url('../wwwroot/images/pattern.png') and when generating</span>
              <span class="hljs-comment">// the CSS file, file-loader will output as</span>
              <span class="hljs-comment">// url(../images/pattern.png), which is relative</span>
              <span class="hljs-comment">// to '/css/site.css'</span>
              <span class="hljs-attr">publicPath</span>: <span class="hljs-string">"../images"</span>,
<span class="hljs-comment">// When this option is 'true', the loader will emit the</span>
              <span class="hljs-comment">// image to output.path</span>
              <span class="hljs-attr">emitFile</span>: <span class="hljs-literal">false</span>
            }
          }
        ]
      }
    ]
  },
  <span class="hljs-attr">plugins</span>: [
    <span class="hljs-comment">// Configuration options for MiniCssExtractPlugin. Here I'm only</span>
    <span class="hljs-comment">// indicating what the CSS output file name should be and</span>
    <span class="hljs-comment">// the location</span>
    <span class="hljs-keyword">new</span> MiniCssExtractPlugin({
      <span class="hljs-attr">filename</span>: devMode ? <span class="hljs-string">"css/site.css"</span> : <span class="hljs-string">"css/site.min.css"</span>
    })
  ]
};
</code></pre>
<p>Refer to the comments in the code to understand the configuration. (More readable file <a target="_blank" href="https://github.com/esausilva/netcore-sass-webpack/blob/master/netcore-sass-webpack/webpack.config.js">here</a>.)</p>
<p>Now we need to create some bindings in <strong>Task Runner Explorer</strong>. Navigate to <strong>View -&gt; Other Windows -&gt; Task Runner Exp</strong>lorer. The window will show at the bottom and you will see the scripts you created in <code>package.json</code> listed there <strong>under</strong> Custom. You will also see some tasks <strong>under De</strong>faults, but you can just ignore them.</p>
<p>We need two bindings:</p>
<ul>
<li>Right click <strong>build -&gt; Bindings -&gt; Before</strong> Build — Visual Studio will run this task before each build. Remember this npm script runs Webpack for production and will optimize the CSS file.</li>
<li>Right click <strong>dev -&gt; Bindings -&gt; Projec</strong>t Open — Visual Studio will run this task when you open the project. Remember this npm script runs Webpack in watch mode and <em>will</em> watch for any changes in your Sass files and output the processed CSS file.</li>
</ul>
<p><strong>Task Runner Explorer</strong> should look like this:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/cEQsi3RjNiBTTQr1tAhSoAARAmhkc79kQRza" alt="Image" width="392" height="209" loading="lazy">
<em>Task Runner Explorer</em></p>
<p><strong>Note:</strong> For some reason, Visual Studio sometimes will fail to start the <strong>dev</strong> task upon opening the project. If that happens, just open the Task Explorer and run the task manually.</p>
<p>You can get the full code from the <a target="_blank" href="https://github.com/esausilva/netcore-sass-webpack">GitHub repository</a>.</p>
<h3 id="heading-final-thoughts">Final Thoughts</h3>
<p>And that’s all there is too it. Since you already have Visual Studio open, none of the tasks are running. Go ahead and <em>right click</em> the <strong>dev</strong> task and select run. You will see the task loading and when it finishes you will see that a <code>site.css</code> file was created under <code>wwwroot/css</code> directory. Open <code>site.scss</code>, make a change and save it. Now open <code>site.css</code>, you will see your change reflected there. Cool!!</p>
<p>Run your project by pressing <strong>Ctrl + F5</strong>, you will see a <code>site.min.css</code> file created under <code>wwwroot/css</code> directory. This file was created when Task Runner <em>ran</em> the <code>build</code> script before it built the project.</p>
<p>The final site should look like this:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/CBTg3rcS670jv5PSQzM35LZ9awQdUfzS2Nb3" alt="Image" width="800" height="527" loading="lazy">
<em>Final site</em></p>
<p>I know, I know, the background is very cheesey…but I needed an image to show the Webpack <code>file-loader</code> in action.</p>
<p>With this configuration, you can even add support to transpile modern JavaScript (ES6+) to ES5. Look into these: <code>@babel/core</code>, <code>babel-loader</code>, <code>@babel/preset-env</code>.</p>
<p>Thank you for reading, and I hope you enjoyed it. If you have any questions, suggestions, or corrections let me know in the comments below. Don’t forget to give this article a share, and you can follow me on <a target="_blank" href="https://twitter.com/_esausilva">Twitter</a>, <a target="_blank" href="https://github.com/esausilva/">GitHub</a>, <a target="_blank" href="https://medium.com/@_esausilva">Medium</a>, <a target="_blank" href="https://www.linkedin.com/in/esausilva/">LinkedIn</a>.</p>
<p>You can also visit my personal <a target="_blank" href="https://esausilva.com">blogging site</a>.</p>
<hr>
<p><strong>Update 8/25/19:</strong> I have been building a prayer web app called "<strong>My Quiet Time - A Prayer Journal</strong>". If you would like to stay in the loop please sign up through the following link: <a target="_blank" href="http://b.link/mqt">http://b.link/mqt</a>  </p>
<p>The app will be released before the end of the year, I have big plans for this app. To see some mockup screenshots follow the following link: <a target="_blank" href="http://pc.cd/Lpy7">http://pc.cd/Lpy7</a></p>
<p>My DMs on <a target="_blank" href="https://twitter.com/_esausilva">Twitter</a> are open if you have any questions regarding the app ?</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Sass — a preprocessor for your web garnishes ]]>
                </title>
                <description>
                    <![CDATA[ By Chandrabhan Singh Importance of aesthetics, its impact, and tool to achieve it. I remember as a child, every time I’d walk up to a bakery, I’d choose the pastries with the most beautiful toppings. Only after having the first bite would I know if i... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/give-more-oompf-to-your-web-garnishes-with-preprocessors-in-sass-bd379226a114/</link>
                <guid isPermaLink="false">66d45dd5182810487e0ce0f3</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Sass ]]>
                    </category>
                
                    <category>
                        <![CDATA[ ux design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 27 Jun 2018 23:31:24 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/0*BKMwiv00w7wdMbnQ" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Chandrabhan Singh</p>
<h4 id="heading-importance-of-aesthetics-its-impact-and-tool-to-achieve-it">Importance of aesthetics, its impact, and tool to achieve it.</h4>
<p>I remember as a child, every time I’d walk up to a bakery, I’d choose the pastries with the most beautiful toppings. Only after having the first bite would I know if it was the one I was longing for.</p>
<p>A well-plated dish can trump taste at times. The tendency to pick on appearance has a significant impact on our choices. This inclination towards plating is not only confined to food. Trendy clothes, a decorated apartment, and a well-designed car are a few examples.</p>
<p>A master chef understands the importance of presentation for a successful restaurant. The art of garnishing can differentiate a culinary masterpiece from a novice’s plate. Moreover, a creative plating would add pleasure and taste, encouraging customers to pay frequent visits. The web is no different from any gourmet meal in this sense. Visual impact has had a crucial role in all successful web applications, too.</p>
<p>You need to make significant efforts to make web applications look pleasant. This is where Cascade Style Sheets (CSS) come in.</p>
<p>As the web evolves, applications grow bigger and bigger. To match our needs, we need more from CSS out of the box. But CSS has some limitations.</p>
<p>Since you’re reading this article, you’ve already finished the toppings, and now is the time to taste the rest of the cake. Let’s see what limitations CSS has and how we can overcome them. The goal is to take your plating technique to the next level.</p>
<h3 id="heading-prerequisites">Prerequisites</h3>
<p>You need to have a fair understanding of CSS and CSS selectors. You’ll also need Node.js and npm installed.</p>
<h3 id="heading-css-limitations">CSS Limitations</h3>
<p>Identifying limitations is subjective, though I would like to mention a few.</p>
<ol>
<li>Programming mechanism: Features like variables, functions, classes, and operators are missing in CSS3 itself.</li>
<li>Lengthy CSS file: In rich user interface applications, style sheets may grow overnight. Large files can be a nightmare for maintenance.</li>
<li>Absent math operators: Math operators like <code>+</code>, <code>-</code>, <code>*</code>, <code>/</code> can be very handy at times.</li>
</ol>
<p>To overcome such limitations, we have preprocessor scripting languages.</p>
<h3 id="heading-the-preprocessor">The preprocessor</h3>
<p>A Preprocessor is a piece of software which takes an input file written in some programming language and processes it to produce a file following syntax of another language. It is used to extend the syntax of an existing programming language by adding new functionality to it.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/CESwXT5CXZaW0zD9UFfMK5-Da4aDae98nXsv" alt="Image" width="800" height="386" loading="lazy">
<em>illustration: Sass preprocessor</em></p>
<p>A CSS preprocessor extends the CSS syntax by adding a programming mechanism to it. SassScript is a superset of CSS. When compiled, it creates valid CSS blocks for your web applications.</p>
<p>There are a few CSS preprocessors available like Less, Stylus, and Sass. Our focus will be on Sass ( Syntactically-awesome style sheets). But the concept is more or less the same for other preprocessors.</p>
<p>We will go through the installation of a Node.js Sass compiler, and later we’ll see various Sass features in action. So, get ready to garnish your delicious web recipes ?.</p>
<h3 id="heading-preparing-sass">Preparing Sass</h3>
<p>Sass was first written in Ruby and then in other languages. You can choose from many available implementations. For this article, we will stick to a Node.js package — <a target="_blank" href="https://www.npmjs.com/package/node-sass">node-sass</a>. This package uses high-performance Sass implementation in C called libSassSass.</p>
<p>First things first: Let’s install node-sass. Then we will set up a sample application to see various Sass features in action. Open a terminal on your machine and execute the below command.</p>
<pre><code>npm install node-sass -g
</code></pre><p>Here we are asking node package manager to install <code>node-sass</code> for us. With flag <code>-g</code>, we installed the package globally. Great! Once it finishes, make sure everything is in place.</p>
<pre><code>node-sass -v
</code></pre><p><img src="https://cdn-media-1.freecodecamp.org/images/HLBJvf-d3thAinPmMy57ICBe-Y7Ajv25U5lf" alt="Image" width="800" height="460" loading="lazy">
<em>command to check node-sass version.</em></p>
<p>Okay! We have all the ingredients we may need. Let’s see what flavors Sass comes with, and afterward we will start our journey to explore Sass.</p>
<h3 id="heading-various-flavors-of-sass">Various flavors of Sass</h3>
<p>There are two ways of creating a Sass file. You can use either of these two syntaxes.</p>
<ol>
<li>Sass style: This syntax uses indentation to separate code blocks and new lines.</li>
<li>SCSS style: This syntax uses blocks like a programming language. We’ll use SCSS syntax in this article.</li>
</ol>
<p>Note: It’s possible to convert from one syntax to another by a simple Sass convert command. Feel free to adopt the one you like.</p>
<h3 id="heading-preparing-the-main-dish">Preparing the main dish</h3>
<p>As we are Sass-ready on our machine, we can start playing around to see what great features it can bring to us. Follow along with me to set up a sample application.</p>
<p>Here I am using <a target="_blank" href="https://code.visualstudio.com/">Visual Studio Code</a>. You can use any code editor of your choice. I have been using it for a long time and I would recommend it. It has some cool productivity plugins that can be of great help.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/zC4AvUGKCWqbLR5DrEeRNgx7QjCadVK5LASJ" alt="Image" width="800" height="422" loading="lazy"></p>
<p>So far, we have created a folder and two files.</p>
<ol>
<li>index.html: an HTML file.</li>
<li>style.scss: root (or main) Sass script file.</li>
</ol>
<p>To start, let’s create a <code>div</code>, an <code>h1</code>, and two <code>button</code>s in the HTML file.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/jTk6IeVPWVD77fz9CvCFXv36nJNtIULc60En" alt="Image" width="800" height="390" loading="lazy"></p>
<p>Let’s iterate through the most used Sass features. On the way, we will also see the compiled CSS blocks.</p>
<h3 id="heading-variables">Variables</h3>
<p>Variables help you centralize CSS properties. You can assign them once at the top of a file and use them throughout the file. These variables are like placeholders for a CSS property’s value. In Sass, a variable name must start with a <code>$</code> sign.</p>
<p>We are going to create two variables: <code>$h1-color</code> and <code>$h1-height</code>. Then we will use these variables to assign color and height properties to an <code>h1</code> element. Below is the Sass snippet.</p>
<pre><code>$h1-color     : blue;
$h1-height    : <span class="hljs-number">50</span>px;
h1{
   <span class="hljs-attr">color</span>  : $h1-color;
   height : $h1-height;
}
</code></pre><p>All right! We have an HTML file and a Sass file so far. What about the CSS file? It hasn’t appeared yet.</p>
<p>Well, we are almost there. Open your terminal to go to the folder we created and execute the command below:</p>
<pre><code>node-sass style.scss style.css
</code></pre><p>The parameters for the <code>node-sass</code> compiler are input and output file path. Now if you open the HTML we created during project setup in a browser, you should see the following.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/Y3ZYYB1x0X-4unWyqymzGItI3HPBe0rEBw6Y" alt="Image" width="800" height="321" loading="lazy">
<em>HTML with CSS applied</em></p>
<p>Notice that the CSS file is already included in the HTML’s <code>head</code>section.</p>
<h3 id="heading-operators">Operators</h3>
<p>Mathematical operators were always missed in CSS. Sass provides basic math operators like addition <code>+</code>, subtraction <code>-</code>, multiplication <code>*</code> and division<code>/</code>.</p>
<p>You can use variables and operators together to manipulate CSS properties. Let’s take an example. We can use operators to calculate padding for an <code>h1</code> element depending upon the width of its parent <code>div</code>. We will use the divide operator <code>/</code> for this example.</p>
<pre><code>$h1-color   : blue;
$h1-font    : <span class="hljs-number">50</span>px;
$div-width  : <span class="hljs-number">500</span>px;
div{
   <span class="hljs-attr">width</span>: $div-width;
}
h1{
   <span class="hljs-attr">color</span>       :  $h1-color;
   height      :  $h1-font;
   padding     :  $div-width / <span class="hljs-number">10</span>;
}
</code></pre><h3 id="heading-mixins">Mixins</h3>
<p>Mixins are like abstract base classes. Mixins are handy to group related properties. Once created, these mixins can be reused in the rest of the style blocks. Moreover, you can even pass variables. Confusing? Let’s take an example.</p>
<p>You must have noticed that creating a style for border-radius is always quite messy. For cross-browser support, we must use vendor-specific properties. However, with mixins, it can be super easy. Let’s see it happen.</p>
<pre><code>@mixin border-radius($radius){
   -webkit-border-radius   : $radius;
   -moz-border-radius      : $radius;
   -ms-border-radius       : $radius;
   border-radius           : $radius;
}
div{
   <span class="hljs-attr">width</span>    : $div-width;
   border   : <span class="hljs-number">2</span>px solid grey;
   @include border-radius(<span class="hljs-number">20</span>px);
}
</code></pre><p>Here we used the <code>@mixin</code> directive to define a mixin named <code>border-radius</code>. This mixin contains all the possible properties to set the radius of a border. We also passed a parameter to this mixin. Whenever you need to set the radius of an element, include this mixin with the <code>@include</code> keyword.</p>
<p>Compile the script once again to generate the CSS. How does it look now?</p>
<pre><code><span class="hljs-comment">//Processed CSS output</span>
div {
   <span class="hljs-attr">width</span>: <span class="hljs-number">500</span>px;
   border: <span class="hljs-number">2</span>px solid grey;
   -webkit-border-radius: <span class="hljs-number">20</span>px;
   -moz-border-radius: <span class="hljs-number">20</span>px;
   -ms-border-radius: <span class="hljs-number">20</span>px;
   border-radius: <span class="hljs-number">20</span>px; 
}
</code></pre><h3 id="heading-nesting">Nesting</h3>
<p>HTML elements have a logical tree-like structure with nested elements. To write structured CSS selectors, CSS should also follow some logical nesting. Yet, CSS does not support nesting.</p>
<p>Since you have Sass on your machine, writing nested CSS selectors is a piece of cake.</p>
<pre><code>div{
   &gt;h1{
      <span class="hljs-attr">color</span>: blue;
      &amp;:hover{
         <span class="hljs-attr">color</span>: greenyellow;
      }
   }
}
</code></pre><p>Here we used two combinators, <code>&amp;</code>gt; a<code>n</code>d &amp;. The purpose of a combinator is to explain the relationship between the elements. Our example will apply blue color to a<code>ll</code> h1 children of <code>a</code> div element. Another selector is the parent select<code>o</code>r &amp;. Use this selector for pseudo-classes like hover, focus, and active.</p>
<p>Compile once again to see the generated CSS blocks.</p>
<pre><code><span class="hljs-comment">//Processed CSS output</span>
div h1 {
   <span class="hljs-attr">color</span>: blue;
}
div h1:hover {
   <span class="hljs-attr">color</span>: greenyellow;
}
</code></pre><h3 id="heading-inheritance">Inheritance:</h3>
<p>Yes — you can use the most popular OOP feature in Sass as well. Accruing the properties of one’s parent is Inheritance. But does it make any sense in CSS? And can we use them? We can! Believe me, and, I am sure you will adore this feature.</p>
<p>Consider an application where you have various types of buttons. Save, Cancel, and Discard to name a few. You realize they share most of their characteristics. For example padding, font-size, margin. The only difference is the background color.</p>
<p>Does it smell like inheritance? Yeah— You guessed it right! We can create a parent style for all these common properties and use them in child blocks.</p>
<pre><code class="lang-css">%<span class="hljs-selector-tag">common-button</span>{
   <span class="hljs-attribute">padding</span>: <span class="hljs-number">16px</span> <span class="hljs-number">8px</span>;
   <span class="hljs-attribute">border</span>: none;
   <span class="hljs-attribute">font-size</span>: <span class="hljs-number">18px</span>;
}
<span class="hljs-selector-class">.save</span>{
   @extend %common-button;
   <span class="hljs-attribute">background-color</span>: blue;
   <span class="hljs-attribute">color</span>: white;
}
<span class="hljs-selector-class">.cancel</span>{
   @extend %common-button;
   <span class="hljs-attribute">background-color</span>: goldenrod;
   <span class="hljs-attribute">color</span>: white;
}
</code></pre>
<p>Here, the <code>save</code> and <code>cancel</code> buttons inherited their common properties from the <code>common-button</code> class. To declare a parent style, use the <code>%</code> sign. Use the <code>@extend</code> directive to inherit a child block.</p>
<h3 id="heading-import">Import</h3>
<p>We have seen many amazing features that Sass provides. We were able to make styles more readable and structured. Still, it can grow and become hard to maintain.</p>
<p>Sass has a solution to this problem as well: a partial file. A partial file is a way to create small modular Sass files. The root Sass file can then import these modular files altogether. The naming convention for partial files is to prefix the file name with an underscore <code>_</code>.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1Gmm4N1YrO2DElcL8igxSY7CTEulf0gqKQNQ" alt="Image" width="800" height="358" loading="lazy"></p>
<pre><code class="lang-css"><span class="hljs-keyword">@import</span> <span class="hljs-string">'_buttonpartial'</span>;
<span class="hljs-selector-tag">h1</span>{
   <span class="hljs-attribute">color</span>:blue;
}
</code></pre>
<p>Use the <code>@import</code> directive to include a partial file in the root Sass script.</p>
<h3 id="heading-loop">Loop</h3>
<p>Iteration is one of the most frequently used programming mechanisms. Sass script allows you to iterate over variables. You can use various directives like <code>@for</code>, <code>@each</code> and <code>@while.</code></p>
<pre><code class="lang-css">$<span class="hljs-selector-tag">totalButton</span>: 2;
<span class="hljs-keyword">@for</span> $i from <span class="hljs-number">1</span> through $totalButton{
   <span class="hljs-selector-class">.button-</span>#{$i} {
      <span class="hljs-attribute">width</span>: <span class="hljs-number">50px</span> * $i;
      <span class="hljs-attribute">height</span>: <span class="hljs-number">120px</span> / $i;
   }
}
</code></pre>
<p>The generated CSS block will have two classes with different styles.</p>
<pre><code class="lang-css">//<span class="hljs-selector-tag">Processed</span> <span class="hljs-selector-tag">CSS</span> <span class="hljs-selector-tag">output</span>
<span class="hljs-selector-class">.button-1</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">120px</span>; }
<span class="hljs-selector-class">.button-2</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">100px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">60px</span>; }
</code></pre>
<h3 id="heading-avoid-repeating-use-a-food-processor">Avoid repeating — use a food processor</h3>
<p>A food processor is a kitchen appliance used to facilitate repetitive tasks in the preparation of food.</p>
<p>We have used a Node.js package for compiling Sass files. It can be very annoying if you have to compile every time you make a change in the Sass script.</p>
<p>There is a fancy way to avoid repetitive compiling: a task runner. Visual Studio Code has a built-in task runner, but you can use any task runner of your choice. <a target="_blank" href="https://gulpjs.com/">Gulp</a> is another popular task runner. For compiling Sass script with Gulp, you would need <a target="_blank" href="https://www.npmjs.com/package/gulp-sass">gulp sass compiler</a> instead.</p>
<p><strong>Warning!</strong> Sass is only a development tool. Avoid shipping any library or file associated with Sass. You would never need them on a production server.</p>
<h3 id="heading-whats-next">What’s next</h3>
<p>We’ve learned how to use preprocessors to create efficient and maintainable CSS blocks. We have seen various Sass features with examples. For more in-depth knowledge, jump to the official <a target="_blank" href="https://sass-lang.com/guide">website</a>.</p>
<p>I have also created a <a target="_blank" href="https://github.com/SinghChandrabhan/SassSample">sample</a> project. Go ahead, clone the project and start playing.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ In Defense of Utility-First CSS ]]>
                </title>
                <description>
                    <![CDATA[ By Sarah Dayan “Favor composition over inheritance”. This piece of wisdom from Design Patterns, one of the most influential software engineering books, is the foundation of utility-first CSS. It also shares many principles with functional programming... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/in-defense-of-utility-first-css-4f406acee6fb/</link>
                <guid isPermaLink="false">66c357f1e9895571912a0cbe</guid>
                
                    <category>
                        <![CDATA[ atomic css ]]>
                    </category>
                
                    <category>
                        <![CDATA[ bem ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Sass ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Utility First ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sat, 27 Jan 2018 01:13:30 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*nHfoojHD3eS-ggpdB6zNJw.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Sarah Dayan</p>
<p><strong><em>“Favor composition over inheritance”</em></strong>.</p>
<p>This piece of wisdom from <a target="_blank" href="https://en.wikipedia.org/wiki/Design_Patterns"><em>Design Patterns</em></a>, one of the most influential software engineering books, is the foundation of <strong>utility-first CSS</strong>. It also shares many principles with <strong>functional programming</strong>: immutability, composability, predictability, and avoidance of side-effects. The goal behind all those fancy terms is to write code that’s <strong>easier to maintain and to scale</strong>.</p>
<p>Despite its growing popularity, utility-first CSS still hasn’t convinced everyone. While some <a target="_blank" href="http://jon.gold/2015/07/functional-css">praise it</a>, others have been <a target="_blank" href="http://www.zeldman.com/2017/01/03/kiss-my-classname">vividly critical</a> about such a practice. <strong>I used to be in the latter group</strong>. I was a BEM fan, sold to an approach I adopted for its advantages and ended up rooting for it like we do for a sports team. I rejected utility-first because it implied that my beloved and familiar approach wasn’t good anymore.</p>
<p>Since then, I’ve dived <em>a lot</em> deeper into the topic. I studied design patterns and functional programming. This allowed me to <strong>radically revise my judgment</strong>.</p>
<p><a target="_blank" href="https://css-tricks.com/growing-popularity-atomic-css/">CSS Tricks</a> and <a target="_blank" href="https://adamwathan.me/css-utility-classes-and-separation-of-concerns">Adam Wathan</a> have done a brilliant job at taking us on a journey from “regular” CSS to utility-first, and explaining the “why” behind it. Rather than paraphrasing, I’ll focus on <strong>the recurring criticism of utility-first</strong> and debunk common misconceptions.</p>
<h3 id="heading-might-as-well-use-inline-styles">“Might as well use inline styles”</h3>
<p>People often compare utility-first CSS to applying CSS rules to HTML nodes through the <code>style</code> attribute. This way of styling is unanimously considered a bad practice, and we have since moved on to separate stylesheets and class abstractions.</p>
<p><strong>Utility-first CSS is no different</strong>. All styles are defined and maintained separately. This allows code reuse, usage of pseudo-classes, pseudo-elements, pre-processors, and browser caching.</p>
<p>Yet, atomic CSS detractors hurriedly associate it to inline styles. Atomic classes are small, they often have only one rule, and they’re named in a <em>functional</em> way instead of being <em>semantic</em>.</p>
<p>All that being said, just because it <em>looks</em> the same doesn’t mean it <em>is</em> the same. Understanding how both practices differ is key to grasping the benefits of utility-first.</p>
<p><strong>Inline styles allow you to do anything you want</strong>. You don’t have to follow any pre-existing definition. You’re re-writing everything from the ground-up every time you style a new HTML node. Similar elements end up with duplicate code, which makes the page unnecessarily heavier. If you’re not careful, it’s easy to ignore pre-existing solutions and reinvent the wheel every time.</p>
<pre><code>&lt;h2 style=<span class="hljs-string">"font-size: 16px; font-weight: bold; color: purple"</span>&gt;Stranger Things&lt;;<span class="hljs-regexp">/h2&amp;gt;&lt;p style="font-size: 13px; font-style: italic"&gt;Stranger Things is an American science fiction-horror web television...&lt;/</span>p&gt;<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"font-size: 16px; font-weight: bold; color: purple"</span>&gt;</span>;Game of Thrones<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span></span><span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"font-size: 13px; font-style: italic"</span>&gt;</span>Game of Thrones is an American fantasy drama television...<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>
</code></pre><p><em>Unnecessarily verbose, heavier file size, multiple sources of truth for a single design concept.</em></p>
<pre><code>&lt;button style=<span class="hljs-string">"padding: 5px 8px; font-size: 13px"</span>&gt;Button&lt;<span class="hljs-regexp">/button&gt;&lt;button style="padding: 0 8px; font-size: 13px; line-height: 23px"&gt;Button&lt;/</span>button&gt;<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"display: flex; padding: 0 8px; font-size: 13px; height: 23px; align-items: center"</span>&gt;</span>Button<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span>
</code></pre><p><em>Three attempts at solving the same problem. This is easily induced by the absence of a single source of truth, and likely to cause visual inconsistencies.</em></p>
<p><strong>Utility classes expose a well-defined API that you can use to compose more complex components</strong>. You’re not re-writing styles; instead, you’re relying on classes that define styles and behaviors once and for all.</p>
<pre><code><span class="hljs-comment">// HTML</span>
</code></pre><pre><code>&lt;h2 <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"font-16 font-bold font-purple"</span>&gt;Stranger Things&lt;<span class="hljs-regexp">/h2&gt;&lt;p class="font-13 font-italic"&gt;Stranger Things is an American science fiction-horror web television...&lt;/</span>p&gt;<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"font-16 font-bold font-purple"</span>&gt;</span>Game of Thrones<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span></span><span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"font-13 font-italic"</span>&gt;</span>Game of Thrones is an American fantasy drama television...<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>
</code></pre><pre><code><span class="hljs-comment">// CSS</span>
</code></pre><pre><code><span class="hljs-comment">/* Font sizes */</span>
</code></pre><pre><code>.font<span class="hljs-number">-13</span> { font-size: <span class="hljs-number">13</span>px } .font<span class="hljs-number">-16</span> { font-size: <span class="hljs-number">16</span>px }...
</code></pre><pre><code><span class="hljs-comment">/* Font styles */</span>
</code></pre><pre><code>.font-bold { font-weight: bold }.font-italic { font-style: italic }...
</code></pre><pre><code><span class="hljs-comment">/* Font colors */</span>
</code></pre><pre><code>.font-purple { <span class="hljs-attr">color</span>: purple }...
</code></pre><p>Using a defined set of existing CSS rules, no matter how atomic, forces you to pick styles from a <strong>limited list</strong>. You’re not granted total freedom like you are with inline styles. You’re maintaining a consistent catalog of <em>allowed</em> styles, and using them to <em>compose</em> larger components.</p>
<p>This approach enforces consistency by limiting the ways you can style elements. Instead of having access to 16+ million colors, you only have access the number of colors defined in your theme.</p>
<p><strong>It also provides a single source of truth.</strong> Instead of re-declaring the same <code>color</code> for each element that uses it, you define it once in a class and use that class wherever you need it. In addition, using separate styling (with atomic classes or not) gives you access to pseudo-classes and pseudo-elements, pre-processors, caching… a whole load of benefits that aren’t available with inline styles.</p>
<p>You may argue that it doesn’t matter if atomic styles are limited: carelessly mixing them may result in inconsistent layouts like with inline styles. But that’s <strong>a human issue, not a technical one</strong>. You get the exact same problem with any approach, and any language for that matter, whether you’re able to scope or not. If you don’t follow the rules, style guides, and best practices that your team put in place, you’re the one to blame. Not the program, not the language, and not the architecture.</p>
<h3 id="heading-it-violates-separation-of-concerns">“It violates separation of concerns”</h3>
<p>One of the biggest arguments against functional CSS is that it goes against separation of concerns. That CSS should strictly be in charge of the styling, and HTML should semantically structure the page. That by using atomic classes and composing components in the HTML, you’re somewhat delegating styling to the HTML instead of doing it in CSS.</p>
<p><strong>This is an extreme, and ultimately warped, vision of what “separation of concerns” means.</strong></p>
<p>A few years ago, I was on a job interview with a front-end developer who told me about his sheer disdain for Bootstrap. According to him, using extra markup to create a grid was a heresy: that’s a job for CSS, and CSS only. HTML should be 100% oblivious to how it’s rendered.</p>
<p>The problem with that kind of thinking is that it’s <strong>deeply impractical</strong>. It raises design principles to a dogmatic level, ignoring concrete use-cases and context. It pushes you to be more concerned about checking all the “good practice” checkboxes than solving actual problems.</p>
<p>Adam Wathan <a target="_blank" href="https://adamwathan.me/css-utility-classes-and-separation-of-concerns">explains it well (see: “Separation of concerns” is a straw man)</a>: when it comes to HTML and CSS, you can’t look at it from a strict “separation of concerns” perspective. <strong>It’s a “which depends on which” relationship</strong>.</p>
<p><strong>Make no mistake:</strong> just because style composition is performed in the HTML <em>document</em> doesn’t mean it’s done <em>in HTML</em>. We’re not using <em>style</em> or <em>align</em> attributes on HTML nodes. We’re assembling pieces that we defined in a proper stylesheet, <em>in CSS</em>. Our HTML becomes a <em>consumer</em> of our CSS “API.” As Vue.js explains it in their <a target="_blank" href="https://vuejs.org/v2/guide/single-file-components.html#What-About-Separation-of-Concerns">documentation</a>, separation of concerns doesn’t equal separation of file types. Your styles can be composed on HTML nodes, <strong>it’s still a CSS job</strong>.</p>
<h3 id="heading-it-bloats-the-html">“It bloats the HTML”</h3>
<p>When people mention code bloat, they usually mean one of two things (or both): code that’s <a target="_blank" href="https://frontstuff.io/in-defense-of-utility-first-css#its-ugly-and-hard-to-read"><strong>hard to read</strong></a>, and a <strong>heavier codebase</strong>.</p>
<p>The complexity of your layout has to exist <em>somewhere</em>. A component-first approach doesn’t remove “bloat,” it only <em>deports</em> it to the stylesheet. Even so, because your larger components reuse the same atomic styles as others, <strong>you inevitably end up with duplicate code</strong>.</p>
<pre><code>$green: #<span class="hljs-number">74</span>b759;
</code></pre><pre><code>.component {  &amp;-title {    <span class="hljs-attr">color</span>: $green;    font-weight: bold;  }}
</code></pre><pre><code>.widget {  &amp;-title {    <span class="hljs-attr">color</span>: $green;    font-style: italic;  }}
</code></pre><pre><code>.footer {  &amp;-links {   <span class="hljs-attr">color</span>: $green;   text-decoration: underline;  }}
</code></pre><p><em>Even with Sass, you get duplicate rules in the source code. <code>@mixin</code> can help, but you still get duplicates in the compiled CSS.</em></p>
<p>Now I know what you’re thinking. We got <code>@extend</code>. That’s an ideal use case for it, right?</p>
<p>Not so fast.</p>
<p><code>@extend</code> may avoid ruleset duplication in the compiled CSS, but the mega comma-separated selector it will generate could end up being <strong>a lot heavier than if you had duplicated the rule</strong>. So much for avoiding bloat.</p>
<p>You’re also concatenating unrelated classes <strong>and moving them all to the top</strong>, where the first <code>@extend</code> takes place. This can quickly result in specificity issues and odd overrides. Not to mention that you can’t <code>@extend</code> an outer class or placeholder from within a media query. So yeah, definitely not a silver bullet.</p>
<p>From a file size standpoint, <strong>you shouldn’t worry about repeated class names in the HTML</strong>. That’s what Gzip is for. The <em>deflate</em> algorithm was <a target="_blank" href="http://www.gzip.org/algorithm.txt">specifically made</a> to handle duplicate strings, so there’s no point in trimming away characters in your HTML. The resulting file size will make <strong>little to no difference</strong> whether you use a few or a lot of classes.</p>
<p>On the other hand, the more a <em>selector</em> is repeated in a stylesheet, <strong>the more work your browser has to do to resolve all styles</strong>. If you have a single <code>.title-green</code> class for a given style, it simply matches all <code>.title-green</code> in the page. But if you have many classes doing the same thing (using <code>@mixin</code>) or similar selectors doing different things (using <code>@extend</code>), the more expensive it will be for the browser to match.</p>
<p>HTML “bloat” doesn’t matter, <strong>but CSS does</strong>. The network and engine don’t care how many classes you have in your HTML, but the way you write your CSS counts. If your decision-making process revolves around performances, make sure you focus your attention on the right things.</p>
<h3 id="heading-bem-is-enough">“BEM is enough”</h3>
<p>OOCSS and all derived methods (SMACSS, BEM, etc.) drastically improved how we handle CSS. Utility-first CSS is an heir of this approach: it, too, defines reusable <em>objects</em>.</p>
<p>The problem with BEM is that it focuses on building components first. Instead of looking for the smallest, unsplittable patterns, you’re building <em>blocks</em> and their child <em>elements</em>. BEM does an excellent job at namespacing and preventing style leaks, but its component-first nature inevitably leads to <a target="_blank" href="http://wiki.c2.com/?PrematureAbstraction">premature abstraction</a>. You make a component for a certain use-case and end up never reusing it (a navbar component, for example).</p>
<p>BEM encourages you to use <em>modifiers</em> to handle component variations. This may seem smart at first, but unfortunately leads up to other problems. You end up creating tons of modifiers you only use once for a specific use-case. Worse: from one component to another, you might end up with similar modifiers, further breaking the <a target="_blank" href="https://en.wikipedia.org/wiki/Don%27t_repeat_yourself">DRY</a> principle.</p>
<pre><code>.card {  <span class="hljs-attr">background</span>: white;  border: <span class="hljs-number">1</span>px solid grey;  text-align: justify;}
</code></pre><pre><code>.card--left {  text-align: left;}
</code></pre><pre><code>.card--right {  text-align: right;}
</code></pre><pre><code>.tooltip {  <span class="hljs-attr">background</span>: black;  color: white;  text-align: center;}
</code></pre><pre><code><span class="hljs-comment">/* Oops, looks like duplicate rules down there! */</span>
</code></pre><pre><code>.tooltip--left {  text-align: left;}
</code></pre><pre><code>.tooltip--right {  text-align: right;}
</code></pre><p>At scale, components can become hard to change without breaking instances throughout a project. Premature abstraction keeps components from evolving and splitting into independent entities if they need to. Modifiers multiply as an attempt to fix it, resulting in non-reusable variations for unicorn use-cases, and undo band-aids when we realize our component does too much.</p>
<p>BEM is a great attempt at fixing inherent CSS problems, but making it the core CSS approach of your project brings all the problems you meet when favoring inheritance over composition.</p>
<h3 id="heading-its-a-whole-other-language-to-learn-on-top-of-css">“It’s a whole other language to learn on top of CSS”</h3>
<p>This statement can be said of any naming system for any specific project, whatever methodology you pick. Your CSS class names ecosystem is a layer of abstraction on top of pure CSS. Whether you’re using semantic names like <code>.card</code> or functional ones like <code>.bg</code>, new contributors will need to familiarize themselves with what does what and when to use it.</p>
<p>You can’t escape having to use a naming interface between your HTML and CSS, unless you’re willing to describe your exact markup in CSS or write inline styles. Ultimately, functional class names are <a target="_blank" href="https://frontstuff.io/in-defense-of-utility-first-css#its-ugly-and-hard-to-read">easier to understand</a> because they describe the style. You know what they do without having to lookup the actual styles, while semantic names force you to either look at the rendering or browse code.</p>
<h3 id="heading-its-unmaintainable">“It’s unmaintainable”</h3>
<p>When people say utility-first CSS is unmaintainable, they often mention that when something changes in the design, you have to change it everywhere. You have buttons with regular corners and you decide to make them rounded, so you need to add the <code>.rounded-corners</code> utility class on every button in the code. Yet, the whole point of utility-<em>first</em> is that you start composing with utility classes, and then create components when you start identifying repetitive patterns.</p>
<p>A button is an ideal and most obvious candidate for being abstracted into its own component. You might not even need to go through the “utility-first, then component” phase for this case. When it comes to larger components, favoring composition <em>first</em> is the best choice for maintainability. Why? <strong>Because it’s safer to add or remove classes on a specific HTML node</strong> than to add or remove styles in a class that applies on many elements.</p>
<p>Too many times have I been subjected to changing designs, and had to duplicate existing components to make them behave differently because I had no other choice. Even when a designer supplies all designs at the beginning of a project, and even if you do a great job at identifying components before you code, <strong>you can’t predict the future</strong>.</p>
<p>Let’s say initial designs have white cards with an inset box shadow and a little ribbon in the corner.</p>
<pre><code><span class="hljs-comment">// CSS</span>
</code></pre><pre><code>.card {  <span class="hljs-attr">position</span>: relative;  background: white;  padding: <span class="hljs-number">22</span>px;  border: <span class="hljs-number">1</span>px solid lightgrey;  text-align: justify;  border-radius: <span class="hljs-number">5</span>px;  box-shadow: <span class="hljs-number">0</span> <span class="hljs-number">0</span> <span class="hljs-number">5</span>px <span class="hljs-number">0</span> rgba(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">.2</span>);  overflow: hidden;}
</code></pre><pre><code>.card::after {  <span class="hljs-attr">position</span>: absolute;  top: <span class="hljs-number">-11</span>px;  right: <span class="hljs-number">9</span>px;  display: block;  width: <span class="hljs-number">10</span>px;  height: <span class="hljs-number">50</span>px;  background: red;  transform: rotateZ(<span class="hljs-number">-45</span>deg);  content: <span class="hljs-string">''</span>;}
</code></pre><pre><code><span class="hljs-comment">// HTML</span>
</code></pre><pre><code>&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"card"</span>&gt;...&lt;/div&gt;
</code></pre><p>This solution is simple, semantic, and reusable. You handle everything in CSS and have minimal HTML to write. But suddenly you get new designs for new pages, and they use the card without the ribbon. Now you have to find a way to remove the ribbon for these new cards.</p>
<pre><code>.card-no-ribbon::after {  <span class="hljs-attr">display</span>: none;}
</code></pre><p>Problem is, this class is <em>undoing</em> something that was previously designed. Having to <em>add</em> a class to <em>remove</em> a feature is an anti-pattern: <strong>it’s counter-intuitive and hard to maintain</strong>. When you decide to change how the base class behaves, you need to keep an eye on the undo modifier to make sure it still works.</p>
<p>We now need to add another ribbon to the bottom left.</p>
<pre><code>.card::before,.card::after {  <span class="hljs-comment">/* shared code */</span>}
</code></pre><pre><code>.card::before {  <span class="hljs-attr">top</span>: <span class="hljs-number">-11</span>px;  right: <span class="hljs-number">9</span>px;}
</code></pre><pre><code>.card::after {  <span class="hljs-attr">bottom</span>: <span class="hljs-number">-11</span>px;  left: <span class="hljs-number">9</span>px;}
</code></pre><p>But now we need to update <code>.card-no-ribbon</code>!</p>
<pre><code>.card-no-ribbon::before,.card-no-ribbon::after {  <span class="hljs-attr">display</span>: none;}
</code></pre><p>This, right here, <strong>is the fragile base class anti-pattern in action</strong>. Because your base class was abstracted too soon, is doing too much, and now needs to evolve, you can’t edit it without worrying about possible side-effects. If new people start contributing to the project, those risks multiply by ten.</p>
<p>The only option you have left this stage is to do a refactor: have a nude <code>.card</code> as the base class, and add the ribbons with <code>.card--top-ribbon</code> and <code>.card--bottom-ribbon</code> modifiers. But now you have to edit all the existing <code>.card</code>s in your code that <em>do</em> need to have a ribbon.</p>
<p><strong>Early refactors are a pretty good indicator of unmaintainability</strong>.</p>
<p>You could argue that a smart developer <em>could</em> have seen it coming. That they <em>should</em> have made a naked <code>.card</code> base class and a <code>.card--ribbon</code> modifier, right from the start.</p>
<p><strong>That’s actually making a case <em>in favor</em> of utility-first and composition</strong>.</p>
<p>You’re taking the decision to break down a given design element that you deemed too monolithic, so it’s easier to scale. <strong>That’s a good call.</strong> The more you go, the more you’ll realize this leads to utility-first.</p>
<p>You might think it doesn’t, and that your job is to <em>foresee</em> what is the bare minimum for a given component. But unless you own a crystal bowl, this is a risky assessment. This is also short-sighted. What if parts of your component need to be extended to other components? For example, what if you now need buttons with ribbons? If you duplicate the <code>.card--ribbon</code> class, your code isn’t DRY anymore, which makes it even more unmaintainable. So? Make a mixin and import it into both modifiers? Again, that’s extra work and “wet” code.</p>
<p>The best solution for this use-case is to write a single utility class for the ribbon, and modifiers for sizes and colors if necessary. This allows you to have <strong>a single source of truth</strong> and use the ribbon anywhere you want to. If you need to put ribbons on avatars, panels, unordered lists, modals, you can do it without having to write a single extra line of CSS.</p>
<p><strong>This is the definition of scalability and maintainability</strong>. All you have to do is reuse the available code you wrote <em>proactively</em>, instead of having to tweak existing code <em>reactively</em>.</p>
<pre><code>.ribbon {  <span class="hljs-attr">position</span>: relative;  overflow: hidden;}
</code></pre><pre><code>.ribbon::after {  <span class="hljs-attr">position</span>: absolute;  display: block;  top: <span class="hljs-number">-11</span>px;  right: <span class="hljs-number">9</span>px;  width: <span class="hljs-number">10</span>px;  height: <span class="hljs-number">50</span>px;  background: red;  transform: rotateZ(<span class="hljs-number">-45</span>deg);  content: <span class="hljs-string">''</span>;}
</code></pre><p><em>By breaking down designs into small elements, we write much more reusable code.</em></p>
<p>Calling utility-first CSS “unmaintainable” is absolutely inaccurate. In fact, <strong>it may be the most maintainable and scalable CSS methodology to this day.</strong></p>
<p>You can’t predict the future. This is why you should always favor composition over inheritance. <strong>A good sign of a healthy and scalable codebase is how things go when you need to change it.</strong></p>
<p>If a new change makes you anxious because you might break something, it’s a sign of poor design. But I would go a step further and say that if you need to write new CSS to make an existing component do something that another component already does, your code isn’t as scalable as you think it is.</p>
<p>If you need to reuse behavior that exists somewhere, <strong>you shouldn’t have to write new code</strong>. You should be able to trust and use what you already wrote and go from there. You have one source of truth on which you can rely, instead of two or more slight variations that you must not forget to keep up to date. <strong>This is the definition of maintainability.</strong></p>
<h3 id="heading-its-ugly-and-hard-to-read">“It’s ugly and hard to read”</h3>
<p>Do you remember the uproar when BEM started to become popular? I do. I remember many people who rejected the whole thing because of its syntax. Praising the model, but disgusted with the idea of chaining two underscores or two hyphens.</p>
<p>As humans, it’s in our nature to be easily put off by what we’re not familiar with. Yet, letting subjective cosmetic considerations come in the way of a potentially useful technique is where developers should draw the line. Our job is to <strong>solve problems</strong>. Our main concern should be <strong>the end user</strong>.</p>
<p>Look at the source code of many big projects: most of them have ended up adopting BEM. Chances are not all their front-end developers were sold at the beginning.</p>
<p>Overcoming initial feelings, especially if driven by personal preference, isn’t that hard <strong>when you’re putting the success of a project first</strong>.</p>
<p>Now on the topic of legibility, I get that long strings of classes can be “scary” when you open a file for the first time. This is not an insurmountable task though. More verbose code is a trade-off of composition, but it’s a <strong>much lesser inconvenience than unscalability</strong>.</p>
<p>I don’t use shorthands like <code>.pt-8</code> or <code>.bb-lemon</code> in my own code. I favor full-length class names like <code>.padding-top-8</code> and <code>.border-bottom-lemon</code>, which are much easier to read. Autocomplete solves the problem of having to type long class names, and there are tools you can use to re-hash class names into smaller ones for production. I doubt this will make any significant change to your performances but hey, if it makes you feel good to shave bytes away, knock yourself out ?</p>
<p>Ultimately, the nature of functional class names might actually be <strong>more expressive</strong>. It’s easy for your brain to make a connection between such a class and what’s happening on screen. Even if you don’t get to see how it renders, you can get a pretty good idea of what <code>.hidden</code> or <code>.opacity-6</code> are supposed to do.</p>
<pre><code>&lt;blockquote <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"border-thick-left-red padding-left-medium font-navy"</span>&gt;  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>You know how they call a Quarter Pounder with Cheese in Paris?<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>&lt;/blockquote&gt;
</code></pre><p><em>Stylistically speaking, it’s pretty easy to know what’s going on here.</em></p>
<p>Semantic class names don’t convey the same thing. It works for small components like buttons or alerts, which are common enough to be easily recognized. Yet, the bigger and the more complex a component gets, the less obvious it is to know what class name maps to what element on the screen, or what it looks like.</p>
<pre><code>&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"entry"</span>&gt;  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"entry-title"</span>&gt;</span>The Shining<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span></span>  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"widget widget-lead"</span>&gt;</span>    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"widget-content"</span>&gt;</span>      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>His breath stopped in a gasp. An almost drowsy terror stole through his veins...<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"author"</span>&gt;</span>      <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"author-avatar"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"..."</span>&gt;</span>      <span class="hljs-tag">&lt;<span class="hljs-name">h3</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"author-name"</span>&gt;</span>Stephen King<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Stephen Edwin King (born September 21, 1947) is an American author of horror, supernatural fiction, suspense, science fiction, and fantasy...<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"btn-group"</span>&gt;</span>        <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"btn"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>;Website<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>        <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"btn"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Twitter<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
</code></pre><p><em>Harder to know what class does what without going through the stylesheet.</em></p>
<p>In that way, functional classes are a lot easier to understand than semantic class names. They demand less catching up time and less file-switching. Ultimately, they give you the very bit of information you’re looking for anyways.</p>
<h3 id="heading-its-not-how-you-write-css">“It’s not how you write CSS”</h3>
<p><strong>CSS specificity is a <em>feature</em>, not a bug.</strong> Use it correctly, and it will give you amazing control.</p>
<p>That’s what CSS veterans say when yet another article about the dangers of specificity pops up. And technically <strong>they’re right</strong>: the CSS priority system isn’t an accident. It usually bothers people who don’t master CSS because of the lack of scope. But a language isn’t broken because it doesn’t behave like what you’re used to. Nested CSS rules are like <code>!important</code>: they’re handy, but have been so poorly used for years that we now see it as something to <em>avoid</em>.</p>
<p>Specificity should be used proactively, not reactively. They should be <em>design decisions</em>, not a quick fix when your styles don’t apply. Harry Roberts explains it well in <a target="_blank" href="https://cssguidelin.es/#specificity">CSS Guidelines</a>:</p>
<blockquote>
<p>“The problem with specificity isn’t necessarily that it’s high or low; it’s the fact it is so variant and that it cannot be opted out of: the only way to deal with it is to get progressively more specific”.</p>
</blockquote>
<p>Specificity is a powerful tool, but it needs to be used with uppermost caution and a good long-term vision of the project. Use them wrong, and you’ll feel the pain of having to go back. Keeping specificity low avoids problems altogether: it relies solely on source order, which is <a target="_blank" href="https://www.xfive.co/blog/itcss-scalable-maintainable-css-architecture">a lot easier to manage</a>. With atomic CSS, if a style doesn’t apply, fixing it is as simple as adding or removing a class on an HTML node. You don’t have to call your stylesheet’s structure into question, which is a lot easier and safer to manage.</p>
<pre><code><span class="hljs-comment">// CSS</span>
</code></pre><pre><code>.color-navy {  <span class="hljs-attr">color</span>: navy;}
</code></pre><pre><code>.color-red {  <span class="hljs-attr">color</span>: red;}
</code></pre><pre><code><span class="hljs-comment">// HTML</span>
</code></pre><pre><code>&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"color-red color-navy"</span>&gt;  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>- Whose motorcycle is this?<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>- It's a chopper baby.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>- Whose chopper is this?<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>- It's Zed's.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>- Who's Zed?<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>- Zed's dead baby, Zed's dead.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>&lt;/div&gt;
</code></pre><p><em>Want the text to be navy? No need to touch the CSS. Simply remove the <code>.color-red</code> class from the encompassing <code>&lt;d</code>iv&gt;. If you need one of the children to be red, then mov<code>e the .col</code>or-red</em> on it.</p>
<blockquote>
<p>“If a feature is sometimes dangerous, and there is a better option, then always use the better option.” — Douglas Crockford</p>
</blockquote>
<p>Using specificity or not isn’t about showing how well you master CSS and how <em>you</em>, unlike others, can keep it under control. It’s about <strong>understanding the advantages and flaws of the features at your disposal</strong>, and making choices in the best interest of the project.</p>
<h3 id="heading-you-end-up-with-plenty-of-unused-css">“You end up with plenty of unused CSS”</h3>
<p>Let’s say you’re using Sass maps to <a target="_blank" href="http://frontstuff.io/generate-all-your-utility-classes-with-sass-maps">generate your utility classes</a>. Colors, font sizes, backgrounds, everything is automatically compiled into proper, ready-to-use CSS. Problem is, if you don’t <em>use</em> everything, you’re left with useless extra bytes in production. This can easily be fixed with <a target="_blank" href="https://github.com/giakki/uncss">UnCSS</a>.</p>
<p>UnCSS is great at dusting off your stylesheets, but it comes with <strong>two caveats</strong>: it only works on HTML files (so, no PHP and no template files) and it only takes into account the JavaScript that’s executed on page load (not classes added on user interactions, for example). If you’re using a language like PHP to render your pages, you can add a job in your deployment workflow that compiles pages into temporary HTML and runs UnCSS on them. For the second issue, you can use the <code>ignore</code> option to list out that are classes added on user interaction.</p>
<p>Now it’s also important to ponder this issue. The cost of unused classes is heavier stylesheets (longer to download) and longer parse time. If you have a lot, and by that I mean a large percentage of your total styles, of unused classes, <strong>this can hurt performances</strong>. If you only have a few here and there, <strong>the impact will be negligible</strong>.</p>
<p>Maintaining your CSS codebase is your job as a developer. No matter what methodology you choose, you have to keep an eye on the project and make sure to remove dead code when things change.</p>
<p><strong>Being careless with that is how you end up with plenty of unused classes, not because you’re generating some of them</strong>.</p>
<p>Need a text color class only for the main color? Make a class for this one only. Need backgrounds for most colors in the theme, yet unsure you’ll use them all right away? Generate the damn classes. They’ll be ready when you need them, you won’t have to maintain them when you add new colors, and the extra code will cost <em>nothing</em>. <strong>This is not where your app’s bottlenecks are</strong>. If you’re having performances issues, there are a million other things to consider before even looking into your CSS.</p>
<h3 id="heading-it-makes-it-hard-to-know-whats-available-to-use">“It makes it hard to know what’s available to use”</h3>
<p>When your CSS codebase is a large collection of small utility classes, reading the source code won’t help you get a good overview of the available styles. But <strong>is it the role of the source code anyway</strong>?</p>
<p>It certainly isn’t. That’s what <strong>style guides</strong> are for.</p>
<p>Exploring source code is <em>far</em> from being enough to get a good understanding of how a full API is designed. This isn’t limited to atomic CSS: OOCSS or BEM projects, even small ones, can reach a level of sophistication which requires at least a <code>README</code>.</p>
<p>Can you imagine having to crawl back in an unminifed version of the master Bootstrap stylesheet every time you don’t remember if this is <code>.col-md-offset-6</code> or <code>.col-offset-md-6</code>? Would anyone new to Bootstrap understand what such a class means without a little literature on how the grid works? Documentation, style guides, and API references are designed to help us make sense of complex systems. Sure, it doesn’t mean documentation should justify poor design and unclear naming conventions, but thinking you should be able to understand an entire project only by reading the source code is pure fantasy.</p>
<p>There are plenty of tools out there to help you generate documentation right from your code. I use <a target="_blank" href="http://warpspire.com/kss/syntax">KSS</a> for most of my projects, but CSS-Tricks shares a <a target="_blank" href="https://css-tricks.com/options-programmatically-documenting-css">list of alternatives</a>. Give it a try!</p>
<h3 id="heading-utility-classes-should-be-used-along-with-components">“Utility classes should be used along with components”</h3>
<p>Yes. Absolutely. That’s precisely why it’s called utility-<em>first</em> and not utility-<em>only</em>.</p>
<p>Utility-first isn’t about ditching components altogether. It means you should start off with utility classes, make the most of them, and only abstract when you see repeating patterns. You’re allowing your project to grow while remaining flexible, and identifying actual components over time, when patterns start to emerge.</p>
<p>It is crucial to understand that a component isn’t <em>just</em> a similar-looking “block” that you <em>can</em> reuse. It’s a pattern that is strongly tied to your specific project. Sure, you’re probably going to use tons of <code>.btn</code> and <code>.modal</code>, so it makes sense to abstract them early on. But are you positive you’re going to ever reuse <code>.testimonial</code>? Or at least reuse it <em>enough</em> to make it worth being a new component? Will it always look like this in every context, or is it specific to the homepage? Keep your options open. It’s a lot easier to later abstract a composite style into a component than to try and undo one.</p>
<h3 id="heading-it-makes-redesigningtheming-a-nightmare">“It makes redesigning/theming a nightmare”</h3>
<p>Because atomic CSS is strongly tied to your design, this can make things more difficult when you have to do a redesign or develop an alternate theme. It’s far from impossible though, and there are a few things you can do to make your utility-first CSS more suited to these kinds of needs.</p>
<p>You can start by keeping class names not too specific. Instead of <code>.margin-bottom-8</code>, you can use a more abstract name like <code>.margin-bottom-xxs</code>. This way you can change the value without making the names invalid.</p>
<p>Another approach would be to create <strong>aliases</strong>. Imagine you’re building an app that has light and dark mode: some colors would change, some others wouldn’t. We don’t want to make all our color utilities contextual: <code>.background-primary</code> and <code>.background-secondary</code> don’t tell us what color is behind the class. You don’t want an entire color system like that. Yet, you could still have color utilities with proper color names (<code>.background-lime</code> or <code>.background-red</code>), and generate aliases for those which might need to change for theming purposes.</p>
<pre><code><span class="hljs-comment">// CSS</span>
</code></pre><pre><code><span class="hljs-comment">/* Backgrounds */</span>
</code></pre><pre><code>.background-lime {  <span class="hljs-attr">background</span>: #cdf2b0;}
</code></pre><pre><code>.background-off-white, .background-light {  <span class="hljs-attr">background</span>: #ebefe8;}
</code></pre><pre><code>.background-dark-grey, .background-dark {  <span class="hljs-attr">background</span>: #<span class="hljs-number">494</span>a4f;}
</code></pre><pre><code><span class="hljs-comment">/* Colors */</span>
</code></pre><pre><code>.color-lime {  <span class="hljs-attr">color</span>: #cdf2b0;}
</code></pre><pre><code>.color-off-white, .color-light {  <span class="hljs-attr">color</span>: #ebefe8;}
</code></pre><pre><code>.color-dark-grey, .color-dark {  <span class="hljs-attr">color</span>: #<span class="hljs-number">494</span>a4f;}
</code></pre><pre><code><span class="hljs-comment">// HTML</span>
</code></pre><pre><code>&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"background-light"</span>&gt;  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"color-lime"</span>&gt;</span>Ezekiel 25:17<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span></span>  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"color-dark"</span>&gt;</span>The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men...<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>&lt;/div&gt;
</code></pre><p>From here, all you have to do is write a JavaScript function that toggles all <code>.*-light</code> and <code>.*-dark</code> classes. And for elements that don’t need to change, you can use the original color classes.</p>
<p>This method works well, but if you have a lot of classes to switch it may end up hurting performances. DOM manipulations are expensive. You want to reduce them as much as possible if you can. Luckily, there’s a nifty technique involving CSS variables (thanks to Adam Wathan for coming up with it) which makes everything simpler.</p>
<pre><code><span class="hljs-comment">// CSS</span>
</code></pre><pre><code>:root {  --green: #<span class="hljs-number">42</span>f49b;  --off-white: #ebefe8;  --dark-grey: #<span class="hljs-number">494</span>a4f;}
</code></pre><pre><code>.theme-dark {  --background: <span class="hljs-keyword">var</span>(--dark-grey);  --text: <span class="hljs-keyword">var</span>(--off-white);}
</code></pre><pre><code>.theme-light {  --background: <span class="hljs-keyword">var</span>(--off-white);  --text: <span class="hljs-keyword">var</span>(--dark-grey);}
</code></pre><pre><code>.color-lime {  <span class="hljs-attr">color</span>: <span class="hljs-keyword">var</span>(--green);}
</code></pre><pre><code>.color-theme {  <span class="hljs-attr">color</span>: <span class="hljs-keyword">var</span>(--text);}
</code></pre><pre><code>.background-theme {  <span class="hljs-attr">background</span>: <span class="hljs-keyword">var</span>(--background);}
</code></pre><pre><code><span class="hljs-comment">// HTML</span>
</code></pre><pre><code>&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"theme-light"</span>&gt;  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"background-theme"</span>&gt;</span>  <span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"color-lime"</span>&gt;</span>Ezekiel 25:17<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>  <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"color-theme"</span>&gt;</span>The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men...<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>&lt;/div&gt;
</code></pre><p>We defined colors with CSS variables and assigned different values for each context. Depending on the encompassing class, <a target="_blank" href="https://jsfiddle.net/hurmktbz">all colors will change thanks to ancestor inheritance</a>. If you were to allow theme switching, all you’d have to do is change <code>.theme-light</code> into <code>.theme-dark</code> on the parent <code>&lt;d</code>iv&gt;, and all colors would adapt.</p>
<p>This technique only works if you don’t have to support Internet Explorer and Edge below version 15. Otherwise, go for the first technique and use CSS ancestor inheritance system to avoid having to toggle too many variables. If you have to assign a text color to an entire block, <strong>set it on the parent instead of the children</strong>.</p>
<pre><code><span class="hljs-comment">/* Nope */</span>&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"background-light"</span>&gt;  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"color-lime"</span>&gt;</span>Ezekiel 25:17<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span></span>  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"color-dark"</span>&gt;</span>The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"color-dark"</span>&gt;</span>Blessed is he, who in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"color-dark"</span>&gt;</span>And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy my brothers.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"color-dark"</span>&gt;</span>And you will know my name is the Lord when I lay my vengeance upon thee.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>&lt;/div&gt;
</code></pre><pre><code><span class="hljs-comment">/* Yes */</span>&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"background-light color-dark"</span>&gt;  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"color-lime"</span>&gt;</span>Ezekiel 25:17<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span></span>  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>The path of the righteous man is beset on all sides by the inequities of the selfish and the tyranny of evil men.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Blessed is he, who in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy my brothers.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>And you will know my name is the Lord when I lay my vengeance upon thee.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>&lt;/div&gt;
</code></pre><h3 id="heading-embracing-change-within-reason">Embracing change, within reason</h3>
<p>Having strong opinions is great. Not everything has to be settled by finding a middle ground. But there’s a clear line to draw between <strong>being opinionated</strong> and <strong>being reluctant to change</strong>.</p>
<p>We, as developers, <strong>must be the first to embrace change</strong>. Looking back at my first reaction towards utility-first CSS, I realize how important it is we keep an open mind instead of rushing to pick a side. <strong>It doesn’t matter how experienced <em>we think</em> we are</strong>. Experience is great, but it can also make us believe we already have all we need to make judgment calls and don’t need to dive deeper to understand new concepts.</p>
<p><strong>Software development changes every day</strong>. Our industry is still young, and we’re figuring things out as we go. It doesn’t mean we should throw away the past, and continuously refactor all our projects to keep up with the latest trends. Past knowledge is the foundation of today’s discoveries. But just because something is tried and true, doesn’t mean it’s set in stone. It’s important we approach novelty with critical thinking.</p>
<p>We’ll probably move on from utility-first CSS at some point, like how we got past many things we used to consider the pinnacle of front-end development. In the meantime, let’s try to stay as open-minded as possible, and <strong>do what’s best for the industry, the projects, and the users</strong>.</p>
<p>Want to learn more about utility-first CSS and how to use it in your projects? Go read <a target="_blank" href="https://css-tricks.com/growing-popularity-atomic-css/">On the Growing Popularity of Atomic CSS</a> on CSS Tricks and <a target="_blank" href="https://adamwathan.me/css-utility-classes-and-separation-of-concerns">CSS Utility Classes and “Separation of Concerns”</a> on Adam Wathan’s blog. You can also check out utility-first libraries on this <a target="_blank" href="https://css-tricks.com/need-css-utility-library/">curated list</a> by CSS Tricks.</p>
<p>Originally published at <a target="_blank" href="https://frontstuff.io/in-defense-of-utility-first-css">frontstuff.io</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
