<?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[ Ramazan Maksyutov - 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[ Ramazan Maksyutov - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Tue, 05 May 2026 22:19:16 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/author/ramazanmaksyutov/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How Atomic CSS and Functional Programming Are Related ]]>
                </title>
                <description>
                    <![CDATA[ Hello, friends! My name is Ramazan, and I'm a front-end developer and enthusiast who loves looking at familiar things in web development from new perspectives. You might have heard of functional progr ]]>
                </description>
                <link>https://www.freecodecamp.org/news/atomic-and-functional-css/</link>
                <guid isPermaLink="false">69bc348fb238fd45a320a2f7</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ layout ]]>
                    </category>
                
                    <category>
                        <![CDATA[ atomic css ]]>
                    </category>
                
                    <category>
                        <![CDATA[ mlut ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Tailwind CSS ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ramazan Maksyutov ]]>
                </dc:creator>
                <pubDate>Thu, 19 Mar 2026 17:38:23 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/uploads/covers/5e1e335a7a1d3fcc59028c64/64d0d72a-075e-42a9-b0fb-ca577f950999.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Hello, friends!</p>
<p>My name is Ramazan, and I'm a front-end developer and enthusiast who loves looking at familiar things in web development from new perspectives.</p>
<p>You might have heard of functional programming (FP). It's a paradigm characterised by the use of pure functions and the preservation of data immutability. There are even languages in which FP principles prevail, like Haskell, OCaml, and Elixir. Other languages like JavaScript, Python, and C++ also support this approach, although they're not limited to it.</p>
<p>But an attentive reader will look at the title and ask: "Functional programming is fine. But what does Atomic CSS have to do with it?" I'll answer that now!</p>
<p>The thing is, back when the atomic approach first appeared, it had another name: Functional CSS. Some people still use it quite often today to avoid confusion with other terms with the same <a href="https://css-tricks.com/the-atomics/">name</a>. But why is this approach to writing CSS called functional?</p>
<p>That's the question I'll try to answer in this article. First, I'll describe the basic principles of FP. Then, I'll talk about the basics of Atomic CSS (which I'll refer to here as ACSS), drawing analogies with functional programming. I'll also try to use simple examples to show what problems you can solve by applying Atomic CSS to styling.</p>
<p>When preparing the materials for this article, I relied a lot on <a href="https://www.youtube.com/watch?v=7g0BHu0kWXo">this tutorial</a> on FP and <a href="https://www.youtube.com/watch?v=uHVqbCPnOwU">this one</a> on Functional CSS.</p>
<p>Well, let's get started!</p>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>To follow along with this article, all you need is a basic understanding of HTML, CSS, and JavaScript. There are also some examples where we'll use the Atomic CSS framework <a href="https://mlut.style/">mlut</a>, but you don't have to know its syntax because I've provided the text with the equivalent CSS styles.</p>
<h2 id="heading-what-well-cover">What We'll Cover:</h2>
<ol>
<li><p><a href="#heading-the-basic-principles-of-functional-programming">The Basic Principles of Functional Programming</a></p>
<ul>
<li><p><a href="#heading-pure-functions">Pure Functions</a></p>
</li>
<li><p><a href="#heading-immutability">Immutability</a></p>
</li>
<li><p><a href="#heading-function-composition">Function Composition</a></p>
</li>
</ul>
</li>
<li><p><a href="#heading-how-the-principles-of-fp-meet-their-incarnation-in-atomic-css">How the Principles of FP Meet Their Incarnation in Atomic CSS</a></p>
<ul>
<li><p><a href="#heading-purity">Purity</a></p>
</li>
<li><p><a href="#heading-immutability-in-acss">Immutability in ACSS</a></p>
</li>
<li><p><a href="#heading-composition">Composition</a></p>
</li>
</ul>
</li>
<li><p><a href="#heading-conclusion">Conclusion</a></p>
</li>
</ol>
<h2 id="heading-the-basic-principles-of-functional-programming">The Basic Principles of Functional Programming</h2>
<p>Functional programming is a broad field that has been the subject of numerous complex articles and an entire scientific <a href="https://www.cambridge.org/core/journals/journal-of-functional-programming">journal</a>. So in my article, I'll focus on exploring only the basic principles of FP and drawing analogies with them in Atomic CSS.</p>
<p>This approach is based on the idea that all the actions we need to perform in a program should be done by calling certain functions and their compositions.</p>
<p>Let me outline the main concepts I'll use to explain the core idea of this approach:</p>
<ol>
<li><p>Pure functions</p>
</li>
<li><p>Immutability</p>
</li>
<li><p>Function composition</p>
</li>
</ol>
<h3 id="heading-pure-functions">Pure Functions</h3>
<p>A function is called pure if it:</p>
<ul>
<li><p>returns the same value for the same input parameters;</p>
</li>
<li><p>has no side effects (changes to external values or entities).</p>
</li>
</ul>
<p>Here are a couple of examples to illustrate this:</p>
<pre><code class="language-javascript">let c = 10;
let s = 0;

// Pure function
function pureSum(a,b) {
  return a + b
}

// Impure function
function notPureSum (a) {
  s = a + c
  return s
}
</code></pre>
<p>The first function is pure because if we enter the same arguments, we'll get the same result. Also, this function doesn't change any global variables and doesn't mutate objects.</p>
<p>The second function doesn't meet the concept of purity on both points. It changes the external variable <code>s</code> and uses another external variable <code>c</code> for calculations, which can change.</p>
<p>Pure functions allow you to write more predictable code. An application can grow and a function with an implicit parameter that can change over time can lead to great difficulties in debugging and maintaining the codebase.</p>
<h3 id="heading-immutability">Immutability</h3>
<p>Immutability is a principle which states that data objects shouldn't change after they're created. To make changes to data, you need to create a new instance of it and then work with that new copy.</p>
<p>At first glance, it may seem that this approach limits flexibility in the development process and reduces the speed of the program. But in reality, if the language or runtime has optimisations for immutable data, adhering to this principle helps you avoid many errors and use parallel calculations.</p>
<p>Here's a fairly simple example: let's take a React component that renders a task in a to-do list. The state of the task is described by an object. And in order for React to correctly redraw the state of the task component when the user changes something in it, it's necessary to pass as the new state not the mutated old object, but a new instance of the object with the current state. Here is the example where an immutable object is used for the state of the to-do:</p>
<pre><code class="language-JS">import { useState } from "react";

function TodoItem() {
  const [todo, setTodo] = useState({
    text: "Write article",
    done: false
  });

  const toggleDone = () =&gt; {
    setTodo({
      ...todo,
      done: !todo.done
    });
  };

  return (
    &lt;div&gt;
      &lt;span&gt;
        {todo.text} — {todo.done ? "✅" : "❌"}
      &lt;/span&gt;
      &lt;button onClick={toggleDone}&gt;
        Toggle
      &lt;/button&gt;
    &lt;/div&gt;
  );
}

export default TodoItem;
</code></pre>
<p>Here we'll see that clicking on the button will lead to changes in the state of the to-do and will cause re-rendering of the component. But we could define the function <code>toggleDone()</code> in a different way using mutations of the object:</p>
<pre><code class="language-JS">const toggleDone = () =&gt; {
  todo.done = !todo.done;
  setTodo(todo);
};
</code></pre>
<p>With such an event handler, the effect will not work because the link to the object is still the same, even though the object itself was mutated.</p>
<h3 id="heading-function-composition">Function Composition</h3>
<p>Function composition involves using the result of one function as an argument for another function. Here's an example of a program that capitalises the first letter of each word:</p>
<pre><code class="language-javascript">function compose(f1, f2) {
  return function (str) {
    return f1(f2(str));
  }
}

function makeFirstCapital(str) {
  return str.charAt(0).toUpperCase() + str.slice(1);
}

function upperEveryFirst(str) {
  return str.split(' ').map(makeFirstCapital).join(' ');
}

function lower(str) {
  return str.toLowerCase();
}

const capitalize = compose(upperEveryFirst, lower);
const string = 'this sTring should be Capitalized'

console.log(capitalize(string)) // 'This String Should Be Capitalized'
</code></pre>
<p>Here, we have defined the function <code>compose(f1, f2)</code>, which returns the composition of the functions passed to it in arguments. Next, we use this function to create the function <code>capitalise()</code>, which will capitalise only the first letters of words by composing the functions <code>lower()</code> and <code>upperEveryFirst()</code>. The first one is executed first and returns a string with all lowercase letters to the second function as an argument. The second function capitalises the first letter of each word.</p>
<p>In large projects and when complex calculations are required, such compositions can be larger, and the logic in them can be much richer. In such cases, this approach to calculations helps break down very large transformations into a series of relatively simple and compact functions that are applied one after the other. This makes it easier to develop, refactor, and debug code.</p>
<h2 id="heading-how-the-principles-of-fp-meet-their-incarnation-in-atomic-css">How the Principles of FP Meet Their Incarnation in Atomic CSS</h2>
<p>Now that we know a little about functional programming, let's try to answer the question: ‘What does Atomic CSS have to do with it?’ Let's draw an analogy between these approaches at the level of the principles described above.</p>
<h3 id="heading-what-is-atomic-css">What is Atomic CSS?</h3>
<p>But first, let's take a moment to explain what Atomic CSS is. It's a methodology of styling layouts in which we use small Atomic CSS rules, each of which performs a single action. These classes are called utilities. They usually apply one CSS property, but not necessarily just one.</p>
<p>For example, in the mlut framework, the <code>Bgc-red</code> utility corresponds to the <code>background-colour: red</code> property, and the <code>-Sz50p</code> utility corresponds to two properties at once: <code>width: 50%</code> and <code>height: 50%</code>.</p>
<p>Modern Atomic CSS frameworks, such as mlut and Tailwind, use a so-called JIT engine. This is a component that generates CSS based only on the utilities you used in your markup.</p>
<h3 id="heading-purity">Purity</h3>
<p>Purity in CSS is determined by which selectors, or more specifically, classes, are used to style elements. In clean CSS, the behaviour of an element should be determined solely by the classes that are attached to it in the <code>class</code> attribute. This means that, ideally, a stylesheet should not contain selectors such as <code>section</code> or <code>div &gt; ul</code>.</p>
<p>Firstly, they set too general rules, which are likely to be broken or supplemented in one part of the project or another. So when we style specific elements, we'll have to constantly keep these styles in mind in order to understand how to achieve the necessary styling without spoiling anything.</p>
<p>Secondly, the purity of CSS for each specific element is violated. Let's say we have the following markup:</p>
<pre><code class="language-html">&lt;button class="greeting"&gt;Hello!&lt;/button&gt;
&lt;div class="wrapper"&gt;
  &lt;button class="greeting"&gt;Hello!&lt;/button&gt;
&lt;/div&gt;
</code></pre>
<p>With the CSS styles below:</p>
<pre><code class="language-CSS">.wrapper &gt; .greeting {
  background-color: green;
}
.greeting {
  background-color: red;
}
</code></pre>
<p>As a result, we get that the first button is red, and the nested one is green. It seems pretty harmless in this simple case, but it will cause inconvenience when the project structure grows significantly.</p>
<p>Here we see that the result of the <code>.greeting</code> class's custom styles depends on where the corresponding element is located. This is similar to a function that produces different results for the same input data depending on where it's called.</p>
<p>Atomic CSS allows you to avoid this effect. In this approach, in most cases, styles are applied only to those elements for which the corresponding classes are specified. If you need to make several identical elements, the same utility is specified in the <code>class</code> attribute of each such element.</p>
<p>A similar example can be rewritten in mlut like this:</p>
<pre><code class="language-HTML">&lt;button class="Bgc-red"&gt;Hello!&lt;/button&gt;
&lt;div&gt;
  &lt;button class="Bgc-green"&gt;Hello!&lt;/button&gt;
&lt;/div&gt;
</code></pre>
<p>And JIT-engine will generate the following styles:</p>
<pre><code class="language-CSS">.Bgc-red {
  background-color: red;
}

.Bgc-green {
  background-color: green;
}
</code></pre>
<p>Here we can see that the styles of elements in this approach will depend only on the classes assigned to them.</p>
<p>It's worth noting here that the mlut syntax allows you to do things that deviate from the strict concept of CSS purity. Sometimes this is necessary to create relatively more complex effects.</p>
<p>Let's say we want to implement a card that changes the background colour of the button inside it when hovered. Then we would need to write the following in mlut:</p>
<pre><code class="language-html">&lt;div class="-Ctx"&gt;
  &lt;button class="^:h_Bgc-red"&gt;Greeting&lt;/button&gt;
&lt;/div&gt;
</code></pre>
<p>CSS:</p>
<pre><code class="language-css">.-Ctx:hover .\^\:h_Bgc-red {
  background-color: red;
}
</code></pre>
<h3 id="heading-immutability-in-acss">Immutability in ACSS</h3>
<p>By CSS immutability, I mean that element styles are not rewritten. Immutability in ACSS means that utilities do not typically mutate each other.</p>
<p>For example, in BEM (Block Element Modifier), the main styles are set by a block or element, and a modifier mutates these styles. In other approaches that use combined selectors, such mutations occur more often and less explicitly.</p>
<p>Let me give you a simple example. Suppose we have a product card that can be in its default state or in a highlighted state. In BEM it would look like this:</p>
<pre><code class="language-html">&lt;div class="product-card"&gt;Card 1&lt;/div&gt;
&lt;div class="product-card product-card--selected"&gt;Card 2&lt;/div&gt;
&lt;div class="product-card"&gt;Card 3&lt;/div&gt;
</code></pre>
<pre><code class="language-css">.product-card {
  background-color: red;
  padding: 5px;
}

.product-card--selected {
  background-color: green;
}
</code></pre>
<p>In this example, we see that the <code>product-card</code> class sets the default background colour of the card to red. And in order to somehow mark the selected card with a different background colour we have to add a modifier class that changes the colour from red to green. It does this by rewriting the <code>background-color</code> property, that is by mutating the block styles.</p>
<p>In the Atomic CSS approach, this problem is solved because utilities allow you to set CSS properties independently of each other and apply modifications without resorting to mutation.</p>
<p>Here's what this example would look like if you used mlut:</p>
<pre><code class="language-html">&lt;div class="P5 Bgc-red"&gt;Card 1&lt;/div&gt;
&lt;div class="P5 Bgc-green"&gt;Card 2&lt;/div&gt;
&lt;div class="P5 Bgc-red"&gt;Card 3&lt;/div&gt;
</code></pre>
<pre><code class="language-css">.P5 {
  padding: 5px;
}

.Bgc-red {
  background-color: red;
}

.Bgc-green {
  background-color: green;
}
</code></pre>
<h3 id="heading-composition">Composition</h3>
<p>Functional programming makes extensive use of function composition. In Atomic CSS, function composition is analogous to utility composition when styling elements. Just as in FP we obtain complex behaviour through the sequential application of a set of simple functions, so in ACSS we can obtain non-trivial styling through a set of simple utilities.</p>
<p>As an example, I'll show a simple smiley face made using only Atomic CSS:</p>
<pre><code class="language-html">&lt;div class="-Sz150 Bgc-yellow Bdrd100p M-a Ps"&gt;
  &lt;div class="-Sz20p Bgc-gray Bdrd100p Ps-a T30p L20p"&gt;&lt;/div&gt;
  &lt;div class="-Sz20p Bgc-gray Bdrd100p Ps-a T30p R20p"&gt;&lt;/div&gt;
  &lt;div class="W50p H40p Bdb5;s;gray Bdrd100p Ps-a T40p L25p"&gt;&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<pre><code class="language-css">.-Sz150 {
  width: 150px;
  height: 150px;
}

.Bgc-yellow {
  background-color: yellow;
}

.Bdrd100p {
  border-radius: 100%;
}

.M-a {
  margin: auto;
}

.Ps {
  position: relative;
}

.-Sz20p {
  width: 20%;
  height: 20%;
}

.Bgc-gray {
  background-color: gray;
}

.Ps-a {
  position: absolute;
}

.T30p {
  top: 30%;
}

.L20p {
  left: 20%;
}

.R20p {
  right: 20%;
}

.W50p {
  width: 50%;
}

.H40p {
  height: 40%;
}

.Bdb5;s;gray {
  border-bottom: 5px solid gray;
}

.T40p {
  top: 40%;
}

.L25p {
  left: 25%;
}
</code></pre>
<p>This is how our result will look:</p>
<img src="https://cdn.hashnode.com/uploads/covers/69844106d7e8f3ad9f2dd000/de19a0ca-af4e-45f4-8a90-1a0f55db7950.png" alt="Smiley face" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p>Thus, by applying the utilities one after another, we even made some small CSS art.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>To sum up, I will say that Atomic CSS truly embodies the basic principles of functional programming. Of course, not literally – but in the sense that is relevant for front-end developers and layout designers.</p>
<p>I would be happy to hear your additions and objections – it'll be interesting to read and think about them.</p>
<p>Finally, I would like to say: look at familiar things with a fresh perspective. And, as usual, I wish you success on your exciting journey of front-end development!</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
