<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Little Coding Things</title>
    <link>https://littlecodingthings.com/</link>
    <atom:link href="https://littlecodingthings.com/rss.xml" rel="self" type="application/rss+xml"/>
    <description>Learn web development one little thing at a time. Practical tutorials on JavaScript, CSS, HTML, React, and modern frontend and backend basics.</description>
    <language>en</language>
    <lastBuildDate>Tue, 18 Aug 2026 08:15:00 GMT</lastBuildDate>
    <item>
      <title>How to Set Up Pino Logging in Next.js</title>
      <link>https://littlecodingthings.com/how-to-set-up-pino-logging-in-next-js/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-set-up-pino-logging-in-next-js/</guid>
      <pubDate>Tue, 18 Aug 2026 08:15:00 GMT</pubDate>
      <description>Replace console.log with Pino in your Next.js app: structured JSON logs, readable output in dev, child loggers and log levels per environment.</description>
      <category>Server Side</category>
      <content:encoded><![CDATA[<p>You deploy your Next.js app, something breaks at 2am, you open the hosting dashboard, and you are staring at a wall of grey text that says <code>fetching user</code> and then, forty lines later, <code>done</code>. Which user? How long did it take? Was that even from the request that failed? 😅</p>
<p>That is the moment most of us realise <code>console.log</code> was never a logging system. It was a debugging tool we accidentally shipped to production.</p>
<p>In this post we'll swap it for <strong>Pino</strong>, a logging library that writes one JSON object per line instead of loose strings. We'll install it, make the output readable while we develop, pull it into a single shared logger module, and thread one id through an entire workflow so a request is easy to follow. We're using <strong>pino 10.3.1</strong>, <strong>pino-pretty 13.1.3</strong> and <strong>Next.js 16.3.1</strong>, and the outputs below are all copied straight from a real terminal.</p>
<h2 id="where-consolelog-runs-out">Where console.log runs out<a class="heading-anchor" href="#where-consolelog-runs-out" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><code>console.log</code> is fine right up until someone else has to read what it wrote. Then a few problems show up at once.</p>
<p><strong>The levels don't actually do anything.</strong> You might reasonably point out that <code>console</code> already has <code>debug</code>, <code>info</code>, <code>warn</code> and <code>error</code>, and it does. But in Node, those are mostly just different methods. There is no log level threshold you can configure. They all print.</p>
<p>That means a message you only needed while debugging and a message that means "payments are down" can both end up in production. The only way to silence the first one is to remove the line or add your own condition.</p>
<p>Node does make one distinction: <code>warn</code> and <code>error</code> write to <strong>stderr</strong>, while <code>debug</code>, <code>info</code> and <code>log</code> write to <strong>stdout</strong>. That's two output streams, not a useful logging hierarchy.</p>
<p>There are also <strong>no timestamps</strong> on regular log entries, so you can't tell whether two lines happened a millisecond apart or ten minutes apart. <code>console.time()</code> and <code>console.timeEnd()</code> can measure how long a particular operation takes, but that's different from automatically recording when each log entry happened.</p>
<p>And there is <strong>no structure</strong>. Something like <code>console.log('user', id, 'took', ms)</code> produces a sentence. A sentence is fine for a human reading a terminal, but it isn't very useful when you need to filter, group, or search your logs.</p>
<p>And that's the part that really hurts in production: <strong>searchability</strong>.</p>
<p>Your hosting provider gives you a search box. You type the user ID you're investigating and expect to find every related log entry. But your ID is buried inside a string with spaces and other text around it. There's no field saying <code>userId</code> that the logging system can reliably filter on.</p>
<p>If you'd like a nudge to stop reaching for it, the <a href="/husky-hooks-the-easy-way-to-improve-your-project-workflow/">pre-commit hook setup in our Husky post</a> includes a check that blocks any commit containing a <code>console.log</code>, which pairs nicely with actually having something better to replace it with.</p>
<h2 id="what-pino-gives-you-instead">What Pino gives you instead<a class="heading-anchor" href="#what-pino-gives-you-instead" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Pino writes <strong>one JSON object per line</strong>. That format has a name, NDJSON (newline-delimited JSON), and most log platforms know how to parse it out of the box.</p>
<p>Each line carries a numeric level, a timestamp, the process ID, the hostname and your message. Anything extra you attach becomes a real field, not part of a sentence. So "find me every warning for user 42 in the last hour" becomes a filter rather than a <code>grep</code> that you have to squint at.</p>
<p>But isn't building JSON slower than printing a string, you might wonder? It is a fair question, and the answer is the reason Pino exists. Most logging libraries <strong>format</strong> a message: they take a template, interpolate values into it, apply colours, and pad columns, all before anything gets written. Pino <strong>serialises</strong> instead. It turns your object into a JSON string with as little work as possible and pushes it to stdout, leaving the prettifying to a separate process that only runs when you ask for it. Less work per line means logging costs you less inside a hot request path. ⚡</p>
<h2 id="installing-pino-and-writing-the-first-log">Installing Pino and writing the first log<a class="heading-anchor" href="#installing-pino-and-writing-the-first-log" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Let's install it. In your Next.js project, run:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">npm</span><span style="color:#9ECBFF"> install</span><span style="color:#9ECBFF"> pino</span></span></code></pre></div>
<p>That is the only package you need for production. We'll add <code>pino-pretty</code> shortly, but that one belongs in dev dependencies, so we'll keep them separate on purpose.</p>
<p>If you're on TypeScript, and these days most Next.js projects are, you do <strong>not</strong> need a types package. Pino ships its own type definitions inside the package. <code>@types/pino</code> does exist on npm, but it is only a stub whose description literally says that pino provides its own definitions, so installing it gains you nothing. Every snippet below typechecks under <code>strict</code> as it stands.</p>
<p>Now the smallest possible logger. The question that trips people up here is <em>where do I actually put this</em>, so let's be concrete: it has to be a file that runs on the <strong>server</strong>. The quickest way to see a real line of output is a route handler, so create <code>src/app/api/health/route.ts</code>:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">import</span><span style="color:#E1E4E8"> pino </span><span style="color:#F97583">from</span><span style="color:#9ECBFF"> 'pino'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> log</span><span style="color:#F97583"> =</span><span style="color:#B392F0"> pino</span><span style="color:#E1E4E8">();</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">export</span><span style="color:#F97583"> async</span><span style="color:#F97583"> function</span><span style="color:#B392F0"> GET</span><span style="color:#E1E4E8">() {</span></span>
<span class="line"><span style="color:#E1E4E8">  log.</span><span style="color:#B392F0">info</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'health check requested'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#F97583">  return</span><span style="color:#E1E4E8"> Response.</span><span style="color:#B392F0">json</span><span style="color:#E1E4E8">({ ok: </span><span style="color:#79B8FF">true</span><span style="color:#E1E4E8"> });</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Start your app with <code>npm run dev</code>, then visit <code>http://localhost:3000/api/health</code>.</p>
<p>Now look in the <strong>terminal</strong> where <code>npm run dev</code> is running, not the browser console. This catches nearly everyone once: <code>log.info</code> runs on the server, so its output goes to the server's stdout. Nothing appears in your browser devtools, and that is correct behaviour rather than a broken setup.</p>
<p>We'll move this logger into its own module in a moment, so treat the route handler as a place to see it work rather than where it lives permanently.</p>
<p>That is the whole setup. <code>pino()</code> with no arguments creates a logger with all the defaults, and <code>log.info(...)</code> writes a line at the <code>info</code> level. Here is what came out in the terminal, with the <code>pid</code> and <code>hostname</code> values swapped for neutral ones since yours will differ anyway:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>{"level":30,"time":1787040941389,"pid":71541,"hostname":"my-laptop.local","msg":"health check requested"}</span></span></code></pre></div>
<p>Let's read that line field by field, because every log you write from now on has this shape.</p>
<ul>
<li><strong><code>level</code></strong> is <code>30</code>, which is Pino's numeric code for <code>info</code>.</li>
<li><strong><code>time</code></strong> is a Unix timestamp in milliseconds. It is not pretty, but it is unambiguous, and every log platform converts it for you.</li>
<li><strong><code>pid</code></strong> and <strong><code>hostname</code></strong> tell you <em>which copy</em> of your app wrote the line. <code>pid</code> is the <strong>process ID</strong>, a number the operating system hands to every running program, and <code>hostname</code> is the machine it ran on. While you're developing there is only one copy, so both look like noise. They start earning their place the moment several copies run at the same time, whether that's a cluster of processes on one server or containers spread across several, because then they are the only thing telling you which copy produced the entry you're staring at.</li>
<li><strong><code>msg</code></strong> is the string you passed in.</li>
</ul>
<p>And if your reaction to <code>"level":30</code> is that a number is a lot less readable than the word <code>info</code>, you are completely right. The same goes for a timestamp like <code>1787040941389</code>, which no human reads at a glance. Nobody stares at raw JSON like this while developing, and you won't have to either. We'll fix exactly that in a couple of minutes with a tool called <code>pino-pretty</code>, so let the ugly version stand for now. It is ugly on purpose, because this is the shape a log platform wants to receive, not the shape you read.</p>
<h3 id="the-log-levels-and-which-one-to-reach-for">The log levels, and which one to reach for<a class="heading-anchor" href="#the-log-levels-and-which-one-to-reach-for" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Pino ships six levels, each with a number attached:</p>
<table>
<thead>
<tr>
<th scope="col">Method</th>
<th scope="col">Value</th>
<th scope="col">Reach for it when</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row"><code>log.trace()</code></th>
<td>10</td>
<td>You are following execution step by step, temporarily</td>
</tr>
<tr>
<th scope="row"><code>log.debug()</code></th>
<td>20</td>
<td>Detail that helps you locally but would be noise in production</td>
</tr>
<tr>
<th scope="row"><code>log.info()</code></th>
<td>30</td>
<td>Something normal and noteworthy happened</td>
</tr>
<tr>
<th scope="row"><code>log.warn()</code></th>
<td>40</td>
<td>Something is wrong but the request still succeeded</td>
</tr>
<tr>
<th scope="row"><code>log.error()</code></th>
<td>50</td>
<td>An operation failed and someone should know</td>
</tr>
<tr>
<th scope="row"><code>log.fatal()</code></th>
<td>60</td>
<td>The process cannot continue</td>
</tr>
</tbody>
</table>
<p>The default level is <strong><code>info</code></strong>, and this is the part beginners get caught by. Anything below 30 is silently dropped.</p>
<p>Let's prove that in the route handler we already have, by adding a <code>debug</code> line above the <code>info</code> one:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">export</span><span style="color:#F97583"> async</span><span style="color:#F97583"> function</span><span style="color:#B392F0"> GET</span><span style="color:#E1E4E8">() {</span></span>
<span class="line"><span style="color:#E1E4E8">  log.</span><span style="color:#B392F0">debug</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'starting health check'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  log.</span><span style="color:#B392F0">info</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'health check requested'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#F97583">  return</span><span style="color:#E1E4E8"> Response.</span><span style="color:#B392F0">json</span><span style="color:#E1E4E8">({ ok: </span><span style="color:#79B8FF">true</span><span style="color:#E1E4E8"> });</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Refresh <code>/api/health</code> and only one line comes back:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>{"level":30,"time":1787040941389,"pid":71541,"hostname":"my-laptop.local","msg":"health check requested"}</span></span></code></pre></div>
<p>The <code>debug</code> call ran perfectly well. It just went nowhere. Not an error, not a warning. Nothing. Your logger is working exactly as designed, because you asked it for a level it was told to ignore. We'll turn that dial with an environment variable further down, and this line will come back without you editing the file again.</p>
<h2 id="adding-context-the-object-first-argument">Adding context: the object-first argument<a class="heading-anchor" href="#adding-context-the-object-first-argument" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>A health check is a thin example, because nothing about it ever varies. Every request logs the same sentence. So let's move somewhere the values actually change and keep building there: a route that looks up an order by id, at <code>src/app/api/orders/route.ts</code>.</p>
<p>The single habit that makes Pino worth the install is passing an object <em>before</em> the message:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">import</span><span style="color:#E1E4E8"> pino </span><span style="color:#F97583">from</span><span style="color:#9ECBFF"> 'pino'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> log</span><span style="color:#F97583"> =</span><span style="color:#B392F0"> pino</span><span style="color:#E1E4E8">();</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">export</span><span style="color:#F97583"> async</span><span style="color:#F97583"> function</span><span style="color:#B392F0"> GET</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">request</span><span style="color:#F97583">:</span><span style="color:#B392F0"> Request</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#F97583">  const</span><span style="color:#79B8FF"> orderId</span><span style="color:#F97583"> =</span><span style="color:#F97583"> new</span><span style="color:#B392F0"> URL</span><span style="color:#E1E4E8">(request.url).searchParams.</span><span style="color:#B392F0">get</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'id'</span><span style="color:#E1E4E8">) </span><span style="color:#F97583">??</span><span style="color:#9ECBFF"> 'unknown'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">  const</span><span style="color:#79B8FF"> startedAt</span><span style="color:#F97583"> =</span><span style="color:#E1E4E8"> Date.</span><span style="color:#B392F0">now</span><span style="color:#E1E4E8">();</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">  // stand-in for whatever your real lookup does</span></span>
<span class="line"><span style="color:#F97583">  await</span><span style="color:#F97583"> new</span><span style="color:#79B8FF"> Promise</span><span style="color:#E1E4E8">((</span><span style="color:#FFAB70">resolve</span><span style="color:#E1E4E8">) </span><span style="color:#F97583">=></span><span style="color:#B392F0"> setTimeout</span><span style="color:#E1E4E8">(resolve, </span><span style="color:#79B8FF">120</span><span style="color:#E1E4E8">));</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">  const</span><span style="color:#79B8FF"> durationMs</span><span style="color:#F97583"> =</span><span style="color:#E1E4E8"> Date.</span><span style="color:#B392F0">now</span><span style="color:#E1E4E8">() </span><span style="color:#F97583">-</span><span style="color:#E1E4E8"> startedAt;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">  log.</span><span style="color:#B392F0">info</span><span style="color:#E1E4E8">({ orderId, durationMs }, </span><span style="color:#9ECBFF">'order loaded'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">  return</span><span style="color:#E1E4E8"> Response.</span><span style="color:#B392F0">json</span><span style="color:#E1E4E8">({ id: orderId });</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Notice the order: object first, string second. Visit <code>/api/orders?id=8842</code> and that object gets merged into the top level of the JSON line:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>{"level":30,"time":1787042421780,"pid":80250,"hostname":"my-laptop.local","orderId":"8842","durationMs":120,"msg":"order loaded"}</span></span></code></pre></div>
<p><code>orderId</code> and <code>durationMs</code> are now <strong>fields</strong>. Not text buried inside <code>msg</code>, but real keys with real values. That means your log platform can offer you "filter where orderId = 8842" or "show me every request over 500ms", and it means each value keeps its type, so <code>120</code> is a number you can compare against rather than the characters <code>1</code>, <code>2</code> and <code>0</code>.</p>
<p>Compare it with what most of us write out of habit:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">// Don't do this</span></span>
<span class="line"><span style="color:#E1E4E8">log.</span><span style="color:#B392F0">info</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">`order ${</span><span style="color:#E1E4E8">orderId</span><span style="color:#9ECBFF">} loaded in ${</span><span style="color:#E1E4E8">durationMs</span><span style="color:#9ECBFF">}ms`</span><span style="color:#E1E4E8">);</span></span></code></pre></div>
<p>That produces <code>"msg":"order 8842 loaded in 120ms"</code>. To find the slow ones you now have to match a substring, and the moment you reword the message, every saved search and every alert built on top of it quietly stops matching. <strong>Keep the message a constant string and put the variable parts in the object.</strong> That one rule is most of the benefit.</p>
<h2 id="making-it-readable-while-you-develop">Making it readable while you develop<a class="heading-anchor" href="#making-it-readable-while-you-develop" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Structured JSON is superb for machines and rough on human eyes. That's what <strong>pino-pretty</strong> is for.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">npm</span><span style="color:#9ECBFF"> install</span><span style="color:#79B8FF"> --save-dev</span><span style="color:#9ECBFF"> pino-pretty</span></span></code></pre></div>
<p>There are two ways to wire it up, and they are not equivalent.</p>
<p><strong>The first way is piping.</strong> Leave your logger untouched and send the output through the <code>pino-pretty</code> binary:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">next</span><span style="color:#9ECBFF"> dev</span><span style="color:#F97583"> |</span><span style="color:#B392F0"> npx</span><span style="color:#9ECBFF"> pino-pretty</span></span></code></pre></div>
<p>Which turns those JSON lines into this:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#e1e4e8">[11:50:21.717] </span><span style="color:#34d058">INFO</span><span style="color:#e1e4e8"> (82862): </span><span style="color:#39c5cf">order loaded</span></span>
<span class="line"><span style="color:#b392f0">    orderId</span><span style="color:#e1e4e8">: "8842"</span></span>
<span class="line"><span style="color:#b392f0">    durationMs</span><span style="color:#e1e4e8">: 120</span></span></code></pre></div>
<p>Readable timestamp, the level spelled out and colour-coded, and your extra fields indented underneath. Your app never knows any of this happened. It is still writing plain JSON to stdout, and a separate process is doing the formatting.</p>
<p><strong>The second way is a transport</strong>, configured on the logger itself. That means passing an option to the <code>pino()</code> call in your route handler for now, though in the next section we'll move this into a single shared logger file where it really belongs:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> log</span><span style="color:#F97583"> =</span><span style="color:#B392F0"> pino</span><span style="color:#E1E4E8">({</span></span>
<span class="line"><span style="color:#E1E4E8">  transport:</span></span>
<span class="line"><span style="color:#E1E4E8">    process.env.</span><span style="color:#79B8FF">NODE_ENV</span><span style="color:#F97583"> !==</span><span style="color:#9ECBFF"> 'production'</span></span>
<span class="line"><span style="color:#F97583">      ?</span><span style="color:#E1E4E8"> { target: </span><span style="color:#9ECBFF">'pino-pretty'</span><span style="color:#E1E4E8">, options: { colorize: </span><span style="color:#79B8FF">true</span><span style="color:#E1E4E8"> } }</span></span>
<span class="line"><span style="color:#F97583">      :</span><span style="color:#79B8FF"> undefined</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">});</span></span></code></pre></div>
<p>The <code>transport</code> option tells Pino to hand each line to a <strong>worker thread</strong> running <code>pino-pretty</code>. The <code>isDev</code> guard is doing real work here: in production you want raw JSON, because your host is going to parse it.</p>
<p>So which one? Here's the tradeoff:</p>
<table>
<thead>
<tr>
<th scope="col"></th>
<th scope="col">Piping through the CLI</th>
<th scope="col">Transport in the config</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Setup</th>
<td>Change your <code>dev</code> script</td>
<td>Change your logger file</td>
</tr>
<tr>
<th scope="row">App code</th>
<td>Untouched</td>
<td>Knows about formatting</td>
</tr>
<tr>
<th scope="row">Covers Next.js's own output</th>
<td>Yes</td>
<td>No, only your logger</td>
</tr>
<tr>
<th scope="row">Extra thread</th>
<td>No</td>
<td>Yes, one worker</td>
</tr>
<tr>
<th scope="row">Risk of bundler trouble</th>
<td>None</td>
<td>Some, it runs in a worker thread</td>
</tr>
</tbody>
</table>
<p>Piping is the safer default, and it has a bonus: it prettifies everything on stdout, including Next.js's own startup lines. The transport wins when you can't control how the app is started, like a hosted dev environment or a script someone else owns.</p>
<p>For what it's worth, I went with the piping. This was my first time setting Pino up, and I did not fancy walking into surprises on day one.</p>
<p>And we are not finished with this setup. What we have works, but the structure is still rough around the edges: the logger is created inside a route file, and every route that wants to log has to build its own. We'll tidy that up as we go, so treat what follows as improvements to this same setup rather than a fresh start.</p>
<h2 id="one-logger-module-not-one-per-file">One logger module, not one per file<a class="heading-anchor" href="#one-logger-module-not-one-per-file" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Your instinct will be to call <code>pino()</code> wherever you need to log. Resist it. 🙂</p>
<p>A Pino logger holds a write stream, and if a transport is configured it holds a worker thread too. Creating a fresh one inside a route handler means building all of that on every single request, then throwing it away. And if a transport is involved, that's a thread spawned per request, which is a genuinely expensive way to write a line of text.</p>
<p>So we create it once. Make a file at <code>src/lib/logger.ts</code>, which is where it will live from now on:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">import</span><span style="color:#E1E4E8"> pino </span><span style="color:#F97583">from</span><span style="color:#9ECBFF"> 'pino'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">export</span><span style="color:#F97583"> const</span><span style="color:#79B8FF"> logger</span><span style="color:#F97583"> =</span><span style="color:#B392F0"> pino</span><span style="color:#E1E4E8">({</span></span>
<span class="line"><span style="color:#E1E4E8">  level: process.env.</span><span style="color:#79B8FF">LOG_LEVEL</span><span style="color:#F97583"> ||</span><span style="color:#9ECBFF"> 'info'</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">  base: { env: process.env.</span><span style="color:#79B8FF">NODE_ENV</span><span style="color:#E1E4E8"> },</span></span>
<span class="line"><span style="color:#E1E4E8">});</span></span></code></pre></div>
<p>You don't have to annotate the return type. Pino infers it, and hovering <code>logger</code> in your editor shows <code>Logger&#x3C;never, boolean></code>, which is the type you'd import as <code>Logger</code> from <code>pino</code> if you ever need to write it down (passing the logger into a helper function, for instance).</p>
<p>Two options in there. <code>level</code> reads from an environment variable with a sensible fallback, which we'll come back to. <code>base</code> replaces the default <code>pid</code> and <code>hostname</code> fields with whatever you give it. Here we're tagging every line with the environment, so staging and production logs are told apart at a glance.</p>
<p>Then everywhere else you import it:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">import</span><span style="color:#E1E4E8"> { logger } </span><span style="color:#F97583">from</span><span style="color:#9ECBFF"> '@/lib/logger'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">export</span><span style="color:#F97583"> async</span><span style="color:#F97583"> function</span><span style="color:#B392F0"> GET</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">request</span><span style="color:#F97583">:</span><span style="color:#B392F0"> Request</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#F97583">  const</span><span style="color:#79B8FF"> orderId</span><span style="color:#F97583"> =</span><span style="color:#F97583"> new</span><span style="color:#B392F0"> URL</span><span style="color:#E1E4E8">(request.url).searchParams.</span><span style="color:#B392F0">get</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'id'</span><span style="color:#E1E4E8">) </span><span style="color:#F97583">??</span><span style="color:#9ECBFF"> 'unknown'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">  logger.</span><span style="color:#B392F0">info</span><span style="color:#E1E4E8">({ orderId }, </span><span style="color:#9ECBFF">'order loaded'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">  return</span><span style="color:#E1E4E8"> Response.</span><span style="color:#B392F0">json</span><span style="color:#E1E4E8">({ id: orderId });</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h3 id="child-loggers-when-you-want-context-to-stick">Child loggers, when you want context to stick<a class="heading-anchor" href="#child-loggers-when-you-want-context-to-stick" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Once you have the singleton, you can branch off it. A <strong>child logger</strong> carries fields automatically so you stop repeating yourself:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> requestLog</span><span style="color:#F97583"> =</span><span style="color:#E1E4E8"> logger.</span><span style="color:#B392F0">child</span><span style="color:#E1E4E8">({ requestId });</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">requestLog.</span><span style="color:#B392F0">info</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'started'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">requestLog.</span><span style="color:#B392F0">info</span><span style="color:#E1E4E8">({ ms: </span><span style="color:#79B8FF">42</span><span style="color:#E1E4E8"> }, </span><span style="color:#9ECBFF">'finished'</span><span style="color:#E1E4E8">);</span></span></code></pre></div>
<p>Both lines carry <code>requestId</code> without you passing it twice. A child is cheap, because it shares the parent's stream rather than opening a new one, so this is the right way to add per-request context, and the wrong way is a fresh <code>pino()</code> call.</p>
<p>That per-request use is the one most people reach for first. There is a second one that pays off just as much, though, and it is worth knowing about early: <strong>labelling whole areas of your app</strong>. If your codebase has invoicing, payments and ordering, give each of them a child logger and create it once, next to the singleton:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">// src/lib/logger.ts</span></span>
<span class="line"><span style="color:#F97583">export</span><span style="color:#F97583"> const</span><span style="color:#79B8FF"> paymentsLog</span><span style="color:#F97583"> =</span><span style="color:#E1E4E8"> logger.</span><span style="color:#B392F0">child</span><span style="color:#E1E4E8">({ module: </span><span style="color:#9ECBFF">'payments'</span><span style="color:#E1E4E8"> });</span></span>
<span class="line"><span style="color:#F97583">export</span><span style="color:#F97583"> const</span><span style="color:#79B8FF"> ordersLog</span><span style="color:#F97583"> =</span><span style="color:#E1E4E8"> logger.</span><span style="color:#B392F0">child</span><span style="color:#E1E4E8">({ module: </span><span style="color:#9ECBFF">'orders'</span><span style="color:#E1E4E8"> });</span></span></code></pre></div>
<p>Every line those write now carries its label, without a single extra argument at the call site:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>{"level":30,...,"module":"payments","msg":"charge captured"}</span></span>
<span class="line"><span>{"level":40,...,"module":"orders","orderId":"8842","msg":"stock low"}</span></span></code></pre></div>
<p>Which turns "show me everything payments did this morning" into a filter on one field, rather than you trying to remember which messages the payments code happens to use. It also survives refactors, because the label lives in the logger rather than in the wording of each message.</p>
<p>The two uses stack, which is where this gets genuinely useful. Branch a per-request child off a module child and the line carries both:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> requestLog</span><span style="color:#F97583"> =</span><span style="color:#E1E4E8"> ordersLog.</span><span style="color:#B392F0">child</span><span style="color:#E1E4E8">({ requestId });</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">requestLog.</span><span style="color:#B392F0">info</span><span style="color:#E1E4E8">({ ms: </span><span style="color:#79B8FF">42</span><span style="color:#E1E4E8"> }, </span><span style="color:#9ECBFF">'finished'</span><span style="color:#E1E4E8">);</span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>{"level":30,...,"module":"orders","requestId":"req-77","ms":42,"msg":"finished"}</span></span></code></pre></div>
<p>And there is one more thing a child can carry: <strong>its own level</strong>, set independently of its parent. That is what the second argument to <code>child()</code> is for, an options object where <code>level</code> is one of the things you can set:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">export</span><span style="color:#F97583"> const</span><span style="color:#79B8FF"> paymentsLog</span><span style="color:#F97583"> =</span><span style="color:#E1E4E8"> logger.</span><span style="color:#B392F0">child</span><span style="color:#E1E4E8">({ module: </span><span style="color:#9ECBFF">'payments'</span><span style="color:#E1E4E8"> }, { level: </span><span style="color:#9ECBFF">'debug'</span><span style="color:#E1E4E8"> });</span></span></code></pre></div>
<p>Leave that second argument off, as we did earlier, and the child simply inherits whatever the parent is set to.</p>
<p>With the root logger sitting at <code>info</code>, that one line means payments emits its <code>debug</code> output while every other area of the app stays quiet. When you are chasing a bug in one subsystem in production, that is the difference between the detail you need and a firehose of everything at once.</p>
<h2 id="where-logging-actually-runs-in-a-nextjs-app">Where logging actually runs in a Next.js app<a class="heading-anchor" href="#where-logging-actually-runs-in-a-nextjs-app" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>This one catches people who put a <code>logger.info()</code> in a component and then hunt for it in the browser console. Next.js runs your code in more than one place, and Pino is a <strong>Node.js</strong> library.</p>
<table>
<thead>
<tr>
<th scope="col">Where your code runs</th>
<th scope="col">Does Pino work?</th>
<th scope="col">What to know</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Server Components</th>
<td>Yes</td>
<td>Full Pino, output goes to your server terminal or host logs</td>
</tr>
<tr>
<th scope="row">Route Handlers (<code>app/api/*</code>)</th>
<td>Yes</td>
<td>The natural home for request logging</td>
</tr>
<tr>
<th scope="row">Server Actions</th>
<td>Yes</td>
<td>Great place to log the mutation and its outcome</td>
</tr>
<tr>
<th scope="row"><code>middleware.ts</code> on Edge</th>
<td>No</td>
<td>The Edge runtime lacks the Node APIs Pino needs</td>
</tr>
<tr>
<th scope="row">Client Components</th>
<td>No</td>
<td>Runs in the browser; there is no stdout to write to</td>
</tr>
</tbody>
</table>
<p>The rule that keeps you out of trouble: <strong>import the logger only from files that are server-only.</strong> If a client component imports your logger module, the bundler follows that import and you'll get a build error about a Node module in browser code, which is confusing until you realise it's the import chain talking, not the logging call.</p>
<p>For middleware on the Edge runtime, <code>console.log</code> genuinely is the tool you have. It's a small enough surface that it rarely matters.</p>
<h2 id="log-levels-per-environment-with-log_level">Log levels per environment with LOG_LEVEL<a class="heading-anchor" href="#log-levels-per-environment-with-log_level" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Remember our logger reading <code>process.env.LOG_LEVEL</code>? Now we can use it.</p>
<p>Add it to <code>.env.local</code> for your own machine:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">LOG_LEVEL</span><span style="color:#F97583">=</span><span style="color:#9ECBFF">debug</span></span></code></pre></div>
<p>With that set, every <code>log.debug()</code> you sprinkled around starts printing, and when you unset it, they all go quiet again without you touching a line of code. That is the whole point of levels: <code>debug</code> calls are permanent instrumentation you leave in the codebase, not temporary lines you delete before committing.</p>
<p>A setup that works well in practice:</p>
<ul>
<li><strong>local development</strong>: <code>debug</code>, so you see the detail while building</li>
<li><strong>staging</strong>: <code>debug</code> or <code>info</code>, depending on how noisy things get</li>
<li><strong>production</strong>: <code>info</code>, or <code>warn</code> on a very high-traffic service</li>
</ul>
<p>Set it in your hosting provider's environment variable settings rather than committing it, the same way you handle everything else in there. Our post on <a href="/environment-variables-101-secure-your-secrets-like-a-pro/">keeping secrets out of your repo with environment variables</a> covers the <code>.env</code> file conventions and what belongs in each one. <code>LOG_LEVEL</code> isn't a secret, but it lives alongside the ones that are.</p>
<p>One thing worth knowing: the level is read <strong>once</strong>, when the logger is created. Changing the variable means restarting the process. You can also change it at runtime with <code>logger.level = 'debug'</code>, which is handy behind an admin-only route on a service you can't restart casually.</p>
<h2 id="frequently-asked-questions">Frequently Asked Questions<a class="heading-anchor" href="#frequently-asked-questions" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<h3 id="should-i-log-the-error-and-throw-it-as-well">Should I log the error and throw it as well?<a class="heading-anchor" href="#should-i-log-the-error-and-throw-it-as-well" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong>Usually, no. Pick one place to log it.</strong></p>
<p>A useful rule is:</p>
<p><strong>Throw where it fails, log where you handle it.</strong></p>
<p>Here is what goes wrong when you do both.</p>
<p>Say <code>saveOrder()</code> catches a database error, logs it, and then throws it. The code that called it catches the error and logs it again:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">async</span><span style="color:#F97583"> function</span><span style="color:#B392F0"> saveOrder</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">order</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#F97583">  try</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">    await</span><span style="color:#E1E4E8"> db.orders.</span><span style="color:#B392F0">create</span><span style="color:#E1E4E8">(order);</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#F97583">catch</span><span style="color:#E1E4E8"> (err) {</span></span>
<span class="line"><span style="color:#E1E4E8">    log.</span><span style="color:#B392F0">error</span><span style="color:#E1E4E8">({ err }, </span><span style="color:#9ECBFF">'failed to save order'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#F97583">    throw</span><span style="color:#E1E4E8"> err;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">async</span><span style="color:#F97583"> function</span><span style="color:#B392F0"> checkout</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">order</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#F97583">  try</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">    await</span><span style="color:#B392F0"> saveOrder</span><span style="color:#E1E4E8">(order);</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#F97583">catch</span><span style="color:#E1E4E8"> (err) {</span></span>
<span class="line"><span style="color:#E1E4E8">    log.</span><span style="color:#B392F0">error</span><span style="color:#E1E4E8">({ err }, </span><span style="color:#9ECBFF">'order could not be completed'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>The result is two log entries for one failure:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>{"level":50,...,"msg":"failed to save order"}</span></span>
<span class="line"><span>{"level":50,...,"msg":"order could not be completed"}</span></span></code></pre></div>
<p>Now when you are looking at your logs, you have to figure out whether those are two separate problems or the same problem being reported twice.</p>
<p>Usually, the second message is the useful one.</p>
<p><code>saveOrder()</code> only knows that saving the order failed. The code handling the checkout knows what that failure means to the application: <strong>the order could not be completed</strong>.</p>
<p>That's the message you actually want to see when you are investigating a problem.</p>
<p>So <code>saveOrder()</code> should throw the error and let its caller decide what to do with it:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">async</span><span style="color:#F97583"> function</span><span style="color:#B392F0"> saveOrder</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">order</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#F97583">  try</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">    await</span><span style="color:#E1E4E8"> db.orders.</span><span style="color:#B392F0">create</span><span style="color:#E1E4E8">(order);</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#F97583">catch</span><span style="color:#E1E4E8"> (err) {</span></span>
<span class="line"><span style="color:#F97583">    throw</span><span style="color:#F97583"> new</span><span style="color:#B392F0"> OrderSaveError</span><span style="color:#E1E4E8">({ cause: err });</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>The caller can then log it once:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">try</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">  await</span><span style="color:#B392F0"> saveOrder</span><span style="color:#E1E4E8">(order);</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#F97583">catch</span><span style="color:#E1E4E8"> (err) {</span></span>
<span class="line"><span style="color:#E1E4E8">  log.</span><span style="color:#B392F0">error</span><span style="color:#E1E4E8">({ err }, </span><span style="color:#9ECBFF">'order could not be completed'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>This also keeps your lower-level functions reusable. The same database failure might need to be retried in one place, turned into an error response somewhere else, or simply recorded and ignored in a background job.</p>
<p>The function that caused the error usually doesn't know which one is appropriate.</p>
<h3 id="why-dont-my-logdebug-lines-show-up">Why don't my log.debug() lines show up?<a class="heading-anchor" href="#why-dont-my-logdebug-lines-show-up" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong>Because the default level is <code>info</code>,</strong> and anything below it is dropped without a word. <code>debug</code> is 20, <code>info</code> is 30, so <code>debug</code> calls run and go nowhere.</p>
<p>Set <code>LOG_LEVEL=debug</code> in <code>.env.local</code> and restart. The level is read when the logger is created, so a running process will not pick up the change on its own.</p>
<h3 id="how-do-i-keep-passwords-and-tokens-out-of-my-logs">How do I keep passwords and tokens out of my logs?<a class="heading-anchor" href="#how-do-i-keep-passwords-and-tokens-out-of-my-logs" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong>Use the <code>redact</code> option</strong>, which takes the paths you never want written:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">export</span><span style="color:#F97583"> const</span><span style="color:#79B8FF"> logger</span><span style="color:#F97583"> =</span><span style="color:#B392F0"> pino</span><span style="color:#E1E4E8">({</span></span>
<span class="line"><span style="color:#E1E4E8">  redact: [</span><span style="color:#9ECBFF">'password'</span><span style="color:#E1E4E8">, </span><span style="color:#9ECBFF">'req.headers.authorization'</span><span style="color:#E1E4E8">, </span><span style="color:#9ECBFF">'*.token'</span><span style="color:#E1E4E8">],</span></span>
<span class="line"><span style="color:#E1E4E8">});</span></span></code></pre></div>
<p>Anything matching comes out as <code>"[Redacted]"</code> while the rest of the object is untouched, and the wildcard form catches the same key wherever it is nested. This is worth setting up on day one, because structured logging makes it far easier to accidentally log a whole user object than <code>console.log</code> ever did.</p>
<h2 id="where-to-go-next">Where to go next<a class="heading-anchor" href="#where-to-go-next" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>At this point you have structured logs with real levels, one logger module the whole app shares, readable output while you develop, and a correlation id that follows a request wherever it goes.</p>
<p>The obvious next question is where those JSON lines should end up once they leave your server, since a terminal that scrolls away is not much of an archive. Shipping logs to a hosted destination is its own topic with its own set of gotchas, and it's the subject of a follow-up post. 🚀</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/why-did-your-new-next-js-deployment-fail-on-render-com/">Why Your Next.js Deploy Fails on Render</a></li>
<li><a href="/how-to-deploy-a-next-js-app-with-render-com-2024/">Deploy a Next.js App with Render.com</a></li>
<li><a href="/how-to-restart-your-node-apps-without-nodemon/">How to Restart Your Node App Without Nodemon</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How Password Hashing Works</title>
      <link>https://littlecodingthings.com/why-websites-dont-store-your-password/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/why-websites-dont-store-your-password/</guid>
      <pubDate>Wed, 08 Jul 2026 13:24:00 GMT</pubDate>
      <description>Websites don’t store your password, they store a hash. How hashing works, why that’s the reason password reset exists, and why storing less is safer.</description>
      <category>Thoughts &amp; Theory</category>
      <content:encoded><![CDATA[<p>When you create an account on a website, you usually type your password once and never think about it again. The next time you log in, you enter the same password and everything works as expected.</p>
<p>It’s easy to assume that somewhere on the server there’s a database containing your username next to your password. After all, how else would the website know whether you’ve entered the correct one?</p>
<p>The surprising answer is that, on a well-designed system, your password is never stored in a form that anyone can read, not even the company that owns the website.</p>
<h2 id="your-password-is-transformed-not-stored">Your password is transformed, not stored<a class="heading-anchor" href="#your-password-is-transformed-not-stored" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Instead of saving your password directly, the server runs it through something called a <strong>hash function</strong>. You can think of a hash as a digital fingerprint. It always produces the same output for the same password, but it’s designed to work in only one direction.</p>
<p>For example, if we take the password:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>myPassword123</span></span></code></pre></div>
<p>and hash it, we get something that looks like this:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>a336f671080fb420c27461fcf4f2c8d1d87b8a5f6d6f8b5f8f13c2b7d5ad7168</span></span></code></pre></div>
<p>That long string of seemingly random characters is what gets stored in the database, not your actual password. Modern applications typically use dedicated password hashing algorithms such as <strong>bcrypt</strong> or <strong>Argon2</strong>, but the basic idea is the same: the password is transformed into a value that can’t realistically be reversed.</p>
<p>The next time you log in, the server hashes the password you entered again and compares the new hash with the one stored in the database. If they match, you entered the correct password, even though the server never needed to know what your password actually was.</p>
<p>And once you’re through that door, your password isn’t checked again on every page — the site remembers you with a cookie, which exists precisely because <a href="/did-you-know-why-are-browser-cookies-called-cookies/">the early web had no memory between page loads</a>.</p>
<h2 id="then-how-does-password-reset-work">Then how does password reset work?<a class="heading-anchor" href="#then-how-does-password-reset-work" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>This was the question that confused me the first time I learned about password hashing.</p>
<p>If a website doesn’t actually know my password anymore, how can it send it back to me when I click <strong>Forgot Password</strong>?</p>
<p>The answer is that it can’t.</p>
<p>A properly designed system never emails your existing password because it doesn’t have access to it. Instead, it generates a temporary, time-limited token that proves you requested a password reset. After you choose a new password, the old hash is discarded and replaced with a new one.</p>
<p>That’s also why receiving your original password in an email should immediately raise a red flag. It usually means the website stored it in plain text or used an insecure method to protect it.</p>
<h2 id="good-security-is-often-about-storing-less">Good security is often about storing less<a class="heading-anchor" href="#good-security-is-often-about-storing-less" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>One of the things I enjoy most about software engineering is discovering ideas that seem counterintuitive at first.</p>
<p>Most people assume security is about building stronger walls around sensitive information. While that’s certainly part of it, an even better approach is to avoid storing information you don’t actually need.</p>
<p>It’s the same shape of idea as <a href="/why-invalid-card-numbers-fail-instantly/">why an invalid card number fails instantly</a>: the best move often isn’t doing the work more securely or more quickly, but arranging things so the work never has to happen.</p>
<p>A website doesn’t need to know your password after you’ve signed up. It only needs a reliable way to verify that the password you enter later is the same one you originally chose.</p>
<p>That small design decision dramatically reduces the damage a data breach can cause. Even if someone steals the database, they won’t find a list of everyone’s passwords waiting for them.</p>
<p>Sometimes the smartest engineering decision isn’t protecting more data—it’s making sure you never keep it in the first place.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/why-invalid-card-numbers-fail-instantly/">Why Invalid Card Numbers Fail Instantly</a></li>
<li><a href="/environment-variables-101-secure-your-secrets-like-a-pro/">Environment Variables with Dotenv</a> — keeping secrets out of your own codebase</li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Why Invalid Card Numbers Fail Instantly</title>
      <link>https://littlecodingthings.com/why-invalid-card-numbers-fail-instantly/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/why-invalid-card-numbers-fail-instantly/</guid>
      <pubDate>Sun, 05 Jul 2026 20:27:00 GMT</pubDate>
      <description>Payment forms reject invalid card numbers instantly thanks to the Luhn algorithm — a 1954 checksum your browser runs before contacting anyone at all.</description>
      <category>Thoughts &amp; Theory</category>
      <content:encoded><![CDATA[<p>Have you ever noticed that payment forms sometimes reject a credit card number almost instantly? In many cases, the validation happens before you’ve even clicked <strong>Pay</strong>.</p>
<p>At first glance, it feels as though the website is checking your card with your bank in real time. After all, how else could it know that the number is invalid?</p>
<p>The surprising part is that, most of the time, it doesn’t contact anyone.</p>
<p>Instead, your browser performs a simple mathematical check that has been around for decades.</p>
<h2 id="its-checking-the-structure-not-the-card-itself">It’s checking the structure, not the card itself<a class="heading-anchor" href="#its-checking-the-structure-not-the-card-itself" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Credit card numbers aren’t just a random sequence of digits. The final digit is calculated from all the previous ones using the <strong>Luhn algorithm</strong>, a checksum formula designed to catch common typing mistakes.</p>
<p>The algorithm is named after <strong>Hans Peter Luhn</strong>, an IBM engineer who developed it in 1954. More than 70 years later, it’s still used by every major credit card network to detect common typing errors.</p>
<p>When you enter your card number, your browser runs the algorithm locally. It processes the digits, performs a few simple calculations, and determines whether the number follows the expected pattern.</p>
<p>If it doesn’t, the form already knows something is wrong.</p>
<p>No request is sent to the bank.</p>
<p>No payment provider is contacted.</p>
<p>The entire check happens on your own device and usually finishes in less time than it takes to blink.</p>
<h2 id="why-bother-checking-before-sending-the-request">Why bother checking before sending the request?<a class="heading-anchor" href="#why-bother-checking-before-sending-the-request" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Imagine every payment form immediately contacted the payment provider every time someone accidentally pressed the wrong key.</p>
<p>That would mean millions of unnecessary requests every single day.</p>
<p>Instead, websites filter out obviously invalid numbers before they ever leave your browser. It’s faster for the user, reduces unnecessary network traffic, and saves payment providers from processing requests that were never valid to begin with.</p>
<p>Only after a card number passes this initial validation does the payment process continue.</p>
<p>That doesn’t mean the card is real, active, or has enough funds. It simply means the number is structured correctly.</p>
<h2 id="a-clever-design-hiding-in-plain-sight">A clever design hiding in plain sight<a class="heading-anchor" href="#a-clever-design-hiding-in-plain-sight" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>One of the things I enjoy most about software engineering is discovering solutions like this. They’re rarely complicated, yet they solve real problems remarkably well.</p>
<p>Most users assume the validation is happening somewhere in a distant data center. In reality, it’s often nothing more than a lightweight mathematical check running directly in the browser.</p>
<p>It’s a good reminder that not every performance improvement comes from faster servers or more powerful hardware.</p>
<p>Sometimes the smartest solution is simply avoiding work that never needed to happen in the first place.</p>
<h2 id="how-does-the-luhn-algorithm-work">How does the Luhn algorithm work?<a class="heading-anchor" href="#how-does-the-luhn-algorithm-work" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The Luhn algorithm performs a few simple calculations on the digits of a card number to check whether its structure is valid. Starting from the right, every second digit is doubled.</p>
<p>If doubling a digit produces a number greater than 9, 9 is subtracted from the result. Once every digit has been processed, they’re all added together. If the final sum is evenly divisible by 10, the card number passes the check.</p>
<p>It’s important to remember that this doesn’t verify whether the card is real, active, or has enough available funds. It simply confirms that the number follows the expected mathematical pattern, allowing websites to catch typing mistakes before sending a payment request to the server.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/why-websites-dont-store-your-password/">How Password Hashing Works</a></li>
<li><a href="/did-you-know-why-are-browser-cookies-called-cookies/">Why are internet cookies called cookies?</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Will AI Replace Junior Developers?</title>
      <link>https://littlecodingthings.com/will-ai-replace-junior-developers-i-think-were-asking-the-wrong-question/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/will-ai-replace-junior-developers-i-think-were-asking-the-wrong-question/</guid>
      <pubDate>Fri, 03 Jul 2026 12:23:00 GMT</pubDate>
      <description>The junior role is changing rather than disappearing. Why the first job gets harder, and which developers end up with the advantage as AI spreads.</description>
      <category>Thoughts &amp; Theory</category>
      <content:encoded><![CDATA[<p>Every few weeks, another headline appears claiming that AI is going to replace junior developers. Depending on the day, the prediction is either that nobody will hire entry-level engineers anymore or that software development as a profession is coming to an end.</p>
<p>If you’re trying to get your first job, it’s hard not to let those headlines get to you. You spend months learning JavaScript, React, or Python, only to read that companies will soon generate everything with AI.</p>
<p>I understand why people are worried. AI is improving at an incredible pace, and pretending nothing is changing would be unrealistic.</p>
<p>What I don’t agree with is the conclusion that junior developers simply won’t be needed anymore.</p>
<h2 id="the-role-is-changing-not-disappearing">The role is changing, not disappearing<a class="heading-anchor" href="#the-role-is-changing-not-disappearing" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>I use AI almost every day now. Sometimes it saves me half an hour. Sometimes it helps me understand a library I’ve never worked with before. Other times it confidently generates code that looks convincing but contains subtle bugs that only become obvious once you actually understand the problem.</p>
<p>That’s probably the biggest lesson AI has taught me so far.</p>
<p>Generating code isn’t the difficult part anymore. Knowing whether that code is correct, maintainable, secure, and actually solves the problem is where the real work begins.</p>
<p>People often describe junior developers as if their only purpose is to write small features or fix simple bugs. If that were true, then yes, AI would make many of those tasks much faster.</p>
<p>But that has never been the full picture.</p>
<p>A junior developer is learning how software is built inside a real company. They’re learning how to understand a codebase they didn’t write, how to communicate with teammates, how to ask good questions, how to investigate bugs, how to respond to code reviews, and how to make better decisions over time.</p>
<p>Those aren’t skills you download overnight. They’re developed by working with other engineers, making mistakes, and gradually building experience.</p>
<h2 id="every-senior-developer-started-somewhere">Every senior developer started somewhere<a class="heading-anchor" href="#every-senior-developer-started-somewhere" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>One thing I rarely hear people mention is a simple question.</p>
<p>If companies stop hiring junior developers today, where exactly will senior developers come from five years from now?</p>
<p>Every experienced engineer was once the person asking basic questions during code reviews. Every tech lead was once the developer trying to understand why their <a href="/how-to-create-better-pull-requests-3-proven-tips/">pull request</a> needed twenty changes before it could be merged.</p>
<p>Experience isn’t something you can skip. It’s accumulated through hundreds of small decisions, failed ideas, production incidents, and conversations with other developers.</p>
<p>AI can certainly accelerate that learning process, but it doesn’t replace it.</p>
<h2 id="the-first-job-will-probably-become-harder">The first job will probably become harder<a class="heading-anchor" href="#the-first-job-will-probably-become-harder" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>This is the part where I think the conversation should be more honest.</p>
<p>I do think AI will make it harder to land that first job.</p>
<p>If an experienced developer can complete routine work twice as fast with the help of AI, a company may decide it needs fewer people doing that kind of work. That naturally reduces some of the opportunities that junior developers relied on in the past.</p>
<p>But saying that entry-level hiring becomes more competitive is very different from saying junior developers disappear altogether.</p>
<p>Companies still need engineers who understand their systems, products, customers, and internal processes. They also need people who can grow into senior engineers over the next five or ten years. Hiring only experienced developers forever isn’t a realistic strategy for most engineering teams.</p>
<h2 id="the-developers-who-adapt-will-have-the-advantage">The developers who adapt will have the advantage<a class="heading-anchor" href="#the-developers-who-adapt-will-have-the-advantage" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>If I were starting my career today, I wouldn’t ignore AI, and I definitely wouldn’t be afraid to use it.</p>
<p>I’d use it to explain concepts I don’t understand, review my code, suggest improvements, and help me explore unfamiliar technologies. At the same time, I’d make sure I understand <em>why</em> the generated solution works instead of copying it blindly.</p>
<p>That ability is becoming a skill in its own right.</p>
<p>The developers who stand out over the next few years won’t necessarily be the ones who write every line of code manually. They’ll be the ones who know when AI is helping, when it’s making incorrect assumptions, and when the right answer is to ignore its suggestion completely.</p>
<p>The industry is changing, just as it has many times before. New tools have always shifted the way we work, but they’ve rarely eliminated the need for people who understand how software is built.</p>
<p>I don’t think junior developers are disappearing.</p>
<p>I think the expectations are rising, the competition is increasing, and the learning curve is changing. That may make the journey more challenging than it was a few years ago, but it doesn’t make the role any less important.</p>
<p>After all, every senior developer the industry will need five years from now has to start somewhere.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/am-i-too-old-to-learn-coding/">Am I Too Old to Learn Coding?</a></li>
<li><a href="/what-is-scrum-101-guide-for-new-developers/">What is Scrum? 101 Guide For New Developers</a></li>
<li><a href="/best-job-sites-for-web-developers/">Best Job Sites for Web Developers</a></li>
<li><a href="/why-i-stopped-memorizing-docker-commands-and-built-a-workflow-instead/">Why I Stopped Memorizing Docker Commands</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Why I Stopped Memorizing Docker Commands</title>
      <link>https://littlecodingthings.com/why-i-stopped-memorizing-docker-commands-and-built-a-workflow-instead/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/why-i-stopped-memorizing-docker-commands-and-built-a-workflow-instead/</guid>
      <pubDate>Fri, 03 Jul 2026 12:21:00 GMT</pubDate>
      <description>Forgetting Docker commands isn’t a sign you’re failing. Why experienced developers look things up, and why a personal cheat sheet beats memorization.</description>
      <category>Thoughts &amp; Theory</category>
      <content:encoded><![CDATA[<p>A few months ago I started building a new side project. Nothing particularly complicated, just a small application that needed a backend, a frontend, and a database. Docker Compose was the obvious choice because it made running everything together incredibly easy.</p>
<p>The funny thing is that I quickly found myself opening Google over and over again.</p>
<p><em>“How do I rebuild the containers?”</em></p>
<p><em>“Was it <code>--build</code> or <code>--force-recreate</code>?”</em></p>
<p><em>“How do I remove the volumes again?”</em></p>
<p>At first, I found it a little frustrating. I’ve been a developer for years, so surely I should know these commands by heart by now.</p>
<p>Then it hit me.</p>
<p>I don’t use Docker every single day.</p>
<p>At work, I spend most of my time building features, <a href="/how-to-create-better-pull-requests-3-proven-tips/">reviewing pull requests</a>, fixing bugs, discussing ideas with the team, and trying to understand business requirements. Docker is just one of many tools I use. Some weeks I barely touch it, while other weeks I use it constantly.</p>
<p>Why would I expect myself to remember commands that I only need once every few weeks?</p>
<h2 id="the-best-developers-dont-memorize-everything">The best developers don’t memorize everything<a class="heading-anchor" href="#the-best-developers-dont-memorize-everything" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>For a long time I believed experienced developers had incredible memories. I imagined senior engineers sitting at their keyboards, effortlessly typing every Git command, every Docker option, every Linux flag, without ever opening a browser.</p>
<p>Working alongside experienced developers completely changed that perception.</p>
<p>People Google things all the time.</p>
<p>They read documentation.</p>
<p>They search old Slack messages.</p>
<p>They copy commands from previous projects.</p>
<p>The difference isn’t that they remember everything. The difference is that they know what they’re looking for and they understand why they’re using it.</p>
<p>That distinction is much more important than memorization.</p>
<p>Once I accepted that, I stopped trying to build a perfect memory and started building better notes instead.</p>
<p>Whenever I found myself searching for the same command twice, I added it to a personal cheat sheet. Not every Docker command—just the ones that were genuinely useful for the way I work. Duke went through exactly the same thing and published his, if you want a starting point: <a href="/docker-docker-compose-commands-i-keep-forgetting-cheat-sheet/">Docker &#x26; Docker Compose Cheat Sheet</a>.</p>
<p>Over time, that little document became one of the most valuable resources I had. Every time I returned to a side project after a few weeks away, I didn’t have to search the internet again. Everything I actually needed was already there.</p>
<h2 id="understanding-beats-memorization">Understanding beats memorization<a class="heading-anchor" href="#understanding-beats-memorization" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Interestingly, the cheat sheet also revealed something about my own workflow.</p>
<p>I wasn’t forgetting Docker because Docker was complicated.</p>
<p>I was forgetting commands because they weren’t the important part.</p>
<p>The important part was understanding what was happening.</p>
<p>Once you understand the difference between rebuilding an image, recreating a container, removing a volume, or simply restarting a service, looking up the exact command becomes a twenty-second task instead of a stressful experience.</p>
<p>That’s something I wish someone had told me much earlier in my career.</p>
<p>Programming isn’t about carrying thousands of commands around in your head.</p>
<p>It’s about building mental models.</p>
<p>If you understand how the pieces fit together, the syntax is just a detail. Documentation exists for a reason, and even experienced developers rely on it more often than people realize.</p>
<p>So if you’re learning Docker and you find yourself repeatedly searching for the same commands, don’t take it as a sign that you’re failing.</p>
<p>Build your own reference instead.</p>
<p>Write down the commands you actually use. Add a short note explaining <em>why</em> you use each one. Keep improving it every time you learn something new.</p>
<p>A year from now, you probably won’t remember every Docker command.</p>
<p>And that’s perfectly okay.</p>
<p>You’ll have something much more valuable: a workflow that lets you get back to solving real problems instead of trying to prove how much you can memorize.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/docker-docker-compose-commands-i-keep-forgetting-cheat-sheet/">Docker &#x26; Docker Compose Cheat Sheet</a></li>
<li><a href="/husky-hooks-the-easy-way-to-improve-your-project-workflow/">Husky Hooks: The Easy Way to Improve Your Project Workflow</a></li>
<li><a href="/will-ai-replace-junior-developers-i-think-were-asking-the-wrong-question/">Will AI Replace Junior Developers?</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Why You Should Still Know curl in 2026</title>
      <link>https://littlecodingthings.com/why-every-developer-should-still-know-curl-in-2026/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/why-every-developer-should-still-know-curl-in-2026/</guid>
      <pubDate>Wed, 18 Mar 2026 08:17:00 GMT</pubDate>
      <description>curl still matters in 2026. Why AI-generated fetch calls don’t replace it, and how curl teaches you HTTP through headers, debugging and API testing.</description>
      <category>Setup &amp; Tools</category>
      <content:encoded><![CDATA[<p>In 2026, with AI-powered IDEs writing your fetch calls, Postman generating collections from a description, and copilots auto-completing your entire API integration layer — you might wonder: <em>do I still need to learn <strong>curl</strong>?</em></p>
<p>Yes. Absolutely. And here’s why.</p>
<h2 id="what-is-curl">What is curl?<a class="heading-anchor" href="#what-is-curl" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><strong><a href="https://curl.se" title="curl">curl</a></strong> (Client URL) is a command-line tool for transferring data using network protocols — most commonly HTTP and HTTPS. It has been around since 1998, ships on virtually every Unix-based system, and is available on Windows. It requires no GUI, no account, no setup. You open a terminal and you run it.</p>
<p>That simplicity is precisely why it remains irreplaceable.</p>
<h2 id="the-ai-argument--and-why-it-doesnt-replace-curl">The AI Argument — and Why It Doesn’t Replace curl<a class="heading-anchor" href="#the-ai-argument--and-why-it-doesnt-replace-curl" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Let’s address the obvious: AI tools are genuinely good at generating <strong>curl</strong> commands. You describe what you want, and a model will produce a well-structured command. That’s useful. But there’s a trap here that catches a lot of developers.</p>
<p>When AI generates a curl command for you, you still need to understand what it’s doing.</p>
<p>Consider this scenario: an AI tool generates an API call with an <code>Authorization: Bearer</code> header. Your request returns a <code>401 Unauthorized</code>. Is the token expired? Is the header name wrong? Is the endpoint expecting a different format? Is the request being blocked before it even hits your application? You cannot audit that without understanding what curl is sending and what the server is returning.</p>
<p>AI accelerates the writing. It does not replace the reading.</p>
<p>Understanding curl means you can:</p>
<ul>
<li><strong>Verify what an AI-generated command is actually doing</strong> before you run it in production</li>
<li><strong>Audit requests</strong> — check headers, payloads, authentication schemes, and encoding</li>
<li><strong>Catch security issues</strong> — misrouted credentials, accidental plain-HTTP calls, exposed tokens in query strings</li>
<li><strong>Reproduce and isolate bugs</strong> precisely, without UI noise</li>
</ul>
<p>In 2026, the developers who get the most value from AI tooling are the ones who can critically evaluate the output. <code>curl</code> is one of the tools that lets you do that for HTTP.</p>
<h2 id="simple-debugging--your-first-line-of-defence">Simple Debugging — Your First Line of Defence<a class="heading-anchor" href="#simple-debugging--your-first-line-of-defence" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The most common use of <strong>curl</strong> is also the most underrated: quick sanity checks.</p>
<p>Is the server up? Is the endpoint responding? Is the response what you expect?</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>curl -i https://api.yourapp.com/health</span></span></code></pre></div>
<p>The <code>-i</code> flag (short for <code>--include</code>) tells curl to include the response headers in the output. In one command, you get the HTTP status code, response headers, and body. No browser. No Postman. No waiting for a frontend to render. Just raw, unambiguous output.</p>
<p>You can try this right now against a real public endpoint built for exactly this purpose:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>curl -i https://httpbin.org/get</span></span></code></pre></div>
<p>You’ll see something like this in your terminal:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>HTTP/2 200</span></span>
<span class="line"><span>date: Wed, 18 Mar 2026 08:03:11 GMT</span></span>
<span class="line"><span>content-type: application/json</span></span>
<span class="line"><span>content-length: 253</span></span>
<span class="line"><span>server: gunicorn/19.9.0</span></span>
<span class="line"><span>access-control-allow-origin: *</span></span>
<span class="line"><span>access-control-allow-credentials: true</span></span>
<span class="line"><span></span></span>
<span class="line"><span>{</span></span>
<span class="line"><span>  "args": {},</span></span>
<span class="line"><span>  "headers": {</span></span>
<span class="line"><span>    "Accept": "*/*",</span></span>
<span class="line"><span>    "Host": "httpbin.org",</span></span>
<span class="line"><span>    "User-Agent": "curl/8.7.1",</span></span>
<span class="line"><span>    "X-Amzn-Trace-Id": "Root=1-69ba5c3f-0f5b955166ab5fd523bff65c"</span></span>
<span class="line"><span>  },</span></span>
<span class="line"><span>  "origin": "31.152.0.126",</span></span>
<span class="line"><span>  "url": "https://httpbin.org/get"</span></span>
<span class="line"><span>}</span></span></code></pre></div>
<p>Notice what you’re reading: the status line (<code>HTTP/2 200</code>), every response header the server sent, and then the JSON body below. The body itself echoes back what headers <em>you</em> sent — which is useful when you want to verify curl is attaching the right <code>Authorization</code> or <code>Content-Type</code> header to your request.</p>
<p><a href="https://httpbin.org" title="httpbin.org">httpbin.org</a> is a free, public testing service. You can use it to test GET, POST, headers, authentication, redirects, and more — no account needed.</p>
<p>This is invaluable when debugging in environments where you have no GUI — a <a href="/docker-docker-compose-commands-i-keep-forgetting-cheat-sheet/">Docker container</a>, a remote server, a CI pipeline, a production incident at 2am.</p>
<p>When something breaks, <strong>curl</strong> is how you rule out the network layer, the server, and the endpoint in under ten seconds.</p>
<h2 id="qa-and-api-testing--beyond-the-happy-path">QA and API Testing — Beyond the Happy Path<a class="heading-anchor" href="#qa-and-api-testing--beyond-the-happy-path" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>QA engineers and backend developers both reach for <strong>curl</strong> when testing API contracts. It lets you construct exact requests — control every header, set the method, define the body, specify the content type — and observe exactly what comes back.</p>
<p>Here’s a POST request with a JSON body:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>curl -X POST https://api.yourapp.com/v1/goals \</span></span>
<span class="line"><span>  -H "Content-Type: application/json" \</span></span>
<span class="line"><span>  -H "Authorization: Bearer your_token_here" \</span></span>
<span class="line"><span>  -d '{"name": "House down payment", "targetAmount": 50000, "targetDate": "2027-06-01"}'</span></span></code></pre></div>
<p>This is readable, shareable, and reproducible. You can paste it into a bug report, into a Slack message, into a GitHub issue. Anyone with a terminal can run it exactly as written and see exactly what you saw.</p>
<p>That reproducibility is something GUIs struggle to provide cleanly. curl commands are self-documenting. They are also scriptable — you can put them in shell scripts to automate repetitive QA workflows.</p>
<h2 id="inspecting-headers--where-bugs-actually-hide">Inspecting Headers — Where Bugs Actually Hide<a class="heading-anchor" href="#inspecting-headers--where-bugs-actually-hide" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>A significant class of production bugs live in HTTP headers, not in response bodies. CORS errors, misconfigured caches, wrong content types, missing security headers — none of these show up clearly in a browser’s response body. You need to look at the headers.</p>
<p><strong>curl</strong> gives you the full picture with <code>-v</code> (verbose mode):</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>curl -v https://httpbin.org/headers</span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>* Host httpbin.org:443 was resolved.</span></span>
<span class="line"><span>* IPv6: 64:ff9b::3653:e965, 64:ff9b::36d2:2394, 64:ff9b::22eb:43ee, 64:ff9b::3402:3c33, 64:ff9b::20c3:2e3f, 64:ff9b::6432:e5a4, 64:ff9b::3417:5e26, 64:ff9b::20c0:1c5b</span></span>
<span class="line"><span>* IPv4: 32.192.28.91, 54.83.233.101, 54.210.35.148, 100.50.229.164, 52.23.94.38, 52.2.60.51, 34.235.67.238, 32.195.46.63</span></span>
<span class="line"><span>*   Trying [64:ff9b::3653:e965]:443...</span></span>
<span class="line"><span>* Connected to httpbin.org (64:ff9b::3653:e965) port 443</span></span>
<span class="line"><span>* ALPN: curl offers h2,http/1.1</span></span>
<span class="line"><span>* (304) (OUT), TLS handshake, Client hello (1):</span></span>
<span class="line"><span>*  CAfile: /etc/ssl/cert.pem</span></span>
<span class="line"><span>*  CApath: none</span></span>
<span class="line"><span>* (304) (IN), TLS handshake, Server hello (2):</span></span>
<span class="line"><span>* TLSv1.2 (IN), TLS handshake, Certificate (11):</span></span>
<span class="line"><span>* TLSv1.2 (IN), TLS handshake, Server key exchange (12):</span></span>
<span class="line"><span>* TLSv1.2 (IN), TLS handshake, Server finished (14):</span></span>
<span class="line"><span>* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):</span></span>
<span class="line"><span>* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):</span></span>
<span class="line"><span>* TLSv1.2 (OUT), TLS handshake, Finished (20):</span></span>
<span class="line"><span>* TLSv1.2 (IN), TLS change cipher, Change cipher spec (1):</span></span>
<span class="line"><span>* TLSv1.2 (IN), TLS handshake, Finished (20):</span></span>
<span class="line"><span>* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256 / [blank] / UNDEF</span></span>
<span class="line"><span>* ALPN: server accepted h2</span></span>
<span class="line"><span>* Server certificate:</span></span>
<span class="line"><span>*  subject: CN=httpbin.org</span></span>
<span class="line"><span>*  start date: Jul 20 00:00:00 2025 GMT</span></span>
<span class="line"><span>*  expire date: Aug 17 23:59:59 2026 GMT</span></span>
<span class="line"><span>*  subjectAltName: host "httpbin.org" matched cert's "httpbin.org"</span></span>
<span class="line"><span>*  issuer: C=US; O=Amazon; CN=Amazon RSA 2048 M03</span></span>
<span class="line"><span>*  SSL certificate verify ok.</span></span>
<span class="line"><span>* using HTTP/2</span></span>
<span class="line"><span>* [HTTP/2] [1] OPENED stream for https://httpbin.org/headers</span></span>
<span class="line"><span>* [HTTP/2] [1] [:method: GET]</span></span>
<span class="line"><span>* [HTTP/2] [1] [:scheme: https]</span></span>
<span class="line"><span>* [HTTP/2] [1] [:authority: httpbin.org]</span></span>
<span class="line"><span>* [HTTP/2] [1] [:path: /headers]</span></span>
<span class="line"><span>* [HTTP/2] [1] [user-agent: curl/8.7.1]</span></span>
<span class="line"><span>* [HTTP/2] [1] [accept: */*]</span></span>
<span class="line"><span>> GET /headers HTTP/2</span></span>
<span class="line"><span>> Host: httpbin.org</span></span>
<span class="line"><span>> User-Agent: curl/8.7.1</span></span>
<span class="line"><span>> Accept: */*</span></span>
<span class="line"><span>></span></span>
<span class="line"><span>* Request completely sent off</span></span>
<span class="line"><span>&#x3C; HTTP/2 200</span></span>
<span class="line"><span>&#x3C; date: Wed, 18 Mar 2026 08:06:07 GMT</span></span>
<span class="line"><span>&#x3C; content-type: application/json</span></span>
<span class="line"><span>&#x3C; content-length: 172</span></span>
<span class="line"><span>&#x3C; server: gunicorn/19.9.0</span></span>
<span class="line"><span>&#x3C; access-control-allow-origin: *</span></span>
<span class="line"><span>&#x3C; access-control-allow-credentials: true</span></span>
<span class="line"><span>&#x3C;</span></span>
<span class="line"><span>{</span></span>
<span class="line"><span>  "headers": {</span></span>
<span class="line"><span>    "Accept": "*/*",</span></span>
<span class="line"><span>    "Host": "httpbin.org",</span></span>
<span class="line"><span>    "User-Agent": "curl/8.7.1",</span></span>
<span class="line"><span>    "X-Amzn-Trace-Id": "Root=1-69ba5cef-25ce2a403835b096102690f0"</span></span>
<span class="line"><span>  }</span></span>
<span class="line"><span>}</span></span>
<span class="line"><span>* Connection #0 to host httpbin.org left intact</span></span></code></pre></div>
<p>Verbose output shows you:</p>
<ul>
<li>The full request headers sent by curl</li>
<li>The TLS handshake details</li>
<li>The response status line</li>
<li>Every response header returned</li>
<li>The response body</li>
</ul>
<p>You can immediately see whether <code>Cache-Control</code> is set correctly, whether <code>Access-Control-Allow-Origin</code> is present, whether the server is returning <code>application/json</code> or accidentally serving <code>text/html</code> for error responses. These are the kinds of details that matter and that most GUI tools obscure behind tabs and dropdowns.</p>
<h2 id="curl-teaches-you-http">curl Teaches You HTTP<a class="heading-anchor" href="#curl-teaches-you-http" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>This is the deeper argument. Learning curl is not really about the tool — it is about what the tool forces you to confront. Every flag in curl maps to an HTTP concept:</p>
<ul>
<li><code>-H</code> / <code>--header</code> → HTTP headers</li>
<li><code>-X</code> / <code>--request</code> → HTTP methods (GET, POST, PUT, PATCH, DELETE)</li>
<li><code>-d</code> / <code>--data</code> → request body</li>
<li><code>-i</code> / <code>--include</code> → response headers</li>
<li><code>-L</code> / <code>--location</code> → following redirects</li>
<li><code>-b</code> / <code>--cookie</code> → cookie handling</li>
<li><code>-u</code> / <code>--user</code> → HTTP Basic Authentication</li>
</ul>
<p>When you learn curl, you learn HTTP. You develop an accurate mental model of the request/response cycle that abstract clients hide from you. That model makes you a better API designer, a better debugger, and a better reviewer of AI-generated code.</p>
<h2 id="who-should-learn-curl">Who Should Learn curl?<a class="heading-anchor" href="#who-should-learn-curl" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><strong>Backend developers</strong> — to test endpoints during development without spinning up a frontend</li>
<li><strong>Frontend developers</strong> — to isolate whether</li>
<li>a bug is in the API or in the client code</li>
<li><strong>QA engineers</strong> — to write reproducible test cases and regression scripts</li>
<li><strong>DevOps and platform engineers</strong> — to probe services, check health endpoints, and diagnose network-level issues</li>
<li><strong>Anyone using AI tools</strong> — to verify and audit what the AI is generating</li>
</ul>
<h2 id="the-bottom-line">The Bottom Line<a class="heading-anchor" href="#the-bottom-line" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><code>curl</code> is not glamorous. It has been around for nearly three decades. It has no UI, no drag-and-drop, no AI suggestions built in. And it is still, in 2026, one of the most useful things you can have in your toolkit.</p>
<p>It is fast, available everywhere, scriptable, and honest. It shows you exactly what is on the wire. In a world where AI can generate HTTP calls but cannot tell you whether those calls are correct for your specific situation, that honesty matters more than ever.</p>
<p>Learn <code>curl</code>. Not instead of modern tools — but alongside them. Use it to debug, to test, to audit, and to build the kind of intuition about HTTP that no GUI can give you.</p>
<p>The terminal is not going anywhere. Neither is curl.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/docker-docker-compose-commands-i-keep-forgetting-cheat-sheet/">Docker &#x26; Docker Compose Cheat Sheet</a></li>
<li><a href="/how-to-setup-an-express-js-server-using-typescript-2024/">Express.js Server with TypeScript</a></li>
<li><a href="/what-is-a-cron-job-simple-guide-for-beginners/">What Is a Cron Job? Simple Guide for Beginners</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Remote Work! Freedom or Burnout?</title>
      <link>https://littlecodingthings.com/remote-work-freedom-or-burnout/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/remote-work-freedom-or-burnout/</guid>
      <pubDate>Mon, 09 Feb 2026 13:49:00 GMT</pubDate>
      <description>The honest case for and against remote work as a developer — the freedom and flexibility against distraction, isolation and blurred hours.</description>
      <category>Thoughts &amp; Theory</category>
      <content:encoded><![CDATA[<p>Remote work has become the ‘Big Dream’ for many people, especially for us, the programmers! Is this a correct choice, or in other words, are we truly walking the right path? How about moving forward and analyzing it a bit further?</p>
<h2 id="the-shiny-features-of-working-remotely">The shiny features of working remotely<a class="heading-anchor" href="#the-shiny-features-of-working-remotely" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Below, we’ll explore why working remotely is such an excellent option — one that offers <strong>freedom and flexibility</strong> that we can benefit from.</p>
<h3 id="the-liberty-to-live-life-your-way">The liberty to live life your way<a class="heading-anchor" href="#the-liberty-to-live-life-your-way" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><img src="/working-remotely-lifestyle.webp" alt="A happy woman sitting in an armchair drinking coffee, eating cake and listening to the music while looking the rain outside the window" style="max-width:42%" class="img-narrow"></p>
<p>Rolling out of bed, throwing on your fluffy sportswear, <strong>sidestepping the strict office 👠 dress code</strong>. Drinking the first cup ☕ of coffee in your cozy place, listening to music, and eating this amazing lemon cake you made yesterday, you know, the one with the strawberries on top.Your long-awaited chance to <strong>start the healthy diet</strong> you’ve wanted, free from distractions and street food, has finally arrived, too. It’s a win-win situation, for both work and health, admit it!
In addition, <strong>no worries about running outside in the morning ☔</strong> <strong>rain</strong> or <strong>wasting time in 🛵</strong> <strong>traffic</strong>. And guess what? <strong>Dealing with upset faces and angry looks for delays</strong> is thankfully one less thing to worry about. It really feels like living inside an amazing 🌌 dream. Isn’t it?</p>
<h3 id="building-your-working-environment">Building your working environment<a class="heading-anchor" href="#building-your-working-environment" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><img src="/working-remotely-desired-office.webp" alt="A futuristic colorful office" style="max-width:42%" class="img-narrow"></p>
<p>One of the most exciting parts of working remotely is the chance to <strong>design your own “coding land”</strong>, avoiding difficult coworkers and the constant 📢 noise of an open office. An extra-large desk, exclusively for you, and huge 🖥 monitors with mood lighting. On top of that, the comfy chair that provides a massage to the back and makes debugging 🐞 less painful. It looks like you are the first one to appear in the credits of a science fiction movie 🎬 ✨. What a futuristic, inspiring world! Isn’t this a dreamy place to work?</p>
<p><img src="/working-remotely-outland.webp" alt="" style="max-width:42%" class="img-narrow"></p>
<p>Plus, do you need a change from this scenery? I doubt it, but let’s say that you need. With <strong>just a laptop and wifi</strong>, you could join meetings from a cabin 🏡 in the woods or fixing bugs and pushing commits under the trees by the 🏞 river. Well, as far as I can tell, that’s a real perk! But be careful and stay focused if you stare too long at the water, your ideas may jump in instead of 🌼 blooming on your screen, or even worse, your 💻 laptop decides to take a dive and go with the flow! 🌊</p>
<h3 id="the-flexibility-you-enjoy-out-in-the-world">The flexibility you enjoy out in the world<a class="heading-anchor" href="#the-flexibility-you-enjoy-out-in-the-world" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>To make matters even better, what about <strong>this fantastic option to create your daily program as you always wish?</strong> You can eventually arrange this appointment with the 🩺 doctor you haven’t been able to reach for ages, since afternoons are always booked up.</p>
<p><img src="/working-remotely-exersice.webp" alt="A woman jogging in the park" style="max-width:42%" class="img-narrow"></p>
<p><strong>Remote work allows you to go wherever suits you</strong>. You can take long walks in the park, which brings more joy and laughter into your life. Additionally, you can fill your day with sports, whether 🚴‍♀️ individual or ⚽ team-based. <strong>Sports can relax you and energize you at the same time</strong>. <strong>Plus you balance the solitude working from home</strong> as team-based sports surround you with companionship, friendship, and a sense of belonging.</p>
<p><img src="/working-remotely-shopping.webp" alt="A woman singing while shopping in a supermarket" style="max-width:42%" class="img-narrow"></p>
<p>And what a miracle! Join the <strong>🛒</strong> supermarket at 9 o’clock in the morning, shopping while whistling around alone, <strong>avoiding these never-ending lines</strong>. Do not pretend that this way of life doesn’t seem dreamy, too?</p>
<p>Let’s be honest, the pros are definitely appealing, but is it all sunshine and rainbows? 🌈✨ Perhaps it’s time to flip the script and see the other side before your dream becomes a nightmare, after all, every rose has its thorn.</p>
<h2 id="the-hidden-bugs-of-pajama-life">The hidden bugs of pajama Life<a class="heading-anchor" href="#the-hidden-bugs-of-pajama-life" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Below, we’ll analyze why working remotely can quickly turn into a disaster. <strong>Once you get freedom, every day will be an unstoppable battle to stick to a schedule</strong> and soon chaos will become your constant company.</p>
<h3 id="the-unbeatable-alarm-clock">The unbeatable alarm clock<a class="heading-anchor" href="#the-unbeatable-alarm-clock" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><img src="/working-remotely-sleeping-ezgif-com-optiwebp.webp" alt="A woman sleeping deep while alarm clock ticking" style="max-width:42%" class="img-narrow"></p>
<p>Rolling out of bed… Ops!! You do not have to! You are planning your daily program now! <strong>All these must…, must… are not really necessary anymore!</strong> Let’s roll over and return to the dreamland for a few more minutes! Suddenly…. Oh my God! What time is it? Where am I? What about all these deadlines at work? <strong>Yes, work is still in the game, or at least this is what you wish 💸 for</strong>.
The most significant mistake we make when we lose the “<em>Boss</em>“, the one who is always hovering over and keeping us focused and in line. <strong>No discipline! No focus! No program!</strong></p>
<h3 id="the-constant-parade-of-distractions">The constant parade of distractions<a class="heading-anchor" href="#the-constant-parade-of-distractions" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><img src="/working-remotely-cat-ezgif-com-optiwebp.webp" alt="A woman working on a laptop while a cat disturb her" style="max-width:42%" class="img-narrow"></p>
<p>Working remotely can also lead to an endless lack of focus. Your fluffy, warm bed on a cold 🌨 day. Another 🎞 episode of your favorite series, and just when you’re finally deep in your code, the laundry machine decides to announce—loudly and proudly—with a nonstop <em>“bip-bip-bip”</em> 🔔 that it’s done. You finally sit back down at your desk, only to find your cat has claimed it as their personal 👑 throne, demanding attention at the exact moment you need to focus.</p>
<p><img src="/working-remotely-distractions.webp" alt="" style="max-width:42%" class="img-narrow"></p>
<p>And just when you manage to reclaim your keyboard, “<em>ding-dong</em>” the doorbell rings because the delivery guy is here with yet another package 📦 from that “one last 🤣 online order.” By the time you get back to your screen, you’ve completely forgotten what bug you were even fixing in the first place.</p>
<h3 id="coworkers-but-not-connected">Coworkers but not connected<a class="heading-anchor" href="#coworkers-but-not-connected" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Besides that, your colleague’s status still shows as offline/away, making it very difficult to get in touch. <strong>Jumping into their desk and asking a quick question is no longer an option</strong>, remember? So, all signs indicate that a former common day “at work” can now take ages, so you can grow a beard while waiting. A 30-second, straightforward question at the office can quickly turn into an hour or even longer 😫 of back-and-forth messages.</p>
<p><img src="/working-remotely-coworkers.webp" alt="Two happy coworkers" style="max-width:42%" class="img-narrow"></p>
<p>And just like that, this coworker, who was once known as “<em>the office weirdo</em>“, appears to be the perfect fit for you. It seems like you’re experiencing the sense of missing someone for the first time and loneliness hangs in the air like a heavy 🌫 fog.</p>
<h3 id="the-isolation-factor--living-with-system-errors">The isolation factor &#x26; living with system errors<a class="heading-anchor" href="#the-isolation-factor--living-with-system-errors" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Another crucial aspect we must pay attention to is detachment, and one of the biggest challenges of remote work. At first, everything seemed ideal. Finally, alone! My life, my rules! Then <strong>it is slowly creating distance not only from coworkers but also from the sense of belonging to a team</strong>. Soon, this silence can start to feel heavy, and even the cat can’t bridge the weird sense of emptiness.</p>
<p><img src="/working-remotely-isolation-factor.webp" alt="A neglected woman working in a messy room in front of a computer in the dark" style="max-width:44%" class="img-narrow"></p>
<p>Excessive isolation can easily lead to an <strong>unbalanced life</strong>, where <strong>work begins to dominate and personal well-being is neglected</strong>. Your daily schedule is now destroyed and this can be extremely harmful. Much like running on buggy code, it eventually crashes. Without clear boundaries, <strong>stress, 😰</strong> <strong>exhaustion and lower productivity</strong> will be your besties. These awful <a href="/the-burnout-syndrome-how-to-identify-and-overcome-it/">“burnout syndrome”</a> (a state of physical and mental exhaustion) and “<a href="/unmasking-impostor-syndrome-in-tech-watch-out-for-these-signs/">impostorism or impostor syndrome</a>” (the nagging feeling that you are never doing enough or not good enough at what you do) will knock on your door without hesitation.</p>
<h2 id="remote-work--bottom-line">Remote work – Bottom line<a class="heading-anchor" href="#remote-work--bottom-line" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Whether working remotely is a good choice depends on the person. The balance between the benefits and drawbacks ultimately depends on personal circumstances.
What about you? Have you ever worked remotely or considered doing so? Do you agree with these points? Are these benefits and challenges in your mind? Do you believe this kind of work is the right fit for you? What makes you feel that way? What are your thoughts right now?
Recognizing how these factors align with your own goals and answering the <strong>key questions</strong> above is essential before making your final decision about whether to work remotely or not. And for those who are already working remotely, these questions can help you understand if this setup trully works for you.</p>
<p><img src="/working-remotely-guestions.webp" alt="A woman in front of a crossroad looking at a key" style="max-width:44%" class="img-narrow"></p>
<p>Having the option to work from anywhere can be a dreamy scenario, but it only works if you manage to <strong>stay disciplined and focused</strong>, striking the right ⚖️ balance between life and work. Good routines and rules are crucial. Frankly, this is the time of your life when 📅 <strong>planning matters more than ever</strong>.</p>
<p>Think of it as your compass to enjoy all the freedom without losing your 🎯 direction. Just remember: whether you’re in an office, at home, or somewhere outside, the job still needs to be done, and no amount of pajamas or the gentle “murmur” of the flowing river will change that. After all, the bills 💵have been paid.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/the-burnout-syndrome-how-to-identify-and-overcome-it/">Developer Burnout: Signs and Recovery</a></li>
<li><a href="/how-to-decide-if-programming-is-right-for-you/">How To Decide If Programming Is Right For You?</a></li>
<li><a href="/best-job-sites-for-web-developers/">Best Job Sites for Web Developers</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Docker &amp; Docker Compose Cheat Sheet</title>
      <link>https://littlecodingthings.com/docker-docker-compose-commands-i-keep-forgetting-cheat-sheet/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/docker-docker-compose-commands-i-keep-forgetting-cheat-sheet/</guid>
      <pubDate>Thu, 22 Jan 2026 13:27:00 GMT</pubDate>
      <description>A practical Docker and Docker Compose cheat sheet: start and stop services, follow logs, run commands inside containers, and clean up what you don’t need.</description>
      <category>Setup &amp; Tools</category>
      <content:encoded><![CDATA[<p>I recently started building a side project and decided to use <strong>Docker Compose</strong> to manage my containers. While working on it, I noticed that there are quite a few commands I keep reaching for—and I wanted to have them written down somewhere.</p>
<p>In my day-to-day (9–5) work, I don’t use Docker extensively beyond the basic <code>up</code> and <code>down</code> commands, so some of the more advanced or less frequent commands tend to get rusty over time. That is a very normal place to end up, and it’s the argument for <a href="/why-i-stopped-memorizing-docker-commands-and-built-a-workflow-instead/">not memorising Docker commands at all</a> and building a workflow you can look things up in instead.</p>
<p>While refreshing my Docker and Docker Compose knowledge, I decided to collect all the commands I actually use and put them into one place. Think of this post as a <strong>personal cheat sheet</strong>—useful for quick debugging, reminders, or getting unstuck when something isn’t behaving as expected. Hopefully, it helps you too. 😊</p>
<h2 id="docker-compose-commands">Docker Compose Commands<a class="heading-anchor" href="#docker-compose-commands" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Docker Compose allows you to define and run multi-container applications using a single configuration file, making local development and orchestration much easier.. These are the commands I use most.</p>
<h3 id="starting-services">Starting Services<a class="heading-anchor" href="#starting-services" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>These commands are used to start one or more services defined in your <code>docker-compose.yml</code> file, either in the foreground or background.</p>
<p>Start all services defined in <code>docker-compose.yml</code>:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>docker compose up</span></span></code></pre></div>
<p>Start in background (detached mode) – you get your terminal back:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>docker compose up -d</span></span></code></pre></div>
<p>Start services and force a rebuild of images (useful after changing a <code>Dockerfile</code> or dependencies):</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>docker compose up --build</span></span></code></pre></div>
<p>Start specific service only:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>docker compose up -d service-a</span></span></code></pre></div>
<p>or start multiple services at once:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>docker compose up -d service-a service-b</span></span></code></pre></div>
<h3 id="stopping-services">Stopping Services<a class="heading-anchor" href="#stopping-services" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Use these commands to stop running containers, with options to either keep or completely remove them.</p>
<p>Stop all services (containers are stopped but not removed):</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>docker compose stop</span></span></code></pre></div>
<p>Stop and remove containers (this is what you usually want):</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>docker compose down</span></span></code></pre></div>
<p>Stop, remove containers <strong>and volumes</strong>
⚠️ <strong>Warning:</strong> This deletes persisted data such as databases.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>docker compose down -v</span></span></code></pre></div>
<p>Stop specific service:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>docker compose stop service-a</span></span></code></pre></div>
<h3 id="restarting-services">Restarting Services<a class="heading-anchor" href="#restarting-services" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Restarting services is useful after configuration changes or when a container becomes unresponsive.</p>
<p>Restart all services:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>docker compose restart</span></span></code></pre></div>
<p>Restart specific service:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>docker compose restart service-a</span></span></code></pre></div>
<p>For Node.js apps, you might also want file-watching inside your container using <a href="/how-to-restart-your-node-apps-without-nodemon/" title="How to Restart Your Node App Without Nodemon">Node’s built-in <code>--watch</code> flag</a>.</p>
<h3 id="viewing-statuses">Viewing statuses<a class="heading-anchor" href="#viewing-statuses" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>These commands help you quickly check which services are running and their current state.</p>
<p>List running containers for this project:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>docker compose ps</span></span></code></pre></div>
<p>List all containers (including stopped):</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>docker compose ps -a</span></span></code></pre></div>
<h2 id="docker-commands">Docker commands<a class="heading-anchor" href="#docker-commands" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>In addition to Docker Compose, these core Docker commands are useful for inspecting and interacting with individual containers.</p>
<h3 id="executing-commands-in-containers">Executing Commands in Containers<a class="heading-anchor" href="#executing-commands-in-containers" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>These commands let you access a running container directly, which is especially helpful for debugging and inspecting the runtime environment.</p>
<p>Using an interactive shell:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>docker exec -it container_name bash</span></span></code></pre></div>
<p>If <code>bash</code> is not available (for example, in Alpine images), use <code>sh</code> instead:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>docker exec -it container_name sh</span></span></code></pre></div>
<p>These commands let you enter a running container with an interactive shell, so you can inspect files, run commands, and debug things directly from inside the container.</p>
<h3 id="cleanup-commands">Cleanup commands<a class="heading-anchor" href="#cleanup-commands" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Docker can accumulate unused containers, images, and volumes over time—these commands help keep your system clean.</p>
<p>Remove stopped containers, images or volumes:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>docker container prune</span></span>
<span class="line"><span></span></span>
<span class="line"><span>docker image prune</span></span>
<span class="line"><span></span></span>
<span class="line"><span>docker volume prune</span></span></code></pre></div>
<p>or in case you need something more generic</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>docker system prune --volumes</span></span></code></pre></div>
<p>which removes all unused resources, including volumes.</p>
<h3 id="removing-containers-by-name-prefix">Removing Containers by Name Prefix<a class="heading-anchor" href="#removing-containers-by-name-prefix" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>While setting up my project, I found some containers from old projects that i had probably forgotten to cleanup. Instead of removing them one by one, because they were a lot, I tried to find a command that removes all of them, by using their prefix (needless to say they were sharing the same prefix). The following command removed all containers with the prefix si:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>docker rm -f $(docker ps -aq --filter "name=si_")</span></span></code></pre></div>
<h2 id="viewing-logs">Viewing Logs<a class="heading-anchor" href="#viewing-logs" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Logs are often the first place to look when something isn’t working. These commands help you inspect service output, debug errors, and monitor behavior in real time.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>docker compose logs</span></span>
<span class="line"><span>docker compose logs -f service-a # -f keeps streaming logs in real time</span></span>
<span class="line"><span>docker compose logs --tail=100 # Only the last 100 log lines</span></span></code></pre></div>
<p>So if you wanted to see logs for a specific container, in real time you could use</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>docker compose logs -f --tail=100 &#x3C;container-name></span></span></code></pre></div>
<h3 id="copy-files-from-container">Copy Files From Container<a class="heading-anchor" href="#copy-files-from-container" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>docker cp container_name:/path/in/container ./local-path</span></span></code></pre></div>
<h2 id="docker-compose-vs-docker-compose"><code>docker-compose</code> vs <code>docker compose</code><a class="heading-anchor" href="#docker-compose-vs-docker-compose" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>You may see Docker Compose used in two different ways:</p>
<ul>
<li><code>docker-compose</code></li>
<li><code>docker compose</code></li>
</ul>
<p>They do the same thing, but they’re <strong>not the same tool</strong>.</p>
<h3 id="docker-compose-legacy"><code>docker-compose</code> (Legacy)<a class="heading-anchor" href="#docker-compose-legacy" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<ul>
<li>Older, standalone CLI</li>
<li>Installed separately</li>
<li>Common in older projects and tutorials</li>
</ul>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>docker-compose up -d</span></span></code></pre></div>
<h3 id="docker-compose-recommended"><code>docker compose</code> (Recommended)<a class="heading-anchor" href="#docker-compose-recommended" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<ul>
<li>Built into the Docker CLI</li>
<li>Installed by default with modern Docker</li>
<li>Actively maintained and recommended</li>
</ul>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>docker compose up -d</span></span></code></pre></div>
<h3 id="which-one-should-you-use">Which One Should You Use?<a class="heading-anchor" href="#which-one-should-you-use" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong>Existing projects:</strong> stick with whatever the project already uses</p>
<p><strong>New projects:</strong> use <code>docker compose</code></p>
<p><em>Setting up a new project? You might also want to automate git hooks, check our <a href="/husky-hooks-the-easy-way-to-improve-your-project-workflow/" title="Husky Hooks: The Easy Way to Improve Your Project Workflow">husky hooks intro guide</a> to learn how.</em></p>
<h2 id="quick-reference-card">Quick Reference Card<a class="heading-anchor" href="#quick-reference-card" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>This section provides a compact overview of the most commonly used Docker and Docker Compose commands for quick access.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>╔═══════════════════════════════════════════════════════════════╗</span></span>
<span class="line"><span>║                 DOCKER COMMANDS QUICK REFERENCE               ║</span></span>
<span class="line"><span>╠═══════════════════════════════════════════════════════════════╣</span></span>
<span class="line"><span>║ COMPOSE                                                       ║</span></span>
<span class="line"><span>║   docker compose up -d          Start in background           ║</span></span>
<span class="line"><span>║   docker compose down           Stop and remove               ║</span></span>
<span class="line"><span>║   docker compose logs -f api    Follow service logs           ║</span></span>
<span class="line"><span>║   docker compose up --build     Rebuild and start             ║</span></span>
<span class="line"><span>║   docker compose exec api sh    Shell into service            ║</span></span>
<span class="line"><span>╠═══════════════════════════════════════════════════════════════╣</span></span>
<span class="line"><span>║ CONTAINERS                                                    ║</span></span>
<span class="line"><span>║   docker ps                     List running                  ║</span></span>
<span class="line"><span>║   docker ps -a                  List all                      ║</span></span>
<span class="line"><span>║   docker stop name              Stop container                ║</span></span>
<span class="line"><span>║   docker rm -f name             Force remove                  ║</span></span>
<span class="line"><span>║   docker exec -it name sh       Shell into container          ║</span></span>
<span class="line"><span>╠═══════════════════════════════════════════════════════════════╣</span></span>
<span class="line"><span>║ IMAGES                                                        ║</span></span>
<span class="line"><span>║   docker images                 List images                   ║</span></span>
<span class="line"><span>║   docker rmi name               Remove image                  ║</span></span>
<span class="line"><span>║   docker build -t name .        Build image                   ║</span></span>
<span class="line"><span>║   docker pull name:tag          Pull from registry            ║</span></span>
<span class="line"><span>╠═══════════════════════════════════════════════════════════════╣</span></span>
<span class="line"><span>║ LOGS &#x26; DEBUG                                                  ║</span></span>
<span class="line"><span>║   docker logs -f name           Follow logs                   ║</span></span>
<span class="line"><span>║   docker logs --tail 100 name   Last 100 lines                ║</span></span>
<span class="line"><span>║   docker inspect name           Full container info           ║</span></span>
<span class="line"><span>║   docker stats                  Resource usage                ║</span></span>
<span class="line"><span>╠═══════════════════════════════════════════════════════════════╣</span></span>
<span class="line"><span>║ CLEANUP                                                       ║</span></span>
<span class="line"><span>║   docker system prune           Remove unused                 ║</span></span>
<span class="line"><span>║   docker system prune -a        Remove all unused             ║</span></span>
<span class="line"><span>║   docker volume prune           Remove unused volumes         ║</span></span>
<span class="line"><span>║   docker system df              Check disk usage              ║</span></span>
<span class="line"><span>╚═══════════════════════════════════════════════════════════════╝</span></span>
<span class="line"><span>```</span></span></code></pre></div>
<p>Do you have any Docker or Docker Compose commands that have saved you in tricky situations, or ones you use every day?
Feel free to share them—we’d love to expand this cheat sheet with more real-world examples.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/why-i-stopped-memorizing-docker-commands-and-built-a-workflow-instead/">Why I Stopped Memorizing Docker Commands</a> — the case for keeping a sheet like this one</li>
<li><a href="/environment-variables-101-secure-your-secrets-like-a-pro/">Beginner’s Guide to Environment Variables with Dotenv</a></li>
<li><a href="/why-every-developer-should-still-know-curl-in-2026/">Why Every Developer Should Still Know curl in 2026</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Javascript Testing Tools Explained</title>
      <link>https://littlecodingthings.com/javascript-testing-tools-explained-what-beginners-really-need-to-know/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/javascript-testing-tools-explained-what-beginners-really-need-to-know/</guid>
      <pubDate>Fri, 02 Jan 2026 12:01:00 GMT</pubDate>
      <description>Jest, Vitest, Testing Library, Mocha, Chai and Sinon explained for beginners — what each tool actually does, and which one to start with.</description>
      <category>Setup &amp; Tools</category>
      <content:encoded><![CDATA[<p>If you just learned what testing is and you’re still a bit unsure how to start, you’re not alone. Many beginner developers feel overwhelmed by the amount of tools and libraries in the Javascript testing world. You might wonder: do I need Jest? What is Vitest? Why does everyone keep talking about mocking things?</p>
<p>Let me help you make sense of it all.</p>
<p>This post builds on the one you (hopefully) already read: <a href="/javascript-testing-for-beginners-a-simple-practical-introduction/">Javascript testing for beginners: A simple, practical introduction</a>. If not, it’s a good starting point to understand why testing matters in the first place. Here, we’ll talk about what tools are out there, why they exist, and how to choose the right one for your project.</p>
<h2 id="why-so-many-testing-tools">Why so many testing tools?<a class="heading-anchor" href="#why-so-many-testing-tools" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The short answer is: because testing needs can be very different. Some developers need to test just one small function. Others need to simulate how a user clicks buttons on a real webpage. Some need to test backend logic or APIs. And some want all of that together.</p>
<p>Different tools are created to solve different testing problems. Let’s look at the main ones you’ll hear about.</p>
<h2 id="what-is-a-testing-framework">What is a testing framework?<a class="heading-anchor" href="#what-is-a-testing-framework" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Before going further, let’s clear something up. When people say “testing framework” or “testing library,” they sometimes mix up terms. In this post, we’ll use them loosely. Don’t worry too much about definitions.</p>
<p>But just so we’re on the same page:</p>
<ul>
<li>A <strong>testing framework</strong> usually provides the structure: how to describe a test, run it, and report results.</li>
<li>A <strong>testing library</strong> might focus on one specific part of the testing process (like simulating user actions or helping with mocking).</li>
</ul>
<p>Now let’s see what each popular tool actually does.</p>
<h2 id="jest-the-default-for-many-projects">Jest: The default for many projects<a class="heading-anchor" href="#jest-the-default-for-many-projects" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><a href="https://jestjs.io/">Jest</a> is probably the first tool you’ll hear about in Javascript testing. It’s widely used, especially in React projects. And for good reason—it comes with most things you need built in: test runner, assertion library, and mocking tools.</p>
<ul>
<li>You can write simple tests using <code>test()</code> and <code>expect()</code>.</li>
<li>You can mock functions easily (see what a mock is if you’re unsure).</li>
<li>It works out of the box with many setups.</li>
</ul>
<p>A basic test in Jest looks like this:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">import</span><span style="color:#E1E4E8"> { sum } </span><span style="color:#F97583">from</span><span style="color:#9ECBFF"> './math'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">test</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'adds two numbers'</span><span style="color:#E1E4E8">, () </span><span style="color:#F97583">=></span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#B392F0">  expect</span><span style="color:#E1E4E8">(</span><span style="color:#B392F0">sum</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">2</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">3</span><span style="color:#E1E4E8">)).</span><span style="color:#B392F0">toBe</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">5</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">});</span></span></code></pre></div>
<p>Jest is great for <strong>unit tests</strong>, which are explained more deeply in <em><a href="/integration-and-unit-tests-how-to-choose-the-right-one/">Integration and unit tests: How to choose the right one?</a></em>. But it also supports more advanced setups.</p>
<p>Still, Jest isn’t perfect for every case.</p>
<h2 id="vitest-fast-and-vite-friendly">Vitest: Fast and Vite-Friendly<a class="heading-anchor" href="#vitest-fast-and-vite-friendly" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>If you’re using <a href="https://vite.dev/">Vite</a>, you might prefer <a href="https://vitest.dev/">Vitest</a>. It’s a newer test runner that works very similarly to Jest but is built for speed and modern dev setups.</p>
<p>It supports:</p>
<ul>
<li>ES modules by default</li>
<li>Fast startup thanks to Vite integration</li>
<li>Very similar API to Jest, so switching isn’t too hard</li>
</ul>
<p>If you’re just starting and you already use Vite for your project, Vitest is a great alternative. It feels lighter and quicker, especially for frontend apps.</p>
<h2 id="testing-library-rtl-for-testing-ui-like-a-real-user">Testing Library (RTL): For testing UI like a real user<a class="heading-anchor" href="#testing-library-rtl-for-testing-ui-like-a-real-user" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><a href="https://testing-library.com/">React Testing Library</a> (often called RTL) is a library for testing user interfaces. It doesn’t replace Jest—it works with Jest.</p>
<p>RTL helps you simulate how users actually interact with your app:</p>
<ul>
<li>Clicking buttons</li>
<li>Typing in inputs</li>
<li>Checking if the right text shows up</li>
</ul>
<p>Instead of testing if a certain component method was called, you test what the user sees. This makes your tests more realistic.</p>
<p>It follows a rule: <em>“The more your tests resemble the way your software is used, the more confidence they can give you.”</em></p>
<h2 id="mocha-chai-sinon-the-classic-trio">Mocha, Chai, Sinon: The Classic Trio<a class="heading-anchor" href="#mocha-chai-sinon-the-classic-trio" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Before Jest became popular, many Javascript projects used this combo:</p>
<ul>
<li><a href="https://mochajs.org/">Mocha</a> for running tests</li>
<li><a href="https://www.chaijs.com/">Chai</a> for writing assertions</li>
<li><a href="https://sinonjs.org/">Sinon</a> for creating mocks and spies</li>
</ul>
<p>These tools are still good and used in some backend or legacy projects. They give you more flexibility, but also more setup.</p>
<p>For example, to run tests with Mocha and Chai, you’ll usually need to install them separately and configure them more manually.</p>
<p>If you’re just starting, you don’t need to go this route unless you’re joining a project that already uses them.</p>
<h2 id="what-about-mocks-spies-and-stubs">What about Mocks, Spies, and Stubs?<a class="heading-anchor" href="#what-about-mocks-spies-and-stubs" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>You’ll hear these words a lot when testing. Here’s what they mean in simple terms:</p>
<ul>
<li>A <strong>mock</strong> is a fake function that replaces a real one during testing. It lets you test what happens without calling the real thing.</li>
<li>A <strong>spy</strong> is a function that records if and how it was called, but still lets the real function run.</li>
<li>A <strong>stub</strong> is like a mock but with more control—you can decide what it returns.</li>
</ul>
<p>If you’re confused, check the glossary entries for mock and spy.</p>
<p>These tools are helpful in <strong>unit testing</strong>, when you want to isolate just one part of your code. For example, you might want to check that a function <em>called</em> another one, but without actually doing what the second one does.</p>
<h2 id="what-should-you-use-as-a-beginner">What should you use as a beginner?<a class="heading-anchor" href="#what-should-you-use-as-a-beginner" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Here’s a simple suggestion:</p>
<ul>
<li><strong>Start with Jest.</strong> It’s well-documented, easy to set up, and covers most use cases.</li>
<li>If you’re using <strong>Vite</strong>, try <strong>Vitest</strong> instead.</li>
<li>If you’re building user interfaces, add <strong>Testing Library</strong> to test what the user sees.</li>
</ul>
<p>You don’t need everything at once. Focus on learning how to write a few tests. You’ll naturally learn the tools better as you write more code.</p>
<h3 id="a-quick-example-putting-it-together">A quick example: Putting it together<a class="heading-anchor" href="#a-quick-example-putting-it-together" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Let’s say you have a small function like this:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">export</span><span style="color:#F97583"> function</span><span style="color:#B392F0"> greetUser</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">name</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#F97583">  return</span><span style="color:#9ECBFF"> `Hello, ${</span><span style="color:#E1E4E8">name</span><span style="color:#9ECBFF">}!`</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>A simple unit test using Vitest would be:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">import</span><span style="color:#E1E4E8"> { describe, it, expect } </span><span style="color:#F97583">from</span><span style="color:#9ECBFF"> 'vitest'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">import</span><span style="color:#E1E4E8"> { greetUser } </span><span style="color:#F97583">from</span><span style="color:#9ECBFF"> './greet'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">describe</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'greetUser'</span><span style="color:#E1E4E8">, () </span><span style="color:#F97583">=></span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#B392F0">  it</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'greets by name'</span><span style="color:#E1E4E8">, () </span><span style="color:#F97583">=></span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#B392F0">    expect</span><span style="color:#E1E4E8">(</span><span style="color:#B392F0">greetUser</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'Anna'</span><span style="color:#E1E4E8">)).</span><span style="color:#B392F0">toBe</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'Hello, Anna!'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  });</span></span>
<span class="line"><span style="color:#E1E4E8">});</span></span></code></pre></div>
<p>You could use Jest instead—the code would almost be the same. This test checks the return value, no mocking needed.</p>
<p>Later, if your function becomes more complex (calls an API, uses another function), you might use a <strong>mock</strong> to isolate the behavior. You can then write more detailed tests, like we discuss in <em><a href="/integration-and-unit-tests-how-to-choose-the-right-one/">Integration and unit tests: How to choose the right one?</a></em>.</p>
<h2 id="final-thoughts">Final thoughts<a class="heading-anchor" href="#final-thoughts" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Don’t feel like you need to master every testing tool at once. Testing is a skill you build slowly. Start small, use a simple tool like Jest or Vitest, and practice writing real tests.</p>
<p>If you’re ever stuck on what kind of test to write, go back to <a href="/javascript-testing-for-beginners-a-simple-practical-introduction/">Javascript testing for beginners</a> and <a href="/integration-and-unit-tests-how-to-choose-the-right-one/">Integration and unit tests: How to choose the right one?</a> to refresh the theory.</p>
<p>The tools are just tools—they’re here to help you write better, safer code. And soon, you’ll start to feel that they do.  🥳</p>]]></content:encoded>
    </item>
    <item>
      <title>Javascript Testing for Beginners</title>
      <link>https://littlecodingthings.com/javascript-testing-for-beginners-a-simple-practical-introduction/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/javascript-testing-for-beginners-a-simple-practical-introduction/</guid>
      <pubDate>Sun, 28 Dec 2025 09:45:00 GMT</pubDate>
      <description>A plain-English introduction to Javascript testing: what a test actually is, why it matters, the types worth knowing, and the tools to start with.</description>
      <category>Setup &amp; Tools</category>
      <content:encoded><![CDATA[<p>Learning Javascript often feels clear at the beginning. You write some code, refresh the browser, and see something working on the screen. That feedback is immediate and encouraging. But as soon as your code grows beyond a few files or functions, things start to feel less predictable.</p>
<p>You change a small piece of logic, and something unrelated breaks. You fix that, and another issue appears somewhere else. At that point, many beginners feel stuck. They know <em>something</em> is wrong, but they don’t have a reliable way to understand what changed or why.</p>
<p>This is where testing becomes useful.</p>
<p>Javascript testing is not about writing perfect code or preventing every bug. Especially for beginners, testing is about building <strong>confidence and clarity</strong>. It gives you a way to check that your code behaves the way you think it does, and it gives you fast feedback when that behavior changes.</p>
<p>This guide introduces Javascript testing in a practical, beginner-friendly way. It focuses on understanding the ideas first, without pushing tools or complexity before they make sense.</p>
<h2 id="what-is-javascript-testing">What is Javascript testing?<a class="heading-anchor" href="#what-is-javascript-testing" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Javascript testing is the practice of writing code that checks other code.</p>
<p>A test runs part of your Javascript program and verifies that the result matches what you expect. If the result is correct, the test passes. If it’s not, the test fails and shows you that something is wrong.</p>
<p>Most tests are built around very simple expectations. You might expect a function to return a specific value, handle invalid input gracefully, or behave consistently when called multiple times. Testing gives you a repeatable way to verify those expectations instead of relying on manual checks.</p>
<p>Testing is part of a broader idea known as software testing, which exists across all programming languages. Javascript testing applies the same principles to Javascript code, whether it runs in the browser, on a server, or inside a larger application.</p>
<p>The key benefit of testing is not automation alone. It’s <strong>trust</strong>. When you have tests, you don’t have to wonder whether something still works. You can check.</p>
<h2 id="why-javascript-testing-matters-for-beginners">Why Javascript testing matters for beginners<a class="heading-anchor" href="#why-javascript-testing-matters-for-beginners" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Many beginners believe testing is something you add later, once you are “good enough” at Javascript. In reality, testing is often most helpful when you are still learning.</p>
<p>When you write tests, you are forced to be precise about what your code should do. That process often exposes misunderstandings early. A test might fail not because your code is broken, but because your assumption about how something works was incorrect.</p>
<p>Without tests, debugging tends to rely on trial and error. You log values, refresh the page, and hope you notice what went wrong. With tests, failures give you direct signals. They tell you that something changed and help narrow down where the problem lives.</p>
<p>Testing also makes change safer. Beginners often avoid refactoring because they’re afraid of breaking something they already fixed. Tests reduce that fear by giving you quick feedback when behavior changes.</p>
<h2 id="how-javascript-testing-works-at-a-basic-level">How Javascript testing works at a basic level<a class="heading-anchor" href="#how-javascript-testing-works-at-a-basic-level" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>At a basic level, Javascript testing follows a simple pattern.</p>
<p>You provide some input, run the code you want to test, and then check the result. That final check is done using something called an <strong>assertion</strong>. An assertion compares what actually happened with what you expected to happen and decides whether the test should pass or fail.</p>
<p>To make this more concrete, here’s a very small example using Jest.</p>
<p>Imagine you have a simple function that adds two numbers:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">export</span><span style="color:#F97583"> const</span><span style="color:#B392F0"> add</span><span style="color:#F97583"> =</span><span style="color:#E1E4E8"> (</span><span style="color:#FFAB70">a</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">b</span><span style="color:#E1E4E8">) </span><span style="color:#F97583">=></span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">  return</span><span style="color:#E1E4E8"> a </span><span style="color:#F97583">+</span><span style="color:#E1E4E8"> b;</span></span>
<span class="line"><span style="color:#E1E4E8">};</span></span></code></pre></div>
<p>Now you want to test that this function works as expected. A basic Jest test might look like this:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">import</span><span style="color:#E1E4E8"> { add } </span><span style="color:#F97583">from</span><span style="color:#9ECBFF"> './add'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">test</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'adds two numbers correctly'</span><span style="color:#E1E4E8">, () </span><span style="color:#F97583">=></span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#B392F0">  expect</span><span style="color:#E1E4E8">(</span><span style="color:#B392F0">add</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">2</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">3</span><span style="color:#E1E4E8">)).</span><span style="color:#B392F0">toBe</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">5</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">});</span></span></code></pre></div>
<p>In this example:</p>
<ul>
<li><code>test</code> defines a test case</li>
<li><code>add(2, 3)</code> runs the code being tested</li>
<li><code>expect(add(2, 3)).toBe(5)</code> is the assertion</li>
</ul>
<p>The assertion checks whether the actual result matches the expected result. If <code>add(2, 3)</code> returns <code>5</code>, the test passes. If it returns anything else, the test fails.</p>
<p>You don’t need to understand every detail of the syntax right away. What matters is the idea: tests describe expected behavior and automatically verify it.</p>
<h2 id="types-of-javascript-testing-you-should-be-aware-of">Types of Javascript testing you should be aware of<a class="heading-anchor" href="#types-of-javascript-testing-you-should-be-aware-of" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Javascript testing includes different approaches, but beginners don’t need to use all of them immediately.</p>
<p>The most common starting point is <strong>unit testing</strong>. Unit tests focus on small, isolated pieces of code, usually individual functions. They are fast to run, easy to understand, and easier to debug when something goes wrong.</p>
<p>Other testing types exist, such as integration testing and end-to-end testing. These focus on how different parts of an application work together or how the entire application behaves from a user’s perspective.</p>
<p><a href="/integration-and-unit-tests-how-to-choose-the-right-one/">One common question beginners ask is whether to focus on unit tests or integration tests first, and how to choose between them.</a></p>
<p>As a beginner, it’s enough to understand that these testing types exist and serve different purposes. You can explore them gradually as your projects grow in size and complexity.</p>
<h2 id="javascript-testing-tools-and-why-they-exist">Javascript testing tools and why they exist<a class="heading-anchor" href="#javascript-testing-tools-and-why-they-exist" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>To run tests, you need a testing tool. A Javascript testing tool provides a way to execute your tests, make assertions, and show clear feedback when something fails.</p>
<p>At a basic level, testing tools take care of the repetitive work. They find your test files, run them, and report which tests passed or failed. This lets you focus on writing and understanding tests instead of building your own testing system from scratch.</p>
<p>Different tools exist because they solve slightly different problems.</p>
<p>Some tools, like <strong><a href="https://jestjs.io/">Jest</a></strong> and <strong><a href="https://vitest.dev/">Vitest</a></strong>, are all-in-one solutions. They include a test runner, an assertion system, and helpful features like watching for file changes. These tools are often a good starting point for beginners because everything works together out of the box.</p>
<p>Other tools focus on specific parts of the testing process. For example, <strong><a href="https://www.chaijs.com/">Chai</a></strong> is an assertion library that helps you express expectations clearly, while <strong><a href="https://sinonjs.org/">Sinon</a></strong> is commonly used for creating mocks and spies when you need more control over how code behaves during tests.</p>
<p>In frontend-focused projects, especially those using frameworks like React, you may also encounter <strong><a href="https://testing-library.com/">React Testing Library (RTL)</a></strong>. Its goal is to help you test components in a way that reflects how real users interact with them, rather than testing internal implementation details.</p>
<p>It’s important to understand that you don’t need all of these tools at once. Many beginners start with a single, integrated tool and add others only when a specific need appears. The concepts behind testing matter far more than the number of libraries you use.</p>
<p>Testing tools exist to support learning and confidence. They should make testing feel easier, not heavier.</p>
<p>Not sure what tool to start with? I broke down the main ones like <a href="/javascript-testing-tools-explained-what-beginners-really-need-to-know/">Jest and Vitest in a separate post: Javascript Testing Tools Explained</a>, so you can pick without the overwhelm.</p>
<h2 id="how-testing-changes-the-way-you-write-javascript">How testing changes the way you write Javascript<a class="heading-anchor" href="#how-testing-changes-the-way-you-write-javascript" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Over time, testing influences how you approach writing code.</p>
<p>When you write tests, you naturally start thinking in terms of inputs and outputs. You tend to write smaller, clearer functions because they are easier to test. This leads to code that is easier to read, reason about, and maintain.</p>
<p>Tests also act as a form of documentation. They show how your code is expected to behave in real situations, which is helpful when you return to a project later or share it with others.</p>
<p>Some developers take this further by writing tests before writing code, a practice often called test-driven development. You don’t need to follow this approach strictly, but understanding it helps put testing into a professional context.</p>
<h2 id="common-beginner-worries-about-testing">Common beginner worries about testing<a class="heading-anchor" href="#common-beginner-worries-about-testing" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>It’s normal to feel unsure when starting with testing. Many beginners worry about writing tests the wrong way or not testing enough.</p>
<p>The truth is that imperfect tests are still useful. Testing is a skill that improves with repetition. Early tests may feel awkward, but they still provide feedback and build understanding.</p>
<p>Avoiding testing because it feels unfamiliar only delays that learning. Progress matters more than getting everything right.</p>
<h2 id="final-thoughts">Final thoughts<a class="heading-anchor" href="#final-thoughts" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>You don’t need a large project to begin testing. One function is enough.</p>
<p>Write a test. Let it fail. Fix the code. Run the test again and see it pass. That small loop is where learning happens.</p>
<p>As you gain experience, you can add more tests, improve structure, and adopt better practices. But the foundation remains the same: define expected behavior and verify it automatically.</p>
<p>Javascript testing is not about rigid rules or unnecessary complexity. It’s about clarity, confidence, and understanding how your code behaves over time.</p>
<p>For beginners, testing provides structure in a learning process that can otherwise feel chaotic. It helps you move from guessing to knowing, and from hesitation to confidence.</p>
<p>This post is meant to be a foundation. You don’t need to master everything at once. Testing will grow with you, quietly supporting your progress as your skills develop.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/javascript-testing-tools-explained-what-beginners-really-need-to-know/">Javascript Testing Tools Explained</a></li>
<li><a href="/integration-and-unit-tests-how-to-choose-the-right-one/">Integration vs Unit Tests: How to Choose</a></li>
<li><a href="/husky-hooks-the-easy-way-to-improve-your-project-workflow/">Husky Hooks: Improve Your Git Workflow</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Component Naming Conventions in React</title>
      <link>https://littlecodingthings.com/naming-conventions-how-to-name-your-components-without-fighting-your-ui-library/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/naming-conventions-how-to-name-your-components-without-fighting-your-ui-library/</guid>
      <pubDate>Tue, 23 Dec 2025 06:08:00 GMT</pubDate>
      <description>Three naming conventions for components that clash with your UI library — wrapping, naming by purpose, and prefixes — with the tradeoffs of each.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>At some point in pretty much every project, whether you’re setting up the infrastructure or introducing an important library that will be used throughout your app, you run into a tiny problem that turns out not to be so tiny: <strong>naming conventions</strong>.</p>
<p>Let’s take a classic example.</p>
<p>You need a <code>&#x3C;Modal /></code>.
Your UI library already has a <code>&#x3C;Modal /></code>.</p>
<p>So you open a file and write the imports, and suddenly you’re staring at something like this:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">import</span><span style="color:#E1E4E8"> { Modal } </span><span style="color:#F97583">from</span><span style="color:#9ECBFF"> "@heroui/react"</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">import</span><span style="color:#E1E4E8"> { Modal } </span><span style="color:#F97583">from</span><span style="color:#9ECBFF"> "./my-components/Modal"</span><span style="color:#E1E4E8">;</span></span></code></pre></div>
<p>You see? You’re not the only one thinking <code>Modal</code> is a great name for a component about… well, a modal! In my case, I liked the name, but the developers building the HeroUI library also liked it.</p>
<p>Now you have a small issue: how are you going to denote that a modal is one of yours, or that it’s imported from your UI library?</p>
<p>In this example you’re probably thinking, “Well, maybe I’ll just rename one.” Obviously. Maybe <code>&#x3C;HeroModal /></code>. Maybe <code>&#x3C;MyModal /></code>. It works, JavaScript has no issues, TypeScript stops complaining, and you move on.</p>
<p>The problem with this approach is that your code may start feeling noisy after a while. Not broken, but slightly uncomfortable. You might see different files using different aliases, which isn’t the best approach. This increases your cognitive load because you have to <em>remember</em> things instead of intuitively understanding them.</p>
<p>That’s usually when people think the issue is naming.</p>
<p>It’s not.</p>
<p>What’s actually happening is that two completely different ideas are being treated like they’re the same thing.</p>
<p>A library modal is just a tool. It renders a dialog, handles focus, animates, and gets out of the way.</p>
<p>A modal in your app has meaning. It shows up for specific reasons. It follows product rules. It has opinions.</p>
<p>Once you see that difference, naming stops being a guessing game.</p>
<p>To avoid all this headache, the best thing you can do is stop for a bit, think about your approach, and decide what naming convention—a pattern, if you’d like—will help you intuitively understand what’s going on in your app without having to scroll up to your imports every time you see a component used.</p>
<h2 id="naming-convention-1-your-app-owns-modal-the-library-is-the-base">Naming convention 1: Your app owns “Modal”, the library is the “Base”<a class="heading-anchor" href="#naming-convention-1-your-app-owns-modal-the-library-is-the-base" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>This is the easiest convention, the one you probably thought about first. The idea behind this is:</p>
<ul>
<li>Your app gets to use the “clean” name <strong>Modal</strong></li>
<li>The UI library gets a more technincal name: <strong>ModalBase</strong></li>
</ul>
<p>Example</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">import</span><span style="color:#E1E4E8"> { Modal </span><span style="color:#F97583">as</span><span style="color:#E1E4E8"> ModalBase } </span><span style="color:#F97583">from</span><span style="color:#9ECBFF"> "@heroui/react"</span><span style="color:#E1E4E8">;</span></span></code></pre></div>
<p>Then inside your component’s implementation would be:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">function</span><span style="color:#B392F0"> Modal</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">props</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#F97583">  return</span><span style="color:#E1E4E8"> &#x3C;</span><span style="color:#79B8FF">ModalBase</span><span style="color:#E1E4E8"> {</span><span style="color:#F97583">...</span><span style="color:#E1E4E8">props} />;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Other examples for naming your components using this convention could be</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#FDAEB7;font-style:italic">ModalBase</span><span style="color:#E1E4E8"> /></span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#FDAEB7;font-style:italic">BaseModal</span><span style="color:#E1E4E8"> /></span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#FDAEB7;font-style:italic">HeroModal</span><span style="color:#E1E4E8"> /> // (library-prefixed)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#FDAEB7;font-style:italic">ModalCore</span><span style="color:#E1E4E8"> /></span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#FDAEB7;font-style:italic">UIModal</span><span style="color:#E1E4E8"> /></span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#FDAEB7;font-style:italic">ModalRaw</span><span style="color:#E1E4E8"> /></span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#FDAEB7;font-style:italic">RawModal</span><span style="color:#E1E4E8"> /></span></span></code></pre></div>
<h3 id="pros">Pros<a class="heading-anchor" href="#pros" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<ul>
<li>✅ Everyone on your team can use <code>&#x3C;Modal /></code> without worrying about where it came from.</li>
<li>✅ If you ever change your UI library, you only change this wrapper, not your whole codebase.</li>
<li>✅ Great for beginners because it keeps things simple and consistent.</li>
</ul>
<h3 id="cons"><strong>Cons</strong><a class="heading-anchor" href="#cons" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<ul>
<li>❌ If your wrapper grows too much, it can become “magic”. Teammates may not be able to understand why the modal has more complex logic implementation</li>
<li>❌ You must be disciplined with naming</li>
</ul>
<h2 id="naming-convention-2-name-your-modals-based-on-what-they-actually-do">Naming convention 2: Name your modals based on what they actually do<a class="heading-anchor" href="#naming-convention-2-name-your-modals-based-on-what-they-actually-do" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>In this case you skip the generic name and instead name your modals based on what they are doing. This is helpful for large codebases, not small side projects.</p>
<p>Examples of that could be:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#FDAEB7;font-style:italic">EditProfileModal</span><span style="color:#E1E4E8"> /></span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#FDAEB7;font-style:italic">DeleteAccountModal</span><span style="color:#E1E4E8"> /></span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#FDAEB7;font-style:italic">InviteUserModal</span><span style="color:#E1E4E8"> /></span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#FDAEB7;font-style:italic">SettingsModal</span><span style="color:#E1E4E8"> /></span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#FDAEB7;font-style:italic">ShareModal</span><span style="color:#E1E4E8"> /></span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#FDAEB7;font-style:italic">ConfirmActionModal</span><span style="color:#E1E4E8"> /></span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#FDAEB7;font-style:italic">FeedbackModal</span><span style="color:#E1E4E8"> /></span></span></code></pre></div>
<h3 id="pros-1">Pros<a class="heading-anchor" href="#pros-1" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<ul>
<li>✅ Very clear meaning – you know what <code>&#x3C;DeleteAccountModal /></code> does just by reading it.</li>
<li>✅ Great for beginners – easier to understand than a generic <code>&#x3C;Modal /></code> everywhere.</li>
</ul>
<h3 id="cons-1">Cons<a class="heading-anchor" href="#cons-1" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<ul>
<li>❌ Can repeat logic – if all modals need the same props or behavior, you might duplicate code.</li>
<li>❌ Too many similar names – if you have lots of modals, the list can get long and harder to scan.</li>
</ul>
<h2 id="naming-convention-3-use-prefix-or-suffix-to-show-ownership">Naming convention 3: Use prefix or suffix to show ownership<a class="heading-anchor" href="#naming-convention-3-use-prefix-or-suffix-to-show-ownership" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>If the word Modal confuses you because you are not sure where it came from, which is a valid point, you could ignore using the word Modal by itself and instead decide on a good suffix/prefix identifier.</p>
<p>For your UI library component:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#FDAEB7;font-style:italic">AppModal</span><span style="color:#E1E4E8"> /></span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#FDAEB7;font-style:italic">ProjectModal</span><span style="color:#E1E4E8"> /></span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#FDAEB7;font-style:italic">MainModal</span><span style="color:#E1E4E8"> /></span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#FDAEB7;font-style:italic">CoreModal</span><span style="color:#E1E4E8"> /></span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#FDAEB7;font-style:italic">ClientModal</span><span style="color:#E1E4E8"> /></span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#FDAEB7;font-style:italic">CustomModal</span><span style="color:#E1E4E8"> /></span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#FDAEB7;font-style:italic">ETModal</span><span style="color:#E1E4E8"> /> // Prefixing your modal with your app's initials e.g Energy Tracker app</span></span></code></pre></div>
<p>For your App component:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#FDAEB7;font-style:italic">HeroModal</span><span style="color:#E1E4E8"> /></span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#FDAEB7;font-style:italic">LibModal</span><span style="color:#E1E4E8"> /></span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#FDAEB7;font-style:italic">UIModal</span><span style="color:#E1E4E8"> /></span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#FDAEB7;font-style:italic">ModalLib</span><span style="color:#E1E4E8"> /></span></span></code></pre></div>
<h3 id="pros-2">Pros<a class="heading-anchor" href="#pros-2" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<ul>
<li>✅ Very explicit – you can tell at a glance which modal is from your app vs the library.</li>
<li>✅ Works well in mixed environments – e.g. multiple UI libraries, monorepos, shared packages.</li>
</ul>
<h3 id="cons-2">Cons<a class="heading-anchor" href="#cons-2" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<ul>
<li>❌ Names get longer – <code>&#x3C;AppModal /></code>, <code>&#x3C;HeroModal /></code> are not as clean as <code>&#x3C;Modal /></code>.</li>
<li>❌ Can become inconsistent – if people invent new prefixes (<code>&#x3C;BaseModal /></code>, <code>&#x3C;CoreModal /></code>, <code>&#x3C;MainModal /></code>) without a rule.</li>
</ul>
<h2 id="naming-conventions-that-usually-cause-trouble">Naming conventions that usually cause trouble<a class="heading-anchor" href="#naming-conventions-that-usually-cause-trouble" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Most teams try at least one of these at some point.</p>
<p><code>MyModal</code> sounds harmless but doesn’t mean anything to anyone else.</p>
<p><code>CustomModal</code> stops being descriptive the moment you have more than one.</p>
<p>Library-branded names everywhere tie your feature code to a vendor, even when it shouldn’t care.</p>
<p>Versioned names like <code>Modal2</code> or <code>NewModal</code> are usually a sign that a decision was postponed, not solved.</p>
<p>All of them work… until they don’t.</p>
<h2 id="a-simple-question-that-keeps-things-clean">A simple question that keeps things clean<a class="heading-anchor" href="#a-simple-question-that-keeps-things-clean" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>When naming feels hard, this question usually cuts through the noise:</p>
<p><strong><em>Is this a basic UI building block, or does it express actual product behavior?</em></strong></p>
<p>If it’s a tool, name it like one.
<em>Example: <code>&#x3C;ModalBase /></code>, <code>&#x3C;InputPrimitive /></code>, <code>&#x3C;ButtonCore /></code>.</em></p>
<p>If it’s intent, name it like intent.
<em>Example: <code>&#x3C;EditProfileModal /></code>, <code>&#x3C;CreateProjectForm /></code>, <code>&#x3C;DeleteAccountModal /></code>.</em></p>
<p>That’s the whole trick. You’ll know you’ve landed in a good place when your imports start feeling calm again:</p>
<h2 id="wrapping-up">Wrapping up<a class="heading-anchor" href="#wrapping-up" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Naming might look like a small detail, but it affects how your whole project feels. Usually when I’m building a project and it’s time to decide on a UI library, I don’t want to spend time trying to identify names — I just start using whatever the import gives me and continue.</p>
<p>The problem is that after a while I usually find myself needing to refactor because my app is getting more complex. You might say, “Well, it’s fine, you’re following the simple-now, refactor-later idea,” and you might be right. There’s a principle in programming, called YAGNI, that says you shouldn’t build complex systems <em>just in case</em>. You build infrastructure when you <em>know</em> you will need it soon.</p>
<p>This applies directly to naming conventions.
If you’re building a small side project just for fun, go ahead and use the UI library names like <code>&#x3C;Modal /></code> and skip the wrappers.</p>
<p>But if you’re building an app you plan to present, monetize, or seriously grow, then stop for a moment, decide on your conventions, and <em>then</em> continue. The time you spend choosing now will be far less than the time you’ll lose later dealing with refactors and headaches.</p>
<p><strong>If you’re just getting started with app development, naming conventions are one of those topics that only start to matter <em>after</em> your environment is properly set up. If you’re still at that stage, you might find these guides useful before diving deeper into UI architecture:</strong>
– <a href="/how-to-install-git-on-mac-macos-for-beginners/">How to install Git on macOS</a>
– <a href="/how-to-install-homebrew-macos-for-beginners/">How to install Homebrew on macOS</a>
– <a href="/how-to-install-npm-on-macos/">How to install npm on macOS</a>
– <a href="/how-to-install-postgres-on-macos/">How to install PostgreSQL on macOS</a>
– <a href="/how-to-install-java-on-mac-step-by-step-guide/">How to install Java on macOS</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Simple Ways to Create a CSS Overlay Effect</title>
      <link>https://littlecodingthings.com/simple-ways-to-create-a-css-overlay-effect/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/simple-ways-to-create-a-css-overlay-effect/</guid>
      <pubDate>Fri, 12 Dec 2025 10:14:00 GMT</pubDate>
      <description>Lay a gradient or solid tint over an image using a ::before pseudo-element. Four copy-ready overlays with before-and-after photos.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Have you ever wanted to add cool effects to your website? With the CSS overlay effect, you can easily create stylish overlays to make your content stand out! Let’s see how it works!</p>
<h2 id="what-are-overlay-effects">What are overlay effects?<a class="heading-anchor" href="#what-are-overlay-effects" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>A <strong>CSS overlay effect</strong> is a powerful technique for placing an extra layer on top of your web content, typically an image or a background, to enhance its appearance or improve readability.</p>
<p>This effect allows you to create various visual enhancements, such as darkening an image or adding a color tint.</p>
<p>You can achieve overlays using the CSS <code>background-color</code> and <code>background-image</code> properties, enabling you to apply stunning visual effects to images. With these properties, you can easily modify the look and feel of your content, making it more engaging and visually appealing.</p>
<p>Let’s dive into an example to see how the CSS overlay effect works.</p>
<h2 id="basic-html-and-css-setup-for-a-css-overlay-effect">Basic HTML and CSS setup for a CSS overlay effect<a class="heading-anchor" href="#basic-html-and-css-setup-for-a-css-overlay-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>First, we need to create an HTML element to hold our image and assign it a class. This class will contain all the necessary CSS rules to achieve the desired overlay effect.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"overlay-container"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p>Next, we write the CSS for our class, setting a background image without repetition. This ensures the image fits nicely within a <code>400x600px</code> box. With this setup, we can easily apply overlay effects or make further adjustments as needed.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.overlay-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">400</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">600</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">url</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'your-image-url-here'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  background-repeat</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">no-repeat</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">cover</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>At this stage, this is how our image appears on the screen.</p>
<figure><img src="/overlay-colorful-tips-and-tricks-original-image.webp" alt="This image shows a photo of a red car with old buildings as a background.This photo was captured in Verona city Italy." style="max-width:35%" class="img-narrow"><figcaption>Original photo by <a href="https://unsplash.com/@jonatanhernandez?utm_content=creditCopyText&#x26;utm_medium=referral&#x26;utm_source=unsplash">Jonatan Hernandez</a> on <a href="https://unsplash.com/photos/AWkEp5ap-vw?utm_content=creditCopyText&#x26;utm_medium=referral&#x26;utm_source=unsplash">Unsplash</a></figcaption></figure>
<h2 id="using-pseudo-elements-for-the-css-overlay-effect">Using pseudo-elements for the CSS overlay effect<a class="heading-anchor" href="#using-pseudo-elements-for-the-css-overlay-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>A common technique for creating overlay effects is <strong><a href="/coding-made-easy-with-css-selectors-an-ultimate-guide/#before-and-after" title="pseudo-elements">pseudo-elements</a></strong> (<code>::before</code> and <code>::after</code>). To get this effect working, we have to prepare our class by setting <code>position: relative</code>. Then, we apply <code>position: absolute</code> to the <code>::before</code> pseudo-element. This ensures that <code>::before</code> is positioned relative to its parent — the overlay container.</p>
<p>We also use the <code>content: ""</code> declaration to make sure the pseudo-element is generated. In this case, the content remains empty since we want the image to be visible underneath.</p>
<p>Additionally, we set <code>width: 100%;</code> and <code>height: 100%;</code> to ensure the <code>::before</code> pseudo-element covers the entire area of its parent container, completely overlaying the image.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.overlay-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.overlay-container::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>🔖 For the time being, nothing has changed on our screen; we just made the appropriate preparations for our effect. Let’s continue.</p>
<h2 id="applying-the-css-overlay-effect">Applying the CSS overlay effect<a class="heading-anchor" href="#applying-the-css-overlay-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Overlay effects come in various types, each adding a unique touch to our images. The CSS property that helps us to create this effect is <code>background-image</code>.</p>
<p>Below, I’ve created different variations for you to explore. 👩‍💻 Enjoy!</p>
<h3 id="using-a-linear-gradient-for-the-overlay-effect">Using a linear gradient for the overlay effect<a class="heading-anchor" href="#using-a-linear-gradient-for-the-overlay-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>In the following CSS code snippet, you can see that the <code>background-image</code> property is set to <a href="/css-linear-gradient-techniques-how-to-make-colorful-line-drawings/"><code>linear-gradient(...)</code></a>, creating a multi-color overlay effect with different transparency levels. This produces a smooth gradient overlay from top to bottom with shades of teal, yellow, and purple that make the perfect match for our image.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.overlay-container::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#79B8FF">    rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.3</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#79B8FF">    rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.2</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#79B8FF">    rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">155</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">155</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.2</span><span style="color:#E1E4E8">)</span></span>
<span class="line"><span style="color:#E1E4E8">  );</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<figure><img src="/overlay-colorful-tips-and-tricks-linear-gradient.webp" alt="Utilizing the linear-gradient overlay. This image shows a photo of a red car with old buildings as a background.This photo was captured in Verona city Italy. We set the background-image: linear-gradient(
rgba(0, 255, 255, 0.3),
rgba(255, 255, 0, 0.2),
rgba(155, 0, 155, 0.2)
); and it adds a line drawing overlay from top to bottom with shades of teal, yellow, and purple." style="max-width:28%" class="img-narrow"><figcaption>with linear-gradient overlay effect</figcaption></figure>
<h3 id="using-a-radial-gradient-for-the-overlay-effect">Using a radial gradient for the overlay effect<a class="heading-anchor" href="#using-a-radial-gradient-for-the-overlay-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>We continue with a more creative approach. Here, <a href="/css-radial-gradient-techniques-how-to-make-colorful-infinite-loops/"><code>radial-gradient(...)</code></a> creates a unique overlay effect using a circular pattern. It transitions from shades of light gray to dark gray, adding a subtle yet eye-catching touch to the image.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.overlay-container::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">radial-gradient</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#79B8FF">    rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.1</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#79B8FF">    rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">128</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">128</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">128</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.2</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#79B8FF">    rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.6</span><span style="color:#E1E4E8">)</span></span>
<span class="line"><span style="color:#E1E4E8">  );</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<figure><img src="/overlay-colorful-tips-and-tricks-radial-gradient.webp" alt="Utilizing the radial-gradient overlay. This image shows a photo of a red car with old buildings as a background.This photo was captured in Verona city Italy. We set the background-image: radial-gradient(
rgba(255, 255, 255, 0.1),
rgba(128, 128, 128, 0.2),
rgba(0, 0, 0, 0.6)
); and it creates a unique overlay effect using a circular pattern. It transitions from shades of light gray to dark gray." style="max-width:28%" class="img-narrow"><figcaption>with radial-gradient overlay effect</figcaption></figure>
<h3 id="creating-a-rainbow-css-overlay-effect">Creating a rainbow CSS overlay effect<a class="heading-anchor" href="#creating-a-rainbow-css-overlay-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Another vibrant and playful effect is the rainbow gradient. Often used for decorative purposes, this effect adds bright, joyful colors to the image, creating a fun and lively vibe. 🌈✨</p>
<p>When you apply this gradient as a background, it creates a smooth transition of colors from purple to red, mimicking the colors of a rainbow (ROYGBIV). The use of semi-transparent alpha values gives a soft blending effect between the colors, creating a visually appealing and harmonious overlay.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.overlay-container::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">to</span><span style="color:#79B8FF"> bottom</span><span style="color:#79B8FF"> left</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">148</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">211</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.5</span><span style="color:#E1E4E8">), </span><span style="color:#79B8FF">rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">75</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">130</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.3</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#79B8FF">    rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.2</span><span style="color:#E1E4E8">), </span><span style="color:#79B8FF">rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.2</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#79B8FF">    rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.3</span><span style="color:#E1E4E8">), </span><span style="color:#79B8FF">rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">127</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.3</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#79B8FF">    rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.3</span><span style="color:#E1E4E8">)</span></span>
<span class="line"><span style="color:#E1E4E8">  );</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>In this example, I changed my image to make the outcome clearer, adding a colorful vibe to create a playful atmosphere.</p>
<figure><img src="/overlay-colorful-tips-and-tricks-original-image2.webp" alt="This image shows a diary with a gold pen. It also shows some flowers scattered around." style="max-width:28%" class="img-narrow"><figcaption>Original photo by <a href="https://unsplash.com/@kharp?utm_content=creditCopyText&#x26;utm_medium=referral&#x26;utm_source=unsplash">Katie Harp</a> on <a href="https://unsplash.com/photos/pink-and-white-book-on-white-and-green-floral-textile-mhx-T3pOHm4?utm_content=creditCopyText&#x26;utm_medium=referral&#x26;utm_source=unsplash">Unsplash</a></figcaption></figure>
<figure><img src="/overlay-colorful-tips-and-tricks-rainbow-effect.webp" alt="Utilizing the css overlay effect. This image shows a diary with a gold pen. It also shows some flowers scattered around. We set the background-image: linear-gradient(to bottom left,
rgba(148, 0, 211, 0.5), rgba(75, 0, 130, 0.3),
rgba(0, 0, 255, 0.2), rgba(0, 255, 0, 0.2),
rgba(255, 255, 0, 0.3), rgba(255, 127, 0, 0.3),
rgba(255, 0, 0, 0.3)
); and we add a rainbow effect." style="max-width:28%" class="img-narrow"><figcaption>with a rainbow overlay effect</figcaption></figure>
<h3 id="adding-a-solid-color-css-overlay-effect">Adding a solid color CSS overlay effect<a class="heading-anchor" href="#adding-a-solid-color-css-overlay-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>You are always free to use a single color as an overlay. In that case, we will apply the <code>background-color</code> CSS property to the <code>::before</code> pseudo-element.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.overlay-container::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">220</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">135</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">135</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.2</span><span style="color:#E1E4E8">); </span><span style="color:#6A737D">/* pale pink */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>In this example, I kept the second image to make the outcome clearer. I’ve given it a softer, more romantic feel, where the pale pink color with the slight see-through effect adds a charming and gentle mood.</p>
<p><img src="/simple-ways-to-create-a-css-overlay-effect-overlay-colorful-tips-and-tricks-original-image2.webp" alt="This image shows a diary with a gold pen. It also shows some flowers scattered around." style="max-width:28%" class="img-narrow"></p>
<figure><img src="/overlay-colorful-tips-and-tricks-one-color.webp" alt="Utilizing the css overlay effect. This image shows a diary with a gold pen. It also shows some flowers scattered around. We set the background-color: rgba(220, 135, 135, 0.2); and we add a pale pink color with a slight see-through effect." style="max-width:28%" class="img-narrow"><figcaption>with one color overlay effect</figcaption></figure>
<p>🌼 Hope you found my post interesting and helpful.
Thanks for being here! 🌼</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/the-unique-css-opacity-check-out-this-amazing-property/">Using CSS Opacity for Transparency</a></li>
<li><a href="/introduction-to-the-powerful-css-blur-effect/">Introduction To The Powerful CSS Blur Effect</a></li>
<li><a href="/what-you-need-to-know-about-css-color-methods/">What You Need to Know About CSS Color Methods</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Practices Behind Clean Lines Of Code</title>
      <link>https://littlecodingthings.com/practices-behind-clean-lines-of-code/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/practices-behind-clean-lines-of-code/</guid>
      <pubDate>Fri, 05 Dec 2025 14:42:00 GMT</pubDate>
      <description>The unglamorous half of programming — reading other people's code, naming things well, chasing bugs, and keeping a codebase alive.</description>
      <category>Thoughts &amp; Theory</category>
      <content:encoded><![CDATA[<p>Coding looks extremely charming from the outside. Lines of text turning into apps, games, and devices that seem to appear from nothing. What most people don’t see is the quiet and messy, hidden side of it all. The side where developers struggle with uncertainty, clean up old mistakes, and make dozens of small adjustments that never get listed and users never see, but still matter a lot.</p>
<p>The hidden side of coding isn’t about writing fast or showing off clever tricks. It’s about slow care, patience, and the quiet effort to make something work just a little better today than it did yesterday.</p>
<h2 id="the-art-of-reading-code">The Art of Reading Code<a class="heading-anchor" href="#the-art-of-reading-code" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Reading code is an underestimated skill. Writing feels creative, it’s your ideas that are taking form. Reading, on the other hand, is about patience. You step into someone else’s logic and try to follow their philosophy. To clean up. To improve.</p>
<p>Sometimes you find brightness: clear approaches, smart patterns and neat solutions. Other times, it’s a labyrinth of chaos. But reading teaches you how others think and how decisions impact the project’s direction. You learn to recognize what makes code clear or messy, and you start borrowing small habits from others that make your own work stronger. All these make you grow!</p>
<p>The more you read, the more you understand that programming is a discussion between people’s minds and habits. With every new project, your knowledge and experience expand, and clarity follows.</p>
<h2 id="naming-things">Naming Things<a class="heading-anchor" href="#naming-things" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Naming looks simple. You’re just labeling today a <a href="/made-easy-with-reusable-code-why-classes-matter/">class</a>, a <a href="/make-your-work-easier-by-using-variables-in-css/">variable</a> or a function tomorrow. But is that true? Good names require empathy.</p>
<p>When you name something, you’re trying to communicate with the next person who reads your code. You’re creating hints about what matters. A good name can make code self-explanatory. A bad one turns every future action into a guessing game.</p>
<p>Most of us have seen both ends of that scope, but a beautiful, clear function that tells you exactly what it does just by reading it is what we all need. Naming is one of those quiet acts of kindness in programming. No one thanks you for it, but everyone benefits.</p>
<h2 id="the-battle-with-bugs">The Battle with Bugs<a class="heading-anchor" href="#the-battle-with-bugs" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Every developer knows the sinking feeling of a <a href="/the-unique-origin-of-the-term-bug-in-software-development/">bug</a> that just won’t leave you. You change one line, and suddenly five other things break. Time passes. Coffee cools. The sun is going down and you are wondering <a href="/how-to-decide-if-programming-is-right-for-you/">if you chose the right profession</a>.
And just like that, there it is! One missing semicolon, a false variable, a condition you ignored.</p>
<p>Debugging isn’t just about fixing errors. It’s about understanding how systems behave. You start to see patterns, predict where problems might hide, and learn to remain peaceful when everything seems impossible. In time, you realize that every frustrating bug is really a teacher. Forcing you to slow down and gain a better understanding of how programming works.</p>
<p>And most of the time, that understanding feels more pleasing than the fix itself.</p>
<h2 id="the-value-of-maintenance">The Value of Maintenance<a class="heading-anchor" href="#the-value-of-maintenance" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>In the tech world, there’s a heavy emphasis on building new things. That sounds exciting only if you aren’t the one fixing what’s broken. Maintenance work is like the ‘behind-the-scenes’ side of development, but it’s the heart of what keeps products alive.</p>
<p>Maintaining a codebase means respecting its history. You observe the fingerprints of every developer before you and instead of pulling everything down, you learn to adapt it. To make changes that keep things running smoothly.</p>
<p>Good maintenance is about discipline. It’s a long game, and those who play it well are the steady force of every successful project that stands the test of time.</p>
<h2 id="the-patience-behind-progress">The Patience Behind Progress<a class="heading-anchor" href="#the-patience-behind-progress" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Technology moves fast, but real mastery takes time. The quiet work of reading, naming, cleaning, and fixing bugs is what helps someone grow from just coding into building with purpose. It’s the key to see problems not as blocks in your way, but as parts of a bigger picture.</p>
<p>Solving problems is not always about speed. Patience can bring you pleasure. Sometimes, staying calm when nothing works is a huge victory.</p>
<p>All these good practices lead to quiet wins. They help you stay grounded, build confidence, reduce chaos, and prevent your future selves from <a href="/the-burnout-syndrome-how-to-identify-and-overcome-it/">burnout</a> and <a href="/unmasking-impostor-syndrome-in-tech-watch-out-for-these-signs/">impostor syndrome</a>, which often tries to take over.</p>
<p>In the end, that’s what makes programming more than just a technical skill. It’s an act that depends on your own patience and creativity. In the code you write and in the way you treat the already existing code that surrounds it. In this invisible work that keeps it all running.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/made-easy-with-reusable-code-why-classes-matter/">Made Easy With Reusable Code – Why Classes Matter</a></li>
<li><a href="/the-burnout-syndrome-how-to-identify-and-overcome-it/">Developer Burnout: Signs and Recovery</a></li>
<li><a href="/how-to-decide-if-programming-is-right-for-you/">How To Decide If Programming Is Right For You?</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>The border-image-slice CSS Property</title>
      <link>https://littlecodingthings.com/border-image-slice-css-property-for-one-of-a-kind-border-effects/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/border-image-slice-css-property-for-one-of-a-kind-border-effects/</guid>
      <pubDate>Fri, 28 Nov 2025 11:40:00 GMT</pubDate>
      <description>Slice a photo into a nine-patch grid and wrap it around a box. What one, two, three and four border-image-slice values each do.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>The <code>border-image-slice</code> CSS property allows us to be extremely creative with our borders. We can <strong>cut (slice) a source</strong>, such as an image with a nice pattern or a gradient, into pieces so it can stretch or repeat those slices around an element’s border. We specify how far in from each edge the slicing occurs and <strong>those slices are sketched to be the border areas</strong> (edges and corners).</p>
<h2 id="outline-of-the-border-image-slice-css-property">Outline of the border-image-slice CSS property<a class="heading-anchor" href="#outline-of-the-border-image-slice-css-property" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Let’s see our property more analytically. First, you pick a visual source and then decide where to “slice” it. After that, CSS uses those pieces to sketch the border. Kind of like cutting a picture into a <strong>nine-patch grid</strong> and placing it around a box.
We have <strong>4 corners</strong>, <strong>4 sides</strong>, <strong>and the main content</strong>. Only 8 of them actually showed up and used for borders, the corners and the sides. The 9th slice, which is the main part of the element, is optional and it usually carries our content.</p>
<p><img src="/css-border-image-slice-explanation-sketch.webp" alt="A nine-patch grid outline about border-image-slice CSS property" style="max-width:56%" class="img-narrow"></p>
<p>A few critical points about those pieces:</p>
<ul>
<li><strong>Corners</strong>: Depending on the value, they may not stretch (value 1), they just sit there like little anchors, or they may stretch (higher or more values).</li>
<li><strong>Sides</strong>: Stretch or repeat, depending on your border settings. They control most of the visual essence.</li>
<li><strong>Center</strong>: The middle part usually isn’t drawn as part of the border at all—it’s ignored unless you explicitly choose to fill it.</li>
</ul>
<h2 id="practical-examples-how-border-image-slice-works">Practical examples: How border-image-slice works<a class="heading-anchor" href="#practical-examples-how-border-image-slice-works" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>To better understand how this property works, we first need to insert an image with a width and height of 300px.
Next, we’ll apply properties like <code>object-fit: cover</code>, <code>background-size: cover</code>, and <code>background-position: center</code> to keep the image centered and fully visible without distortion.
🔖 These properties are only here so we can clearly see the image at this stage — they aren’t required for the next steps.
Finally, we add the source of our image.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"image"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.image</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  object-fit</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">cover</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">cover</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">:  </span><span style="color:#79B8FF">url</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">https://images.unsplash.com/photo-1553526777-5ffa3b3248d8?ixlib=rb-4.1.0&#x26;ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&#x26;auto=format&#x26;fit=crop&#x26;q=80&#x26;w=987</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<figure><img src="/css-border-image-slice-initial-image.webp" alt="Image with pattern" style="max-width:36%" class="img-narrow"><figcaption>Photo by <a href="https://unsplash.com/@bubbafat?utm_source=unsplash&#x26;utm_medium=referral&#x26;utm_content=creditCopyText">Robert Horvick</a> on <a href="https://unsplash.com/photos/a-close-up-of-a-building-with-a-pattern-on-it-1R4uPYipCFM?utm_source=unsplash&#x26;utm_medium=referral&#x26;utm_content=creditCopyText">Unsplash</a></figcaption></figure>
<p>With our image set up, we can continue and see how <code>border-image-slice</code> handles different inputs.</p>
<p>This CSS property can take one to four values.
– <strong>One value</strong>: uses the same slice for every side.
– <strong>Two values</strong>: set the first for top and bottom, and the second for left and right.
– <strong>Three values</strong>: apply the first for the top, the second for both left and right and the third for the bottom.
– <strong>Four values</strong>: follow the standard CSS direction: top, right, bottom, left.
With so many options, there is plenty of room to create some truly great-looking border effects.</p>
<h3 id="setting-the-value-1">Setting the value: 1<a class="heading-anchor" href="#setting-the-value-1" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Let’s start with value <code>1</code>.
First, we need to add a <strong>20px border but transparent</strong>. This gives us the space the image-based border will later occupy, without showing the standard solid <a href="/how-to-be-creative-with-different-css-border-styles/">border</a>. The image also has to be set as the <strong>border image source</strong> — <code>border-image-slice</code> has nothing to slice without it.</p>
<p>Then, we set <strong>border-image-slice to 1</strong>. In this way, the browser takes a very thin section, just one pixel wide, from each edge of the image and stretches it along the borders. As a result, we have only stripes.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.image</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">url</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">https://images.unsplash.com/photo-1553526777-5ffa3b3248d8?ixlib=rb-4.1.0&#x26;ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&#x26;auto=format&#x26;fit=crop&#x26;q=80&#x26;w=987</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  border-image-slice</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-border-image-slice-value1.webp" alt="Border effect setting the border-image-slice-value: 1" style="max-width:36%" class="img-narrow"></p>
<h3 id="setting-one-value">Setting one value<a class="heading-anchor" href="#setting-one-value" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>We continue following the same tactic, but this time instead of <code>1</code> we use a value of <code>100</code>. By doing this, the browser cuts a 100-pixel-wide section from each edge of the image and uses those slices to form the new borders. In that way, we are closer to our initial image as we use a wider section of it.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.image</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  border-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">url</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">...</span><span style="color:#E1E4E8">); </span><span style="color:#6A737D">/* the same image as above */</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-image-slice</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-border-image-slice-1value-100.webp" alt="Border effect setting the border-image-slice-value: 100" style="max-width:36%" class="img-narrow"></p>
<h3 id="setting-two-values">Setting two values<a class="heading-anchor" href="#setting-two-values" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Next, we will use two values, <code>1 100</code>, to see how different slice sizes affect the borders. The first value (1) applies to both the top and bottom, creating very thin slices, close to line-like borders. The second value (100) applies to both the left and right, creating wider slices that maintain more of the image’s details.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.image</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  border-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">url</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">...</span><span style="color:#E1E4E8">); </span><span style="color:#6A737D">/* the same image as above */</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-image-slice</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#79B8FF"> 100</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-border-image-slice-2values-1-100.webp" alt="Border effect setting the border-image-slice-value: 1 100" style="max-width:36%" class="img-narrow"></p>
<h3 id="setting-three-values">Setting three values<a class="heading-anchor" href="#setting-three-values" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Moving forward, it’s time to see the results when using three values. The first value (<code>150</code>) applies to the top, the second value (<code>80</code>) to the left and right and finally the third value (<code>5</code>) to the bottom. As we can observe again, the higher the value, the closer to the image’s characteristics.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.image</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  border-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">url</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">...</span><span style="color:#E1E4E8">); </span><span style="color:#6A737D">/* the same image as above */</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-image-slice</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">150</span><span style="color:#79B8FF"> 80</span><span style="color:#79B8FF"> 5</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-border-image-slice-3values-150-80-5.webp" alt="Border effect setting the border-image-slice-value: 150 80 5" style="max-width:36%" class="img-narrow"></p>
<h3 id="setting-four-values">Setting four values<a class="heading-anchor" href="#setting-four-values" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Our final option is to use four different values, one for each side of our element. The values apply in a clockwise direction – top, right, bottom, left. That creates an uneven but interesting border effect.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.image</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  border-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">url</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">...</span><span style="color:#E1E4E8">); </span><span style="color:#6A737D">/* the same image as above */</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-image-slice</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#79B8FF"> 80</span><span style="color:#79B8FF"> 120</span><span style="color:#79B8FF"> 150</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-border-image-slice-4values-50-80-120-150.webp" alt="Border effect setting the border-image-slice-value: 50 80 120 150" style="max-width:36%" class="img-narrow"></p>
<p>Playing with <code>border-image-slice</code> feels a bit like trimming a photo into fancy frames — every small tweak shifts the mood of the border in surprising ways.
What do you think? Are you ready to try it out yourself? Be my guest and have fun! 😃</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/create-playful-border-effects-combining-css-gradients-with-the-border-image-slice-css-property/">CSS Gradient Borders with border-image</a></li>
<li><a href="/how-to-be-creative-with-different-css-border-styles/">CSS Border Styles Explained</a></li>
<li><a href="/clip-path-inset-css-property-cropping-elements-as-a-pro/">clip-path: inset() Explained</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>CSS Gradient Borders with border-image</title>
      <link>https://littlecodingthings.com/create-playful-border-effects-combining-css-gradients-with-the-border-image-slice-css-property/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/create-playful-border-effects-combining-css-gradients-with-the-border-image-slice-css-property/</guid>
      <pubDate>Fri, 21 Nov 2025 13:12:00 GMT</pubDate>
      <description>Turn a plain border into a gradient with border-image and border-image-slice. Linear, radial and conic examples, no image files needed.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Borders have long been one of the simplest tools in web design. Yet, that’s no reason to look boring. Combining the <code>border-image-slice</code> property with the power of <strong>CSS gradients</strong>, we can turn simple static lines into 🎨 colorful, eye-catching details that make your designs stand out. Besides, a playful <a href="/how-to-be-creative-with-different-css-border-styles/">border</a> effect adds fun and energy to a page, helping shapes and sections feel more alive. No images needed, just blending colors with clean CSS.
In other words, it’s a small touch that can make your design feel fresh and creative, adding personality and vibrance. 🌈 ✨</p>
<h2 id="border-effect-explanation-setting-linear-gradient">Border effect explanation setting linear-gradient<a class="heading-anchor" href="#border-effect-explanation-setting-linear-gradient" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We’ll begin by creating a box with a 150px width and height that temporarily has a solid 5px black border. This is the box we’ll use to experiment with <strong>different gradient border effects</strong> and make it pop! 🥳</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"box"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">150</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">150</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-border-image-slice-initial-box-example.webp" alt="A white box with 5 pixels solid black border" style="max-width:35%" class="img-narrow"></p>
<p>With our box in place, we can make things more interesting by replacing the simple black border with a color 🍭 splash of CSS gradients.</p>
<ul>
<li>First, we need to add the <strong>transparent</strong> value to the border.</li>
<li>Next, we continue with the gradient. I decided to start with the <a href="/css-linear-gradient-techniques-how-to-make-colorful-line-drawings/"><code>linear-gradient</code></a> and use three colors (magenta, cyan, orange). Feel free to use as many colors as you want.</li>
<li>In the final step, we set <strong>border-image-slice to 1</strong>. In that way, the browser uses the whole gradient evenly on all sides of the border.</li>
</ul>
<p>The browser doesn’t know how to spread the gradient across the border area. Without the <strong>border-image-slice</strong> property, the gradient <strong>won’t appear at all</strong>. It is essential to add it as it will <strong>activate and display</strong> the gradient border.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  border-image-slice</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-border-image-slice-linear-gradient-example.webp" alt="Border effect with magenta, cyan and orange made combining the linear-gradient technique and the border-image-slice: 1 CSS property" style="max-width:35%" class="img-narrow"></p>
<p>It’s good to know that the <code>border-image-slice</code> property can take <strong>up to four values</strong>, each one responsible for <strong>how to cut (slice) the gradient</strong> we use as a border.</p>
<p>More analytically:</p>
<p><code>border-image-slice: 1;</code> simply put the whole gradient evenly on all sides</p>
<p><code>border-image-slice: 20;</code> it cuts 20 (px or percentages, depending on what you use) from each edge to make the border</p>
<p><code>border-image-slice: 20 30;</code> the same as above but the first value is for <em>top and bottom</em>, the second for <em>left and right</em></p>
<p><code>border-image-slice: 20 30 10;</code> the first value is for <em>top</em>, the second for <em>left and right</em> and the third for <em>bottom</em></p>
<p><code>border-image-slice: 20 30 10 5;</code> finally, the first value is for <em>top</em>, the second for <em>right</em>, the third for <em>bottom</em> and the fourth for <em>left</em></p>
<p>🔖 When we use a gradient, we usually just write <strong><code>1</code></strong> because a gradient isn’t a picture with pixels or edges to slice. <strong>It smoothly fills the space, so there’s nothing to “cut”.</strong> The value <strong><code>1</code></strong> simply tells the browser to use the whole gradient for the border.</p>
<h2 id="more-border-effect-ideas-with-linear-gradient-technique-and-border-image-slice-1">More border effect ideas with linear-gradient <strong>technique</strong> and border-image-slice: 1<a class="heading-anchor" href="#more-border-effect-ideas-with-linear-gradient-technique-and-border-image-slice-1" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Below, I included a few more examples to help you see how changing the gradient can completely transform the look of a border, making the concept clearer and easier to follow. 😃</p>
<h3 id="flipping-the-colors-the-reverse-linear-gradient"><strong>Flipping the colors: The reverse linear-gradient</strong><a class="heading-anchor" href="#flipping-the-colors-the-reverse-linear-gradient" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Colorful linear gradients that flow from top to bottom or the reverse way are like creating amazing color bands that wrap around the box.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">to</span><span style="color:#79B8FF"> top</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  border-image-slice</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-border-image-slice-reverce-linear-gradient-example.webp" alt="Border effect with magenta, cyan and orange made combining the linear-gradient technique and the border-image-slice: 1 CSS property" style="max-width:35%" class="img-narrow"></p>
<h3 id="smooth-side-to-side-color-flow-with-linear-gradient">Smooth side-to-side color flow with <strong>linear-gradient</strong><a class="heading-anchor" href="#smooth-side-to-side-color-flow-with-linear-gradient" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Colors travel from one side to the other, giving the border’s box a bright, balanced look.</p>
<p>Firstly, from left to right</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">to</span><span style="color:#79B8FF"> right</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  border-image-slice</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-border-image-slice-linear-gradient-sides-to-right-example.webp" alt="Border effect with magenta, cyan and orange made combining the linear-gradient technique and the border-image-slice: 1 CSS property" style="max-width:35%" class="img-narrow"></p>
<p>Then, from right to left</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">to</span><span style="color:#79B8FF"> left</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  border-image-slice</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-border-image-slice-linear-gradient-sides-to-left-example.webp" alt="Border effect with magenta, cyan and orange made combining the linear-gradient technique and the border-image-slice: 1 CSS property" style="max-width:35%" class="img-narrow"></p>
<h3 id="playing-with-diagonal-directions"><strong>Playing with diagonal directions</strong><a class="heading-anchor" href="#playing-with-diagonal-directions" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>A diagonal direction gives the sense of a wavy, moving effect. Plus, changing the angle, you can create a more dynamic look.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">45</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  border-image-slice</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-border-image-slice-linear-gradient-diagonal-example.webp" alt="Diagonal border effect with magenta, cyan and orange made combining the linear-gradient technique and the border-image-slice: 1 CSS property" style="max-width:35%" class="img-narrow"></p>
<h3 id="color-loops-the-repeating-linear-gradient-technique"><strong><strong>Color loops: The repeating</strong> linear-gradient technique</strong><a class="heading-anchor" href="#color-loops-the-repeating-linear-gradient-technique" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>With repeating gradients, you can build patterns that literally look like an impressive dancing effect or all these amazing <a href="/how-to-create-stunning-vibrant-neon-effect-css-only/">neon light</a> effects. How cool is that!? 😎</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">45</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  border-image-slice</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-border-image-slice-linear-gradient-diagonal-with-repeating-pattern-example.webp" alt="Repeating border effect with magenta, cyan and orange made combining the linear-gradient technique and the border-image-slice: 1 CSS property" style="max-width:35%" class="img-narrow"></p>
<p>Moreover, we are free to experiment with the other two (<a href="/css-radial-gradient-techniques-how-to-make-colorful-infinite-loops/">radial-gradient</a> and <a href="/css-conic-gradient-technique-how-to-make-stunning-visual-effects/">conic-gradient</a>) CSS gradients as well. So, let’s dive into some more examples and discover how different gradient ideas come to life.</p>
<h2 id="border-effects-with-different-border-image-slice-values">Border effects with different border-image-slice values<a class="heading-anchor" href="#border-effects-with-different-border-image-slice-values" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<h3 id="radial-gradient-for-spinning-border-effects"><strong>Radial gradient</strong> for spinning border effects<a class="heading-anchor" href="#radial-gradient-for-spinning-border-effects" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Now, let’s see what would happen if we use the same gradient, in this case, the <code>radial-gradient</code>, with many different values on <code>border-image-slice</code>.
For these examples, I used cyan, pink and violet. 🎨 ✨</p>
<p>In the first example, we maintain the value <code>1</code> while in the second, we replace it with a value of <code>50</code>.
The <code>border-image-slice: 1;</code> applies the entire gradient, <strong>spreading the colors smoothly</strong> around the border. With this transition, the gradient stays wide and soft.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">radial-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">violet</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">violet</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">violet</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">violet</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">violet</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">violet</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">violet</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">violet</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">violet</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">violet</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">violet</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  border-image-slice</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-border-image-slice-radial-gradient-example.webp" alt="Border effect with cyan, pink and violet made combining the radial-gradient technique and the border-image-slice: 1 CSS property" style="max-width:35%" class="img-narrow"></p>
<p>The <code>border-image-slice: 50;</code> applies a small piece of the gradient. Since it’s using only a part of the gradient’s color range, <strong>the colors repeat more often</strong> and look like stripes that are spinning around.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">radial-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">violet</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">violet</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">violet</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">violet</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">violet</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">violet</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">violet</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">violet</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">violet</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">violet</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">violet</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  border-image-slice</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-border-image-slice-to-50-radial-gradient-example.webp" alt="Border effect with repeating stripes from cyan, pink and violet made combining the radial-gradient technique and the border-image-slice: 50 CSS property" style="max-width:35%" class="img-narrow"></p>
<p>To sum up, increasing the slice value tells the browser to <strong>take a smaller “slice”</strong> of the gradient and <strong>reuse it</strong> around the border. As a result, with a smaller slice, we have more repetition and eventually stronger striping.</p>
<h3 id="conic-gradient-for-more-complex-border-effect">Conic gradient for more complex border effect<a class="heading-anchor" href="#conic-gradient-for-more-complex-border-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Next, let’s see what would happen if we use the same gradient, in this case, the <code>conic-gradient</code>, but different values on <code>border-image-slice</code>.
For these examples, I changed the colors and used black, orange, magenta, and black again. 🎨 ✨</p>
<p>🔖 A small detail to keep in mind is that starting and ending with the same color (in this case, black) helps to keep the transitions soft and seamless.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  border-image-slice</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-border-image-slice-conic-gradient.webp" alt="Border effect with black, orange and magenta made combining the conic-gradient technique and the border-image-slice: 1 CSS property" style="max-width:35%" class="img-narrow"></p>
<h4 id="conic-gradient-with-repeating-pattern">Conic-gradient with repeating pattern<a class="heading-anchor" href="#conic-gradient-with-repeating-pattern" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p>In this case, with a <code>1</code> value it uses almost the <strong>entire conic gradient</strong> around the border. The colors flow <strong>smoothly and evenly</strong>, creating a soft circular blend with gentle transitions.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">,</span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#6A737D">  /* all around the same value */</span></span>
<span class="line"><span style="color:#79B8FF">  border-image-slice</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-border-image-slice-conic-gradient-with-many-color-stops.webp" alt="Repeating border effect with black, orange and magenta made combining the conic-gradient technique and the border-image-slice: 1 CSS property" style="max-width:35%" class="img-narrow"></p>
<p>On the other hand, with a value <code>30</code> it takes a <strong>smaller portion</strong> of the gradient and stretches it around the border. The border starts showing <strong>clearer color sections</strong> with mild curves and slight breaks at the corners.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">,</span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#6A737D">  /* all around the same value (30) */</span></span>
<span class="line"><span style="color:#79B8FF">  border-image-slice</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">30</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-border-image-slice-conic-gradient-with-color-stops-border-image-slice-30.webp" alt="Border effect with black, orange and magenta made combining the conic-gradient technique and the border-image-slice: 30 CSS property" style="max-width:35%" class="img-narrow"></p>
<p>Finally, with a value of <code>60</code> it uses a <strong>very small wedge</strong> of the conic gradient and repeats it. As a result, the border shows <strong>strong, repeating color bands</strong> or <strong>striped details</strong>, especially near the corners.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">,</span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#6A737D">  /* all around the same value (60) */</span></span>
<span class="line"><span style="color:#79B8FF">  border-image-slice</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-border-image-slice-conic-gradient-with-color-stops-border-image-slice-70.webp" alt="Border effect with black, orange and magenta made combining the conic-gradient technique and the border-image-slice: 60 CSS property" style="max-width:35%" class="img-narrow"></p>
<p>In this case, we use two values: <code>1 60</code>. The result is a creative mix of two effects. The first value (1) applies to the <em>top and bottom borders</em>. Due to this we have a smooth and gentle look with wide color transitions. The second value (60) applies to both the <em>left and right borders</em>. Because of that, the effect is a tighter and more striped pattern as the gradient slice we use is smaller and repeated more often.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">,</span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#6A737D">  /* top &#x26; bottom - left &#x26; right */</span></span>
<span class="line"><span style="color:#79B8FF">  border-image-slice</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#79B8FF"> 60</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-border-image-slice-conic-gradient-with-color-stops-border-image-slice-1-70.webp" alt="Border effect with black, orange and magenta made combining the conic-gradient technique and the border-image-slice: 1 60 CSS property" style="max-width:35%" class="img-narrow"></p>
<p>Our final example takes four values: <code>1 60 60 1</code>. This setup makes our border appear asymmetric, calm, and energetic at the same time. More analytically, the first value (1) is for the <em>top border</em> and uses almost the entire gradient. The second and the third values (60 60) are for the <em>right and bottom</em> borders and use a smaller slice (tighter pattern). While the last value (1) is for the <em>left border</em> and uses almost the entire gradient again. Due to these values, we have smooth and continuous top and left borders, while the right and bottom are striped.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">,</span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#6A737D">  /* top - right - bottom - left */</span></span>
<span class="line"><span style="color:#79B8FF">  border-image-slice</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#79B8FF"> 60</span><span style="color:#79B8FF"> 60</span><span style="color:#79B8FF"> 1</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-border-image-slice-conic-gradient-with-color-stops-border-image-slice-1-60-60-1.webp" alt="Border effect with black, orange and magenta made combining the conic-gradient technique and the border-image-slice: 1 60 60 1 CSS property" style="max-width:35%" class="img-narrow"></p>
<h4 id="conic-gradient-with-color-stops">Conic-gradient with color stops<a class="heading-anchor" href="#conic-gradient-with-color-stops" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p>Furthermore, we can control the color stops by using percentages, allowing us to decide exactly where the colors start and end each time.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> 75</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#79B8FF"> 75</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#79B8FF"> 80</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> 85</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,  </span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> 90</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#79B8FF"> 95</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  border-image-slice</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-border-image-slice-conic-gradient-with-color-stops-to-the-angle.webp" alt="Border effect with black, orange and magenta made combining the conic-gradient technique and the border-image-slice: 1 CSS property" style="max-width:35%" class="img-narrow"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> 15</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#79B8FF"> 15</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> 25</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#79B8FF"> 25</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#79B8FF"> 30</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> 30</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> 35</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#79B8FF"> 35</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#79B8FF"> 40</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> 40</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> 45</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#79B8FF"> 45</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> 55</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#79B8FF"> 55</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> 65</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#79B8FF"> 65</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#79B8FF"> 70</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> 70</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> 75</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#79B8FF"> 75</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#79B8FF"> 80</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> 80</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> 85</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#79B8FF"> 85</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#79B8FF"> 90</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> 90</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> 95</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#79B8FF"> 95</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  border-image-slice</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-border-image-slice-conic-gradient-with-specific-color-stops.webp" alt="Border effect with black and magenta stripes made combining the conic-gradient technique and the border-image-slice: 1 CSS property" style="max-width:35%" class="img-narrow"></p>
<p>The results we observe when utilizing all these specific values above on the <code>border-image-slice</code> CSS property concerns only a box of 150 pixels in width and height. It is critical to adjust the values if you have different dimensions.</p>
<p>Take into consideration that gradients with the <code>1</code> value look better in square shapes, as the color flow fits perfectly within equal sides.</p>
<p>Experimenting with gradient borders opens the door to an endless palette of styles — from soft pastel outlines that frame content elegantly to bold, vibrant strokes that command attention. The key lies in balance: using color transitions and subtle motion to enhance, not overpower, the user experience. Whether you’re styling buttons, containers, or entire sections, CSS gradient borders are a reminder that even the smallest design detail can carry a playful spark — proof that borders don’t just separate elements, they can also bring them to life.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/border-image-slice-css-property-for-one-of-a-kind-border-effects/">The border-image-slice CSS Property</a></li>
<li><a href="/how-to-be-creative-with-different-css-border-styles/">CSS Border Styles Explained</a></li>
<li><a href="/css-conic-gradient-technique-how-to-make-stunning-visual-effects/">CSS Conic Gradient Made Easy</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How to Install Java on Mac: Step-by-Step Guide</title>
      <link>https://littlecodingthings.com/how-to-install-java-on-mac-step-by-step-guide/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-install-java-on-mac-step-by-step-guide/</guid>
      <pubDate>Fri, 14 Nov 2025 07:31:00 GMT</pubDate>
      <description>Install Java on a Mac with Homebrew or the Oracle JDK, set JAVA_HOME, verify the install, and fix “Unable to locate a Java Runtime” errors.</description>
      <category>Setup &amp; Tools</category>
      <content:encoded><![CDATA[<p>If you’ve ever tried running a Java program on a Mac without setting anything up, you’ve probably seen an error about a missing <strong>Java Runtime</strong>. That’s because, unlike JavaScript, Java doesn’t come built into your computer — you need to install a <strong>Java Development Kit (JDK)</strong> first.</p>
<p>In this guide, we’ll go step by step:</p>
<ul>
<li>Check if Java is already installed (so you don’t install it twice by mistake)</li>
<li>Learn what a JDK kit is and why most developers use it</li>
<li>Install Java on a Mac using either Homebrew or the official Oracle download</li>
<li>Set up your environment so the <code>java</code> command works anywhere in your terminal</li>
<li>Verify the installation, uninstall if needed, and fix common issues</li>
</ul>
<p>Whether you’re new to Java or just coming from another language like JavaScript, this guide will give you a clear path to getting Java up and running on macOS.</p>
<h2 id="check-if-java-is-already-installed">Check if Java is Already Installed<a class="heading-anchor" href="#check-if-java-is-already-installed" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Before installing Java, it’s worth checking if it’s already on your Mac. Maybe you’re not on your personal machine, or you installed it months ago for a side project and completely forgot.</p>
<p>To check if Java is already installed:</p>
<ol>
<li>Open your <strong>Terminal</strong></li>
<li>Type <code>java -version</code></li>
<li>If Java is installed, you’ll see something like:</li>
</ol>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>OpenJDK version 11.x</span></span></code></pre></div>
<p>If it’s <strong>not</strong> installed, you’ll get a message like:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>The operation couldn’t be completed. Unable to locate a Java Runtime.</span></span>
<span class="line"><span>Please visit http://www.java.com for information on installing Java.</span></span></code></pre></div>
<p>If you see the “Unable to locate” message, don’t worry — just continue with this guide to install Java on your Mac.</p>
<h2 id="what-is-a-jdk">What is a JDK?<a class="heading-anchor" href="#what-is-a-jdk" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>If this is your first programming language, or if you’re like me, coming from another one — in my case, Javascript — you might not know much about the Java ecosystem. And honestly, you don’t really need to at first, right?</p>
<p>Still, because of assumptions, you might expect the installation to be as simple as running <code>brew install java</code>. But when you look it up, you’ll quickly see that the recommended way is to install a <strong>JDK</strong> instead. Before we continue, let’s take a quick look at what that actually is.</p>
<p><strong>JDK</strong> – <strong>Java Development Kit</strong> is an open-source implementation of Java, maintained by big tech companies such as Oracle, Red Hat, and others.</p>
<p>When we refer to an <em>open-source implementation</em>, it simply means software built according to official rules. In this case, the rules come from the <strong><a href="https://docs.oracle.com/javase/specs/">Java SE Specification</a></strong>.</p>
<p>So what does the JDK provide? It contains:</p>
<ul>
<li><strong>Compiler</strong> – turns your <code>.java</code> files into an executable form called bytecode.</li>
<li><strong>Runtime (JVM)</strong> – executes that bytecode on any computer (Windows, Mac, Linux, etc.).</li>
<li><strong>Standard library</strong> – a huge set of built-in tools to help you out with your code.</li>
</ul>
<p>It essentially has everything you need to use Java on your machine. The JDK is considered an essential tool for developers working with Java, and the OpenJDK project and Oracle distribute it.</p>
<h2 id="install-java-on-mac">Install Java on Mac<a class="heading-anchor" href="#install-java-on-mac" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>You can install Java on macOS in two main ways:</p>
<ol>
<li><strong>Install Using Homebrew</strong> – quick and beginner-friendly</li>
<li><strong>Install by Downloading from Oracle</strong></li>
</ol>
<p>If you’re new to Java or simply want the fastest setup, the <strong>Homebrew method</strong> is the best choice. (We have a separate <a href="/how-to-install-homebrew-macos-for-beginners/">post that walks you through installing Homebrew</a> if you don’t have it yet.)</p>
<p><strong>In this guide, we’ll use the Homebrew method.</strong></p>
<p>To find out which is the latest version of Java, you can <a href="https://jdk.java.net/.">visit</a> <a href="https://jdk.java.net/.">this page.</a></p>
<h3 id="install-java-using-homebrew">Install Java using Homebrew<a class="heading-anchor" href="#install-java-using-homebrew" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>To install Java using Homebrew:</p>
<ol>
<li><strong>Update Homebrew</strong>
Open your terminal and run: <code>brew update</code>
This makes sure you’re working with the latest package list.</li>
<li><strong>Install OpenJDK 21</strong>
After updating, run:
<code>brew install openjdk@21</code></li>
<li><strong>Verify installation</strong>
Open your terminal and run:</li>
</ol>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>java -version</span></span></code></pre></div>
<p>At the time of writing this guide, version <strong>21</strong> is the latest long-term support (LTS) release. If you want to install a different version, just replace <code>21</code> with the version number you need (for example, <code>openjdk@17</code>).</p>
<p><strong>Optional: Read More About the Package</strong>
You can check out the official <a href="https://formulae.brew.sh/formula/openjdk#default">Homebrew formula page for OpenJDK here</a>.</p>
<h2 id="set-java_home-environment-variable">Set JAVA_HOME Environment Variable<a class="heading-anchor" href="#set-java_home-environment-variable" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>After installing OpenJDK, you could have tried to verify the installation and found out that you still get</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>The operation couldn’t be completed. Unable to locate a Java Runtime.</span></span>
<span class="line"><span>Please visit http://www.java.com for information on installing Java.</span></span></code></pre></div>
<p>In that case, you will need to add the Java home directory to your PATH. Since we installed OpenJDK@21, the command to add this to our PATH is</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">echo </span><span style="color:#9ECBFF">'export PATH="/opt/homebrew/opt/openjdk@21/bin:$PATH"'</span><span style="color:#F97583"> >></span><span style="color:#F97583"> ~/</span><span style="color:#E1E4E8">.zshrc</span></span></code></pre></div>
<p><em>You’ll also see this message in the Homebrew installation logs for OpenJDK, near the end of the process.</em></p>
<p>What this command essentially does is prepend the existing list of paths with the directory where OpenJDK is installed. So when you ask it to run a java program, it will search first there.</p>
<p>If you installed a different version, change the version accordingly to the command above.</p>
<h2 id="verify-installation">Verify Installation<a class="heading-anchor" href="#verify-installation" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>To verify our installation regardless of the method we used we should type <code>java --version</code>. By now you should be seeing</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>➜  ~ java -version</span></span>
<span class="line"><span>openjdk version "21.0.8" 2025-07-15</span></span>
<span class="line"><span>OpenJDK Runtime Environment Homebrew (build 21.0.8)</span></span>
<span class="line"><span>OpenJDK 64-Bit Server VM Homebrew (build 21.0.8, mixed mode, sharing)</span></span></code></pre></div>
<h2 id="uninstalling-java-homebrew">Uninstalling Java (Homebrew)<a class="heading-anchor" href="#uninstalling-java-homebrew" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>If you want to remove a specific version of OpenJDK installed via Homebrew, run:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">brew</span><span style="color:#9ECBFF"> uninstall</span><span style="color:#9ECBFF"> openjdk@21</span></span></code></pre></div>
<h2 id="checking-installed-versions">Checking Installed Versions<a class="heading-anchor" href="#checking-installed-versions" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>To see all the Java versions (and other packages) you currently have installed, run:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">brew</span><span style="color:#9ECBFF"> list</span><span style="color:#79B8FF"> --versions</span></span></code></pre></div>
<p>You might see something like this:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>...</span></span>
<span class="line"><span>openjdk@17 17.0.12</span></span>
<span class="line"><span>openjdk@21 21.0.4</span></span>
<span class="line"><span>...</span></span></code></pre></div>
<p>This means you have both Java 17 and Java 21 installed on your system.</p>
<h2 id="choosing-an-ide-for-java">Choosing an IDE for Java<a class="heading-anchor" href="#choosing-an-ide-for-java" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Now that you’ve installed Java, the next step is picking an <strong>Integrated Development Environment (IDE)</strong> to support your learning. An IDE helps you compile code, catch mistakes, and debug programs more easily — making your path to mastering Java smoother.</p>
<p>Some popular free choices include:</p>
<ul>
<li><strong><a href="https://www.jetbrains.com/idea/">IntelliJ IDEA Community Edition</a></strong>, published by JetBrains. This is my personal recommendation, since it’s beginner-friendly and offers a free edition.</li>
<li><strong><a href="https://eclipseide.org/">Eclipse</a></strong>, maintained by the Eclipse Foundation</li>
<li><strong><a href="https://netbeans.apache.org/front/main/index.html">NetBeans</a></strong>, maintained by the Apache Foundation</li>
</ul>
<p>Pick one of these tools, set it up, and you’ll be ready to start coding your very first Java programs with confidence!</p>
<h2 id="troubleshooting-common-issues">Troubleshooting Common Issues<a class="heading-anchor" href="#troubleshooting-common-issues" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Below are some common issues you might face when installing or using Java on macOS.
If you’re dealing with a different problem and haven’t figured out the solution, drop it in the comments — we’ll try to help you out.
Also, if you’ve solved a tricky Java issue yourself, share it in the comments so other readers can benefit too.</p>
<h3 id="wrong-java-version-running">Wrong Java Version Running<a class="heading-anchor" href="#wrong-java-version-running" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong>Cause:</strong> Multiple Java versions are installed, and the wrong one is first in your PATH.
<strong>Fix:</strong> Check which Java is being used</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>which java</span></span></code></pre></div>
<p>Then adjust your PATH so the version you want comes first. You can do that by typing:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">export</span><span style="color:#79B8FF"> PATH</span><span style="color:#F97583">=</span><span style="color:#9ECBFF">"/opt/homebrew/opt/openjdk@&#x3C;version-you-want>/bin:$PATH"</span></span></code></pre></div>
<h3 id="brew-install-fails">brew install fails<a class="heading-anchor" href="#brew-install-fails" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong>Cause:</strong> Homebrew may be outdated or missing.</p>
<p><strong>Fix:</strong> Update Homebrew:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">brew</span><span style="color:#9ECBFF"> update</span></span></code></pre></div>
<p>If Homebrew is not installed, see our <a href="/how-to-install-homebrew-macos-for-beginners/">homebrew installation guide</a>.</p>
<h3 id="java-command-not-found"><code>java</code> Command Not Found<a class="heading-anchor" href="#java-command-not-found" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong>Cause:</strong> OpenJDK is installed but not linked to your environment.</p>
<p><strong>Fix:</strong> Link the installed version so the <code>java</code> command is available:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">brew</span><span style="color:#9ECBFF"> link</span><span style="color:#79B8FF"> --force</span><span style="color:#79B8FF"> --overwrite</span><span style="color:#9ECBFF"> openjdk@21</span></span></code></pre></div>
<p>If you installed a different version, replace <code>21</code> with that version number.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-install-homebrew-macos-for-beginners/">How to install Homebrew – MacOS for beginners</a></li>
<li><a href="/how-to-install-npm-on-macos/">How to Install npm on MacOS</a></li>
<li><a href="/macos-shortcuts-cheatsheet-for-new-users/">MacOS Shortcuts – Cheatsheet for New Users</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Am I Too Old to Learn Coding?</title>
      <link>https://littlecodingthings.com/am-i-too-old-to-learn-coding/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/am-i-too-old-to-learn-coding/</guid>
      <pubDate>Fri, 07 Nov 2025 07:00:00 GMT</pubDate>
      <description>Am I too old to learn coding? A developer who started late on why age is rarely the real obstacle, what the learning curve looks like, and where to begin.</description>
      <category>Thoughts &amp; Theory</category>
      <content:encoded><![CDATA[<p>I have to say, this is a question I’ve been hearing for a long time since I got into the web development world. It’s a very common question, so please don’t feel like you’re alone when asking it. Many people are in your shoes and wonder the exact same thing.
This question is probably not just about coding, but about change in general. Deep down, the question might not be “Am I too old to learn coding?” but rather “Am I too old to change?” Let’s explore this together.</p>
<p>For those of you looking for a TLDR answer: No! You are not too old!
But I’m quite sure that doesn’t fully convince you—so let me explain.</p>
<h2 id="my-late-start-in-web-development">My Late Start in Web Development<a class="heading-anchor" href="#my-late-start-in-web-development" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Here’s a short story about me, just so you know we might have been walking a similar path.</p>
<p>I’m not 100% a tech person. I didn’t study Computer Science or anything related when I finished school. I started working in a completely different field—sales in supermarket goods. At some point, I went on to take an MSc in Information Systems, a program designed for non-tech people. It had no coding lessons related to web development.</p>
<p>I discovered web development while browsing sites like Coursera and edX—and I loved it. I was in my mid-30s at the time, and I asked myself the same question: <em>Am I too old to learn coding?</em> Let me tell you what I found out.</p>
<p>By the way, I’ve been working as a web developer for the past 7 years. So yes—there <em>are</em> success stories out there, and yours can definitely be one of them too!</p>
<h2 id="youre-not-starting-from-zero">You’re Not Starting from Zero<a class="heading-anchor" href="#youre-not-starting-from-zero" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>This is 100% true—you’re <em>not</em> starting from zero. You might be thinking, “But I have no experience with programming. How can that be true?” Well, even if you’re new to coding, programming is about more than just writing code.</p>
<p>While you’ll focus on technical skills when learning for a job, that’s only part of what you’ll need to succeed in tech. Like any job, being a good developer also depends on other important skills, such as:</p>
<ul>
<li><strong>Soft skills</strong> – How you communicate and work with your team.</li>
<li><strong>Product skills</strong> – How well you understand product requirements and how they should be built.</li>
<li><strong>People skills</strong> – How you interact with clients and stakeholders (the people asking for new features).</li>
<li><strong>Organizational skills</strong> – Coding isn’t just about typing code. It’s also about planning your work, breaking it into smaller tasks, staying focused, and delivering on time. Most teams do this through a framework with its own vocabulary, so it’s worth knowing <a href="/what-is-scrum-101-guide-for-new-developers/">what scrum is</a> before your first sprint planning rather than during it.</li>
<li><strong>Life balance skills</strong> – <a href="/the-burnout-syndrome-how-to-identify-and-overcome-it/">Avoiding burnout</a>, keeping a healthy routine, getting enough rest—these all matter too.</li>
</ul>
<p>You might think this sounds like a lot—but it’s all true. If you want to grow into a great developer, you’ll need to develop more than just technical knowledge.</p>
<p>From what I’ve seen, the best developers aren’t always the ones who know every new framework or advanced technique. They’re often the ones who are humble, reliable, and great team players.</p>
<p>So if you feel like you have nothing to offer—think again!
You already have experience, even if it’s not from the tech world.</p>
<ul>
<li>If you’ve been a <strong>taxi driver</strong>, you’ve learned how to stay patient and handle people in all situations.</li>
<li>If you’re a <strong>mother</strong>, you’ve mastered multitasking and managing emotions—skills that come in handy at work too, especially with your managers!</li>
<li>If you’ve been a <strong>gardener</strong>, you probably have a great eye for detail and know how to focus on repetitive tasks.</li>
</ul>
<p>Every job teaches you something valuable.
So now that we’ve cleared that up — you <em>are</em> skilled, let’s talk about age…</p>
<h2 id="too-old-compared-to-what">Too Old Compared to What?<a class="heading-anchor" href="#too-old-compared-to-what" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>This is one of the most common — and most unrealistic — comparisons: <em>“Am I too old?”</em> Too old compared to who?</p>
<p>Are you 15? Then yes, you’re older than a 5-year-old.
Are you 65? Then sure, you’re older than someone who’s 30.</p>
<p>But here’s the real question: <strong>You know who you’re younger than?</strong>
The version of <em>you</em> a few years from now. I mean you can choose to start learning now—whether you’re in your teens, your 40s, or your 70s.
Or you can wait… and reach your 30s, 60s, or 90s having never started.</p>
<p>So what’s the difference between the version of you who starts learning and the one who doesn’t?</p>
<p><strong>Time will pass</strong> either way (<em>Even Gandalf doesn’t help here</em>).</p>
<p><img src="/gandalf-no-memory.webp" alt="Am I too old to code?" style="max-width:69%" class="img-narrow"></p>
<p>Both versions of you will grow older. But only one will arrive at that next age with a new skill—or even a new career.</p>
<p>So why not start your path right now? Of course, you could avoid it. You could push it away.</p>
<h2 id="whats-the-alternative">What’s the Alternative?<a class="heading-anchor" href="#whats-the-alternative" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Well, there is one—and it’s a bit grim. I asked myself the same thing when I was wondering, <em>“If I’m too old, what does that really mean?”</em> The answer? You can just wait—wait until death comes sometime in the far future.</p>
<blockquote>
<p>Don’t fight for your dreams! Just don’t!</p>
</blockquote>
<p>Yes, do nothing. <strong>Don’t fight for your dreams.</strong> Don’t live the life you want. Don’t start learning and keep learning until you have no energy left. Just stay where you are and let time pass. Eventually, your journey will end.</p>
<p>Does that sound like something you would actually do? No, right? Because in reality, there is no real alternative. You either try — or you don’t. You could try and realize it’s not something you enjoy. Or you could find out it’s something that changes your life — because it turns out to be something you truly love doing.</p>
<h2 id="the-learning-curve-yes-its-real--and-beatable">The Learning Curve: Yes, It’s Real – and Beatable<a class="heading-anchor" href="#the-learning-curve-yes-its-real--and-beatable" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Ok, now we’re getting somewhere. But is it hard? Will you have tough times? Will you make it through?</p>
<p>Well, I have to be honest — being a programmer is a great profession to be in. Some of its advantages are:</p>
<p><strong>Continuous learning</strong>—which can sometimes feel like a disadvantage too.</p>
<p><strong>Great compensation</strong>, especially if you’re working fully remote.</p>
<p><strong>Remote flexibility</strong>—wherever your laptop goes, you can go.</p>
<p>But it’s not all sunshine. Like any career, programming has its own set of challenges. In my opinion, the two most challenging aspects are the <strong>steep learning curve</strong> and <a href="/unmasking-impostor-syndrome-in-tech-watch-out-for-these-signs/">impostor syndrome</a>.</p>
<p>You might want to reflect a bit before diving in and ask yourself: <a href="/how-to-decide-if-programming-is-right-for-you/">Is programming really for me</a>? If you’re unsure, don’t worry—we’ve got you covered with a post comparing its pros and cons in more detail.</p>
<p>Let’s talk about the learning curve first. It’s steep. You <em>will</em> feel overwhelmed—sooner or later. That depends on your personality, energy, and life situation. If you’re going through a tough period, it may hit harder.</p>
<p>Why is it so steep? Because there’s so much to learn—and even while learning, you may catch yourself thinking, <em>I don’t know enough.</em> Let me stop you right there: <strong>you will never know everything</strong>. And that’s perfectly normal.</p>
<p>When I first started, that exact fear hit me hard—<em>How will I ever learn it all?</em> Then I came across a tweet that changed my perspective. It went something like this:</p>
<blockquote>
<p>Beginner programmers are anxious because of their uncertainty. Senior programmers find peace in the fact that they’ll never be certain.</p>
</blockquote>
<p>That moment was eye-opening for me. I realized: this is just the nature of the game. No one knows everything—and that’s OK. The only thing that truly matters is to <strong>show up, keep learning, and keep having fun</strong>.</p>
<p>If you can combine fun with perseverance, you won’t lose — I promise.</p>
<p>But even if you’ve got the patience and the motivation to start… is there still a chance this might not work out?</p>
<h2 id="whats-the-worst-that-could-happen">What’s the Worst That Could Happen?<a class="heading-anchor" href="#whats-the-worst-that-could-happen" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Let’s be honest—there’s always a worst-case scenario. It might look different for each of you, but I’ll try to cover a few common ones that apply to many people starting this journey.</p>
<h3 id="what-if-you-love-coding-but-still-cant-get-a-job">What If You Love Coding but Still Can’t Get a Job?<a class="heading-anchor" href="#what-if-you-love-coding-but-still-cant-get-a-job" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Yes, this is a tough one. I’ve seen it happen, and I’ve <em>been</em> there myself. Let me tell you how I dealt with it.</p>
<p>When I first started applying for jobs, all employers saw on my CV was: sales, sales, and more sales. No one trusted me because I had no experience. Classic case of “no experience, but no way to get it either.”</p>
<p>At that point, I saw two possible options:</p>
<ul>
<li>Get a non-paid internship</li>
<li>Start building a portfolio with real projects (like websites for friends, local businesses, or anything you can find)</li>
</ul>
<p>For me, the internship route worked. I landed a 6-month unpaid internship that offered the chance for paid work afterward. Financially, it was a tough decision. But I took it—and it changed everything.</p>
<p>Suddenly, my CV didn’t just say “sales.” It showed real web development experience. The next time I applied for a job, I imagine employers were thinking, “Well, if he managed to work in one company, maybe he can work for us too.”</p>
<p>The day I started that internship was a great one.</p>
<h3 id="what-if-you-try-coding-and-dont-like-it">What If You Try Coding and Don’t Like It?<a class="heading-anchor" href="#what-if-you-try-coding-and-dont-like-it" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>This is another real possibility. Not everything is for everyone. Maybe you love the thrill of the first lessons, but later you feel overwhelmed, bored, or just not that into it.</p>
<p>There are two ways this can go:</p>
<ul>
<li>You’re just hitting a tough spot and need to push through</li>
<li>Or you’ve genuinely discovered that coding isn’t for you</li>
</ul>
<p>If it’s the second one, that’s perfectly fine. You’ve now stopped wondering, “Am I too old to learn coding?”—because you’ve answered a more important question: <em>“Is coding for me?”</em></p>
<p>And honestly, that’s a win too. Knowing what’s <strong>not</strong> for you is just as important as finding what <em>is</em>. Now you can move on to your next adventure, with no regrets—because you tried.</p>
<h2 id="ready-to-start-lets-talk-about-where-to-begin">Ready to Start? Let’s Talk About Where to Begin<a class="heading-anchor" href="#ready-to-start-lets-talk-about-where-to-begin" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>So, now that you’re (hopefully) feeling more confident—not because there’s nothing to fear, but because you’re ready to commit even <em>with</em> those fears—where do you start?</p>
<p>Well, I can only speak for web development, not every path in programming.</p>
<p>Think of coding like becoming a doctor—there are many different specializations, and no one can explain them all at once. Don’t like that comparison? Try this: imagine walking into a chocolate shop for the first time. How do you figure out what you like? Simple—you start tasting.</p>
<p>From my point of view, the fastest route to getting a developer job is through <strong>frontend development</strong>.</p>
<p>In case you don’t know, a frontend developer is the person who builds what users see and interact with on a website. I believe it’s the quickest path because you can learn a few core building blocks and start seeing results fast. You’ll be able to create things, show them to potential employers, and feel a sense of progress early on.</p>
<p>This means faster feedback, less overwhelm, and a shorter path to your first job.</p>
<p>Once you’ve moved past the age question, the next step is figuring out if programming fits your personality. Learn <a href="/how-to-decide-if-programming-is-right-for-you/" title="How To Decide If Programming Is Right For You?">how to decide if programming Is right for you</a>.</p>
<p>Ready to start looking for your first role? Check out some of the <a href="/best-job-sites-for-web-developers/" title="Best Job Sites for Web Developers">Best Job Sites for Web Developers</a>.</p>]]></content:encoded>
    </item>
    <item>
      <title>clip-path: inset() Explained</title>
      <link>https://littlecodingthings.com/clip-path-inset-css-property-cropping-elements-as-a-pro/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/clip-path-inset-css-property-cropping-elements-as-a-pro/</guid>
      <pubDate>Thu, 30 Oct 2025 09:38:00 GMT</pubDate>
      <description>Crop an element by pushing its sides in with clip-path: inset(). What one, two, three and four values do, plus the round keyword.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Another efficient and user-friendly CSS method to cut down ✂ and “play” 🤹‍♀️ with existing HTML elements. In contrast to most <code>clip-path</code> methods that use coordinate pairs(X, Y) to define <a href="/clip-path-for-quick-polygons-ready-code-to-copy/">points</a> (that act as the corners of the shape) <code>inset()</code> <strong>manipulate the sides of the element</strong>. How so? Let’s discover it together!</p>
<p>The <code>clip-path: inset()</code> is a way to <strong>restrict the visible area of an element by “pushing in” its sides from the element’s bounding box.</strong> This function doesn’t create a new shape as every element’s box is rectangular (and it can be a square if the width and height match), it just “<em>trims</em>” the existing one. <strong>The result is always a four-sided shape with right angles</strong>, which can be either a rectangle or, in special cases, a square.</p>
<p>Now, let’s proceed with a more detailed analysis and try out this amazing tool. For better understanding, I have prepared some practical examples for you. This is our “working area” for today! 👷‍♀️ 🏗 👷‍♂️</p>
<h2 id="clip-path-inset-function-explained">Clip-path: inset() function explained<a class="heading-anchor" href="#clip-path-inset-function-explained" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>First things first. What does this mean? Well.. We need a rectangular or a square shape in order to work with <code>clip-path: inset()</code> CSS property.</p>
<p>The following code snippet and image illustrate how we create a simple black square with 200px width and 200px height.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* square */</span></span>
<span class="line"><span style="color:#B392F0">.square-shape</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span></code></pre></div>
<p><img src="/clip-path-inset-initial-square.webp" alt="A black square with 200px width and height" style="max-width:42%" class="img-narrow"></p>
<p><strong><code>Inset</code> accepts up to four values, each controlling how far the sides are pushed inward</strong>.</p>
<p>So, how about analyzing the different cases based on these values, and then proceeding with examples?</p>
<ul>
<li><em>One value</em>: it applies to <strong>all four sides</strong></li>
<li><em>Two values</em>: the first one is for <strong>top &#x26; bottom</strong>, while the second is for <strong>left &#x26; right</strong></li>
<li><em>Three values</em>: the first one is for <strong>top</strong>, the second for <strong>left &#x26; right</strong> and the third for <strong>bottom</strong></li>
<li><em>Four values</em>: the first one is for <strong>top</strong>, the second for <strong>right</strong>, the third for <strong>bottom</strong> and finally the fourth value is for the <strong>left</strong> side (clockwise, the same order as <code>margin</code> and <code>padding</code>).</li>
</ul>
<p>We can now proceed with our examples. The code snippets and images that follow display these four cases.</p>
<p><em><strong>First case – One value</strong></em></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.square-shape</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span></code></pre></div>
<p><img src="/clip-path-inset-one-value-example.webp" alt="A black square with 100 pixels width and height. Applying to all sides clip-path: inset(50px);" style="max-width:49%" class="img-narrow"></p>
<p><em>NOTE</em>: ⬜ The gray color is used only for clarity, to distinguish the initial square from the clipped one. In practice, this part would be cut out (hidden).</p>
<p><em><strong>Second case – Two values</strong></em></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.square-shape</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 30</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span></code></pre></div>
<figure><img src="/clip-path-inset-two-values-example.webp" alt="A black square with 100 pixels width and height. Applying to all sides clip-path: inset(20px 30px);" style="max-width:49%" class="img-narrow"><figcaption><strong>Third case – Three values</strong></figcaption></figure>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.square-shape</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 30</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span></code></pre></div>
<figure><img src="/clip-path-inset-three-values-example-ezgif-com-gif-maker.webp" alt="A black square with 100 pixels width and height. Applying to all sides clip-path: inset(20px 30px 10px);" style="max-width:49%" class="img-narrow"><figcaption><strong>Fourth case – Four values</strong></figcaption></figure>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.square-shape</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 40</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 30</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span></code></pre></div>
<p><img src="/clip-path-inset-four-values-example.webp" alt="A black square with 100 pixels width and height. Applying to all sides clip-path: inset(20px 40px 10px 30px);" style="max-width:49%" class="img-narrow"></p>
<h2 id="making-your-elements-smooth-with-rounded-corners">Making your elements smooth with rounded corners<a class="heading-anchor" href="#making-your-elements-smooth-with-rounded-corners" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Apart from cropping, <code>inset()</code> <strong>allows you to round the corners of the clipped shape</strong> as well. This is achieved by adding the optional <code>round</code> keyword, followed by a radius value, which functions similarly to the <a href="/how-to-create-stunning-vibrant-neon-effect-css-only/"><code>border-radius</code> CSS property</a>.
By utilizing it, we can transform the sharp corners into rounded ones.</p>
<p>As previously with the <code>inset()</code>, <code>round</code> takes up to four values, too.</p>
<ul>
<li><em>One value</em>: it applies to <strong>all corners the same value</strong></li>
<li><em>Two values</em>: they applied diagonal, the first one is for <strong>top-left &#x26; bottom-right</strong> corners, while the second is for <strong>top-right &#x26; bottom-left</strong> corners</li>
<li><em>Three values</em>: the first one is for the <strong>top-left</strong> corner, the second goes diagonally and is applied to both the <strong>top-right &#x26; bottom-left</strong> corners, and the third for the <strong>bottom-right</strong> corner</li>
<li><em>Four values</em>: the first one is for the <strong>top-left</strong> corner, the second for the <strong>top-right</strong>, the third for the <strong>bottom-right</strong>, and finally the fourth value is for the <strong>bottom-left</strong> corner (clockwise).</li>
</ul>
<p>We move forward with our examples. The following code snippets and images display these four cases.</p>
<p><em><strong>First case – One value</strong></em></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.square-shape</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#F97583"> round</span><span style="color:#79B8FF"> 25</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span></code></pre></div>
<figure><img src="/clip-path-inset-rounded-cornes-with-just-one-value.webp" alt="A black square with 100 pixels width and height. Applying clip-path: inset(50px round 25px);" style="max-width:49%" class="img-narrow"><figcaption><strong>Second case – Two values</strong></figcaption></figure>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.square-shape</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#F97583"> round</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 25</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span></code></pre></div>
<figure><img src="/clip-path-inset-rounded-with-only-two-values.webp" alt="A black square with 100 pixels width and height. Applying clip-path: inset(50px round 0px 25px);" style="max-width:49%" class="img-narrow"><figcaption><strong>Third case – Three values</strong></figcaption></figure>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.square-shape</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#F97583"> round</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 25</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span></code></pre></div>
<figure><img src="/clip-path-inset-rounded-cornes-with-the-three-values.webp" alt="A black square with 100 pixels width and height. Applying clip-path: inset(50px round 0px 25px 10px);" style="max-width:49%" class="img-narrow"><figcaption><strong>Fourth case – Four values</strong></figcaption></figure>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.square-shape</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#F97583"> round</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 25</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span></code></pre></div>
<p><img src="/clip-path-inset-rounded-cornes-with-the-four-values.webp" alt="A black square with 100 pixels width and height. Applying clip-path: inset(50px round 0px 25px 10px 20px);" style="max-width:49%" class="img-narrow"></p>
<p>Apart from pixels, all values can also be written in percentages. The two units, <code>px</code> and <code>%</code>, can even be combined.</p>
<p>The following examples, along with their code snippets and images, illustrate these cases.</p>
<p><em><strong>Using percentages as values</strong></em></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.square-shape</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">25</span><span style="color:#F97583">%</span><span style="color:#F97583"> round</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 25</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span></code></pre></div>
<figure><img src="/clip-path-inset-rounded-using-only-persentages.webp" alt="A black square with 100 pixels width and height. Applying clip-path: inset(25% round 0% 25% 5% 10%);" style="max-width:49%" class="img-narrow"><figcaption><strong>Combine percentages with pixels</strong></figcaption></figure>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.square-shape</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">25</span><span style="color:#F97583">%</span><span style="color:#F97583"> round</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 30</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span></code></pre></div>
<p><img src="/clip-path-inset-combine-units.webp" alt="A black square with 100 pixels width and height. Applying clip-path: inset(25% round 10px 30% 5% 60px);" style="max-width:49%" class="img-narrow"></p>
<p>Well, something like a 🍋 lemon is here!! Cool, hug!?</p>
<h2 id="clip-path-inset-function--manipulating-images">Clip-path inset function – manipulating images<a class="heading-anchor" href="#clip-path-inset-function--manipulating-images" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Images can also be clipped, revealing only part of them, by simply utilizing the <code>clip-path: inset()</code> CSS property.</p>
<p>Below, we have an image of a bicycle 🚴‍♀️ out in nature. 🏞 Let’s say that we want to isolate the bicycle and display it within a rounded shape, pretty much like a frame. ✨</p>
<p><img src="/clip-path-inset-image.webp" alt="An image with 100px width and height, showing a bicycle in nature." style="max-width:42%" class="img-narrow"></p>
<p>Depending on our prefrences, we cut away the unnecessary parts. First, our initial square image turns into a rectangle. After that, we add the <code>round</code> with a value of <code>50%</code> which gives the remaining part a smooth, nicely rounded shape.</p>
<p><em>NOTE</em>: To make things more straightforward, I’ve prepared an image with colored code and overlays 🎨 ✂ showing which values correspond to the parts we cut away.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.image</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">47</span><span style="color:#F97583">px</span><span style="color:#79B8FF">  14</span><span style="color:#F97583">px</span><span style="color:#79B8FF">  7</span><span style="color:#F97583">px</span><span style="color:#79B8FF">  20</span><span style="color:#F97583">px</span><span style="color:#F97583">  round</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span></code></pre></div>
<p>Now we see just the bicycle kept in view, while everything else is clipped out. Exactly the effect we want to achieve.</p>
<p><img src="/ezgif-com-webp-maker.webp" alt="An image with 100px width and height, showing a bicycle in nature. Applying clip-path: inset(47px 14px 7px 20px round 50%);" style="max-width:56%" class="img-narrow"></p>
<p>Voila!! There we have it! Our final updated image!! 🥳 Ready to be styled even more with all those amazing CSS properties!</p>
<p><img src="/clip-path-inset-image-final.webp" alt="A rounded image showing a bicycle" style="max-width:56%" class="img-narrow"></p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/easy-made-circles-a-simple-guide-to-clip-path-css-property/">clip-path: circle() Explained</a></li>
<li><a href="/clip-path-for-quick-polygons-ready-code-to-copy/">Clip-path For Quick Polygons – Ready Code-To-Copy</a></li>
<li><a href="/make-a-unique-folded-corner-effect-utilizing-the-clip-path-css-property/">CSS Folded Corner Effect with clip-path</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>CSS Triangles with clip-path</title>
      <link>https://littlecodingthings.com/clip-path-for-simplified-triangles-ready-code-to-copy/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/clip-path-for-simplified-triangles-ready-code-to-copy/</guid>
      <pubDate>Fri, 24 Oct 2025 06:00:00 GMT</pubDate>
      <description>Copy-ready clip-path: polygon() code for triangles — right, isosceles, acute and obtuse — all built by moving one corner of a square.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Have you come across the clip-path CSS property before? It’s a unique tool that helps us to create a variety of shapes from scratch without the need for complex code. A truly captivating addition in web design.</p>
<p>The <code>clip-path</code> accepts several values: <a href="/easy-made-circles-a-simple-guide-to-clip-path-css-property/"><code>circle()</code></a>, <code>ellipse()</code>, <a href="/clip-path-for-quick-polygons-ready-code-to-copy/"><code>polygon()</code></a>, and <a href="/clip-path-inset-css-property-cropping-elements-as-a-pro/"><code>inset()</code></a>. These values <strong>define the shape of the clipping path applied to an element</strong> and we utilize them depending on the shape we want to create each time.
Specifically, in today’s post, we will learn how to <strong>clip an element into a triangle shape</strong> by setting the <code>clip-path: polygon()</code>.</p>
<h2 id="clip-path-polygon-function-explained">Clip-path polygon() function explained<a class="heading-anchor" href="#clip-path-polygon-function-explained" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>It’s time to continue and focus on our triangles. Let’s proceed with the example I prepared and see how this special tool works. 🪄 Below we have a black square. We used to create squares by setting the <em>width</em> and <em>height</em> CSS properties, but for today, let’s see how we can replace them with the <code>clip-path</code> property.</p>
<p>Take a look below. I begin with a ⬛ square, making it easier to understand our function as squares (boxes) are the most familiar shapes in CSS. Then I will transform this square into a 📐 triangle. <strong>The color code shows how we position the square along both the X-axis and Y-axis. The colored points on the corners represent the clipping region.</strong></p>
<p>🖇 Despite having three magenta points and one green point, for now, all points behave the same. The <em>differentiation of the green point</em> will be meaningful later and hold significance for the following stages in our work.</p>
<p><img src="/clip-path-square-explanation.webp" alt="A square made by setting the clip-path: polygon(0% 0%,100% 0%,100% 100%, 0% 100%);" style="max-width:42%" class="img-narrow"></p>
<p>Each pair of values inside the <code>clip-path: polygon()</code> function represents a point, and all these points together define a clipping region.</p>
<h2 id="create-right-triangles">Create right triangles<a class="heading-anchor" href="#create-right-triangles" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Now, let’s see how we can transform it into a triangle. The square has four corners (points) while the triangle has three corners. <strong>Depending on the type of triangle we want to create, we need to cut the corresponding corner.</strong>
In my example, I create a right triangle. I cut the top-right corner (100% 0%). As you can see in the following image, cutting this corner, we have the triangle we need.</p>
<p><img src="/clip-path-triangle-explanation-1.webp" alt="A right triangle made by setting the clip-path: polygon(0% 0%,100% 100%,0% 100%);" style="max-width:42%" class="img-narrow"></p>
<p>What do you think? It looks good! Isn’t it? 😎 With just a simple line of code!</p>
<p>🔖 I opted to clip the top-right corner (100% 0%). Alternatively, it would also be correct to clip the top-left corner (0% 0%), the bottom-right corner (100% 100%), or the bottom-left corner (0% 100%). All these clippings yield the same result, so you can choose the one that best fits your preferences. Additionally, you can use <code>transform: rotate</code> to adjust the orientation as needed.</p>
<p><img src="/clip-path-orthogonal-triangles-explanation-image.webp" alt="Creating right triangles setting the clip-path CSS property." style="max-width:56%" class="img-narrow"></p>
<p>With our triangles now in place, let’s explore how we can move them along both axes and discover the variety of triangles we can create.</p>
<h2 id="create-isosceles-triangles">Create isosceles triangles<a class="heading-anchor" href="#create-isosceles-triangles" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We move forward by keeping the initial design where we <strong>cut the top-right</strong> corner (100% 0%). We will work with this triangle.</p>
<p>To start, I’ve chosen to create isosceles triangles. This involves first <em>focusing on the remaining top-left corner and then on the remaining bottom-right corner</em>. Don’t worry and don’t feel confused, we’ll clear everything up. As mentioned above, the code and diagrams for clarity are ready!</p>
<p>As you can see below, we maintain the bottom corners as they are, and we change the remaining <em>top-left corner</em>, where we move it right to 50% along the X-axis. By doing so, we transform our right triangle into an isosceles triangle.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           50% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 100%);</span></span></code></pre></div>
<p><img src="/clip-path-equilateral-triangle1.webp" alt="Two triangles. On the left a right triangle made by setting the clip-path: polygon(0% 0%,100% 100%,0% 100%);
while on the right an isosceles triangle made by setting the clip-path: polygon(50% 0%,100% 100%,0% 100%);"></p>
<p>This right triangle can give us one more isosceles triangle. We maintain the top-left and bottom-left corners, and we change the <em>bottom-right corner</em> by moving it up to 50% on the Y-axis.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 50%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 100%);</span></span></code></pre></div>
<p><img src="/clip-path-equilateral-triangle2.webp" alt="Two triangles. On the left a right triangle made by setting the clip-path: polygon(0% 0%,100% 100%,0% 100%);
while on the right an isosceles triangle made by setting the clip-path: polygon(0% 0%,100% 50%,0% 100%);"></p>
<h2 id="create-acute-triangles">Create acute triangles<a class="heading-anchor" href="#create-acute-triangles" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We continue with the acute triangles. Once again, we maintain the bottom corners as they are, and we change the remaining <em>top-left corner</em>. Here, we have two cases. First, we move it right to 15% along the X-axis, while in the second case, we move it right to 85%. By doing so, we transform our right triangle into acute triangles. Depending on our preferences.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           15% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 100%);</span></span></code></pre></div>
<p><img src="/clip-path-triangle-acute1.webp" alt="Two triangles. On the left we see a right triangle made by setting the clip-path: polygon(0% 0%,100% 100%,0% 100%);
while on the right we see an acute triangle made by setting the clip-path: polygon(15% 0%,100% 100%,0% 100%);"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           85% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 100%);</span></span></code></pre></div>
<p><img src="/clip-path-triangle-acute2.webp" alt="Two triangles. On the left we see a right triangle made by setting the clip-path: polygon(0% 0%,100% 100%,0% 100%);
while on the right we see an acute triangle made by setting the clip-path: polygon(85% 0%,100% 100%,0% 100%);"></p>
<p>Another approach is to work with the <em>bottom-right corner</em> and adjust the values on the Y-axis. Let’s see how our triangle will become then. I move the bottom-right corner first up to 35% and then up to 65%.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 35%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 100%);</span></span>
<span class="line"><span style="color:#6A737D">           /* OR */</span></span>
<span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 65%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 100%);</span></span></code></pre></div>
<p><img src="/clip-path-triangles-acute3-4-1.webp" alt="Two acute triangles. On the left it is made by setting the clip-path: polygon(0% 0%,100% 35%,0% 100%);
while on the right it is made by setting the clip-path: polygon(0% 0%,100% 65%,0% 100%);"></p>
<p>🔖 The values I use to create the triangles are indicative. Feel free to choose any value that suits your preferences and requirements. 😃</p>
<h2 id="create-obtuse-triangles">Create obtuse triangles<a class="heading-anchor" href="#create-obtuse-triangles" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Finally, it’s time to work with the <em>bottom-left corner</em>. We leave the top-left and bottom-right corners unchanged while modifying the values of the bottom-left corner. Initially, I adjust the X-axis value, shifting the corner right to 20%. Next, I adjust the Y-axis value, moving the corner up to 80%.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           20% 100%);</span></span></code></pre></div>
<p><img src="/clip-path-triangle-acute1-1.webp" alt="Two triangles. On the left we see a right triangle made by setting the clip-path: polygon(0% 0%,100% 100%,0% 100%);
while on the right we see an obtuse triangle made by setting the clip-path: polygon(0% 0%,100% 100%,20% 100%);"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 80%);</span></span></code></pre></div>
<p><img src="/clip-path-triangle-acute2-2.webp" alt="Two triangles. On the left we see a right triangle made by setting the clip-path: polygon(0% 0%,100% 100%,0% 100%);
while on the right we see an obtuse triangle made by setting the clip-path: polygon(0% 0%,100% 100%,0% 80%);"></p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/clip-path-for-quick-polygons-ready-code-to-copy/">Clip-path For Quick Polygons – Ready Code-To-Copy</a></li>
<li><a href="/clip-path-for-navigation-ready-code-to-copy/">CSS Arrow Shapes with clip-path</a></li>
<li><a href="/easy-made-circles-a-simple-guide-to-clip-path-css-property/">clip-path: circle() Explained</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>CSS Arrow Shapes with clip-path</title>
      <link>https://littlecodingthings.com/clip-path-for-navigation-ready-code-to-copy/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/clip-path-for-navigation-ready-code-to-copy/</guid>
      <pubDate>Fri, 17 Oct 2025 06:00:00 GMT</pubDate>
      <description>Copy-ready clip-path: polygon() code for direction signs, arrows and pointers in all four directions, with a diagram for every shape.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Have you ever wondered if you can create all these directional signs (⬆,↙, etc.), you see everywhere around, using only CSS? I have the solution for you! What about exploring the unique clip-path CSS property, where you can create complex shapes following specific movements!</p>
<p>The <code>clip-path</code> property allows us to <strong>cut ✂ an element to a shape of our choice by specifying a series of points</strong>. It takes many values, but in our case, we will use the <code>clip-path: polygon()</code> function. I’ll briefly note <a href="/easy-made-circles-a-simple-guide-to-clip-path-css-property/"><code>circle()</code></a>, <code>ellipse()</code>, and <a href="/clip-path-inset-css-property-cropping-elements-as-a-pro/"><code>inset()</code></a> which are the rest of the functions. In this post, we will analyze how we can create navigation signs only.</p>
<h2 id="clip-path-polygon-function-explained">Clip-path: polygon() function explained<a class="heading-anchor" href="#clip-path-polygon-function-explained" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>It would be an excellent start to examine the <em>syntax</em> of this amazing tool. Below I’ve illustrated the code along with explanatory diagrams.
The first one shows how we can make a square setting the <code>clip-path: polygon()</code> function. We used to create square shapes ⬛ by simply setting the <em>width</em> and <em>height</em> CSS properties. However, I opted to use the clip-path to utilize its familiarity and improve clarity. 😎
I used colored code to show you how we measured on both the axis-X and axis-Y. <strong>Each pair of values represents a point</strong>, with the first value indicating the horizontal position and the second value indicating the vertical position. Then an image accompanied the code and display a series of colored <strong>points illustrate how we form our visual element</strong>.</p>
<p><img src="/clip-path-css-initial-design.webp" alt="Creating square with clip-path: polygon() function - clip-path: polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%);" style="max-width:65%" class="img-narrow"></p>
<p><strong>“Clip-path is extremely flexible. We can create any shape we desire from scratch, but we can also apply it to existing shapes and create transformations of our choice”.</strong></p>
<p>The second case shows how we can transform the square into a directional sign that points to the top. Again, the <code>clip-path: polygon</code> function is defined by coordinates relative to the element’s bounding box, but this time it is a bit harder. 🤯 Don’t worry, I am here to clarify for you! 🤓</p>
<ul>
<li>It starts at the top-middle <code>(50% 0%)</code>.</li>
<li>Then it moves diagonally down and right <code>(70% 25%)</code>.</li>
<li>From there, it continues straight down <code>(70% 100%)</code> where it turns diagonally again for two times in a row.</li>
<li>First up and left <code>(50% 75%)</code>, then down and left <code>(30% 100%)</code>.</li>
<li>Finally, it moves straight up <code>(30% 25%)</code> where it completes its movements.</li>
</ul>
<p><img src="/clip-path-css-direction-up.webp" alt="Creating a shape &#x27;direction to up&#x27; with clip-path: polygon() function - clip-path: polygon(50% 0%, 70% 25%, 70% 100%, 50% 75%, 30% 100%, 30% 25%);" style="max-width:88%" class="img-narrow"></p>
<p>These <strong>one-direction moves</strong> enable you to create complicated shapes by strategically placing each point to outline the desired polygonal form. This method allows for <strong>precise control over the path of the shape</strong>, facilitating the design of visually appealing and geometrically complex elements on web pages.</p>
<h2 id="ready-to-copy-code-snippets">Ready-to-copy code snippets<a class="heading-anchor" href="#ready-to-copy-code-snippets" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Below, I have prepared ready-to-copy code for directional signs. Feel free to use it everywhere you need. Enjoy! 🎊</p>
<h3 id="directions">Directions<a class="heading-anchor" href="#directions" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Ready code and explanation diagrams for directions.</p>
<h4 id="direction-to-up">Direction to Up<a class="heading-anchor" href="#direction-to-up" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           50% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           70% 25%,</span></span>
<span class="line"><span style="color:#E1E4E8">           70% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           50% 75%,</span></span>
<span class="line"><span style="color:#E1E4E8">           30% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           30% 25%);</span></span></code></pre></div>
<p><img src="/clip-path-css-up.webp" alt="Creating a shape &#x27;direction to up&#x27; with clip-path: polygon() function. clip-path: polygon(
50% 0%,
70% 25%,
70% 100%,
50% 75%,
30% 100%,
30% 25%);" style="max-width:65%" class="img-narrow"></p>
<h4 id="direction-to-down">Direction to Down<a class="heading-anchor" href="#direction-to-down" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           30% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           50% 25%,</span></span>
<span class="line"><span style="color:#E1E4E8">           70% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           70% 75%,</span></span>
<span class="line"><span style="color:#E1E4E8">           50% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           30% 75%);</span></span></code></pre></div>
<p><img src="/clip-path-css-down.webp" alt="Creating a shape &#x27;direction to down&#x27; with clip-path: polygon() function. clip-path: polygon(
30% 0%,
50% 25%,
70% 0%,
70% 75%,
50% 100%,
30% 75%);" style="max-width:65%" class="img-narrow"></p>
<h4 id="direction-to-the-left">Direction to the Left<a class="heading-anchor" href="#direction-to-the-left" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           25% 30%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 30%,</span></span>
<span class="line"><span style="color:#E1E4E8">           75% 50%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 70%,</span></span>
<span class="line"><span style="color:#E1E4E8">           25% 70%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 50%);</span></span></code></pre></div>
<p><img src="/clip-path-css-left.webp" alt="Creating a shape &#x27;direction to left&#x27; with clip-path: polygon() function. clip-path: polygon(
25% 30%,
100% 30%,
75% 50%,
100% 70%,
25% 70%,
0% 50%);" style="max-width:65%" class="img-narrow"></p>
<h4 id="direction-to-the-right">Direction to the Right<a class="heading-anchor" href="#direction-to-the-right" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 30%,</span></span>
<span class="line"><span style="color:#E1E4E8">           75% 30%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 50%,</span></span>
<span class="line"><span style="color:#E1E4E8">           75% 70%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 70%,</span></span>
<span class="line"><span style="color:#E1E4E8">           25% 50%);</span></span></code></pre></div>
<p><img src="/clip-path-css-right.webp" alt="Creating a shape &#x27;direction to right&#x27; with clip-path: polygon() function. clip-path: polygon(
0% 30%,
75% 30%,
100% 50%,
75% 70%,
0% 70%,
25% 50%);" style="max-width:65%" class="img-narrow"></p>
<p>🔖 We are always free to skip all these signs and create just one, 😇 to show only one direction, then we can <a href="/clip-path-for-quick-polygons-ready-code-to-copy/">rotate</a> it until it aligns with our preferences.</p>
<h3 id="arrows">Arrows<a class="heading-anchor" href="#arrows" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Ready code and explanation diagrams for arrows.</p>
<h4 id="arrow-up">Arrow up<a class="heading-anchor" href="#arrow-up" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           50% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 25%,</span></span>
<span class="line"><span style="color:#E1E4E8">           75% 25%,</span></span>
<span class="line"><span style="color:#E1E4E8">           75% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           25% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           25% 25%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 25%);</span></span></code></pre></div>
<p><img src="/clip-path-css-arrow-up.webp" alt="Creating a shape &#x27;arrow to up&#x27; with clip-path: polygon() function.
clip-path: polygon(
50% 0%,
100% 25%,
75% 25%,
75% 100%,
25% 100%,
25% 25%,
0% 25%);" style="max-width:65%" class="img-narrow"></p>
<h4 id="arrow-down">Arrow down<a class="heading-anchor" href="#arrow-down" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           25% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           75% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           75% 75%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 75%,</span></span>
<span class="line"><span style="color:#E1E4E8">           50% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 75%,</span></span>
<span class="line"><span style="color:#E1E4E8">           25% 75%);</span></span></code></pre></div>
<p><img src="/clip-path-css-arrow-down.webp" alt="Creating a shape &#x27;arrow to down&#x27; with clip-path: polygon() function. clip-path: polygon(
25% 0%,
75% 0%,
75% 75%,
100% 75%,
50% 100%,
0% 75%,
25% 75%);" style="max-width:65%" class="img-narrow"></p>
<h4 id="arrow-to-the-left">Arrow to the left<a class="heading-anchor" href="#arrow-to-the-left" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           25% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           25% 20%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 20%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 80%,</span></span>
<span class="line"><span style="color:#E1E4E8">           25% 80%,</span></span>
<span class="line"><span style="color:#E1E4E8">           25% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 50%);</span></span></code></pre></div>
<p><img src="/clip-path-css-arrow-left.webp" alt="Creating a shape &#x27;arrow to the left&#x27; with clip-path: polygon() function.
clip-path: polygon(
25% 0%,
25% 20%,
100% 20%,
100% 80%,
25% 80%,
25% 100%,
0% 50%);" style="max-width:65%" class="img-narrow"></p>
<h4 id="arrow-to-the-right">Arrow to the right<a class="heading-anchor" href="#arrow-to-the-right" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           75% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 50%,</span></span>
<span class="line"><span style="color:#E1E4E8">           75% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           75% 80%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 80%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 20%,</span></span>
<span class="line"><span style="color:#E1E4E8">           75% 20%);</span></span></code></pre></div>
<p><img src="/clip-path-css-arrow-right.webp" alt="Creating a shape &#x27;arrow to the right&#x27; with clip-path: polygon() function.
clip-path: polygon(
75% 0%,
100% 50%,
75% 100%,
75% 80%,
0% 80%,
0% 20%,
75% 20%);" style="max-width:65%" class="img-narrow"></p>
<h3 id="points">Points<a class="heading-anchor" href="#points" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Ready code and explanation diagrams for points.</p>
<h4 id="point-up">Point up<a class="heading-anchor" href="#point-up" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           50% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 25%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 25%);</span></span></code></pre></div>
<p><img src="/clip-path-css-point-up.webp" alt="Creating a shape &#x27;point up&#x27; with clip-path: polygon() function.
clip-path: polygon(
50% 0%,
100% 25%,
100% 100%,
0% 100%,
0% 25%);" style="max-width:65%" class="img-narrow"></p>
<h4 id="point-down">Point down<a class="heading-anchor" href="#point-down" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 75%,</span></span>
<span class="line"><span style="color:#E1E4E8">           50% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 75%);</span></span></code></pre></div>
<p><img src="/clip-path-css-point-down.webp" alt="Creating a shape &#x27;point down&#x27; with clip-path: polygon() function.
clip-path: polygon(
0% 0%,
100% 0%,
100% 75%,
50% 100%,
0% 75%);" style="max-width:65%" class="img-narrow"></p>
<h4 id="point-left">Point left<a class="heading-anchor" href="#point-left" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           25% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           25% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 50%);</span></span></code></pre></div>
<p><img src="/clip-path-css-point-left.webp" alt="Creating a shape &#x27;point left&#x27; with clip-path: polygon() function.
clip-path: polygon(
25% 0%,
100% 0%,
100% 100%,
25% 100%,
0% 50%);" style="max-width:65%" class="img-narrow"></p>
<h4 id="point-right">Point right<a class="heading-anchor" href="#point-right" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           75% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 50%,</span></span>
<span class="line"><span style="color:#E1E4E8">           75% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 100%);</span></span></code></pre></div>
<p><img src="/clip-path-css-point-right.webp" alt="Creating a shape &#x27;point right&#x27; with clip-path: polygon() function.
clip-path: polygon(
0% 0%,
75% 0%,
100% 50%,
75% 100%,
0% 100%);" style="max-width:65%" class="img-narrow"></p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/clip-path-for-quick-polygons-ready-code-to-copy/">Clip-path For Quick Polygons – Ready Code-To-Copy</a></li>
<li><a href="/clip-path-for-simplified-triangles-ready-code-to-copy/">CSS Triangles with clip-path</a></li>
<li><a href="/easy-made-circles-a-simple-guide-to-clip-path-css-property/">clip-path: circle() Explained</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Clip-path For Quick Polygons – Ready Code-To-Copy</title>
      <link>https://littlecodingthings.com/clip-path-for-quick-polygons-ready-code-to-copy/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/clip-path-for-quick-polygons-ready-code-to-copy/</guid>
      <pubDate>Fri, 10 Oct 2025 06:00:00 GMT</pubDate>
      <description>Copy-ready clip-path: polygon() code for pentagons, hexagons, heptagons, octagons, nonagons and decagons, with diagrams for each.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Welcome! Today we’ll dig ⛏ deep and dive into geometric layouts exploring the fascinating clip-path CSS property. This amazing tool helps us to <strong>define specific regions within an element</strong>, allowing creative shape manipulation. We <strong>declare specific points based on the shape we intend to create</strong>, offering precise control over our work preferences and needs.</p>
<p>Clip-path CSS property supports several shapes. Depending on the shape we want to create we have the following options: <a href="/easy-made-circles-a-simple-guide-to-clip-path-css-property/"><code>circle()</code></a>, <code>ellipse()</code>, <a href="/clip-path-inset-css-property-cropping-elements-as-a-pro/"><code>inset()</code></a>, and <code>polygon()</code>. In today’s post we’ll spend time on <code>clip-path: polygon()</code> as this enables us to <strong>clip an element into a polygon shape</strong>.</p>
<h2 id="clip-path-polygon-function-explained">Clip-path polygon() function explained<a class="heading-anchor" href="#clip-path-polygon-function-explained" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>To illustrate the <code>clip-path: polygon()</code> CSS property I chose to start with a square, as it is the most common type of polygon.
Below, we can see the code marked with colors. Each pair of values, inside the parentheses, symbolizes a point. In our case, we have four pairs of values, hence we have a shape with four points (square).
<strong>The four color points represent the clipping area and display how we position the square on both axes X and Y</strong>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* square */</span></span>
<span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 100%);</span></span></code></pre></div>
<p><img src="/clip-path-polygon-example-with-square.webp" alt="A square with highlight marks, positioned on both X and Y axes."></p>
<p>Below is ready-to-copy code for polygons. Feel free to use it wherever you need! 🤗</p>
<h2 id="create-pentagon">Create pentagon<a class="heading-anchor" href="#create-pentagon" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* pentagon */</span></span>
<span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           50% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 40%,</span></span>
<span class="line"><span style="color:#E1E4E8">           80% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           20% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 40%);</span></span></code></pre></div>
<p><img src="/clip-path-polygon-pentagon-up.webp" alt="A pentagon with highlight marks, positioned on both X and Y axes."></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* pentagon oriented downward */</span></span>
<span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           20% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           80% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 60%,</span></span>
<span class="line"><span style="color:#E1E4E8">           50% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 60%);</span></span></code></pre></div>
<p><img src="/clip-path-polygon-pentagon-down-1.webp" alt="A pentagon oriented downward with highlight marks, positioned on both X and Y axes."></p>
<h2 id="create-hexagon">Create hexagon<a class="heading-anchor" href="#create-hexagon" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* hexagon vertical */</span></span>
<span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           25% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           75% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 50%,</span></span>
<span class="line"><span style="color:#E1E4E8">           75% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           25% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 50%);</span></span></code></pre></div>
<p><img src="/clip-path-polygon-hexagon-vertical-1.webp" alt="A vertical hexagon with highlight marks, positioned on both X and Y axes."></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* hexagon horizontal */</span></span>
<span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           50% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 25%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 75%,</span></span>
<span class="line"><span style="color:#E1E4E8">           50% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 75%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 25%);</span></span></code></pre></div>
<p><img src="/clip-path-polygon-hexagon-horizontal.webp" alt="A horizontal hexagon with highlight marks, positioned on both X and Y axes."></p>
<h2 id="create-heptagon">Create heptagon<a class="heading-anchor" href="#create-heptagon" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* heptagon */</span></span>
<span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           50% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           90% 20%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 60%,</span></span>
<span class="line"><span style="color:#E1E4E8">           75% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           25% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 60%,</span></span>
<span class="line"><span style="color:#E1E4E8">           10% 20%);</span></span></code></pre></div>
<p><img src="/clip-path-polygon-heptagon-up.webp" alt="A heptagon with highlight marks, positioned on both X and Y axes."></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* heptagon oriented downward */</span></span>
<span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           25% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           75% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 40%,</span></span>
<span class="line"><span style="color:#E1E4E8">           90% 80%,</span></span>
<span class="line"><span style="color:#E1E4E8">           50% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           10% 80%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 40%);</span></span></code></pre></div>
<p><img src="/clip-path-polygon-heptagon-down.webp" alt="A heptagon oriented downward with highlight marks, positioned on both X and Y axes."></p>
<h2 id="create-octagon">Create octagon<a class="heading-anchor" href="#create-octagon" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* octagon */</span></span>
<span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           30% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           70% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 30%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 70%,</span></span>
<span class="line"><span style="color:#E1E4E8">           70% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           30% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 70%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 30%);</span></span></code></pre></div>
<p><img src="/clip-path-polygon-octagon.webp" alt="An octagon with highlight marks, positioned on both X and Y axes."></p>
<h2 id="create-nonagon">Create nonagon<a class="heading-anchor" href="#create-nonagon" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* nonagon */</span></span>
<span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           50% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           83% 12%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 43%,</span></span>
<span class="line"><span style="color:#E1E4E8">           94% 78%,</span></span>
<span class="line"><span style="color:#E1E4E8">           68% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           32% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           6% 78%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 43%,</span></span>
<span class="line"><span style="color:#E1E4E8">           17% 12%);</span></span></code></pre></div>
<p><img src="/clip-path-polygon-nonagon-up.webp" alt="A nonagon with highlight marks, positioned on both X and Y axes."></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* nonagon oriented downward */</span></span>
<span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           32% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           68% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           95% 23%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 57%,</span></span>
<span class="line"><span style="color:#E1E4E8">           85% 87%,</span></span>
<span class="line"><span style="color:#E1E4E8">           50% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           15% 87%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 57%,</span></span>
<span class="line"><span style="color:#E1E4E8">           5% 23%);</span></span></code></pre></div>
<p><img src="/clip-path-polygon-nonagon-down.webp" alt="A nonagon oriented downward with highlight marks, positioned on both X and Y axes."></p>
<h2 id="create-decagon">Create decagon<a class="heading-anchor" href="#create-decagon" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* decagon */</span></span>
<span class="line"><span style="color:#85E89D">clip-path</span><span style="color:#E1E4E8">: polygon(</span></span>
<span class="line"><span style="color:#E1E4E8">           50% 0%,</span></span>
<span class="line"><span style="color:#E1E4E8">           80% 10%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 35%,</span></span>
<span class="line"><span style="color:#E1E4E8">           100% 65%,</span></span>
<span class="line"><span style="color:#E1E4E8">           80% 90%,</span></span>
<span class="line"><span style="color:#E1E4E8">           50% 100%,</span></span>
<span class="line"><span style="color:#E1E4E8">           20% 90%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 65%,</span></span>
<span class="line"><span style="color:#E1E4E8">           0% 35%,</span></span>
<span class="line"><span style="color:#E1E4E8">           20% 10%);</span></span></code></pre></div>
<p><img src="/clip-path-polygon-decagon.webp" alt="A decagon with highlight marks, positioned on both X and Y axes."></p>
<h2 id="adjust-polygon-rotation-for-simplicity">Adjust polygon rotation for simplicity<a class="heading-anchor" href="#adjust-polygon-rotation-for-simplicity" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>To make things easier, we are free to create only one type of shape at a time and <strong>adjust its direction</strong> by customizing its orientation.
For instance, as demonstrated below, we can use a decagon shape, which is the last shape we created above, and modify its degrees through the transform: rotate() CSS property. In that way, we set the orientation according to our preferences.</p>
<p>More specifically:</p>
<ul>
<li><em>In case 1</em>, we notice our decagon rotating 90 degrees to the right</li>
<li><em>In case 2</em>, with the use of a negative value, our decagon moves anticlockwise and rotates 90 degrees to the left</li>
<li><em>In case 3</em>, it rotates 180 degrees to the right, resembling a downward orientation</li>
</ul>
<p>🔖 Pay attention to how the colorful dots shift from one place to another, updating their positions each time we change the rotating value. 🥳</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* case 1 */</span></span>
<span class="line"><span style="color:#E1E4E8">transform: rotate(90deg);</span></span>
<span class="line"><span style="color:#6A737D">/* case 2 */</span></span>
<span class="line"><span style="color:#E1E4E8">transform: rotate(-90deg);</span></span>
<span class="line"><span style="color:#6A737D">/* case 3 */</span></span>
<span class="line"><span style="color:#E1E4E8">transform: rotate(180deg);</span></span></code></pre></div>
<p><img src="/clip-path-polygon-rotate90deg.webp" alt="A decagon with highlight marks and 90 deg rotation, positioned on both X and Y axes."></p>
<p><img src="/clip-path-polygon-rotate-90deg.webp" alt="A decagon with highlight marks and -90 deg rotation, positioned on both X and Y axes."></p>
<p><img src="/clip-path-polygon-rotate180deg.webp" alt="A decagon with highlight marks and 180 deg rotation, positioned on both X and Y axes." style="max-width:31%" class="img-narrow"></p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/clip-path-for-simplified-triangles-ready-code-to-copy/">CSS Triangles with clip-path</a></li>
<li><a href="/clip-path-for-navigation-ready-code-to-copy/">CSS Arrow Shapes with clip-path</a></li>
<li><a href="/easy-made-circles-a-simple-guide-to-clip-path-css-property/">clip-path: circle() Explained</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>clip-path: circle() Explained</title>
      <link>https://littlecodingthings.com/easy-made-circles-a-simple-guide-to-clip-path-css-property/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/easy-made-circles-a-simple-guide-to-clip-path-css-property/</guid>
      <pubDate>Fri, 03 Oct 2025 07:00:00 GMT</pubDate>
      <description>Crop any element to a circle with clip-path: circle(). Radius, positioning with at, and how to isolate one face in a group photo.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>The <code>clip-path</code> property in CSS lets you control which part of an element is visible by defining a specific shape, no matter what the element’s shape is. It’s like <strong>placing a mask over an element</strong>—only the area inside the shape will be shown. Everything outside will be hidden. This provides a clever way to “cut out” parts of an element without needing extra images or complex code.</p>
<p>A great tool for creating unique layouts, applying image effects, and designing custom shapes. CSS supports several shapes for <code>clip-path</code>, including <code>circle()</code>, <code>ellipse()</code>, <a href="/clip-path-inset-css-property-cropping-elements-as-a-pro/"><code>inset()</code></a>, and <a href="/clip-path-for-quick-polygons-ready-code-to-copy/"><code>polygon()</code></a>—each giving you different ways to shape your content and hide any parts you don’t need. 🪄</p>
<p>In today’s post, we’ll focus on the <code>circle()</code> ⚫ function and explore how it works. 🧐
Let’s dive in!</p>
<h2 id="the-circle-function">The circle() function<a class="heading-anchor" href="#the-circle-function" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The <code>circle()</code> function is one of the simpler ways to create circles by <strong>clipping an element into a rounded shape</strong> with a <strong>radius of our preference</strong> based on the element’s <strong>smaller dimension</strong> (width or height, selecting the smaller one, ensuring the circle fits within the element).
Traditionally, we can use pixels <code>px</code> and percentages <code>%</code> to define the dimensions and the position of the circle. Otherwise, we can just utilize the handy <code>center</code> keyword, which is responsible for positioning our circle.</p>
<p>Below, we see the starting setup we’ll use to explore this awesome CSS property. It shows a <strong>dark grey square</strong>, with a width and height of <strong>200px</strong>. Also, a small <strong>white dot</strong> marks its center. This allows us to visualize exactly how the circle is positioned. The square is placed on an axis to make things even clearer.
This helps explain both <strong>positioning</strong> and how the circle will be <strong>clipped</strong> inside it (inside the square element). 📐 😃</p>
<p><img src="/clip-path-circle-initial-design.webp" alt="A square we will transform to a circle using clip-path: circle()" style="max-width:55%" class="img-narrow"></p>
<h3 id="the-circleradius-at-axis-x-axis-y-function-using-pixels-and-percentages">The circle(radius <em>at</em> axis-X axis-Y) function using pixels and percentages<a class="heading-anchor" href="#the-circleradius-at-axis-x-axis-y-function-using-pixels-and-percentages" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>It defines a circular clipping area using <strong>two values</strong>: the <strong>radius</strong> of the circle and its <strong>center point</strong>. We set the radius to 100px wide or 50% of the element’s width, and we positioned it 100px from the left and 100px from the top of the element or 50% 50%, which places the circle right in the element’s center. Everything outside the circle will be invisible.
This creates <strong>a circle that is perfectly centered</strong> within the square.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.circle</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#6A737D">      /* circle(radius at axis-X axis-Y) */</span></span>
<span class="line"><span style="color:#79B8FF">clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">circle</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#F97583"> at</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"><span style="color:#6A737D">              /* OR */</span></span>
<span class="line"><span style="color:#B392F0">.circle</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#6A737D">   /* circle(radius at axis-X axis-Y) */</span></span>
<span class="line"><span style="color:#79B8FF">clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">circle</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#F97583"> at</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/clip-path-circle-centered.webp" alt="A perfectlry centered circle with a 50% radius using clip-path" style="max-width:55%" class="img-narrow"></p>
<p>Now, let’s try to cut ✂ a smaller circle. Maybe with a radius of 80px. How would our code and circle look now? Check out the updated code snippet below.</p>
<p>We’re still cutting out a specific shape, a circle, from the element, but this time <strong>the circle is smaller</strong> (radius of 80px or 40% of the element’s width), though it is centered at the same spot as before (100px from the left and 100px from the top or 50% 50%). That means <strong>the circle stays perfectly centered</strong> within the square.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.circle</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">circle</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">80</span><span style="color:#F97583">px</span><span style="color:#F97583"> at</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"><span style="color:#6A737D">              /* OR */</span></span>
<span class="line"><span style="color:#B392F0">.circle</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">circle</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">40</span><span style="color:#F97583">%</span><span style="color:#F97583"> at</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/clip-path-circle-smaller-centered.webp" alt="A perfectlry centered circle with a 40% radius using clip-path" style="max-width:55%" class="img-narrow"></p>
<p>🔖 Bear in mind that we can combine pixels with percentages, too. E.g. <code>clip-path: circle(80px at 50% 50%);</code></p>
<p>Using <code>%</code> instead of <strong>pixels</strong>, it makes our shapes responsive and adjusts to the size of our elements each time. In that way, our designs are more flexible and adaptable to different screen sizes.</p>
<h4 id="the-circleradius-function">The circle(radius) function<a class="heading-anchor" href="#the-circleradius-function" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p>Another way to create circles using clip-path is the <code>circle(%)</code>. It clips the element into a <strong>perfect circle</strong> with a <strong>radius of our preference</strong>. Additionally, since you do not specify a position, it centers by <strong>default at 50% 50%</strong> (50% horizontally and 50% vertically).</p>
<p>Below, we have two examples. The first one has a radius of 50%, while the second has a radius of 40%, allowing for easy comparison with the previous examples.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.circle</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">circle</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"><span style="color:#6A737D">      /* OR */</span></span>
<span class="line"><span style="color:#B392F0">.circle</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">circle</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">40</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/clip-path-circle-centered.webp" alt="A perfectlry centered circle with a 50% radius using clip-path" style="max-width:55%" class="img-narrow"></p>
<p><img src="/clip-path-circle-smaller-centered.webp" alt="A perfectlry centered circle with a 40% radius using clip-path" style="max-width:55%" class="img-narrow"></p>
<h3 id="the-circleradius-at-center-function-using-the-center-keyword">The circle(radius <em>at</em> center) function using the ‘center’ keyword<a class="heading-anchor" href="#the-circleradius-at-center-function-using-the-center-keyword" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>It defines a circular clipping area using the <strong>radius</strong> and the keyword <code>center</code>. Using this method, we create a circle with a 100px radius <strong>perfectly 🎯 centered</strong> inside the element. Anything outside that circle will be hidden.</p>
<p>🔖 Note that setting the <code>center</code> it is the same as writing <code>50% 50%</code>, maintain a cleaner and clearer code. ✨</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.circle</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">circle</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#F97583"> at</span><span style="color:#79B8FF"> center</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"><span style="color:#6A737D">            /* OR */</span></span>
<span class="line"><span style="color:#B392F0">.circle</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">circle</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#F97583"> at</span><span style="color:#79B8FF"> center</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/clip-path-circle-centered.webp" alt="A perfectlry centered circle with a 50% radius using clip-path" style="max-width:55%" class="img-narrow"></p>
<p>Likewise, if we create a smaller circle.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.circle</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">circle</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">80</span><span style="color:#F97583">px</span><span style="color:#F97583"> at</span><span style="color:#79B8FF"> center</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"><span style="color:#6A737D">            /* OR */</span></span>
<span class="line"><span style="color:#B392F0">.circle</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">circle</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">40</span><span style="color:#F97583">%</span><span style="color:#F97583"> at</span><span style="color:#79B8FF"> center</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/clip-path-circle-smaller-centered.webp" alt="A perfectlry centered circle with a 40% radius using clip-path" style="max-width:55%" class="img-narrow"></p>
<h2 id="clip-path-circle-vs-border-radius">clip-path: circle() VS border-radius<a class="heading-anchor" href="#clip-path-circle-vs-border-radius" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Now, let’s see why we are utilizing the <code>clip-path</code> instead of simply relying on the <code>border-radius</code> CSS property. As we mentioned earlier, when setting the clip-path, we deal with two main values: the <strong>radius</strong>, similar to what <code>border-radius</code> offers, and the <strong>positioning</strong>, which is particularly important if we want to create a circle that is <strong>not 🎯</strong> <strong>centered</strong> within the element.</p>
<p>Let’s create our circle again, with a radius of 80px or 40% (depending on your preferences – if you use <code>px</code> or <code>%</code>). Next, position it, but <strong>not</strong> in the center of our element (50% 50%).</p>
<p>🔶 If we want the <strong>visible part to be closer to the top side</strong>, we keep axis-X at 50%, but we change the axis-Y from 50% to 40%.
🔶 If we want the <strong>visible part closer to the left side</strong>, we keep the axis-Y at 50%, but we will change the axis-X from 50% to 40%.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.circle</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#6A737D">     /* circle(radius at axis-X axis-Y) */</span></span>
<span class="line"><span style="color:#79B8FF">  clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">circle</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">80</span><span style="color:#F97583">px</span><span style="color:#F97583"> at</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 40</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"><span style="color:#6A737D">              /* OR */</span></span>
<span class="line"><span style="color:#B392F0">.circle</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">circle</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">40</span><span style="color:#F97583">%</span><span style="color:#F97583"> at</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 40</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.circle</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#6A737D">   /* circle(radius at axis-X axis-Y) */</span></span>
<span class="line"><span style="color:#79B8FF">  clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">circle</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">80</span><span style="color:#F97583">px</span><span style="color:#F97583"> at</span><span style="color:#79B8FF"> 40</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"><span style="color:#6A737D">              /* OR */</span></span>
<span class="line"><span style="color:#B392F0">.circle</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">circle</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">40</span><span style="color:#F97583">%</span><span style="color:#F97583"> at</span><span style="color:#79B8FF"> 40</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/clip-path-not-centered-axis-y.webp" alt="A circle with a 40% radius using clip-path. It&#x27;s center is placed at the top-left corner of the element" style="max-width:55%" class="img-narrow"></p>
<p><img src="/clip-path-not-centered-axis-x.webp" alt="A circle with a 40% radius using clip-path" style="max-width:55%" class="img-narrow"></p>
<p>Setting <code>clip-path</code> instead of <code>border-radius</code> gives us the privilege to <strong>focus on any part</strong> of our element we prefer, not just the center. A really useful method, especially when working with <strong>images</strong> 📸 and you want to keep a part of the image that is <strong>not necessarily at the center</strong>.</p>
<p>Let’s examine another case. What do you think? Are we able to vanish 🎩🐇 a whole piece of our circle and keep only a small part if needed? Let’s see the following code snippet. We position the center of the circle at <strong>zero</strong> (<code>0%</code>) on both axis. This means that the center of our circle will be placed at the <strong>top-left corner</strong> of the initial element, as that’s the point where both axes X and Y begin.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.circle</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">circle</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">80</span><span style="color:#F97583">px</span><span style="color:#F97583"> at</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"><span style="color:#6A737D">              /* OR */</span></span>
<span class="line"><span style="color:#B392F0">.circle</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">circle</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">40</span><span style="color:#F97583">%</span><span style="color:#F97583"> at</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Take a closer look at the image below. Since the circle is positioned at the element’s top-left corner, only the 🕞 quarter of the circle that fits <strong>within the element’s bounds will be visible</strong>, all the rest, that is extended beyond the element’s boundaries, will not be displayed at all. Cool hug! 😎</p>
<p><img src="/clip-path-circle-centered-at-00.webp" alt="Only the quarter of a circle centred at 0% 0% that falls inside the element stays visible" style="max-width:55%" class="img-narrow"></p>
<h2 id="apply-clip-path-to-images">Apply clip-path to images<a class="heading-anchor" href="#apply-clip-path-to-images" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Now it’s the perfect time to analyze how we can utilize <code>clip-path</code> with images. A clever way to control their shape and also <strong>‘cut out’</strong> and leave in view only a specific part of the image.</p>
<p>In the following example, we’re working with an image that contains <strong>four avatars</strong>, each placed in one of the image’s corners: top-left, top-right, bottom-left, and bottom-right. The image is divided into <strong>four equal parts</strong>, with one avatar in each. By using the <code>clip-path: circle()</code> function, we can focus on just one avatar at a time.</p>
<p><img src="/clip-path-circle-image.webp" alt="An image with four avatars, each placed in one of the image&#x27;s corners" style="max-width:55%" class="img-narrow"></p>
<p>First, we apply <code>clip-path: circle()</code> to cut out the <strong>top-right</strong> part of the image, revealing only the avatar placed there. Then, we do the same for the <strong>top-left</strong> corner to show the avatar in that section. We repeat this process for the <strong>bottom-left</strong> and <strong>bottom-right</strong> parts as well, effectively isolating each avatar with a circular crop.</p>
<p>Depending on the visual balance and spacing, you can choose <strong>45%</strong> (blue 🔵 border) to match the <strong>exact size of the avatar</strong> or go with <strong>50%</strong> (green 🟢 border) to include a bit of extra white space from the image background for a more relaxed look. 🌈 😎</p>
<p>To target and isolate each avatar at the top of the image:</p>
<p>🔶 For the <strong>top-left</strong> avatar, we place the circle’s center <strong>at 25% 25%</strong>. This moves the circle’s center closer to the top-left side of the image.</p>
<p>🔶 For the <strong>top-right</strong> avatar, we set the position <strong>at 75% 25%</strong>. This turns the focus to the top-right area of the image.</p>
<p>Adjusting these percentages gives you fine control over <strong>what part of the image stays visible</strong>, allowing you to highlight exactly what you want.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.circle</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#6A737D">    /* circle(radius at axis-X axis-Y) */</span></span>
<span class="line"><span style="color:#79B8FF">clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">circle</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">45</span><span style="color:#F97583">%</span><span style="color:#F97583"> at</span><span style="color:#79B8FF"> 25</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 25</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"><span style="color:#6A737D">              /* OR */</span></span>
<span class="line"><span style="color:#B392F0">.circle</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">circle</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#F97583"> at</span><span style="color:#79B8FF"> 25</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 25</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.circle</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#6A737D">    /* circle(radius at axis-X axis-Y) */</span></span>
<span class="line"><span style="color:#79B8FF">clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">circle</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">45</span><span style="color:#F97583">%</span><span style="color:#F97583"> at</span><span style="color:#79B8FF"> 75</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 25</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"><span style="color:#6A737D">              /* OR */</span></span>
<span class="line"><span style="color:#B392F0">.circle</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">circle</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#F97583"> at</span><span style="color:#79B8FF"> 75</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 25</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/clip-path-circle-image-case1.webp" alt="An image with four avatars, each placed in one of the image&#x27;s corners. Setting the clip-path: circle() we place the circle&#x27;s center at 25% 25% and move the circle&#x27;s center closer to the top-left side of the image" style="max-width:55%" class="img-narrow"></p>
<p><img src="/clip-path-circle-image-case2.webp" alt="An image with four avatars, each placed in one of the image&#x27;s corners. Setting the clip-path: circle() we place the circle&#x27;s center at 75% 25% and move the circle&#x27;s center closer to the top-right side of the image" style="max-width:55%" class="img-narrow"></p>
<p>Below we can see the final results for the two avatars. The first image displays only the first avatar while the second presents only the second one. All the rest of the avatars will be hidden. Pretty cool, right?</p>
<p><img src="/clip-path-circle-image-case1-final.webp" alt="Desplaying only the first avatar" style="max-width:55%" class="img-narrow"></p>
<p><img src="/clip-path-circle-image-case2-final.webp" alt="Desplaying only the second avatar" style="max-width:55%" class="img-narrow"></p>
<p>This technique allows us to <strong>pinpoint and display specific parts of the image</strong>. Then, with the necessary positioning, we put this specific part of the image in our desired place. 😃 ✨</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/clip-path-for-quick-polygons-ready-code-to-copy/">Clip-path For Quick Polygons – Ready Code-To-Copy</a></li>
<li><a href="/clip-path-inset-css-property-cropping-elements-as-a-pro/">clip-path: inset() Explained</a></li>
<li><a href="/make-a-unique-folded-corner-effect-utilizing-the-clip-path-css-property/">CSS Folded Corner Effect with clip-path</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Why are internet cookies called cookies?</title>
      <link>https://littlecodingthings.com/did-you-know-why-are-browser-cookies-called-cookies/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/did-you-know-why-are-browser-cookies-called-cookies/</guid>
      <pubDate>Fri, 26 Sep 2025 04:00:00 GMT</pubDate>
      <description>Why are internet cookies called cookies? The name traces back to magic cookies in Unix, Lou Montulli, and a piece of early 1990s browser history.</description>
      <category>Thoughts &amp; Theory</category>
      <content:encoded><![CDATA[<p>I am sure you have heard of cookies 🍪 no matter how many hours you’ve spent learning programming, or even if you are just a casual user unrelated to the tech world. You’ll see this term used all over the Internet. It’s usually the first thing that pops up when you visit a site for the first time. The site requests that you agree to cookies and explains how it uses them.</p>
<p>A good percentage of internet users often portray cookies as harmful. Mostly because people feel that someone is tracking their behavior while visiting a site — and yes, to some extent, this is true. But have you ever stopped to wonder: <strong>why are internet cookies called cookies</strong>? Why not use some other kind of delicacy? Like tarts or donuts? 🤭</p>
<figure><img src="/monster-cookies.webp" alt="Why are internet cookies called cookies? The Cookie Montster" style="max-width:67%" class="img-narrow"><figcaption>The Cookie Monster – Sesame Street</figcaption></figure>
<h2 id="the-legacy-of-montullis-internet-cookies"><strong>The Legacy of Montulli’s Internet Cookies</strong><a class="heading-anchor" href="#the-legacy-of-montullis-internet-cookies" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>To fully answer why are internet cookies called cookies, we need to start with <a href="https://en.wikipedia.org/wiki/Lou_Montulli">Lou Montulli</a>, one of <a href="https://en.wikipedia.org/wiki/Netscape">Netscape</a>’s founding engineers.</p>
<p>In 1994, Montulli introduced browser cookies as a technical solution to a frustrating problem: <strong>websites had no memory</strong>. Each time you loaded a new page, the website had no idea who you were or what you’d done moments earlier — it couldn’t remember if you had logged in, or what items you’d placed in your shopping cart. This limitation made building useful, user-friendly web experiences nearly impossible.</p>
<figure><img src="/lou-montoull.webp" alt="Why are internet cookies called cookies? Lou Montulli holding a jar of cookies" style="max-width:33%" class="img-narrow"><figcaption>Lou Montulli</figcaption></figure>
<p>Montulli’s solution was simple. He stored small pieces of data in your browser. These allowed websites to “remember” things between visits and page loads. This idea — storing small amounts of information to improve the user’s experience — became a turning point in the history of the web.</p>
<p>But <strong>why are internet cookies called cookies</strong> and not something else? Montulli himself has explained that while he was brainstorming, he recalled a term from his college days in computer science: <strong>“magic cookies.”</strong></p>
<p>As mentioned in <a href="https://web.archive.org/web/20160308032030/http://www.montulli-blog.com/2013/05/the-reasoning-behind-web-cookies.html">Montulli’s blog post</a></p>
<blockquote>
<p>I had heard the term “magic cookie” from an operating systems course from college. The term has a somewhat similar meaning to the way Web Cookies worked and I liked the term “cookies” for aesthetic reasons. Cookies was the first thing I came up with and the name stuck.   </p>
<p>Lou Montulli</p>
</blockquote>
<p>Many say Montulli also drew inspiration from fortune cookies 🥠 — little treats containing small hidden messages. Similarly, browser cookies contain small packets of information about the user. However, Montulli clarified that the fortune cookie analogy was secondary; the real naming influence came from established computing terminology.</p>
<h2 id="magic-cookies-lsd-and-unix-users">Magic cookies, LSD, and Unix users<a class="heading-anchor" href="#magic-cookies-lsd-and-unix-users" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The term <strong>“magic cookie”</strong> existed long before internet cookies, and understanding this connection helps clarify why are internet cookies called cookies today.</p>
<p>In programming, systems often pass a <strong>magic cookie</strong> — a small piece of data — between each other as a kind of identifier or token. The recipient doesn’t care what’s inside the cookie. Programmers took this idea from early computing.</p>
<p>The term <strong>magic cookie</strong> appears in the <a href="https://archive.org/details/unixtimesharings0001bell/page/262/mode/2up">Unix Programmer’s Manual</a>. It helps explain how functions like <code>ftell()</code> and <code>fseek()</code> track file positions using seemingly random numbers. To many programmers, these cookies felt like magic because they just worked.</p>
<blockquote>
<p>ftell returns the current value of the offset… It is measured in bytes on UNIX; on some other systems it is a magic cookie, and the only foolproof way to obtain an offset for fseek.   </p>
<p>Unix documentation</p>
</blockquote>
<p>Montulli liked the term <strong>“cookies”</strong> partly because of this existing technical jargon and partly because of its playful, light-hearted sound.</p>
<p>For added flavor, some point to the 1970s hacker culture, Unix communities, and counterculture comics like <a href="https://en.wikipedia.org/wiki/The_Collective_Unconscience_of_Odd_Bodkins">Odd Bodkins by Dan O’Neil</a>. In these circles, <strong>magic cookies</strong> were tokens with mysterious, sometimes surreal, properties — much like the arbitrary bits of data passed between systems.</p>
<p>So, when asking why are internet cookies called cookies, the answer is clear. It comes from a blend of technical tradition, playful naming, and Montulli’s own preferences.</p>
<h2 id="the-cookie-monster-connection-">The Cookie Monster Connection 🍪<a class="heading-anchor" href="#the-cookie-monster-connection-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>It’s hard to discuss cookies without mentioning Cookie Monster from Sesame Street. He devours cookies mindlessly. Browsers behave in a similar way, silently gobbling up cookies in the background. This connection is mostly playful. Still, it helped reinforce the idea of “cookies” being small, harmless, and consumed without much thought. That light-hearted image made the term easier for people to accept at the time.</p>
<h2 id="why-are-internet-cookies-called-cookies--a-quick-recap">Why Are Internet Cookies Called Cookies? — A Quick Recap<a class="heading-anchor" href="#why-are-internet-cookies-called-cookies--a-quick-recap" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li>Lou Montulli introduced browser cookies in 1994 to give websites “memory.”</li>
<li>He drew on the existing programming term <strong>“magic cookies”</strong> as inspiration.</li>
<li>The term “cookies” was already familiar in tech, playful, and non-threatening.</li>
<li><strong>Fortune cookies</strong> served as a fitting metaphor but weren’t the primary reason.</li>
<li>Why are internet cookies called cookies? Because it combines tech history with simplicity and charm.</li>
</ul>
<p>While researching for this post, I stumbled upon an insightful <a href="https://www.youtube.com/watch?v=CXWWw9t1W6A">Youtube video discussing hidden heroes</a> like Montulli created by Netguru. I recommend giving it a watch as it delves deeper into Montulli’s journey in pioneering the first-ever cookies.</p>
<p>If you’re into history-related programming trivia, you might also enjoy this post about <a href="/the-unique-origin-of-the-term-bug-in-software-development/">the origin of the word “bug”</a> in programming. It’s another quirky and surprising piece of tech history that shows how language shapes the tech world we live in today.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/why-websites-dont-store-your-password/">How Password Hashing Works</a></li>
<li><a href="/why-invalid-card-numbers-fail-instantly/">Why Invalid Card Numbers Fail Instantly</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>MacOS Shortcuts – Cheatsheet for New Users</title>
      <link>https://littlecodingthings.com/macos-shortcuts-cheatsheet-for-new-users/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/macos-shortcuts-cheatsheet-for-new-users/</guid>
      <pubDate>Fri, 19 Sep 2025 07:21:00 GMT</pubDate>
      <description>A macOS shortcuts cheatsheet for new Mac users: editing, Finder, window and screenshot shortcuts, plus the Windows equivalents if you just switched.</description>
      <category>Setup &amp; Tools</category>
      <content:encoded><![CDATA[<p>If you’re a new Mac user (like me!), knowing a few common shortcuts can save you tons of time. Here’s a simple <strong>cheatsheet of macOS shortcuts</strong> — including some of the ones I’ve searched for myself.
<strong>You might want to bookmark this — I’ll keep adding more as I come across new and useful shortcuts.</strong></p>
<p>I switched to macOS from Ubuntu Linux, and honestly the first week was humbling. Muscle memory I’d built over years suddenly did nothing, or worse, did the wrong thing. So this started as my own notes, and it grew from there.</p>
<h2 id="-first-learn-to-read-the-symbols">🔑 First, learn to read the symbols<a class="heading-anchor" href="#-first-learn-to-read-the-symbols" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Before the shortcuts themselves, this one thing trips up almost everyone. Apple writes shortcuts using symbols rather than words, and menus in every app use them. Once you can read them, you can discover shortcuts on your own just by opening a menu.</p>
<table>
<thead>
<tr>
<th scope="col">Symbol</th>
<th scope="col">Key</th>
<th scope="col">Notes</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">⌘</th>
<td>Command</td>
<td>The main modifier — where Windows uses Ctrl, macOS usually uses ⌘</td>
</tr>
<tr>
<th scope="row">⌥</th>
<td>Option (Alt)</td>
<td>Often the “do a variant of this” key</td>
</tr>
<tr>
<th scope="row">⇧</th>
<td>Shift</td>
<td></td>
</tr>
<tr>
<th scope="row">⌃</th>
<td>Control</td>
<td>Exists on Mac too, but used far less than on Windows</td>
</tr>
<tr>
<th scope="row">⇪</th>
<td>Caps Lock</td>
<td></td>
</tr>
<tr>
<th scope="row">fn</th>
<td>Function</td>
<td>Bottom-left, unlocks the F-keys and Forward Delete</td>
</tr>
</tbody>
</table>
<p>So when a menu shows <code>⇧⌘4</code>, that reads as <strong>Shift + Command + 4</strong>. That’s it — that’s the whole trick.</p>
<h2 id="-basic-editing-macos-shortcuts">🔄 Basic Editing macOS Shortcuts<a class="heading-anchor" href="#-basic-editing-macos-shortcuts" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<table>
<thead>
<tr>
<th scope="col">Action</th>
<th scope="col">Shortcut</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Undo</th>
<td>Command (⌘) + Z</td>
</tr>
<tr>
<th scope="row">Redo</th>
<td>Command (⌘) + Shift + Z</td>
</tr>
<tr>
<th scope="row">Copy</th>
<td>Command (⌘) + C</td>
</tr>
<tr>
<th scope="row">Paste</th>
<td>Command (⌘) + V</td>
</tr>
<tr>
<th scope="row">Paste without formatting</th>
<td>Command (⌘) + Shift + Option (⌥) + V</td>
</tr>
<tr>
<th scope="row">Cut</th>
<td>Command (⌘) + X</td>
</tr>
<tr>
<th scope="row">Select all</th>
<td>Command (⌘) + A</td>
</tr>
<tr>
<th scope="row">Save</th>
<td>Command (⌘) + S</td>
</tr>
<tr>
<th scope="row">Find</th>
<td>Command (⌘) + F</td>
</tr>
<tr>
<th scope="row">Forward Delete</th>
<td>fn + Delete (Backspace)</td>
</tr>
</tbody>
</table>
<h2 id="️-moving-around-text-quickly">✍️ Moving around text quickly<a class="heading-anchor" href="#️-moving-around-text-quickly" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>These are the ones that made the biggest difference to my daily typing, and they’re rarely in beginner lists. They work in almost every text field on macOS, including most code editors.</p>
<table>
<thead>
<tr>
<th scope="col">Action</th>
<th scope="col">Shortcut</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Jump to start / end of line</th>
<td>Command (⌘) + Left / Right</td>
</tr>
<tr>
<th scope="row">Jump to top / bottom of document</th>
<td>Command (⌘) + Up / Down</td>
</tr>
<tr>
<th scope="row">Move one word at a time</th>
<td>Option (⌥) + Left / Right</td>
</tr>
<tr>
<th scope="row">Delete the previous word</th>
<td>Option (⌥) + Delete</td>
</tr>
<tr>
<th scope="row">Delete to the start of the line</th>
<td>Command (⌘) + Delete</td>
</tr>
<tr>
<th scope="row">Select to end of line</th>
<td>Command (⌘) + Shift + Right</td>
</tr>
<tr>
<th scope="row">Select a word at a time</th>
<td>Option (⌥) + Shift + Left / Right</td>
</tr>
</tbody>
</table>
<p>If you came from Windows, note that <strong>Home</strong> and <strong>End</strong> don’t behave the way you expect on a Mac. <code>Command + Left</code> and <code>Command + Right</code> are what you actually want.</p>
<p>The Option key has a second job worth knowing about too: held on its own it types special characters rather than moving the cursor, which is how you get <a href="/how-to-do-the-copyright-symbol-on-mac/">the copyright symbol and friends</a> — © is <code>Option + G</code>, ™ is <code>Option + 2</code>.</p>
<h2 id="-developer--focused-macos-shortcuts">👨‍💻 Developer – Focused macOS Shortcuts<a class="heading-anchor" href="#-developer--focused-macos-shortcuts" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<table>
<thead>
<tr>
<th scope="col">Action</th>
<th scope="col">Shortcut</th>
<th scope="col">App / Context</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Open Browser DevTools</th>
<td>Command (⌘) + Option (⌥) + I</td>
<td>Chrome / Edge / Safari</td>
</tr>
<tr>
<th scope="row">Open the Console directly</th>
<td>Command (⌘) + Option (⌥) + J</td>
<td>Chrome / Edge</td>
</tr>
<tr>
<th scope="row">Open Terminal</th>
<td>Command (⌘) + Spacebar → type “Terminal” + Enter</td>
<td>System</td>
</tr>
<tr>
<th scope="row">Hard Refresh (Bypass Cache)</th>
<td>Command (⌘) + Shift + R</td>
<td>Browser</td>
</tr>
<tr>
<th scope="row">Focus the address bar</th>
<td>Command (⌘) + L</td>
<td>Browser</td>
</tr>
<tr>
<th scope="row">Reopen the tab you just closed</th>
<td>Command (⌘) + Shift + T</td>
<td>Browser</td>
</tr>
<tr>
<th scope="row">Switch between browser tabs</th>
<td>Command (⌘) + Option (⌥) + Left / Right</td>
<td>Browser</td>
</tr>
</tbody>
</table>
<p>In Safari, DevTools only appears once you enable the Develop menu: <strong>Safari → Settings → Advanced → Show features for web developers</strong>. This catches out a lot of people who assume the shortcut is broken.</p>
<h2 id="-productivity-macos-shortcuts">💻 Productivity macOS Shortcuts<a class="heading-anchor" href="#-productivity-macos-shortcuts" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<table>
<thead>
<tr>
<th scope="col">Action</th>
<th scope="col">Shortcut</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Open Spotlight Search</th>
<td>Command (⌘) + Spacebar</td>
</tr>
<tr>
<th scope="row">Screenshot (Full Screen)</th>
<td>Command (⌘) + Shift + 3</td>
</tr>
<tr>
<th scope="row">Screenshot (Select Area)</th>
<td>Command (⌘) + Shift + 4</td>
</tr>
<tr>
<th scope="row">Open Finder search window</th>
<td>Command (⌘) + Option (⌥) + Spacebar</td>
</tr>
<tr>
<th scope="row">Open Character Viewer</th>
<td>Control + Command (⌘) + Space</td>
</tr>
<tr>
<th scope="row">Force Quit App</th>
<td>Command (⌘) + Option (⌥) + Esc</td>
</tr>
</tbody>
</table>
<h3 id="-more-on-screenshots">📸 More on screenshots<a class="heading-anchor" href="#-more-on-screenshots" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Screenshots have more depth than the two shortcuts above suggest, and this is genuinely worth two minutes of your time:</p>
<ul>
<li><strong>Command + Shift + 3</strong> — the entire screen.</li>
<li><strong>Command + Shift + 4</strong> — drag to select a region.</li>
<li><strong>Command + Shift + 4, then Space</strong> — the cursor becomes a camera; click any window to capture just that window, with a tidy drop shadow. This is the one I use for blog posts.</li>
<li><strong>Command + Shift + 5</strong> — opens the full capture toolbar, including screen recording and a timer.</li>
</ul>
<p>Add <strong>Control</strong> to any of these to copy the result to your clipboard instead of saving a file to the Desktop. So <code>Control + Command + Shift + 4</code> selects a region and puts it straight on the clipboard, ready to paste.</p>
<h2 id="-window-and-app-management">🪟 Window and app management<a class="heading-anchor" href="#-window-and-app-management" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<table>
<thead>
<tr>
<th scope="col">Action</th>
<th scope="col">Shortcut</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Switch between apps</th>
<td>Command (⌘) + Tab</td>
</tr>
<tr>
<th scope="row">Switch between windows of the <em>same</em> app</th>
<td>Command (⌘) + ` (backtick)</td>
</tr>
<tr>
<th scope="row">Close the window</th>
<td>Command (⌘) + W</td>
</tr>
<tr>
<th scope="row">Quit the app entirely</th>
<td>Command (⌘) + Q</td>
</tr>
<tr>
<th scope="row">Minimize the window</th>
<td>Command (⌘) + M</td>
</tr>
<tr>
<th scope="row">Hide the current app</th>
<td>Command (⌘) + H</td>
</tr>
<tr>
<th scope="row">Hide every other app</th>
<td>Command (⌘) + Option (⌥) + H</td>
</tr>
<tr>
<th scope="row">Toggle full screen</th>
<td>Control + Command (⌘) + F</td>
</tr>
<tr>
<th scope="row">Mission Control (see all windows)</th>
<td>Control + Up</td>
</tr>
<tr>
<th scope="row">Move between desktops / Spaces</th>
<td>Control + Left / Right</td>
</tr>
<tr>
<th scope="row">Show Desktop</th>
<td>Command (⌘) + F3</td>
</tr>
</tbody>
</table>
<p>The distinction between <strong>Command + W</strong> and <strong>Command + Q</strong> matters more on macOS than on Windows. Closing the last window of an app usually doesn’t quit it — the app stays running, which is why you sometimes see apps in the Dock you thought you’d closed. If you’re wrestling with a window that won’t leave full screen, there’s a <a href="/how-to-close-a-full-screen-on-mac/">dedicated guide to exiting full screen on Mac</a>.</p>
<h2 id="-finder-shortcuts-worth-knowing">📁 Finder shortcuts worth knowing<a class="heading-anchor" href="#-finder-shortcuts-worth-knowing" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<table>
<thead>
<tr>
<th scope="col">Action</th>
<th scope="col">Shortcut</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Show / hide hidden files</th>
<td>Command (⌘) + Shift + . (period)</td>
</tr>
<tr>
<th scope="row">Go to folder (type a path)</th>
<td>Command (⌘) + Shift + G</td>
</tr>
<tr>
<th scope="row">New folder</th>
<td>Command (⌘) + Shift + N</td>
</tr>
<tr>
<th scope="row">Move to Trash</th>
<td>Command (⌘) + Delete</td>
</tr>
<tr>
<th scope="row">Quick Look (preview without opening)</th>
<td>Spacebar</td>
</tr>
<tr>
<th scope="row">Rename the selected file</th>
<td>Enter</td>
</tr>
<tr>
<th scope="row">Go to Applications</th>
<td>Command (⌘) + Shift + A</td>
</tr>
<tr>
<th scope="row">Go to Utilities</th>
<td>Command (⌘) + Shift + U</td>
</tr>
<tr>
<th scope="row">Copy, then <em>move</em> instead of paste</th>
<td>Command (⌘) + C, then Command (⌘) + Option (⌥) + V</td>
</tr>
</tbody>
</table>
<p>That first one — <strong>Command + Shift + period</strong> — is essential for developers. It toggles hidden files, which is how you actually see <code>.env</code>, <code>.gitignore</code> and <code>.zshrc</code> in Finder. I looked for this for an embarrassingly long time.</p>
<p>The last one solves something that confused me for weeks: macOS has no “Cut” for files. You copy with <code>Command + C</code>, then paste-as-move with <code>Command + Option + V</code>.</p>
<h2 id="-other-useful-shortcuts">🔤 Other Useful Shortcuts<a class="heading-anchor" href="#-other-useful-shortcuts" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<table>
<thead>
<tr>
<th scope="col">Action</th>
<th scope="col">Shortcut</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Open System Settings</th>
<td>Command (⌘) + Spacebar, type “Settings” + Enter</td>
</tr>
<tr>
<th scope="row">Lock the screen</th>
<td>Control + Command (⌘) + Q</td>
</tr>
<tr>
<th scope="row">Emoji and symbol picker</th>
<td>Control + Command (⌘) + Space</td>
</tr>
<tr>
<th scope="row">Zoom in / out (browsers, editors)</th>
<td>Command (⌘) + Plus / Minus</td>
</tr>
<tr>
<th scope="row">Reset zoom</th>
<td>Command (⌘) + 0</td>
</tr>
</tbody>
</table>
<h2 id="-coming-from-windows-start-here">🔁 Coming from Windows? Start here<a class="heading-anchor" href="#-coming-from-windows-start-here" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>If you’re switching rather than starting fresh, this table probably saves you the most time. Most of the pain is that <strong>Ctrl became Command</strong>, but a handful genuinely differ.</p>
<table>
<thead>
<tr>
<th scope="col">What you did on Windows</th>
<th scope="col">The macOS equivalent</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Ctrl + C / V / Z</th>
<td>Command (⌘) + C / V / Z</td>
</tr>
<tr>
<th scope="row">Alt + Tab</th>
<td>Command (⌘) + Tab</td>
</tr>
<tr>
<th scope="row">Ctrl + Alt + Delete</th>
<td>Command (⌘) + Option (⌥) + Esc (Force Quit)</td>
</tr>
<tr>
<th scope="row">Ctrl + Shift + Esc (Task Manager)</th>
<td>Activity Monitor — via Spotlight</td>
</tr>
<tr>
<th scope="row">Home / End</th>
<td>Command (⌘) + Left / Right</td>
</tr>
<tr>
<th scope="row">Print Screen</th>
<td>Command (⌘) + Shift + 3</td>
</tr>
<tr>
<th scope="row">F2 (rename)</th>
<td>Enter</td>
</tr>
<tr>
<th scope="row">Delete (a file)</th>
<td>Command (⌘) + Delete</td>
</tr>
<tr>
<th scope="row">Windows key (search)</th>
<td>Command (⌘) + Spacebar</td>
</tr>
</tbody>
</table>
<h2 id="️-make-your-own-shortcuts">⚙️ Make your own shortcuts<a class="heading-anchor" href="#️-make-your-own-shortcuts" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Once the built-in ones feel natural, you can assign your own to any menu item in any app. It’s buried, so here’s the path:</p>
<p><strong>System Settings → Keyboard → Keyboard Shortcuts → App Shortcuts → +</strong></p>
<p>Pick the app, type the menu item’s name <strong>exactly</strong> as it appears in the menu, then press the key combination you want. The exact-match part is the bit everyone gets wrong — “Save As…” with the three-dot ellipsis character will not match if you typed three full stops.</p>
<h2 id="frequently-asked-questions">Frequently asked questions<a class="heading-anchor" href="#frequently-asked-questions" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<h3 id="why-doesnt-my-f-key-do-anything">Why doesn’t my F-key do anything?<a class="heading-anchor" href="#why-doesnt-my-f-key-do-anything" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>By default the top row controls brightness, volume and so on. Hold <strong>fn</strong> to use them as real F1–F12 keys, or flip the default in <strong>System Settings → Keyboard → “Use F1, F2, etc. keys as standard function keys”</strong>.</p>
<h3 id="where-do-my-screenshots-go">Where do my screenshots go?<a class="heading-anchor" href="#where-do-my-screenshots-go" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>To the Desktop by default, named with the date and time. Press <code>Command + Shift + 5</code> and use the <strong>Options</strong> menu to change the destination — mine goes to a dedicated folder so the Desktop stays clean.</p>
<h3 id="is-there-a-way-to-see-an-apps-shortcuts">Is there a way to see an app’s shortcuts?<a class="heading-anchor" href="#is-there-a-way-to-see-an-apps-shortcuts" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Yes, and it’s the best habit to build: just open the app’s menus. Every command that has a shortcut shows it on the right using the symbols from the table at the top of this post. That’s why learning ⌘⌥⇧⌃ first pays off — after that, every app documents itself.</p>
<p>Since I’m still fairly new to macOS after switching from Ubuntu Linux, I’ve been collecting these shortcuts to help myself — and hopefully to help you too.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-do-the-copyright-symbol-on-mac/">How to Type the Copyright Symbol on Mac</a> — the Character Viewer shortcut above, put to work</li>
<li><a href="/how-to-close-a-full-screen-on-mac/">How to Close a Full Screen on Mac</a></li>
<li><a href="/how-to-install-homebrew-macos-for-beginners/">How to install Homebrew – MacOS for beginners</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Husky Hooks: Improve Your Git Workflow</title>
      <link>https://littlecodingthings.com/husky-hooks-the-easy-way-to-improve-your-project-workflow/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/husky-hooks-the-easy-way-to-improve-your-project-workflow/</guid>
      <pubDate>Fri, 12 Sep 2025 14:06:00 GMT</pubDate>
      <description>Run lint and tests automatically on every commit with Husky Git hooks. Setup, pre-commit examples, Husky vs GitHub Actions, and how to skip a hook.</description>
      <category>Setup &amp; Tools</category>
      <content:encoded><![CDATA[<p>We all miss stuff sometimes — skipping a test run, forgetting to lint, or pushing code that breaks something.
Yes, guilty as charged! Husky hooks help you catch those issues early by running scripts right when you commit or push. 🐶
It’s a simple way to keep your workflow clean, lower the pressure, save time, and avoid nasty surprises later.</p>
<h2 id="introduction-why-use-husky-hooks-in-your-project">Introduction: Why use Husky hooks in your project?<a class="heading-anchor" href="#introduction-why-use-husky-hooks-in-your-project" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><strong><a href="https://typicode.github.io/husky/" title="Husky">Husky</a> is a great tool to help you out when working on a project and being proactive.</strong> It can catch problems before they are committed and make it into your codebase.</p>
<p>How? By running scripts like tests or linters when committing or pushing your code. It’s a simple way to enforce code quality.</p>
<p>But why not just use native Git hooks or a CI tool like CircleCI or GitHub Actions, you might wonder… and honestly, that’s a fair question — I asked the same thing when I first came across Husky.</p>
<p>The answer really comes down to <em>when</em> you want to catch issues in your code, and whether you’re comfortable setting up native Git hooks or working with a team where shared, versioned hooks make more sense.</p>
<p>Do you want to wait for your CI tool to run all steps just to tell you a test failed or a semicolon was missing?
Or would you rather know right away, <em>before</em> even pushing your code? ⚡</p>
<p>What are you waiting for if you’d like to catch issues immediately? 🚀
Let’s go ahead and install Husky and learn more about this cool tool! 🛠️🐶</p>
<h2 id="installing-and-initializing-husky-in-your-project">Installing and initializing Husky in your project<a class="heading-anchor" href="#installing-and-initializing-husky-in-your-project" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Installing Husky is straightforward; you just type in your terminal</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">npm</span><span style="color:#9ECBFF"> install</span><span style="color:#79B8FF"> --save-dev</span><span style="color:#9ECBFF"> husky</span></span></code></pre></div>
<p>Or (<em>if you are using yarn</em>)</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">yarn</span><span style="color:#9ECBFF"> add</span><span style="color:#79B8FF"> --dev</span><span style="color:#9ECBFF"> husky</span></span></code></pre></div>
<p>Now that we’ve installed the package, let’s go ahead and initialize it by typing:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">npx</span><span style="color:#9ECBFF"> husky</span><span style="color:#9ECBFF"> init</span></span></code></pre></div>
<p>Initializing Husky does the following:</p>
<ul>
<li>creates a <code>.husky</code> directory in your project, which includes:
<ul>
<li>a <code>pre-commit</code> hook file</li>
<li>a <code>_</code> subfolder for additional settings.</li>
</ul>
</li>
<li>Adds a <code>prepare</code> script to your <code>package.json</code> file to ensure Husky is set up when dependencies are installed.</li>
</ul>
<h3 id="huskypre-commit">.husky/pre-commit<a class="heading-anchor" href="#huskypre-commit" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>The <code>pre-commit</code> file is a Git hook managed by Husky. It runs automatically before each commit, allowing you to run scripts like linters or tests to catch issues early.</p>
<p>When Husky initializes its structure, it adds the following content to this hook file:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">npm</span><span style="color:#9ECBFF"> test</span></span></code></pre></div>
<p>This basically means that whenever you are running your <code>git commit</code> command, Husky will first run <code>npm test</code>. If the tests pass, the commit will go through. If they fail, the commit will be blocked, and you’ll need to fix the errors before trying again.</p>
<p>When I tried this in a brand-new project by making a simple change and committing it, here’s what I saw:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">git</span><span style="color:#9ECBFF"> commit</span><span style="color:#79B8FF"> -m</span><span style="color:#9ECBFF"> "A simple change to see pre-commit hook"</span><span style="color:#F97583"> ></span><span style="color:#9ECBFF"> my-project@0.1.0</span><span style="color:#9ECBFF"> test</span><span style="color:#F97583"> ></span><span style="color:#9ECBFF"> jest</span><span style="color:#9ECBFF"> PASS</span><span style="color:#9ECBFF"> src/pages/hello.test.ts</span><span style="color:#9ECBFF"> PASS</span><span style="color:#9ECBFF"> src/components/heading.test.tsx</span><span style="color:#9ECBFF"> Test</span><span style="color:#9ECBFF"> Suites:</span><span style="color:#79B8FF"> 2</span><span style="color:#9ECBFF"> passed,</span><span style="color:#79B8FF"> 2</span><span style="color:#9ECBFF"> total</span><span style="color:#9ECBFF"> Tests:</span><span style="color:#79B8FF"> 2</span><span style="color:#9ECBFF"> passed,</span><span style="color:#79B8FF"> 2</span><span style="color:#9ECBFF"> total</span><span style="color:#9ECBFF"> Snapshots:</span><span style="color:#79B8FF"> 0</span><span style="color:#9ECBFF"> total</span><span style="color:#9ECBFF"> Time:</span><span style="color:#79B8FF"> 0.491</span><span style="color:#9ECBFF"> s,</span><span style="color:#9ECBFF"> estimated</span><span style="color:#79B8FF"> 1</span><span style="color:#9ECBFF"> s</span><span style="color:#9ECBFF"> Ran</span><span style="color:#9ECBFF"> all</span><span style="color:#9ECBFF"> test</span><span style="color:#9ECBFF"> suites.</span><span style="color:#E1E4E8"> [playground </span><span style="color:#9ECBFF">c6e4aaf]</span><span style="color:#9ECBFF"> A</span><span style="color:#9ECBFF"> simple</span><span style="color:#9ECBFF"> change</span><span style="color:#9ECBFF"> to</span><span style="color:#9ECBFF"> see</span><span style="color:#9ECBFF"> pre-commit</span><span style="color:#9ECBFF"> hook</span><span style="color:#79B8FF"> 2</span><span style="color:#9ECBFF"> files</span><span style="color:#9ECBFF"> changed,</span><span style="color:#79B8FF"> 5</span><span style="color:#9ECBFF"> insertions</span><span style="color:#E1E4E8">(</span><span style="color:#B392F0">+</span><span style="color:#E1E4E8">)</span><span style="color:#9ECBFF">,</span><span style="color:#79B8FF"> 1</span><span style="color:#9ECBFF"> deletion</span><span style="color:#E1E4E8">(</span><span style="color:#B392F0">-</span><span style="color:#E1E4E8">) </span><span style="color:#9ECBFF">create</span><span style="color:#9ECBFF"> mode</span><span style="color:#79B8FF"> 100644</span><span style="color:#9ECBFF"> .husky/pre-commit</span></span></code></pre></div>
<p>See? It ran the two tests included in my project and then finalized the commit process.</p>
<h3 id="husky_-folder">.husky/_ folder<a class="heading-anchor" href="#husky_-folder" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>This folder is created by Husky and contains setup code that helps your Git hooks run smoothly across different systems.</p>
<p>You usually don’t need to touch anything here — it just works in the background to support the other hook files.</p>
<h3 id="prepare-script">prepare script<a class="heading-anchor" href="#prepare-script" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>When you set up Husky, it adds a <code>prepare</code> script to your <code>package.json</code> file:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#9ECBFF">"scripts"</span><span style="color:#E1E4E8">: {</span></span>
<span class="line"><span style="color:#79B8FF">  "prepare"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"husky"</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>This script makes sure git hooks are installed whenever someone installs your project’s dependencies (e.g., by running <code>npm install</code> or <code>yarn install</code>).</p>
<p>This could come in handy if you are sharing your project with a team. The <code>prepare</code> script will ensure Husky works automatically for everyone without any extra steps needed.</p>
<h2 id="expanding-pre-commit-catch-more-before-it-hits-your-repo">Expanding pre-commit: Catch more before it hits your repo<a class="heading-anchor" href="#expanding-pre-commit-catch-more-before-it-hits-your-repo" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Although running tests before committing is what Husky suggests by default when it initializes, I personally find that a bit too much. It feels like a blocker when all I want is to make a quick commit to save my progress. So instead of leaving <code>npm run test</code> in the pre-commit file, I prefer to remove the testing and go with simpler, quicker checks at that point.</p>
<p>Before we change our <code>pre-commit</code> file, I just want to share a quick tip — did you know you can test Husky hooks without having to write a new commit message every single time?</p>
<p>Good news: you can do exactly that by adding a simple line at the end of your <code>pre-commit</code> file.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">npm</span><span style="color:#9ECBFF"> test</span></span>
<span class="line"><span style="color:#79B8FF">exit</span><span style="color:#79B8FF"> 1</span></span></code></pre></div>
<p><code>exit 1</code> will stop the script from continuing, which makes it a safe way to test your <code>pre-commit</code> commands without actually committing your changes.</p>
<h3 id="hook-for-linting-checks">Hook for linting checks<a class="heading-anchor" href="#hook-for-linting-checks" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Go to your <code>.husky</code> folder and open the <code>pre-commit</code> file replace its content with:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#79B8FF">echo</span><span style="color:#9ECBFF"> "🐶 Executing pre-commit hook…"</span></span>
<span class="line"><span style="color:#79B8FF">echo</span><span style="color:#9ECBFF"> ""</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D"># Run lint on staged files</span></span>
<span class="line"><span style="color:#79B8FF">echo</span><span style="color:#9ECBFF"> "🔍 Running ESLint on staged files…"</span></span>
<span class="line"><span style="color:#B392F0">npx</span><span style="color:#9ECBFF"> eslint</span><span style="color:#9ECBFF"> .</span></span>
<span class="line"><span style="color:#79B8FF">echo</span><span style="color:#9ECBFF"> "✅ ESLint passed."</span></span></code></pre></div>
<p>By doing this, we’ve added ESLint checks right before committing — simple as that!</p>
<p>To make sure it works, try committing some new changes, and you’ll see the results show up right in your terminal.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>🐶 Executing pre-commit hook…</span></span>
<span class="line"><span>🔍 Running ESLint on staged files…</span></span>
<span class="line"><span>✅ ESLint passed.</span></span></code></pre></div>
<p>Awesome, right? No linting errors! 🎉
But what if there were some? What would that look like?</p>
<p>I added a small linting issue (couple of spaces) to test it, and here’s what showed up when I ran it again:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>🐶 Executing pre-commit hook…</span></span>
<span class="line"><span>🔍 Running ESLint on staged files…</span></span>
<span class="line"><span></span></span>
<span class="line"><span>/my-project/src/components/Heading.test.tsx</span></span>
<span class="line"><span>  6:5  error  Delete `··`</span></span>
<span class="line"><span></span></span>
<span class="line"><span>✖ 1 problem (1 error, 0 warnings)</span></span>
<span class="line"><span>  1 error and 0 warnings potentially fixable with the `--fix` option.</span></span></code></pre></div>
<p>All that’s left now is to fix the issue and commit the changes successfully. ✅</p>
<h3 id="hooks-to-catch-consolelog-statements">Hooks to catch console.log statements<a class="heading-anchor" href="#hooks-to-catch-consolelog-statements" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Now that we’ve got linting checks in place, why not expand them a bit and catch things we definitely don’t want sneaking into our code — like <code>console.log</code>s maybe?</p>
<p>Just add the following content to your <code>pre-commit</code> file:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#79B8FF">echo</span><span style="color:#9ECBFF"> "🐶 Executing pre-commit hook…"</span></span>
<span class="line"><span style="color:#79B8FF">echo</span><span style="color:#9ECBFF"> ""</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D"># Run lint on staged files</span></span>
<span class="line"><span style="color:#79B8FF">echo</span><span style="color:#9ECBFF"> "🔍 Running ESLint on staged files…"</span></span>
<span class="line"><span style="color:#B392F0">npx</span><span style="color:#9ECBFF"> eslint</span><span style="color:#9ECBFF"> .</span></span>
<span class="line"><span style="color:#79B8FF">echo</span><span style="color:#9ECBFF"> "✅ ESLint passed."</span></span>
<span class="line"><span style="color:#79B8FF">echo</span><span style="color:#9ECBFF"> ""</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D"># Match staged JS/TS files</span></span>
<span class="line"><span style="color:#E1E4E8">FILES_PATTERN</span><span style="color:#F97583">=</span><span style="color:#9ECBFF">'\.(js|ts)(x)?$'</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D"># Disallowed patterns: console methods</span></span>
<span class="line"><span style="color:#E1E4E8">FORBIDDEN</span><span style="color:#F97583">=</span><span style="color:#9ECBFF">'(console\.log)'</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">echo</span><span style="color:#9ECBFF"> "🔎 Checking staged files for forbidden patterns (e.g. console.log)…"</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D"># Scan staged files for forbidden patterns</span></span>
<span class="line"><span style="color:#F97583">if</span><span style="color:#B392F0"> git</span><span style="color:#9ECBFF"> diff</span><span style="color:#79B8FF"> --cached</span><span style="color:#79B8FF"> --name-only</span><span style="color:#79B8FF"> --diff-filter=ACM</span><span style="color:#F97583"> |</span><span style="color:#79B8FF"> \</span></span>
<span class="line"><span style="color:#B392F0">  grep</span><span style="color:#79B8FF"> -E</span><span style="color:#9ECBFF"> "</span><span style="color:#E1E4E8">$FILES_PATTERN</span><span style="color:#9ECBFF">"</span><span style="color:#F97583"> |</span><span style="color:#79B8FF"> \</span></span>
<span class="line"><span style="color:#B392F0">  xargs</span><span style="color:#9ECBFF"> grep</span><span style="color:#79B8FF"> --with-filename</span><span style="color:#79B8FF"> -n</span><span style="color:#79B8FF"> -E</span><span style="color:#9ECBFF"> "</span><span style="color:#E1E4E8">$FORBIDDEN</span><span style="color:#9ECBFF">"</span><span style="color:#F97583"> |</span><span style="color:#79B8FF"> \</span></span>
<span class="line"><span style="color:#B392F0">  grep</span><span style="color:#79B8FF"> -v</span><span style="color:#9ECBFF"> '^\s*//'</span><span style="color:#E1E4E8">; </span><span style="color:#F97583">then</span></span>
<span class="line"><span style="color:#79B8FF">  echo</span><span style="color:#9ECBFF"> ""</span></span>
<span class="line"><span style="color:#79B8FF">  echo</span><span style="color:#9ECBFF"> "🚫 COMMIT REJECTED! Found forbidden patterns"</span></span>
<span class="line"><span style="color:#79B8FF">  echo</span><span style="color:#9ECBFF"> "😅 Please clean them up before committing."</span></span>
<span class="line"><span style="color:#79B8FF">  echo</span><span style="color:#9ECBFF"> ""</span></span>
<span class="line"><span style="color:#79B8FF">  exit</span><span style="color:#79B8FF"> 1</span></span>
<span class="line"><span style="color:#F97583">fi</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">echo</span><span style="color:#9ECBFF"> "✅ No forbidden patterns found!"</span></span>
<span class="line"><span style="color:#79B8FF">echo</span><span style="color:#9ECBFF"> "✅ Git pre-commit hook passed. You're good to go 🚀"</span></span>
<span class="line"><span style="color:#79B8FF">exit</span><span style="color:#79B8FF"> 0</span></span></code></pre></div>
<p>Let’s check what each part does</p>
<p><code>echo</code> is a command used to print informational messages in the terminal — basically just outputting text so we can see what’s happening.</p>
<p><code>exit 0</code> means the script completed successfully, while <code>exit 1</code> signals an error or that something failed.</p>
<p>Next, we see:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D"># Match staged JS/TS files</span></span>
<span class="line"><span style="color:#E1E4E8">FILES_PATTERN</span><span style="color:#F97583">=</span><span style="color:#9ECBFF">'\.(js|ts)(x)?$'</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D"># Disallowed patterns: console methods</span></span>
<span class="line"><span style="color:#E1E4E8">FORBIDDEN</span><span style="color:#F97583">=</span><span style="color:#9ECBFF">'(console\.log)'</span></span></code></pre></div>
<p>In this part, by using <code>FILES_PATTERN</code>, we’re basically saying we only want to match files with the extensions <code>.js</code>, <code>.jsx</code>, <code>.ts</code>, or <code>.tsx</code> — and yep, you guessed it, I’m working in a project that’s transitioning from JS to TS!</p>
<p>The next constant, <code>FORBIDDEN</code>, defines what I don’t want slipping into my commits — for now, that’s just <code>console.log</code>s.</p>
<p>The next part is the trickiest one:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">if</span><span style="color:#B392F0"> git</span><span style="color:#9ECBFF"> diff</span><span style="color:#79B8FF"> --cached</span><span style="color:#79B8FF"> --name-only</span><span style="color:#79B8FF"> --diff-filter=ACM</span><span style="color:#F97583"> |</span><span style="color:#79B8FF"> \</span></span>
<span class="line"><span style="color:#B392F0">  grep</span><span style="color:#79B8FF"> -E</span><span style="color:#9ECBFF"> "</span><span style="color:#E1E4E8">$FILES_PATTERN</span><span style="color:#9ECBFF">"</span><span style="color:#F97583"> |</span><span style="color:#79B8FF"> \</span></span>
<span class="line"><span style="color:#B392F0">  xargs</span><span style="color:#9ECBFF"> grep</span><span style="color:#79B8FF"> --with-filename</span><span style="color:#79B8FF"> -n</span><span style="color:#79B8FF"> -E</span><span style="color:#9ECBFF"> "</span><span style="color:#E1E4E8">$FORBIDDEN</span><span style="color:#9ECBFF">"</span><span style="color:#F97583"> |</span><span style="color:#79B8FF"> \</span></span>
<span class="line"><span style="color:#B392F0">  grep</span><span style="color:#79B8FF"> -v</span><span style="color:#9ECBFF"> '^\s*//'</span><span style="color:#E1E4E8">; </span><span style="color:#F97583">then</span></span>
<span class="line"><span style="color:#79B8FF">  echo</span><span style="color:#9ECBFF"> ""</span></span>
<span class="line"><span style="color:#79B8FF">  echo</span><span style="color:#9ECBFF"> "🚫 COMMIT REJECTED! Found forbidden patterns"</span></span>
<span class="line"><span style="color:#79B8FF">  echo</span><span style="color:#9ECBFF"> "😅 Please clean them up before committing."</span></span>
<span class="line"><span style="color:#79B8FF">  echo</span><span style="color:#9ECBFF"> ""</span></span>
<span class="line"><span style="color:#79B8FF">  exit</span><span style="color:#79B8FF"> 1</span></span>
<span class="line"><span style="color:#F97583">fi</span></span></code></pre></div>
<p>It’s a pipeline that runs over all the <a href="/what-does-git-add-a-do/">staged files</a> — whatever you last put in the staging area with <code>git add</code> — and checks each one against every pattern we’ve defined, like <code>console.log</code>. If it finds a match, it prints an error message showing the file and the exact pattern it caught.</p>
<p>Otherwise, it lets us know everything’s clean and we’re good to move forward with the commit:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#79B8FF">echo</span><span style="color:#9ECBFF"> "✅ No forbidden patterns found!"</span></span>
<span class="line"><span style="color:#79B8FF">echo</span><span style="color:#9ECBFF"> "✅ Git pre-commit hook passed. You're good to go 🚀"</span></span></code></pre></div>
<p>To test this script, I added a console.log to one of my files, just to see what it would print when running this hook</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>🐶 Executing pre-commit hook…</span></span>
<span class="line"><span>🔍 Running ESLint on staged files…</span></span>
<span class="line"><span>✅ ESLint passed.</span></span>
<span class="line"><span>🔎 Checking staged files for forbidden patterns (e.g. console.log)…</span></span>
<span class="line"><span>src/components/Heading.test.tsx:6:  console.log('test');</span></span>
<span class="line"><span>🚫 COMMIT REJECTED! Found forbidden patterns</span></span>
<span class="line"><span>😅 Please clean them up before committing.</span></span></code></pre></div>
<p>After fixing that and removing the <code>console.log</code>, I ran it again and saw everything passed — no errors, no blocks. Just a smooth, satisfying commit! 🙌</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>🐶 Executing pre-commit hook…</span></span>
<span class="line"><span>🔍 Running ESLint on staged files…</span></span>
<span class="line"><span>✅ ESLint passed.</span></span>
<span class="line"><span>🔎 Checking staged files for forbidden patterns (e.g. console.log)…</span></span>
<span class="line"><span>✅ No forbidden patterns found!</span></span>
<span class="line"><span>✅ Git pre-commit hook passed. You're good to go 🚀</span></span></code></pre></div>
<p>This script could easily be expanded to catch all console methods like <code>.log</code>, <code>.info</code>, and so on — or even <code>.only</code> in your test files. All you need to do is update the <code>FORBIDDEN</code> constant like this:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D"># Disallowed patterns: console methods</span></span>
<span class="line"><span style="color:#E1E4E8">FORBIDDEN</span><span style="color:#F97583">=</span><span style="color:#9ECBFF">'(console\.(log|info|warn|error|clear|dir)|it\.only)'</span></span></code></pre></div>
<p>Of course, blocking <code>console.log</code> at the commit is only half the job — your app still needs a way to tell you what it’s doing once it’s running. That’s where a real logger comes in, and <a href="/how-to-set-up-pino-logging-in-next-js/">setting up Pino in a Next.js project</a> gives you levels, timestamps and structured output to replace those stray console calls with. 📋</p>
<h2 id="other-git-hook-ideas-to-level-up-your-workflow">Other Git hook ideas to level up your workflow<a class="heading-anchor" href="#other-git-hook-ideas-to-level-up-your-workflow" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Although using the <code>pre-commit</code> hook may seem like it’s blocking your workflow or might appear straightforward in terms of what you can do with it, there are other use cases where you can run scripts at different stages, not just on commit.
Here are a few common Husky hooks you can use:</p>
<ul>
<li><code>commit-msg</code> – Validate or format the commit message using your project’s guidelines or some conventional ones</li>
<li><code>pre-push</code> – Run final checks before pushing to remote</li>
<li><code>post-merge</code> – Automatically sync dependencies or regenerate files after a merge (e.g., run <code>npm install</code> or <code>pnpm install</code>) 🔄</li>
<li><code>post-checkout</code> – Run scripts after switching branches (e.g., load env files, clean build cache)</li>
</ul>
<p>These hooks are just examples of what’s possible — you don’t need to use them all, but knowing they exist can help you pick the right tool for the right task.
Start small, and build up as your project grows!</p>
<h2 id="husky-vs-github-actions-when-to-use-each-tool">Husky vs GitHub actions: When to use each tool<a class="heading-anchor" href="#husky-vs-github-actions-when-to-use-each-tool" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>You might be working on a project that already uses a CI/CD tool like GitHub Actions or CircleCI, and wondering — how is that different from Husky? 🤔
Let’s look at some key differences to help you decide whether Husky is a good fit for your project.</p>
<table>
<thead>
<tr>
<th scope="col">Feature</th>
<th scope="col">Husky</th>
<th scope="col">CI/CD Tools (e.g., GitHub Actions, GitLab CI)</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Runs when?</th>
<td>Locally, before code is committed or pushed</td>
<td>After code is pushed to a remote repository</td>
</tr>
<tr>
<th scope="row">Best for</th>
<td>Catching issues early, enforcing local standards</td>
<td>Automating builds, tests, deployments</td>
</tr>
<tr>
<th scope="row">Speed</th>
<td>Instant feedback (runs on your machine)</td>
<td>Slower (runs in external environments)</td>
</tr>
<tr>
<th scope="row">Purpose</th>
<td>Prevent bad code from leaving your laptop 💻</td>
<td>Handle what happens after it leaves your laptop 🚀</td>
</tr>
</tbody>
</table>
<p>The way I see it, it’s great to save time and feel confident that everything I’m pushing follows the project’s rules and guidelines. That’s why I’d choose to use both: CI/CD tools for automation after pushing, and Husky for those extra checks before the code even leaves my machine.</p>
<h2 id="local-git-hooks-vs-husky-whats-the-difference">Local git hooks vs Husky: What’s the difference?<a class="heading-anchor" href="#local-git-hooks-vs-husky-whats-the-difference" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>If you’ve worked with Git hooks before, it’s only natural to question what Husky really adds on top of them.
I had the exact same thought when I first came across it. And then it clicked — let’s take a closer look at how they differ. 🔍</p>
<table>
<thead>
<tr>
<th scope="col">Feature</th>
<th scope="col">Local Git Hooks</th>
<th scope="col">Husky</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Setup</th>
<td>Manual – you write and place hook scripts</td>
<td>Managed by Husky with simple commands</td>
</tr>
<tr>
<th scope="row">Version control</th>
<td>Not tracked by default</td>
<td>Fully version-controlled in your repo</td>
</tr>
<tr>
<th scope="row">Sharing with team</th>
<td>Hard to sync</td>
<td>Easy to share and maintain across the team</td>
</tr>
</tbody>
</table>
<p>I’d say the most significant and most useful advantage of Husky is that it lets you share your hooks with your team and track them through Git.
I used to try setting up Git hooks manually, even when working solo — but it always felt like this mysterious black box, and I kept putting it off.
Husky makes the whole process way easier and more straightforward. Plus, being able to commit your hooks with the repo and even reuse the same setup across projects? Huge time-saver. Count me in! 🙌</p>
<h2 id="frequently-asked-questions">Frequently Asked Questions<a class="heading-anchor" href="#frequently-asked-questions" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<h3 id="is-there-a-way-to-temporarily-skip-git-hooks">Is there a way to temporarily skip Git hooks?<a class="heading-anchor" href="#is-there-a-way-to-temporarily-skip-git-hooks" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong>Yes, you can!</strong>
If you’re under pressure or just need to skip Git hooks (including Husky hooks) for any reason, you can do it by adding the <code>--no-verify</code> flag to your Git command.</p>
<p>For example</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">git</span><span style="color:#9ECBFF"> commit</span><span style="color:#79B8FF"> -m</span><span style="color:#9ECBFF"> "My quick fix"</span><span style="color:#79B8FF"> --no-verify</span></span></code></pre></div>
<p>Just keep in mind — skipping hooks should be the exception, not the habit. Hooks are there to help your workflow, not get in the way. 😉</p>
<p>Another way to do this is by using <code>HUSKY=0</code> in your script e.g</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>HUSKY=0 git commit …</span></span></code></pre></div>
<p>I got used to using <code>--no-verify</code> when I want to skip hooks, but it’s nice to know that Husky offers an alternative.</p>
<h3 id="can-i-use-husky-locally-even-if-the-rest-of-the-team-isnt">Can I use Husky locally even if the rest of the team isn’t?<a class="heading-anchor" href="#can-i-use-husky-locally-even-if-the-rest-of-the-team-isnt" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Absolutely! You can set up Husky on your own without forcing it on others. Since Husky hooks live in the <code>.husky/</code> folder, you can simply add that folder to <code>.gitignore</code> if you don’t want to commit it.
Alternatively, you can commit it and let others opt in if they want — it’s up to your team’s workflow.</p>
<p>Have you used Husky in your projects, or do you prefer sticking with native Git hooks or CI tools?
Drop a comment and share how you manage your Git workflow — We’d love to hear what’s worked for you! 💬👇</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-install-git-on-mac-macos-for-beginners/">How to install Git on Mac – MacOS for beginners</a></li>
<li><a href="/integration-and-unit-tests-how-to-choose-the-right-one/">Integration and Unit Tests: How to Choose the Right One?</a></li>
<li><a href="/how-to-create-better-pull-requests-3-proven-tips/">How to Improve Pull Requests: 3 Basic Rules</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Infinite CSS Flip Card Animation</title>
      <link>https://littlecodingthings.com/how-to-make-a-css-infinite-flipping-card-animation/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-make-a-css-infinite-flipping-card-animation/</guid>
      <pubDate>Fri, 05 Sep 2025 14:25:00 GMT</pubDate>
      <description>Spin a card forever with animation plus @keyframes — around X, around Y or both — and the rotation value that makes it snap back.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Welcome to this article, where I will guide you through some simple steps of creating a stunning CSS infinite flipping card animation. With my easy-to-follow instructions, you’ll be able to design a beautiful and eye-catching card in no time. Don’t miss this opportunity to elevate your website and impress your audience! 😉</p>
<p>Let’s proceed and direct our attention towards creating this distinctive animation!</p>
<h2 id="css-infinite-flipping-card-effect-animation">CSS Infinite flipping card effect animation<a class="heading-anchor" href="#css-infinite-flipping-card-effect-animation" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The supplied HTML and SCSS (Sass) code generates a flip card that exhibits movement along both the Y and X axes. The X-axis and Y-axis represent two intersecting lines, defining the coordinates of a point in a two-dimensional space.</p>
<p>Now, let’s analyze the code one step at a time:</p>
<h3 id="html-structure">HTML structure<a class="heading-anchor" href="#html-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Let’s start by examining the <a href="/most-useful-html-elements-for-maximizing-better-results/" title="HTML">HTML</a> structure. We begin by creating a container element with the class <code>flip-wrapper</code>. This container acts as the main hub for our animation. Inside this container, we have a special area with the class <code>flip-card</code>. So, now we have a parent element and a child element. The parent element is where we will build the animation while the child element is the one that determines the appearance of our animation.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"flip-wrapper"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"flip-card"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h3 id="css-basic-structure">CSS Basic Structure<a class="heading-anchor" href="#css-basic-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>In our <a href="/how-to-work-with-css-syntax-the-correct-way/" title="CSS">CSS</a> code example, we start by making the whole page’s <code>background-color</code> a shade of gray (#c3c8c3).</p>
<p>Then, for the container called <code>.flip-wrapper</code> we decide its size by giving it a fixed width and height of 300 pixels. We also make it look circular or rounded by using the <code>border-radius</code> property. It’s important to mention that you can keep it square ⬛ if you prefer, but I went with the rounded look ⚫ because it helps us see clearly the effect.</p>
<p>Moving on to the <code>.flip-card</code> element, we set its <code>width</code> and <code>height</code> to 100% as a way to cover the entire available space. We make it look nicer by giving it a linear-gradient <code>background</code> using white and black colors. A subtle gray shadow effect is also a nice touch, giving a sense of depth. To keep the circular style consistent, we add the inherit value to <code>border-radius</code> property.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#213450</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* dark blue */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.flip-wrapper</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#B392F0">  .flip-card</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#e1b6ea</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* lavender */</span></span>
<span class="line"><span style="color:#79B8FF">    box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 30</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inherit</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>This is what’s currently visible on our screen.</p>
<p><img src="/flipping-card-infinite-animation.webp" alt="" style="max-width:42%" class="img-narrow"></p>
<h3 id="creating-the-css-flipping-card-effect-animation">Creating the CSS flipping card effect animation<a class="heading-anchor" href="#creating-the-css-flipping-card-effect-animation" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>To achieve this captivating effect, we must employ the <code>animation</code> CSS property together with the <a href="/keyframes-in-css-explained-make-your-animations-stand-out/"><code>@keyframes</code> rule</a>. Let’s dive deeper into their analytical exploration.</p>
<p>To create an infinite flipping card animation it is essential to <strong>connect</strong> the <code>animation</code> property and the <code>@keyframes</code> rule. Otherwise, it won’t work.</p>
<h4 id="setting-the-animation-css-property">Setting the animation CSS property<a class="heading-anchor" href="#setting-the-animation-css-property" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p>In this section of the code, we’re applying the CSS <code>animation</code> property to the element we want to make the animation, in our case to the <code>.flip-wrapper</code> class. The purpose of this property is to <strong>associate the animation with the element</strong>, as we mentioned above.</p>
<ul>
<li>First of all, we need a <strong>name</strong> for our animation. Here the animation is named <code>rotation</code>. This name acts as a reference point, allowing us to reuse and target this specific animation throughout our stylesheet.</li>
<li>Then we have to give it a <strong>duration</strong>. Our example has a duration of 8 seconds <code>8s</code>. This duration defines how long the animation takes to complete one cycle, indicating that the entire animation, from start to finish, will span over 8 seconds.</li>
<li>Additionally, it’s set to <strong>repeat</strong> infinitely. This means that once the animation completes, it restarts immediately and runs continuously without a break. This creates a continuous animation effect (loop 🌪 😂).</li>
</ul>
<p>In summary, we are using the <code>animation</code> property to apply an animation named ‘rotation’ to the <code>.flip-wrapper</code> class, making it last for 8 seconds and repeat indefinitely, resulting in an uninterrupted, continuous animation for an element.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.flip-wrapper</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  animation</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotation</span><span style="color:#79B8FF"> 8</span><span style="color:#F97583">s</span><span style="color:#79B8FF"> infinite</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#B392F0">  .flip-card</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h4 id="ways-to-add-the-keyframes">Ways to add the @keyframes<a class="heading-anchor" href="#ways-to-add-the-keyframes" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p>In the <code>@keyframes rotation</code> section, we define the <strong>animation behavior</strong>. It specifies a transformation that involves rotating an element around its X-axis and Y-axis. Here’s a breakdown of its key components:</p>
<ul>
<li><strong><code>@keyframes</code></strong>: This is the rule used to define the keyframes for the animation. Keyframes specify how the animation should change over time, in this case, from the starting state (<code>from</code>) to the ending state (<code>to</code>).</li>
<li><strong><code>rotation</code></strong>: This is the name given to the animation, and it will be used to reference the animation when applying it to elements using the <code>animation</code> property.</li>
<li><strong><code>from</code></strong> and <strong><code>to</code></strong>: These define the initial and final states of the animation. In the <code>from</code> state, the element has a rotation of 0 degrees around the X-axis, meaning it starts with no rotation. In the <code>to</code> state, the element is rotated 360 degrees, completing one full rotation, around the X-axis and/or Y-axis.</li>
<li><strong><code>transform</code></strong>: The <code>transform</code> property is used to apply a specific transformation to the element. In rotation animations, (the specific transformation applied can vary, such as rotating, scaling, or skewing the element.) it enables the element to change its orientation.</li>
</ul>
<h5 id="transform-rotatey">transform: rotateY()</h5>
<p>In the following CSS animation, named <code>rotation</code> , our animation starts from a rotation of 0 degrees (<code>from</code>) and smoothly transitions to a 360-degree rotation (<code>to</code>) around the Y-axis.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* ANIMATION */</span></span>
<span class="line"><span style="color:#F97583">@keyframes</span><span style="color:#FFAB70"> rotation</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#B392F0">  from</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateY</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  to</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateY</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">360</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/flipping-card-infinite-animation-axisy.gif" alt="This image shows the infinite flipping card animation around the axis-Y. We set the @keyframes rotation {
from {
transform: rotateY(0deg);
}
to {
transform: rotateY(360deg);
}
}" style="max-width:42%" class="img-narrow"></p>
<h5 id="transform-rotatex">transform: rotateX()</h5>
<p>This CSS animation, named <code>rotation</code> rotates the element around its X-axis. It starts (<code>from</code>) with no rotation (0 degrees) and smoothly completes (<code>to</code>) a full 360-degree rotation.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* ANIMATION */</span></span>
<span class="line"><span style="color:#F97583">@keyframes</span><span style="color:#FFAB70"> rotation</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#B392F0">  from</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  to</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">360</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/flipping-card-infinite-animation-axisx.gif" alt="transform: rotateX() css property. This image shows the infinite flipping card animation around the axis-X. We set the @keyframes rotation {
from {
transform: rotateX(0deg);
}
to {
transform: rotateX(360deg);
}
}" style="max-width:42%" class="img-narrow"></p>
<p>We have the capability to create rotations along <strong>both</strong> the Y and X axis at the same time.</p>
<h5 id="transform-rotatex-rotatey">transform: rotateX() rotateY()</h5>
<p>In this CSS animation named <code>rotation</code> the element is rotated in both the X and Y axes. It starts (<code>from</code>) with no rotation (0 degrees in both axes) and gradually complete (<code>to</code>) a full 360-degree rotation in both the X and Y axes. This animation can create a complex spinning effect that involves rotations in multiple directions. Cool huh!! 😎</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* ANIMATION */</span></span>
<span class="line"><span style="color:#F97583">@keyframes</span><span style="color:#FFAB70"> rotation</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#B392F0">  from</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">rotateY</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  to</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">360</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">rotateY</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">360</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/flipping-card-infinite-animation-axisy-axisx.gif" alt="transform: rotateX() rotate(Y) css property. This image shows the infinite flipping card animation around the axis-X and axis-Y. We set the @keyframes rotation {
from {
transform: rotateX(0deg) rotateY(0deg);
}
to {
transform: rotateX(360deg) rotateY(360deg);
}
}" style="max-width:42%" class="img-narrow"></p>
<h3 id="what-to-avoid-when-making-a-css-flipping-card-effect-animation">What to avoid when making a CSS flipping card effect animation<a class="heading-anchor" href="#what-to-avoid-when-making-a-css-flipping-card-effect-animation" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>As a reminder, it’s important to ensure that our animation transitions smoothly. To achieve a complete rotation, we must rotate <code>(from)</code> 0 degrees <code>(to)</code> 360 degrees. In the provided animation code, the <code>@keyframes</code> specifies a rotation of <code>160deg</code> for both the X and Y axes. Because 160 degrees stops short of a half turn, the card never reaches a face-on position before the animation loops, so it abruptly snaps back to its initial position, giving it a characteristic stop-and-return appearance. To achieve a more natural and realistic flipping effect, we need to ensure a complete 360-degree rotation or a half 180-degree rotation.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* ANIMATION */</span></span>
<span class="line"><span style="color:#F97583">@keyframes</span><span style="color:#FFAB70"> rotation</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#B392F0">  from</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">rotateY</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  to</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">160</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">rotateY</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">160</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/flipping-card-infinite-animation-what-to-avoid.gif" alt="This image shows the flipping card effect animation around the axis-Y and axis-X. We set the @keyframes rotation {
from {
transform: rotateX(0deg) rotateY(0deg);
}
to {
transform: rotateX(160deg) rotateY(160deg);
}
}" style="max-width:42%" class="img-narrow"></p>
<p>🌼 Hope you found my post interesting and helpful.
Thanks for being here! 🌼</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-make-a-css-flipping-card-animation-on-hover/">CSS Flip Card Animation on Hover</a></li>
<li><a href="/make-amazing-css-2d-card-with-flipping-animation-on-hover/">CSS Flip Card with Two Sides</a></li>
<li><a href="/keyframes-in-css-explained-make-your-animations-stand-out/">CSS Keyframes Animation Explained</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>CSS Motion: transform, transition, animation</title>
      <link>https://littlecodingthings.com/static-vs-dynamic-design-with-css-from-stillness-to-action/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/static-vs-dynamic-design-with-css-from-stillness-to-action/</guid>
      <pubDate>Fri, 29 Aug 2025 09:45:00 GMT</pubDate>
      <description>What transform, transition, animation and @keyframes each do in CSS, and every value they take, explained in plain English without code.</description>
      <category>Thoughts &amp; Theory</category>
      <content:encoded><![CDATA[<p>CSS in motion! Another perfect title for this post, as CSS is no longer just a language to style static pages, but also to elevate them with animations. CSS entered a new era and has grown into a clever tool that brings digital interfaces to life through movement. It began to shine, showing its full potential and ultimately becoming part of the experience, not just the look.</p>
<h2 id="css-properties-for-movement">CSS properties for movement<a class="heading-anchor" href="#css-properties-for-movement" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Now, time to focus on where CSS credits its upgrade. Utilizing the following properties: <a href="/how-to-effectively-use-css-transform-scale-on-hover/"><code>transform</code></a>, <code>transition</code>, <code>animation</code> and <a href="/keyframes-in-css-explained-make-your-animations-stand-out/"><code>@keyframes</code></a>, elements can <strong>scale</strong>, <strong>slide</strong>, <strong>fade</strong>, <strong>spin</strong> and <strong>move</strong> through time all without a single line of JavaScript. Today, we’ll focus on understanding how these properties create such amazing visual feedback. We’ll take a step back from the code and examine these features from a more theoretical perspective: what they mean, how they influence behavior, and why they play such a crucial role in modern design.
So, let’s zoom in! 🧐</p>
<h2 id="transform-css-property">Transform CSS property<a class="heading-anchor" href="#transform-css-property" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>It applies <strong>2D</strong> or <strong>3D</strong> transformations 🛠 to an element. It can change the <strong>size</strong>, <strong>rotation</strong>, <strong>position</strong>, and <strong>shape</strong>.
<strong>Values:</strong></p>
<ul>
<li><code>scale()</code>: Resize elements – making them smaller or bigger depending on our preferences (use <strong>unitless numbers</strong>).</li>
<li><code>skew()</code>: Slant elements (use <strong>deg,</strong> which stands for degrees).</li>
<li><code>translate()</code>: Move elements (use length units like: <strong>%</strong>, <strong>px</strong>, <strong>rem,</strong> etc.).</li>
<li><code>rotate()</code>: Spin elements (use <strong>deg</strong>, like skew).</li>
</ul>
<p>📌 Depending on our needs and preferences, we are free to make combinations with the above values.</p>
<ul>
<li><code>perspective()</code>: Creates a 3D effect, giving the elements a sense of depth.</li>
<li><code>matrix()</code>: Creates 2D transformations. It provides a streamlined approach for applying scaling, skewing, translation, and rotation through a unified matrix. (a mathematical representation – <strong>transform: matrix(a, b, c, d, e,</strong> <strong>f</strong>) – that combines the first three transformations into a single matrix. If you want to include rotation as well, you would replace <code>a</code>, <code>b</code>, <code>c</code>, and <code>d</code> with the appropriate cosine and sine values for the desired rotation angle, while keeping <code>e</code> and <code>f</code> for translation.)</li>
</ul>
<h2 id="transition-css-property">Transition CSS property<a class="heading-anchor" href="#transition-css-property" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>It <strong>animates changes</strong> in property values over time ⏳ and <strong>smoothens the transition</strong> between two stages (e.g. on hover, focus)
<strong>Values:</strong></p>
<ul>
<li><code>transition-property</code>: What property will animate (e.g. <strong>transform</strong>, <strong>opacity</strong>)</li>
<li><code>transition-duration</code>: How much time does the transition take to complete (e.g. <strong>0.4s</strong>, <strong>s</strong> stands for seconds, we are free to use <strong>ms</strong> too, for milliseconds)</li>
<li><code>transition-timing-function</code>: Define the speed curve (<strong>ease</strong>, <strong>linear</strong>, <strong>ease-in</strong>, <strong>ease-out</strong>, <strong>ease-in-out</strong>)</li>
<li><code>transition-delay</code>: The time you wait before an animation starts (<strong>s</strong> and <strong>ms</strong>, similar to <code>transition-duration</code>). Its default value is <strong>0s</strong>, which means the transition will start instantly.</li>
</ul>
<h2 id="the-keyframes-css-at-rule">The @keyframes CSS at-rule<a class="heading-anchor" href="#the-keyframes-css-at-rule" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Define intermediate states of an animation 📽 series. Breaks the animation into episodes 🎬, like “first episode, look like this,” “second episode, change to this,” “third episode, change to that,” and “final episode, finish like that.” Each episode represents a point in the timeline where the property-value changes (opacity, rotation, color, etc.).
<strong>Values:</strong></p>
<ul>
<li><code>from</code> / <code>to</code> : Timeline positions</li>
<li>Percentages <code>%</code> : Timeline positions</li>
</ul>
<p>📌 Each one represents a <strong>property-value pair</strong> that defines the appearance at a specific moment</p>
<h2 id="animation-css-property">Animation CSS property<a class="heading-anchor" href="#animation-css-property" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>It runs 🎞 a full animation based on the <code>@keyframes</code> you have defined. Unlike the transition we mentioned above, which moves from one point to another, animations can have many points ⏱ and follow more complex timing rules.
<strong>Values:</strong></p>
<ul>
<li><code>name</code>: the identifier of the @keyframes rule</li>
<li><code>duration</code>: for how long it moves</li>
<li><code>time-function</code>: how the speed flows
<ul>
<li><strong><em>ease</em></strong>: it gives a smooth motion, starts slow, continues faster, and ends slow again (which is the <em>default value</em>)</li>
<li><strong><em>linear</em></strong>: it has the same speed all the way</li>
<li><strong><em>ease-in</em></strong>: it starts slow, then it speeds up</li>
<li><strong><em>ease-out</em></strong>: it starts fast, then it slows down (Suitable for hover effects 😎)</li>
<li><strong><em>ease-in-out</em></strong>: starts slow, in the middle speeds up, then slows down again</li>
</ul>
</li>
<li><code>delay</code>: if the animations begin immediately or with a delay
<ul>
<li>a <strong><em>value of</em> <code>0s</code></strong> (seconds) indicates it starts as soon as it’s applied (which is the <em>default value</em>)</li>
<li>a <strong><em>positive value</em></strong> that it will start after a set amount of time (e.g. <code>2s</code>, which means it will start 2 seconds later)</li>
<li>a <strong><em>negative value</em></strong> that starts straightforward but acts like it has already begun (e.g. <code>-2s</code> the animation won’t wait — it’ll jump in as if it had already been playing for 2 seconds. This can be very helpful if you want animations to be already in motion when the page loads. 😎)</li>
</ul>
</li>
<li><code>iteration-count</code>: how many times to repeat (<strong>infinite</strong>, <strong>1</strong>, <strong>2</strong>, etc)</li>
<li><code>direction</code>: in which direction the animation moves
<ul>
<li><em><strong>normal</strong></em> ➡ the animation moves forward (which is the <em>default value</em>)</li>
<li><em><strong>reverse</strong></em> ⬅ the animation moves backward</li>
<li><em><strong>alternate</strong></em> ➡ ⬅ first forward, then backward</li>
<li><em><strong>alternate-reverse</strong></em> ⬅ ➡ first backward, then forward, alternating from there</li>
</ul>
</li>
<li><code>fill-mode</code>: shows how the element should look like before the animation starts or after it ends. You have the option to freeze the first or last frame so it doesn’t snap back (➡ <strong>forwards</strong>, ⬅ <strong>backwards</strong>). The default value is <em><strong>none</strong></em>, which means it does not apply any styles to the elements.</li>
<li><code>play-state</code>: control if the animation is running or paused, like play ▶ or pause ⏸ buttons (<strong>running</strong>, <strong>paused</strong>)</li>
</ul>
<p>📌 For an animation to actually play, we need to utilize only the: <code>animation-name</code>, <code>animation-duration</code> and the <code>@keyframes</code> rule. All the other CSS properties are optional.</p>
<p>When creating content for the web, even the smallest detail can significantly alter how something appears. The experience of bringing elements to life is amazing! It doesn’t need to be dramatic or complex. A simple yet well-structured and strategically placed change at the right moment can make everything more connected, useful and realistic.</p>
<p>🌼 Hope you found my post interesting and helpful.
Thanks for being here! 🌼</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-css-became-powerful-with-animations/">How CSS Became So Powerful with Animations</a></li>
<li><a href="/keyframes-in-css-explained-make-your-animations-stand-out/">CSS Keyframes Animation Explained</a></li>
<li><a href="/how-to-effectively-use-css-transform-scale-on-hover/">CSS Scale on Hover with transform</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>CSS Flip Card Animation on Hover</title>
      <link>https://littlecodingthings.com/how-to-make-a-css-flipping-card-animation-on-hover/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-make-a-css-flipping-card-animation-on-hover/</guid>
      <pubDate>Fri, 22 Aug 2025 08:02:00 GMT</pubDate>
      <description>Flip a card on hover with transform: rotateY() and a transition — around X, around Y or both, and how to make it flip back on hover-out.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Greetings! Today, I’m excited to walk you through the steps of crafting an amazing CSS flipping card animation that will activate when the user hovers over it. By following my detailed guidance, you’ll learn how to create a stunning animated card that will grab the attention of your viewers and enhance the overall appearance of your website. So, don’t miss out! 😉</p>
<p>Let’s focus on making this unique animation!</p>
<h2 id="css-flipping-card-animation-on-hover">CSS Flipping card animation on hover<a class="heading-anchor" href="#css-flipping-card-animation-on-hover" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The provided HTML and SCSS (Sass) code creates a flip card that moves along the <strong>Y and X axis</strong>. The X-axis and Y-axis are two lines that cross each other. They’re used to define the location of a point in a two-dimensional space.</p>
<p>Let’s break down the code step by step:</p>
<h3 id="html-structure">HTML structure<a class="heading-anchor" href="#html-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>To start, let’s focus on the <a href="/most-useful-html-elements-for-maximizing-better-results/" title="HTML">HTML</a> structure. We begin by creating a parent container with the class <code>flip-wrapper</code>. This container serves as the parent for our captivating animation. Inside this wrapper, we have a child element with the <code>.flip-card</code> class. This particular element is where our animation will take place.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"flip-wrapper"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"flip-card"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h3 id="css-basic-structure">CSS basic structure<a class="heading-anchor" href="#css-basic-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>In our <a href="/how-to-work-with-css-syntax-the-correct-way/" title="CSS">CSS</a> code snippet, we start by setting the <code>background-color</code> of the entire page to a deep shade of dark blue (#213450).</p>
<p>Moving on to the <code>.flip-wrapper</code> container, we specify its dimensions, giving it a fixed <code>width</code> and <code>height</code> of 300 pixels. To create a circular or rounded appearance, we apply <code>border-radius</code>. It’s worth noting that, if desired, you can leave the dimensions as is to maintain a square 🟪 shape. I chose this rounded 🟣 design because it makes it easier for us to observe the effect we’re aiming for. 😉</p>
<p>Next, we focus on the <code>.flip-card</code> element. We set its <code>width</code> and <code>height</code> to 100% to ensure it covers the entire available space. We also enhance its visual appeal with a soothing pastel purple (lavender) <code>background-color</code> and a subtle gray shadow effect. To maintain the circular theme, we add the inherit value to <code>border-radius</code> property.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#213450</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* dark blue */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.flip-wrapper</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#B392F0">  .flip-card</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#e1b6ea</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* lavender */</span></span>
<span class="line"><span style="color:#79B8FF">    box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 30</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inherit</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>This is what’s visible on our screen at the moment.</p>
<p><img src="/flipping-card.webp" alt="This image shows a levander cyclic shape. We will use it as our flipping card." style="max-width:28%" class="img-narrow"></p>
<h3 id="ways-to-add-the-hover-effect">Ways to add the hover effect<a class="heading-anchor" href="#ways-to-add-the-hover-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>For our effect to function as intended we have to work with both the parent and the child element. We begin with the parent element where we apply the <code>:hover</code> effect and change the cursor to a <code>pointer</code> 👆. You can check out all the <a href="https://www.w3schools.com/cssref/pr_class_cursor.php" title="CSS cursor styles">CSS cursor styles</a> and pick the one that suits you best. 🤗</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.flip-wrapper</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">    cursor</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pointer</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/flipping-card-cursor-pointer.webp" alt="This image shows a levander cyclic shape with a pointer (hand) cursor on top." style="max-width:28%" class="img-narrow"></p>
<p>Next, we’ll move on to our child element. Here, we set the <code>transform</code> CSS property to <strong>rotateY</strong> and specify the degree (<code>deg</code>) of rotation we desire.</p>
<p>Afterward, we’ll define the <code>transition</code> CSS property. We can use it in two ways. We add it to the <code>:hover</code> or we can add it directly to the <code>.flip-card</code> class. In the first case, the effect works only when you hover in. In the second case, the effect works when you hover in, but when you hover out it turns back to its original position. Then we set the <code>transform</code> value and specify the duration in seconds (<code>s</code>). In our case, I’ve chosen 8 seconds to make the effect slow and easily observable. 😉</p>
<h4 id="transform-rotatey">transform: rotateY()<a class="heading-anchor" href="#transform-rotatey" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<h5 id="hover-in">hover-in</h5>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.flip-wrapper</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#B392F0">    .flip-card</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">      ...</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateY</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">180</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">      transition</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transform</span><span style="color:#79B8FF"> 8</span><span style="color:#F97583">s</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/hover-in-axisy.webp" alt="CSS flipping card animation on hover. This gif shows a levander cyclic shape which rotates along the Y axis when we hover over it." style="max-width:36%" class="img-narrow"></p>
<h5 id="hover-in-out">hover-in-out</h5>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.flip-wrapper</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#B392F0">  .flip-card</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#79B8FF">    transition</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transform</span><span style="color:#79B8FF"> 8</span><span style="color:#F97583">s</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#B392F0">    .flip-card</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateY</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">180</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/hover-in-out-axisy.webp" alt="CSS flipping card animation on hover. This gif shows a levander cyclic shape which rotates along the Y axis when we hover over it. It returns to its initial position only when we hover out." style="max-width:36%" class="img-narrow"></p>
<h4 id="transform-rotatex">transform: rotateX()<a class="heading-anchor" href="#transform-rotatex" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p>We do the same, but this time along <strong>axisX</strong>.</p>
<h5 id="hover-in-1">hover-in</h5>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.flip-wrapper</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#B392F0">    .flip-card</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">      ...</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">360</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">      transition</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transform</span><span style="color:#79B8FF"> 8</span><span style="color:#F97583">s</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/flipping-card-hover-in-axisx.webp" alt="CSS flipping card animation on hover. This gif shows a levander cyclic shape which rotates along the X axis when we hover over it." style="max-width:36%" class="img-narrow"></p>
<h5 id="hover-in-out-1">hover-in-out</h5>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.flip-wrapper</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#B392F0">  .flip-card</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#79B8FF">    transition</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transform</span><span style="color:#79B8FF"> 8</span><span style="color:#F97583">s</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#B392F0">    .flip-card</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">360</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/flipping-card-hover-in-out-axisx.webp" alt="This gif shows a levander cyclic shape which rotates along the X axis when we hover over it. It returns to its initial position only when we hover out." style="max-width:36%" class="img-narrow"></p>
<p>We have the capability to create rotations along <strong>both</strong> the Y and X axes at the same time.</p>
<h4 id="transform-rotatex-rotatey">transform: rotateX() rotateY()<a class="heading-anchor" href="#transform-rotatex-rotatey" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<h5 id="hover-in-2">hover-in</h5>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.flip-wrapper</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#B392F0">    .flip-card</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">      ...</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">180</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">rotateY</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">180</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">      transition</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transform</span><span style="color:#79B8FF"> 8</span><span style="color:#F97583">s</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/flipping-card-hover-in-both-axis-x-y.webp" alt="This gif shows a levander cyclic shape which rotates along both the X and Y axis when we hover over it." style="max-width:36%" class="img-narrow"></p>
<h5 id="hover-in-out-2">hover-in-out</h5>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.flip-wrapper</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#B392F0">  .flip-card</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#79B8FF">    transition</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transform</span><span style="color:#79B8FF"> 8</span><span style="color:#F97583">s</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#B392F0">    .flip-card</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">180</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">rotateY</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">180</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/flipping-card-hover-in-out-both-axisx-y.webp" alt="This gif shows a levander cyclic shape which rotates along both the X and Y axis when we hover over it. It returns to its initial position only when we hover out." style="max-width:36%" class="img-narrow"></p>
<p>🌼 Hope you found my post interesting and helpful.
Thanks for being here! 🌼</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-make-a-css-infinite-flipping-card-animation/">Infinite CSS Flip Card Animation</a></li>
<li><a href="/make-amazing-css-2d-card-with-flipping-animation-on-hover/">CSS Flip Card with Two Sides</a></li>
<li><a href="/how-to-effectively-use-css-transform-scale-on-hover/">CSS Scale on Hover with transform</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How to Type the Copyright Symbol on Mac</title>
      <link>https://littlecodingthings.com/how-to-do-the-copyright-symbol-on-mac/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-do-the-copyright-symbol-on-mac/</guid>
      <pubDate>Wed, 13 Aug 2025 07:10:00 GMT</pubDate>
      <description>Type the copyright symbol on a Mac with Option + G. Plus the Character Viewer fallback and shortcuts for ™, ®, degree and section symbols.</description>
      <category>Setup &amp; Tools</category>
      <content:encoded><![CDATA[<p>If you’re wondering <strong>how to type the copyright symbol on a Mac</strong>, the solution is quick and easy. Mac keyboards come with built-in shortcuts for special characters, including the copyright symbol.</p>
<h2 id="why-use-the-copyright-symbol">Why use the copyright symbol?<a class="heading-anchor" href="#why-use-the-copyright-symbol" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The <strong>copyright symbol ©</strong> shows that your work is protected by copyright law. You can put it in blog posts, documents, or any other type of creative work. It shows people that your work belongs to you.</p>
<p>Some people also add the year and their name next to it, for example:</p>
<p><strong>© 2025 John Doe</strong></p>
<p>This makes it even clearer who owns the content and when it was created. However, the symbol by itself may not be enough to fully protect your rights in all situations — it’s best to include clear terms and conditions for your website or publications, and seek professional legal advice if you need comprehensive protection.</p>
<h2 id="typing-the-copyright-symbol-on-macos"><strong>Typing the Copyright Symbol on macOS</strong><a class="heading-anchor" href="#typing-the-copyright-symbol-on-macos" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>To type the <strong>©</strong> symbol on a Mac, simply press:</p>
<p><strong><code>Option (⌥) + G</code></strong></p>
<p>That’s all you need to do! This shortcut works across most apps on macOS — whether you’re writing in Pages, Word, Google Docs, or even in your browser.</p>
<p>If you are new to Mac and do not know the Option key: it is next to the Command (⌘) key. On most keyboards, there is one Option key on the left side and one on the right side.</p>
<p>If the shortcut mentioned above <strong>doesn’t work</strong>, you can use the <strong>Character Viewer</strong>:</p>
<ul>
<li>Press <strong>Control</strong> + <strong>Command</strong> + <strong>Space</strong></li>
<li>Search for “copyright”</li>
<li>Double-click the symbol to insert it.</li>
</ul>
<h2 id="related-tips-typing-other-special-symbols-on-mac">Related Tips: Typing Other Special Symbols on Mac<a class="heading-anchor" href="#related-tips-typing-other-special-symbols-on-mac" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Mac has shortcut for many symbols. There are some you might also like:</p>
<ul>
<li><strong>Trademark</strong> (™) – Press <code>Option (⌥) + 2</code></li>
<li><strong>Registered Trademark (®)</strong> — Press <code>Option (⌥) + R</code></li>
<li><strong>Degree (°)</strong> — Press <code>Shift + Option (⌥) + 8</code></li>
<li><strong>Ellipsis (…)</strong> — Press <code>Option (⌥) + ;</code></li>
<li><strong>Section (§)</strong> — Press <code>Option (⌥) + 6</code></li>
</ul>
<p>These shortcuts work almost everywhere on macOS. If you forget them, you can either open the Character Viewer and search for the symbol you want or bookmark this post.</p>
<h2 id="extra-tips-for-mac-beginners">Extra tips for Mac beginners<a class="heading-anchor" href="#extra-tips-for-mac-beginners" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>When I first switched from Ubuntu Linux to macOS, I felt a bit lost. Many things were different. On Linux, I used different key combinations for special characters, and sometimes I had to copy and paste them. On Mac, once I learned the shortcuts, my work became faster. You might be in the same situation — maybe not from Ubuntu, but perhaps you are coming from Windows? Or maybe you are just a newcomer to the computer world.</p>
<p>Regardless, these simple, <strong>everyday</strong> <strong>shortcuts</strong> might also help you:</p>
<ul>
<li><strong>Command + C</strong> to copy</li>
<li><strong>Command + V</strong> to paste</li>
<li><strong>Command + Z</strong> to undo</li>
<li><strong>Command + Shift + 4</strong> to take a screenshot of a selected area</li>
</ul>
<h2 id="but-option--g-doesnt-do-anything-on-my-mac-">“But Option + G doesn’t do anything on my Mac!” 😩<a class="heading-anchor" href="#but-option--g-doesnt-do-anything-on-my-mac-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>If you pressed it and got nothing — or got a different character entirely — you’re not doing it wrong. <strong>These shortcuts belong to your keyboard layout, not to macOS.</strong></p>
<p>The Option key doesn’t have a fixed meaning. It switches your keyboard to a second, hidden layer of characters, and what sits on that layer is decided by the input source you’re using. The shortcuts in this post are the ones on the standard <strong>U.S. / ABC</strong> layout. Switch to a British, German or Greek layout and the same keys produce different symbols.</p>
<p>There’s a lovely way to see this for yourself rather than guessing. Open <strong>System Settings → Keyboard</strong>, turn on the input menu in the menu bar, then choose <strong>Show Keyboard Viewer</strong> from that menu. An on-screen keyboard appears — and when you hold down <strong>Option</strong>, every key relabels itself to show what it will actually type.</p>
<p>Hold Option and look for the ©. Whatever key it’s sitting on is your answer, whichever layout you’re using. That one trick replaces every shortcut list on the internet, this one included.</p>
<p>Also worth knowing: the near-miss almost everyone tries first is <strong>Option + C</strong>, which on the U.S. layout gives you <strong>ç</strong>, not ©. If that’s what you’ve been getting, you’re one key away.</p>
<h2 id="teach-your-mac-to-do-it-for-you-️">Teach your Mac to do it for you ⌨️<a class="heading-anchor" href="#teach-your-mac-to-do-it-for-you-️" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>If you type © often enough to be reading this, stop memorising and let macOS handle it. <strong>Text Replacement</strong> turns any string you choose into any character you like:</p>
<ol>
<li>Open <strong>System Settings → Keyboard</strong>, then <strong>Text Replacements</strong>.</li>
<li>Click <strong>+</strong>.</li>
<li>Under <em>Replace</em>, type something you’d never write by accident — <code>(c)</code> works nicely.</li>
<li>Under <em>With</em>, paste ©.</li>
</ol>
<p>Now typing <code>(c)</code> anywhere becomes © as you go. The best part is that these replacements sync through iCloud, so the shortcut you just made on your Mac also works on your iPhone and iPad — which is handy, because there’s no Option key to press over there.</p>
<p>The same trick works for anything fiddly you type repeatedly: <code>--em</code> for an em dash, <code>(tm)</code> for ™, your email address behind two keystrokes.</p>
<h2 id="typing--in-html-and-css-">Typing © in HTML and CSS 👨‍💻<a class="heading-anchor" href="#typing--in-html-and-css-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Since a fair few of us are here to put a copyright line in a website footer, it’s worth knowing you have options beyond the keyboard.</p>
<p>In HTML, all three of these render the same character:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span><span style="color:#79B8FF">&#x26;copy;</span><span style="color:#E1E4E8"> 2026 Little Coding Things&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>© 2026 Little Coding Things&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span><span style="color:#79B8FF">&#x26;#xA9;</span><span style="color:#E1E4E8"> 2026 Little Coding Things&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><code>&#x26;copy;</code> is the named entity, <code>&#x26;#169;</code> is the decimal code, and <code>&#x26;#xA9;</code> is the hexadecimal version of the same Unicode code point — <strong>U+00A9</strong>.</p>
<p>In CSS, when you want the symbol generated rather than written into the markup, use the escaped code point:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.footer::after</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"</span><span style="color:#79B8FF">\00A9</span><span style="color:#9ECBFF"> 2026 Little Coding Things"</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>And honestly? On any modern page you can simply paste the © character directly into your HTML. Entities exist for the days when encoding was unreliable; with a UTF-8 charset declared — which every modern framework does for you — the literal character is fine and is easier to read in the source.</p>
<h2 id="frequently-asked-questions">Frequently asked questions<a class="heading-anchor" href="#frequently-asked-questions" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<h3 id="whats-the-difference-between---and-">What’s the difference between ©, ™ and ®?<a class="heading-anchor" href="#whats-the-difference-between---and-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Very roughly: © is used for creative works like text, images, music and code. ™ and ® are for brand names and logos, with ® conventionally reserved for marks that have actually been registered. If any of it matters commercially, that’s a question for a lawyer rather than a keyboard shortcut post.</p>
<h3 id="how-do-i-type--on-an-iphone-or-ipad">How do I type © on an iPhone or iPad?<a class="heading-anchor" href="#how-do-i-type--on-an-iphone-or-ipad" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>There’s no Option key, so the neat route is the Text Replacement trick above — set it up once on your Mac and it syncs to your other devices through iCloud. On the iPhone itself, you’ll find the same setting under Settings → General → Keyboard → Text Replacement.</p>
<h3 id="how-do-i-type-the-copyright-symbol-on-windows">How do I type the copyright symbol on Windows?<a class="heading-anchor" href="#how-do-i-type-the-copyright-symbol-on-windows" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Hold <strong>Alt</strong> and type <strong>0169</strong> on the numeric keypad. It needs the separate number pad, not the row of numbers above the letters — which is why it catches out laptop users. Windows also has an emoji and symbol picker on <strong>Windows key + .</strong> that includes it.</p>
<h3 id="does-the--symbol-still-work-if-i-copy-and-paste-it">Does the © symbol still work if I copy and paste it?<a class="heading-anchor" href="#does-the--symbol-still-work-if-i-copy-and-paste-it" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Yes. It’s an ordinary Unicode character, so copying it from this page into your document, your code, or your Text Replacement setting works perfectly. There’s nothing special about typing it with a shortcut versus pasting it — you get the identical character either way.</p>
<h3 id="where-can-i-find-symbols-that-have-no-shortcut-at-all">Where can I find symbols that have no shortcut at all?<a class="heading-anchor" href="#where-can-i-find-symbols-that-have-no-shortcut-at-all" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong>Control + Command + Space</strong> opens the Character Viewer, which has everything — arrows, maths symbols, currency, emoji — with a search box. It’s layout-proof, so it’s also the reliable fallback when an Option shortcut isn’t working on your keyboard.</p>
<p>I’m a new Mac user and have been having questions about shortcuts, processes, and other little details in macOS since I switched from Ubuntu Linux. I started adding these posts to help me remember — and hopefully, they’ll help you too.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/macos-shortcuts-cheatsheet-for-new-users/">MacOS Shortcuts – Cheatsheet for New Users</a></li>
<li><a href="/how-to-close-a-full-screen-on-mac/">How to Close a Full Screen on Mac</a></li>
<li><a href="/how-to-install-homebrew-macos-for-beginners/">How to install Homebrew – MacOS for beginners</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How to Close a Full Screen on Mac</title>
      <link>https://littlecodingthings.com/how-to-close-a-full-screen-on-mac/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-close-a-full-screen-on-mac/</guid>
      <pubDate>Fri, 08 Aug 2025 07:47:00 GMT</pubDate>
      <description>Three ways to exit full screen on Mac: the green button, press and hold Esc, or Control + Command + F — plus what to do when an app won’t budge.</description>
      <category>Setup &amp; Tools</category>
      <content:encoded><![CDATA[<p>If you’re new to Mac, like I am, you might be wondering: <strong>How do I close full screen on Mac?</strong> Don’t worry, it’s very simple once you know how!</p>
<p>Here are <strong>three quick and easy methods</strong> you can use to exit full-screen mode on your Mac:</p>
<h2 id="a-use-the-green-button">A. Use the Green Button<a class="heading-anchor" href="#a-use-the-green-button" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Move your mouse to the top of the screen until you see the menu bar and the three window buttons (red, yellow, green) appear in the top-left corner of the window.</p>
<p>Click the <strong>green button</strong> to exit full screen and return to normal window size. You can also click it again if you want to go back into full screen.</p>
<figure><img src="/how-to-close-full-screen-on-mac-green-icon.webp" alt="How to Close Full Screen on Mac: Green icon on top left is for expanding/minimizing windows on mac." style="max-width:32%" class="img-narrow"><figcaption>The green icon is used to expand or minimize windows on a Mac.</figcaption></figure>
<p><strong>Tip:</strong> In macOS, the green button is not just for full screen — it’s also used to resize or tile windows. If you hold down the <strong>Option</strong> key while clicking, you can maximize the window without entering full screen.</p>
<h2 id="b-press-and-hold-esc">B. Press and Hold Esc<a class="heading-anchor" href="#b-press-and-hold-esc" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>In some apps, you can simply press and hold the Esc key to exit full screen. This works in many media apps, like QuickTime or YouTube, when viewed in Safari.</p>
<p>While this doesn’t work in every app, it’s worth trying. Often, when you move your mouse to the top of the screen, you might see a small message saying: <em>“To exit full screen, press and hold Esc.”</em></p>
<p>Hold <strong>Esc</strong> for about 3 seconds, and you should see the app switch back to windowed mode.</p>
<h2 id="c-keyboard-shortcut">C. Keyboard Shortcut<a class="heading-anchor" href="#c-keyboard-shortcut" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>For a faster method, press <strong>Control + Command + F</strong>. This shortcut works in most Mac apps and will toggle between full screen and windowed mode instantly.</p>
<p><strong>Tip:</strong> If you’re using a MacBook with the Touch Bar, you might see a dedicated “Exit Full Screen” button appear when you’re in full screen. Tapping it is the same as using the keyboard shortcut.</p>
<h2 id="when-full-screen-wont-exit">When Full Screen Won’t Exit<a class="heading-anchor" href="#when-full-screen-wont-exit" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>There could be a case that your app may not respond to the methods mentioned above. In this case, try pressing <strong>Command + Tab</strong> to switch to another app, then close the full-screen one from the Dock.</p>
<p>You can also right-click the app icon in the Dock and select <strong>Options > Exit Full Screen</strong> if available.</p>
<p>If nothing works, press <strong>Command + Option + Esc</strong> to force quit the app, then reopen it in normal mode. This is rare, but it’s good to know if a program freezes while in full screen.</p>
<h2 id="why-full-screen-feels-so-weird-on-a-mac-">Why full screen feels so weird on a Mac 🤔<a class="heading-anchor" href="#why-full-screen-feels-so-weird-on-a-mac-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>This confused me for weeks after switching, so it’s worth explaining rather than just working around.</p>
<p>On a Mac, full screen isn’t “make this window bigger”. <strong>The app is moved into its own Space</strong> — its own virtual desktop, sitting to the right of everything else. That single fact explains all the odd behaviour:</p>
<ul>
<li>The menu bar and the Dock hide because nothing else lives in that Space. Move your pointer to the very top and the menu bar slides back down; move it to where the Dock lives and the Dock comes back.</li>
<li>Your other windows haven’t closed. They’re on a different desktop, one screen to the left.</li>
<li>Switching to another app with <strong>Command + Tab</strong> slides the whole screen sideways instead of putting a window on top, because macOS is walking you to a different Space.</li>
<li>You can’t drag a file from a Finder window onto your full-screen app, because the two are in different Spaces.</li>
</ul>
<p>Once you know that, the fix for “I can’t see anything else” is often not to exit full screen at all — it’s to move between Spaces.</p>
<h2 id="moving-between-full-screen-apps-without-leaving-full-screen">Moving between full-screen apps without leaving full screen<a class="heading-anchor" href="#moving-between-full-screen-apps-without-leaving-full-screen" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Three ways, all worth having in your fingers:</p>
<ul>
<li><strong>Swipe left or right with three or four fingers</strong> on the trackpad (which one depends on your trackpad settings).</li>
<li><strong>Control + Left Arrow / Control + Right Arrow</strong> to slide one Space over.</li>
<li><strong>Control + Up Arrow</strong> opens Mission Control and shows you every Space and window at once. Your full-screen apps appear as tiles along the top.</li>
</ul>
<p>Mission Control is also the quickest way to <em>undo</em> a mess: from there you can see exactly how many full-screen Spaces you’ve accidentally created.</p>
<h2 id="full-screen-vs-just-making-the-window-bigger">Full screen vs. just making the window bigger<a class="heading-anchor" href="#full-screen-vs-just-making-the-window-bigger" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Nine times out of ten, what people actually want isn’t full screen — it’s a big window that still behaves like a window. macOS has that, and it’s hiding behind the same green button:</p>
<ul>
<li><strong>Option-click the green button</strong> to zoom the window to fill the screen while keeping the menu bar, the Dock and your other windows exactly where they are.</li>
<li><strong>Hover</strong> over the green button instead of clicking and a menu drops down, with <strong>Full Screen</strong> as one option and window-tiling choices — left half, right half, and so on — as the others. On recent macOS versions that little menu is the fastest way to arrange two windows side by side.</li>
</ul>
<p>Same button, three completely different behaviours depending on whether you click, Option-click, or hover. That’s not obvious, and it’s not your fault for not knowing.</p>
<h2 id="frequently-asked-questions">Frequently asked questions<a class="heading-anchor" href="#frequently-asked-questions" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<h3 id="where-did-my-menu-bar-go-in-full-screen">Where did my menu bar go in full screen?<a class="heading-anchor" href="#where-did-my-menu-bar-go-in-full-screen" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Nowhere — it’s hidden. Move the pointer to the very top edge of the screen and it slides back into view, along with the red, yellow and green window buttons. It hides again the moment you move away.</p>
<h3 id="why-is-my-dock-missing-in-full-screen">Why is my Dock missing in full screen?<a class="heading-anchor" href="#why-is-my-dock-missing-in-full-screen" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Same reason. Push the pointer past the bottom edge of the screen (or whichever edge your Dock lives on) and hold it there for a second, and the Dock reappears.</p>
<h3 id="how-do-i-stop-an-app-from-opening-in-full-screen-every-time">How do I stop an app from opening in full screen every time?<a class="heading-anchor" href="#how-do-i-stop-an-app-from-opening-in-full-screen-every-time" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>macOS reopens apps in the state you left them. So exit full screen <em>first</em>, then quit the app with <strong>Command + Q</strong>. Next launch, it comes back as a normal window.</p>
<h3 id="can-i-take-a-screenshot-while-in-full-screen">Can I take a screenshot while in full screen?<a class="heading-anchor" href="#can-i-take-a-screenshot-while-in-full-screen" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Yes, and the shortcuts don’t change: <strong>Command + Shift + 3</strong> captures the whole screen, <strong>Command + Shift + 4</strong> lets you drag a selection, and <strong>Command + Shift + 5</strong> opens the screenshot toolbar with recording options. More of these in our <a href="/macos-shortcuts-cheatsheet-for-new-users/">macOS shortcuts cheatsheet</a>.</p>
<h3 id="does-control--command--f-work-in-every-app">Does Control + Command + F work in every app?<a class="heading-anchor" href="#does-control--command--f-work-in-every-app" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Apple’s own wording is “use or stop using the app in full screen, <strong>if supported by the app</strong>”. Most apps support it. A handful of games and older apps have their own idea of full screen, and those are the ones where press-and-hold <strong>Esc</strong> is your best bet instead.</p>
<h3 id="whats-the-difference-between-minimising-and-exiting-full-screen">What’s the difference between minimising and exiting full screen?<a class="heading-anchor" href="#whats-the-difference-between-minimising-and-exiting-full-screen" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Minimising (<strong>Command + M</strong>, or the yellow button) tucks the window down into the Dock and leaves it running. Exiting full screen returns it to a normal, resizable window on your main desktop. If a window has vanished entirely and you can’t find it, check the right-hand end of the Dock — it’s probably minimised down there.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/macos-shortcuts-cheatsheet-for-new-users/">MacOS Shortcuts – Cheatsheet for New Users</a></li>
<li><a href="/how-to-do-the-copyright-symbol-on-mac/">How to Do the Copyright Symbol on Mac</a></li>
<li><a href="/how-to-install-homebrew-macos-for-beginners/">How to install Homebrew – MacOS for beginners</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How to Install Postgres on MacOS</title>
      <link>https://littlecodingthings.com/how-to-install-postgres-on-macos/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-install-postgres-on-macos/</guid>
      <pubDate>Mon, 04 Aug 2025 06:00:00 GMT</pubDate>
      <description>Install PostgreSQL on macOS with Homebrew, run it as a background service, fix “command not found: psql”, and connect with the psql shell.</description>
      <category>Setup &amp; Tools</category>
      <content:encoded><![CDATA[<p>If you’re working on a Node.js project and run into errors like <code>ECONNREFUSED ::1:5432</code>, chances are PostgreSQL isn’t running — or it isn’t even installed. Here’s a quick guide to install postgres on macOS using <strong>Homebrew</strong>, the most reliable and straightforward method.</p>
<p>Before installing PostgreSQL, make sure you already have <strong>Homebrew</strong> installed on your Mac. Homebrew is the package manager we’ll be using to install and manage PostgreSQL.</p>
<p><strong>Don’t have Homebrew yet?</strong> No worries, we got you covered. Check out our guide: <a href="/how-to-install-homebrew-macos-for-beginners/">How to Install Homebrew on macOS</a>.</p>
<p>Once you’ve got Homebrew set up, you’re ready to continue.</p>
<h2 id="step-1-install-postgresql-via-homebrew">Step 1: Install PostgreSQL via Homebrew<a class="heading-anchor" href="#step-1-install-postgresql-via-homebrew" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>With Homebrew installed, adding PostgreSQL is easy:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">brew</span><span style="color:#9ECBFF"> install</span><span style="color:#9ECBFF"> postgresql</span></span></code></pre></div>
<p>If you want to install a specific version of postgres, e.g, version 17 type:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">brew</span><span style="color:#9ECBFF"> install</span><span style="color:#9ECBFF"> postgresql@17</span></span></code></pre></div>
<p><strong>Do the versioned one.</strong> <code>postgresql</code> is just an alias that Homebrew points at whatever the current major release is, so the command you run today and the command a teammate runs in six months can install different databases. And PostgreSQL major versions store their data in incompatible formats — 17 cannot read a cluster that 18 created. Pinning the version now saves you a genuinely annoying afternoon later.</p>
<p>If you’re not sure which one you ended up with:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">brew</span><span style="color:#9ECBFF"> list</span><span style="color:#79B8FF"> --versions</span><span style="color:#F97583"> |</span><span style="color:#B392F0"> grep</span><span style="color:#9ECBFF"> postgresql</span></span></code></pre></div>
<h2 id="step-2-start-the-postgresql-service">Step 2: Start the PostgreSQL Service<a class="heading-anchor" href="#step-2-start-the-postgresql-service" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Once installed, start PostgreSQL as a background service. Use the <strong>same name you installed</strong> — if you took the versioned advice above, that’s <code>postgresql@17</code>, not plain <code>postgresql</code>:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">brew</span><span style="color:#9ECBFF"> services</span><span style="color:#9ECBFF"> start</span><span style="color:#9ECBFF"> postgresql@17</span></span></code></pre></div>
<p>Get this wrong and Homebrew tells you <code>Formula postgresql not found</code>, which is a confusing error when you just watched PostgreSQL install successfully. It only means the service name doesn’t match the formula name.</p>
<p>To confirm it’s running:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">brew</span><span style="color:#9ECBFF"> services</span><span style="color:#9ECBFF"> list</span></span></code></pre></div>
<p>You should see something like:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>Name        Status   User       File</span></span>
<span class="line"><span>postgresql  started  your-name  Library/LaunchAgents/homebrew.mxcl.postgresql@17.plist</span></span></code></pre></div>
<hr>
<h2 id="step-3-confirm-the-installation">Step 3: Confirm the Installation<a class="heading-anchor" href="#step-3-confirm-the-installation" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Check that PostgreSQL is installed correctly:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>psql --version</span></span></code></pre></div>
<p><strong>psql</strong> is the interactive command-line tool when working with Postgres</p>
<p>Expected output:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>psql (PostgreSQL) 17.5 (Homebrew)</span></span></code></pre></div>
<p>In case you are getting a <code>command not found: psql</code> error you have to explicitly link it. For my example, in which i installed version 17, I just had to type</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">brew</span><span style="color:#9ECBFF"> link</span><span style="color:#9ECBFF"> postgresql@17</span><span style="color:#79B8FF"> --force</span></span></code></pre></div>
<p>By typing <code>psql --version</code> you should now see the postgreSQL you just installed.</p>
<h3 id="why-does-this-happen-at-all-">Why does this happen at all? 🧐<a class="heading-anchor" href="#why-does-this-happen-at-all-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Because the versioned formulas are <strong>keg-only</strong>. Homebrew installed everything correctly and then deliberately did <em>not</em> add it to your <code>PATH</code> — that’s how it lets <code>postgresql@17</code> and <code>postgresql@18</code> sit on the same machine without each one claiming the name <code>psql</code>.</p>
<p>So <code>zsh: command not found: psql</code> isn’t a failed install. It’s Homebrew waiting for you to say which version you meant.</p>
<p><code>brew link --force</code> is one answer. The other, which I prefer because it doesn’t touch Homebrew’s symlinks, is to put that one version on your <code>PATH</code> yourself:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#79B8FF">echo</span><span style="color:#9ECBFF"> 'export PATH="/opt/homebrew/opt/postgresql@17/bin:$PATH"'</span><span style="color:#F97583"> >></span><span style="color:#9ECBFF"> ~/.zshrc</span></span>
<span class="line"><span style="color:#79B8FF">source</span><span style="color:#9ECBFF"> ~/.zshrc</span></span></code></pre></div>
<p>That path is for Apple Silicon Macs. On an Intel Mac, Homebrew lives in <code>/usr/local</code> instead — run <code>brew --prefix</code> if you’re not sure which you have.</p>
<hr>
<h2 id="step-4-connect-to-postgresql">Step 4: Connect to PostgreSQL<a class="heading-anchor" href="#step-4-connect-to-postgresql" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>You can now open a PostgreSQL shell:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>psql postgres</span></span></code></pre></div>
<p>Or create your own database:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>createdb mydb</span></span>
<span class="line"><span>psql mydb</span></span></code></pre></div>
<hr>
<h2 id="step-5-optional-choosing-a-gui">Step 5 (Optional): Choosing a GUI<a class="heading-anchor" href="#step-5-optional-choosing-a-gui" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>If you prefer a graphical interface over the terminal, consider installing</p>
<ul>
<li><strong><a href="https://www.pgadmin.org/">pgAdmin</a></strong></li>
<li><strong><a href="https://www.jetbrains.com/datagrip/">Datagrip</a></strong></li>
<li><strong><a href="https://eggerapps.at/postico2/">Postico</a></strong></li>
<li><strong><a href="https://tableplus.com/">TablePlus</a></strong></li>
</ul>
<p>These tools make managing your databases even easier.</p>
<hr>
<h2 id="the-error-everyone-hits-role-postgres-does-not-exist-">The error everyone hits: <code>role "postgres" does not exist</code> 😤<a class="heading-anchor" href="#the-error-everyone-hits-role-postgres-does-not-exist-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>You install Postgres, you follow a tutorial written for Linux, you run something like <code>psql -U postgres</code>, and you get:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed:</span></span>
<span class="line"><span>FATAL:  role "postgres" does not exist</span></span></code></pre></div>
<p>Nothing is broken. There simply is no user called <code>postgres</code> on your Mac.</p>
<p>Here’s why. When Homebrew installs PostgreSQL it runs <code>initdb</code> for you, and <code>initdb</code> creates the superuser named after <strong>whoever ran it</strong> — which is your macOS account, not <code>postgres</code>. On a Linux server the install runs as a system user called <code>postgres</code>, so every tutorial written on Linux assumes that name exists. On your Mac, the superuser is you.</p>
<p>Which is exactly why <code>psql postgres</code> from Step 4 works: <code>postgres</code> there is the name of a <em>database</em> that ships with every cluster, and you’re connecting to it as yourself.</p>
<p>If some tool insists on the <code>postgres</code> role — plenty of Docker-flavoured tutorials and ORM configs do — just create it:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">createuser</span><span style="color:#79B8FF"> -s</span><span style="color:#9ECBFF"> postgres</span></span></code></pre></div>
<p><code>-s</code> makes it a superuser. Now both worlds are happy.</p>
<h2 id="when-brew-services-says-it-started-but-nothing-is-listening">When <code>brew services</code> says it started but nothing is listening<a class="heading-anchor" href="#when-brew-services-says-it-started-but-nothing-is-listening" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><code>ECONNREFUSED ::1:5432</code> after <code>brew services start</code> usually means the service died a second after launching. <code>brew services list</code> will show <code>error</code> rather than <code>started</code>.</p>
<p>Work through these in order:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">brew</span><span style="color:#9ECBFF"> services</span><span style="color:#9ECBFF"> restart</span><span style="color:#9ECBFF"> postgresql@17</span></span>
<span class="line"><span style="color:#B392F0">ls</span><span style="color:#E1E4E8"> $(</span><span style="color:#B392F0">brew</span><span style="color:#79B8FF"> --prefix</span><span style="color:#E1E4E8">)</span><span style="color:#9ECBFF">/var/log</span></span></code></pre></div>
<p>The second command shows you Homebrew’s log folder — there’s a <code>postgresql</code> log in there, and unlike <code>brew services</code>, it tells you the actual reason. The two you’ll most likely find:</p>
<ul>
<li><strong>A stale <code>postmaster.pid</code>.</strong> The Mac was force-restarted while Postgres was running and the lock file outlived the process. The log names the file; delete it and start the service again.</li>
<li><strong>A data directory built by a different major version.</strong> You installed <code>postgresql@18</code> over a cluster <code>initdb</code>-ed by 17. The log says so plainly, in the form of a version mismatch complaint.</li>
</ul>
<p>One more thing worth knowing about <code>ECONNREFUSED ::1:5432</code> specifically: <code>::1</code> is IPv6 localhost. If Postgres is definitely running and your app still can’t reach it, point your connection string at <code>127.0.0.1</code> instead of <code>localhost</code> and see if that fixes it. If it does, the problem was never the database — your app resolved <code>localhost</code> to IPv6 and Postgres was only listening on IPv4.</p>
<h2 id="useful-things-to-type-once-youre-inside-psql">Useful things to type once you’re inside <code>psql</code><a class="heading-anchor" href="#useful-things-to-type-once-youre-inside-psql" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The shell is fantastic once you know four commands, and completely opaque until then:</p>
<table>
<thead>
<tr>
<th scope="col">Command</th>
<th scope="col">What it does</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row"><code>\l</code></th>
<td>List every database</td>
</tr>
<tr>
<th scope="row"><code>\c mydb</code></th>
<td>Connect to a different database</td>
</tr>
<tr>
<th scope="row"><code>\dt</code></th>
<td>List tables in the current database</td>
</tr>
<tr>
<th scope="row"><code>\d users</code></th>
<td>Describe the <code>users</code> table</td>
</tr>
<tr>
<th scope="row"><code>\du</code></th>
<td>List roles (useful right after the error above)</td>
</tr>
<tr>
<th scope="row"><code>\q</code></th>
<td>Quit</td>
</tr>
</tbody>
</table>
<p>And yes — SQL statements need a semicolon. If you press return and get a prompt that ends in <code>-#</code> instead of <code>=#</code>, Postgres is still waiting for you to finish the statement.</p>
<h2 id="frequently-asked-questions">Frequently asked questions<a class="heading-anchor" href="#frequently-asked-questions" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<h3 id="how-do-i-stop-postgresql-on-macos">How do I stop PostgreSQL on macOS?<a class="heading-anchor" href="#how-do-i-stop-postgresql-on-macos" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">brew</span><span style="color:#9ECBFF"> services</span><span style="color:#9ECBFF"> stop</span><span style="color:#9ECBFF"> postgresql@17</span></span></code></pre></div>
<p>Use <code>brew services list</code> to confirm it’s stopped. If you don’t want it launching every time you log in, this is the command you want rather than uninstalling.</p>
<h3 id="what-is-the-default-username-and-password-for-postgres-on-a-mac">What is the default username and password for Postgres on a Mac?<a class="heading-anchor" href="#what-is-the-default-username-and-password-for-postgres-on-a-mac" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>The default user is <strong>your macOS username</strong>, and there is no password prompt for local connections on a fresh Homebrew cluster. You can set one from inside <code>psql</code> with <code>\password</code>. Nothing here is exposed to the internet by default, but the moment you do anything real with it, keep the credentials out of your code — see our <a href="/environment-variables-101-secure-your-secrets-like-a-pro/">guide to environment variables with dotenv</a>.</p>
<h3 id="what-port-does-postgresql-use">What port does PostgreSQL use?<a class="heading-anchor" href="#what-port-does-postgresql-use" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>5432, unless you changed it. If you also run Postgres in Docker, both will fight over that port and the loser is whichever one started second — that’s another common source of <code>ECONNREFUSED</code>.</p>
<h3 id="how-do-i-upgrade-to-a-newer-major-version">How do I upgrade to a newer major version?<a class="heading-anchor" href="#how-do-i-upgrade-to-a-newer-major-version" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Carefully, and not by accident. A new major cannot open the old version’s data directory, so installing <code>postgresql@18</code> next to your <code>postgresql@17</code> cluster does not migrate anything. The dependable route is to dump your databases with <code>pg_dump</code> (or <code>pg_dumpall</code>) <em>before</em> you switch, install the new version, and restore into it. Do the dump first — it’s the step people skip and then regret. If you’d rather not rely on remembering, a <a href="/what-is-a-cron-job-simple-guide-for-beginners/">cron job</a> can run that dump on a schedule for you.</p>
<h3 id="do-i-need-postgres-installed-locally-if-my-app-uses-a-hosted-database">Do I need Postgres installed locally if my app uses a hosted database?<a class="heading-anchor" href="#do-i-need-postgres-installed-locally-if-my-app-uses-a-hosted-database" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>No, and it can be simpler not to. If your app connects to a managed database, all you need locally is a connection string. Installing Postgres locally is worth it when you want to break things without breaking a deployed environment — which, when you’re learning, is most of the time.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-install-homebrew-macos-for-beginners/">How to install Homebrew – MacOS for beginners</a></li>
<li><a href="/how-to-install-npm-on-macos/">How to Install npm on MacOS</a></li>
<li><a href="/environment-variables-101-secure-your-secrets-like-a-pro/">Beginner’s Guide to Environment Variables with Dotenv</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>HTML for Blinking Text – Simple Copy &amp; Paste Code</title>
      <link>https://littlecodingthings.com/html-for-blinking-text-simple-copy-paste-code/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/html-for-blinking-text-simple-copy-paste-code/</guid>
      <pubDate>Fri, 25 Jul 2025 12:00:00 GMT</pubDate>
      <description>The HTML blink tag is obsolete and no longer works in any browser. Here is the CSS animation that recreates blinking text, ready to copy and paste.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>If you’re here, chances are you’re looking for <strong>HTML for Blinking Text</strong> — maybe you remember the old-school <code>&#x3C;blink></code> tag that used to make text flash or flicker on screen. It looked something like this:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#FDAEB7;font-style:italic">blink</span><span style="color:#E1E4E8">>This text will blink&#x3C;/</span><span style="color:#FDAEB7;font-style:italic">blink</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p>Unfortunately (or fortunately, depending on your view), the <code>&#x3C;blink></code> tag is now considered obsolete and is <a href="https://developer.mozilla.org/en-US/docs/Glossary/blink_element">no longer supported by modern browsers</a>.</p>
<p>Modern browsers no longer support <code>&#x3C;blink></code> because it was never officially standardized, causing serious accessibility issues. Visually impaired users, in particular, often rely on assistive technologies that don’t handle blinking content well. Plus, from a design standpoint, constant blinking can be distracting and overwhelming to users.</p>
<h2 id="blinking-text-using-html-and-css">Blinking Text Using HTML and CSS<a class="heading-anchor" href="#blinking-text-using-html-and-css" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>So how do you create blinking text today, in a way that’s clean, compliant, and works across all devices? That’s where HTML and CSS come in. With simple <a href="/keyframes-in-css-explained-make-your-animations-stand-out/">CSS animations powered by @keyframes</a>, you can replicate the blinking effect — only better.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">p</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"blinking"</span><span style="color:#E1E4E8">>This text will blink using CSS&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.blinking</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  animation</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">blink</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">s</span><span style="color:#79B8FF"> step-start</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">s</span><span style="color:#79B8FF"> infinite</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">@keyframes</span><span style="color:#FFAB70"> blink</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#B392F0">  50%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    opacity</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>This CSS-based method offers more flexibility than the old <code>&#x3C;blink></code> tag. You can control <strong>timing</strong>, <strong>opacity</strong>, <strong>color changes</strong>, or even trigger it on events like hover. Plus, it works across all modern browsers, making it a practical solution for attention-grabbing UI elements like warnings or notifications.</p>
<p>You can even combine it with other effects like scaling or background changes for more dynamic visuals. Whether you’re building a retro-style webpage or emphasizing urgent content, this is a reliable, modern solution.</p>
<p>Check this out in our codepen too — and if you want to drop a live demo like this one into your own site, here is <a href="/how-to-embed-codepen-in-a-wordpress-blog/">how to embed CodePen in a blog</a> without hitting the referer error.</p>
<p>See the Pen<a href="https://codepen.io/Little-Coding-Things/pen/azvZgmK">
Blinking Text</a> by Little Coding Things (<a href="https://codepen.io/Little-Coding-Things">@Little-Coding-Things</a>)
on <a href="https://codepen.io">CodePen</a>.</p>
<p>If you’re working on a project and still want that eye-catching flicker using CSS animation is the best and most future-proof way to implement HTML for Blinking Text. It’s responsive, accessible, and keeps your design up to today’s standards.</p>
<p>Want to take it to the next level? <a href="/how-to-make-a-blinking-animation-using-css/">Check out our post</a> on creating a blinking eyes animation using CSS!</p>]]></content:encoded>
    </item>
    <item>
      <title>The CSS text-shadow Property</title>
      <link>https://littlecodingthings.com/enhance-your-content-utilizing-the-css-text-shadow-property/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/enhance-your-content-utilizing-the-css-text-shadow-property/</guid>
      <pubDate>Fri, 25 Jul 2025 11:58:00 GMT</pubDate>
      <description>Five worked text-shadow examples — positive and negative offsets, stacked colors, and the blur value that ruins readability.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hello everybody! In the land of web design, the CSS text shadow property is like adding magic to your text. It helps you create elegant headings that command attention and, many times, make text easier to read. The <code>text-shadow</code> empowers designers to pass beyond the limits of ordinary with just a few lines of simple yet powerful code.</p>
<p>However, it’s essential to use it wisely, overdoing it can sometimes cause confusion and reading can end up difficult. Therefore, we must keep in mind that beyond styling, readability is also important. Always aim to strike a balance between appearance and clarity so our text is accessible to everyone.</p>
<h2 id="text-shadow-structure">Text shadow structure<a class="heading-anchor" href="#text-shadow-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>First things first! We’ll begin with the structure and break down its components:</p>
<p><img src="/text-shadow-css-property-analize-componets.webp" alt="The text-shadow syntax broken into offset-X, offset-Y, blur-radius and color" style="max-width:65%" class="img-narrow"></p>
<ul>
<li><strong>Offset-X and Offset-Y</strong>: They determine the <em>horizontal and vertical distances</em> of the shadow. When we use positive values, the shadow moves to the down and right. When we use negative values, the shadow moves to the top and left.</li>
<li><strong>Blur-radius</strong>: It specifies the <em>extent of blurring</em> for the shadow. A higher value creates a spread, while a lower value sharpens the shadow.</li>
<li><strong>Color</strong>: Here, we <em>set the color</em> of the shadow. All <a href="/what-you-need-to-know-about-css-color-methods/">color methods</a> are accessible (color names, hexadecimal codes, rgba and hsla values).</li>
</ul>
<p>If we don’t want to use a specific color, our shadow <strong>defaults to black</strong>.</p>
<p>Below, I have prepared some examples to make this amazing tool more understandable. I’ll use the charming “Pacifico” font with the text “Text Shadow” to showcase its capabilities. So, let the game begin!! 😃</p>
<h2 id="text-shadow-with-positive-values">Text shadow with positive values<a class="heading-anchor" href="#text-shadow-with-positive-values" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>In our first example, we use positive values and create a gray shadow 5 pixels to the bottom and right of our text. It has a blur radius of 5 pixels, giving it a softened appearance.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.text-shadow</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  text-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> gray</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/text-shadow-css-with-positive-values.webp" alt="A shadow of 5px 5px 5px gray" style="max-width:55%" class="img-narrow"></p>
<h2 id="text-shadow-with-negative-values">Text shadow with negative values<a class="heading-anchor" href="#text-shadow-with-negative-values" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Next, we create a gray shadow 5 pixels to the top and left of our text, using negative values. It has a blur radius of 5 pixels.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.text-shadow</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  text-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> -5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> gray</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/text-shadow-css-with-negative-values.webp" alt="A shadow of -5px -5px 5px gray" style="max-width:55%" class="img-narrow"></p>
<h2 id="text-shadow-with-colors">Text shadow with colors<a class="heading-anchor" href="#text-shadow-with-colors" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Nothing better than playing with colors!! 🌈 In that case, we add two vibrant colors: magenta and cyan, then finish our shadow with color gray. Cool hug!? 😎
As shown in the following code snippet, to create a repeating shadow with different colors, we must increase the pixels along both the X-axis and the Y-axis each time we add a new color.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.text-shadow3</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  text-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">4</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 4</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> cyan</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 6</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> gray</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/text-shadow-css-with-colors.webp" alt="A shadow of 2px 2px 2px magenta, 4px 4px 2px cyan, 6px 6px 5px gray" style="max-width:55%" class="img-narrow"></p>
<h2 id="text-shadow-with-high-blur-radius">Text shadow with high blur-radius<a class="heading-anchor" href="#text-shadow-with-high-blur-radius" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>⛔ In this example, we increase the blur, and we are able to notice that it is very, very important to keep blur-radius at low values, otherwise, our text appears a bit confusing with poor readability.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.text-shadow4</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  text-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> gray</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/text-shadow-css-with-high-blur.webp" alt="Ashadow of 5px 5px 20px gray" style="max-width:55%" class="img-narrow"></p>
<h2 id="text-shadow-with-high-values">Text shadow with high values<a class="heading-anchor" href="#text-shadow-with-high-values" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Finally, let’s get creative. By increasing the values at both the X-axis and Y-axis, we can widen the gap between the text and its shadow, achieving a more strongly marked visual effect.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.text-shadow</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  text-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">70</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> gray</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/text-shadow-css-with-high-values.webp" alt="A shadow of 70px 50px 5px gray" style="max-width:55%" class="img-narrow"></p>
<p>Whether a shadow type is “good” depends on your design goals. For bold, eye-catching text that stands on the page, this approach can be very effective. If you’re going for a more subtle or minimalistic design, you might opt for smaller offsets and blurs. It’s all about finding the balance that fits your overall design concept!</p>
<p>Utilizing the text shadow, you are not only creating a stylish effect, but you are also crafting an experience that users will remember. So, get playful when using it. Experiment! Let your creativity shine through! ✨ 🎉</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-box-shadow-works-made-simple/">How box-shadow Works (Made Simple)</a></li>
<li><a href="/css-colorful-text-crafting-vibrant-effects/">CSS Colorful Text – Crafting Vibrant Effects</a></li>
<li><a href="/css-water-drop-effect-how-to-make-text-look-wet-and-glossy-a-step-by-step-guide/">CSS Water Drop Effect on Text</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How To Build Stunning Rounded Text – Handy Tips</title>
      <link>https://littlecodingthings.com/how-to-build-stunning-rounded-text-handy-tips/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-build-stunning-rounded-text-handy-tips/</guid>
      <pubDate>Mon, 21 Jul 2025 12:12:00 GMT</pubDate>
      <description>Bend a line of text into a circle with one span per letter, absolute positioning and transform: rotate(). Full copy-ready coordinates.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Greetings, all! 😃 I’m excited to share an incredible CSS technique with you today. We’ll learn little by little how to create impressive and rounded text. This technique can give our text a unique and captivating appearance that stands out from the usual. Get ready to take your text to the next level! 🧨 ⚡</p>
<p>Are you interested in learning how to uplevel your typography? Stick around to explore the endless possibilities of CSS and take your website to new heights! Let the game 🌀 begin and happy designing! 😊</p>
<h2 id="html-structure">HTML structure<a class="heading-anchor" href="#html-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>To create a text that appears in a rounded effect we begin with the HTML structure. First, we need an <a href="/most-useful-html-elements-for-maximizing-better-results/" title="HTML">HTML</a> div with a specific class. Let’s call it <code>.wrapper</code>. This div will be the container where the text will be displayed. To achieve the desired effect, we also need to add a <code>span</code> element for each character we want to use. By doing so, it allows us to handle and move each character separately and create the shape we want. 😉</p>
<p>In our example, we will use 15 letters and a star, so we need to add 16 spans. Each span represents a character. You can see the code snippet below for a better understanding.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"wrapper"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character1"</span><span style="color:#E1E4E8">>I&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character2"</span><span style="color:#E1E4E8">>a&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character3"</span><span style="color:#E1E4E8">>m&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character4"</span><span style="color:#E1E4E8">>a&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character5"</span><span style="color:#E1E4E8">>r&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character6"</span><span style="color:#E1E4E8">>o&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character7"</span><span style="color:#E1E4E8">>u&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character8"</span><span style="color:#E1E4E8">>n&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character9"</span><span style="color:#E1E4E8">>d&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character10"</span><span style="color:#E1E4E8">>e&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character11"</span><span style="color:#E1E4E8">>d&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character12"</span><span style="color:#E1E4E8">>t&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character13"</span><span style="color:#E1E4E8">>e&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character14"</span><span style="color:#E1E4E8">>x&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character15"</span><span style="color:#E1E4E8">>t&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character16-emoticon"</span><span style="color:#E1E4E8">>⭐&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h2 id="css-structure">CSS structure<a class="heading-anchor" href="#css-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We move forward with the <a href="/how-to-work-with-css-syntax-the-correct-way/" title="CSS">CSS</a>. We begin by styling the wrapper HTML element with a <code>width</code> and <code>height</code> of 400 pixels. It will also have a purple <code>background-color</code>, an inset magenta shadow (the inset <code>box-shadow</code> is a clever idea 💡 to create a distinctive boundary inside our wrapper, which will help us later with the positioning), and a <code>border-radius</code> of 50%, giving it a completely round shape. Finally, the <code>flex</code> method will <a href="/how-to-center-in-css-using-different-ways/">perfectly align our text inside the wrapper</a>.</p>
<p>Next, we will apply some styling to the spans within the wrapper. They will have a <code>font-family: Arial</code> (we need a really distinct font), a <code>font-size</code> of 40 pixels, and will be colored in a yellowish shade (<code>#eddc42</code>).</p>
<p>🔖 Note that we won’t add spaces between characters since we will place them one by one. By avoiding spaces, we can achieve precise and accurate positioning, which allows for greater control and flexibility in our design.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.wrapper</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">400</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">400</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> magenta</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D"> span</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  font-family</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">Arial</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#eddc42</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Below, we can see what is generated on the screen for now. Well, 🤔 in fact, I’m not a rounded text yet! 😃 So, let’s move on!</p>
<p><img src="/css-rounded-text-1.webp" alt="An image showing a purple ciclic shape with a big (60 pixels) magenta inset shadow and a text." style="max-width:21%" class="img-narrow"></p>
<h2 id="preparation-before-starting-to-position-the-letters">Preparation before starting to position the letters<a class="heading-anchor" href="#preparation-before-starting-to-position-the-letters" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>To be able to <a href="/how-to-center-in-css-using-different-ways/">make the positioning</a>, we set <code>position: relative</code> property to the wrapper and <code>position: absolute</code> property to the span as a way to move them freely. By doing so, all characters take the same place, but we can observe only the last one as it is on the top.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.wrapper</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D"> span</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Now, we can see what is currently shown on the screen.
While I’m not a looping message so far, 🤪 I will be soon! Let’s proceed. 😃</p>
<p><img src="/css-rounded-text-2.webp" alt="An image showing a purple ciclic shape with a big (60 pixels) magenta inset shadow. It has perfect centered characters but we are able to observe only the last (star) one as it is on the top." style="max-width:31%" class="img-narrow"></p>
<h2 id="creating-the-roundedshape">Creating the rounded shape<a class="heading-anchor" href="#creating-the-roundedshape" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Starting from the two ends and going toward the middle side is a smart tactic to divide the space equally. Remember, we have a star that we will put in the center of the circle, so we do not count it. Thus, we initiate our positioning from the letters “I and t”, the first and last letter of our phrase, and place them in the middle of axis-Y by setting <code>top: 50%</code> and <code>transform: translate(0, -50%)</code>.</p>
<p>Also, we keep the letters 40 pixels away from the left and right sides, with the <code>left</code> and <code>right</code> CSS properties respectively.</p>
<p>Finally, transforming our letters setting the <code>transform: rotate()</code> gives them a vibrant and dynamic perspective, bringing them to life in a truly inspiring way.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.character1</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-90</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.character15</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">90</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Now, take a look at this sequence of characters. Notice how both the first and last letters are in their respective positions on the displayed screen. This is a good time to examine how the <code>box-shadow</code> CSS property helps us to count and place the characters accurately. 🟣 🤩 🟣 🤩 🟣</p>
<p><img src="/css-rounded-text-3.webp" alt="An image showing a purple ciclic shape with a big (60 pixels) magenta inset shadow. It has perfect centered characters but we are able to observe only the last (star) one as it is on the top. The first (I) and the last (t) letters of the phrase are positioned at the 50% of the axis-Y." style="max-width:31%" class="img-narrow"></p>
<p>We move forward with this topic by counting the remaining characters. I know! I know! It can be a bit tricky and confusing 🤯 because of the counting, but the result will be amazing!! ✨ 🎉 Therefore, please ensure to maintain the positioning using the same tactic consistently. Finally, I’m including the rest of the code snippet below to complete my work.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.character2</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-75</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">38</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">144</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .character3</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-65</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">42</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">113</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .character4</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-45</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">80</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">68</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .character5</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-32</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">120</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">42</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .character6</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-20</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">140</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">32</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .character7</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-10</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">    right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">208</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">25</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .character8</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">5</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">    right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">175</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">24</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .character9</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">22</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">    right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">145</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">30</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .character10</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">30</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">    right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">118</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">42</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .character11</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">42</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">    right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">90</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .character12</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">65</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">    right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .character13</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">65</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">    right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">45</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">122</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .character14</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">80</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">    right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">38</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">152</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span></code></pre></div>
<p>As we can see, all letters are in their respective positions on the displayed screen and our text is finally taking a rounded shape. 🟣 🤩 🟣 🤩 🟣</p>
<p><img src="/css-rounded-text-4-1.webp" alt="An image showing a purple ciclic shape with a big (60 pixels) magenta inset shadow. It has an also rounded shape text that says: &#x22;I am a rounded text&#x22;. In the center of the ciclic shape stands a star." style="max-width:42%" class="img-narrow"></p>
<p>To finalize, it would be better if the star appears bigger so we modify the <code>.character16-emoticon</code> class and adjust the <code>font-size</code> property to 100px. Additionally, the <code>box-shadow</code> property needs to be updated to achieve the desired visual effect. Therefore, we will need to go back and make the necessary changes to ensure it looks exactly as we want it to.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.wrapper</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 30</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> magenta</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.character16-emoticon</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Tada! Our rounded text is ready! 🥳 💪 Enjoy! 🎊 🎊</p>
<p><img src="/css-rounded-text-5-final.webp" alt="An image showing a purple ciclic shape with a magenta inset shadow. It has an also rounded shape text that says: &#x22;I am a rounded text&#x22;. In the center of the ciclic shape stands a big star(100 pixels)." style="max-width:31%" class="img-narrow"></p>
<h2 id="complete-code-solution">Complete code solution<a class="heading-anchor" href="#complete-code-solution" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Below is the full code referenced in this blog post. Feel free to copy and use it in your own projects. If you have any questions or encounter any issues, don’t hesitate to reach out for assistance. You can easily copy the desired code snippet by clicking on the copy icon, located in the top-right corner of each snippet.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"wrapper"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character1"</span><span style="color:#E1E4E8">>I&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character2"</span><span style="color:#E1E4E8">>a&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character3"</span><span style="color:#E1E4E8">>m&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character4"</span><span style="color:#E1E4E8">>a&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character5"</span><span style="color:#E1E4E8">>r&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character6"</span><span style="color:#E1E4E8">>o&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character7"</span><span style="color:#E1E4E8">>u&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character8"</span><span style="color:#E1E4E8">>n&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character9"</span><span style="color:#E1E4E8">>d&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character10"</span><span style="color:#E1E4E8">>e&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character11"</span><span style="color:#E1E4E8">>d&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character12"</span><span style="color:#E1E4E8">>t&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character13"</span><span style="color:#E1E4E8">>e&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character14"</span><span style="color:#E1E4E8">>x&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character15"</span><span style="color:#E1E4E8">>t&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"character16-emoticon"</span><span style="color:#E1E4E8">>⭐&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">*</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  margin</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  padding</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-sizing</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">border-box</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">html</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">vh</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#f5f5f5</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.wrapper</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">400</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">400</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> magenta</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D"> span</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  font-family</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">Arial</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#eddc42</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.character1</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-90</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.character2</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-75</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">38</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">144</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.character3</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-65</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">42</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">113</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.character4</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-45</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">80</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">68</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.character5</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-32</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">120</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">42</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.character6</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-20</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">140</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">32</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.character7</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-10</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">208</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">25</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.character8</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">5</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">175</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">24</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.character9</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">22</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">145</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">30</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.character10</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">30</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">118</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">42</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.character11</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">42</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">90</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.character12</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">65</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.character13</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">65</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">45</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">122</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.character14</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">80</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">38</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">152</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.character15</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">90</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.character16-emoticon</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>🌼 Hope you found my post interesting and helpful.
Thanks for being here! 🌼</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-center-in-css-using-different-ways/">How to Center in CSS Using Different Ways</a></li>
<li><a href="/how-to-effectively-use-css-transform-scale-on-hover/">CSS Scale on Hover with transform</a></li>
<li><a href="/css-colorful-text-crafting-vibrant-effects/">CSS Colorful Text – Crafting Vibrant Effects</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>What does git add -a do?</title>
      <link>https://littlecodingthings.com/what-does-git-add-a-do/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/what-does-git-add-a-do/</guid>
      <pubDate>Wed, 16 Jul 2025 07:00:00 GMT</pubDate>
      <description>git add -a doesn’t exist. The command you want is git add -A — here’s how it differs from git add . and when that difference actually matters.</description>
      <category>Setup &amp; Tools</category>
      <content:encoded><![CDATA[<p>If you’re reading this post, chances are you’re looking for a Git command that stages <strong>all</strong> changes before committing. To set the record straight: the correct command is <code>git add -A</code>. A quick look at the <a href="https://git-scm.com/docs/git-add#Documentation/git-add.txt-code-Acode">git add documentation</a> will show you that <code>git add -a</code> doesn’t exist. Instead, <code>git add -A</code> is the command that stages <strong>all recent changes</strong> — including new, modified, and deleted files.</p>
<p>Let’s take a closer look to see if this is the command you’re really after.</p>
<h2 id="common-mistake-git-add--a">Common Mistake: <code>git add -a</code><a class="heading-anchor" href="#common-mistake-git-add--a" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>When someone types <code>git add -a</code>, they’re usually trying to stage everything before a commit. It’s often a case of muscle memory or a mistaken assumption that <code>-a</code> stands for “add all.”</p>
<p>In most situations, what the user actually meant was either:</p>
<ul>
<li><code>git add -A</code> to stage <strong>everything</strong>, or</li>
<li><code>git add .</code> to stage changes <strong>in the current folder and below</strong></li>
</ul>
<h2 id="git-add--vs-git-add--a"><code>git add .</code> vs <code>git add -A</code><a class="heading-anchor" href="#git-add--vs-git-add--a" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>These two commands are often used interchangeably, but they’re not exactly the same. While both will stage new, modified, and (in modern Git) deleted files, the main difference lies in their <strong>scope</strong>.</p>
<h3 id="git-add--a-stages-everything-everywhere"><code>git add -A</code>: Stages Everything, Everywhere<a class="heading-anchor" href="#git-add--a-stages-everything-everywhere" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>When you run <code>git add -A</code>, Git stages <strong>all changes</strong> across the <strong>entire working tree</strong>, no matter where you are in the project.
For example, even if you’re working in a deep directory like <code>src/assets/images</code>, <code>git add -A</code> will still stage changes from higher directories like <code>src/</code> or the root.</p>
<h3 id="git-add--stages-from-the-current-directory-down"><code>git add .</code>: Stages From the Current Directory Down<a class="heading-anchor" href="#git-add--stages-from-the-current-directory-down" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>On the other hand, <code>git add .</code> only stages changes in the <strong>current directory and its subdirectories</strong>. The dot (<code>.</code>) refers to “this folder,” so changes in sibling or parent directories won’t be included.</p>
<h2 id="so-when-does-it-matter">So, When Does It Matter?<a class="heading-anchor" href="#so-when-does-it-matter" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>If you’re working from the <strong>root of your repository</strong>, there’s practically <strong>no difference</strong> between <code>git add .</code> and <code>git add -A</code> in modern Git versions — both will stage everything.</p>
<p>But if you’re working in a <strong>subdirectory</strong> and want to stage <strong>all changes in the project</strong>, you should use <code>git add -A</code>.</p>
<p>If you only want to stage changes <strong>within the folder you’re in</strong>, then <code>git add .</code> is the right choice.</p>
<h2 id="or-did-you-mean-git-commit--a-">Or did you mean <code>git commit -a</code>? 🎯<a class="heading-anchor" href="#or-did-you-mean-git-commit--a-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Here’s the thing I suspect brought a fair few of you here. <strong><code>-a</code> is a real flag — just on a different command.</strong></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">git</span><span style="color:#9ECBFF"> commit</span><span style="color:#79B8FF"> -a</span><span style="color:#79B8FF"> -m</span><span style="color:#9ECBFF"> "Fix the login redirect"</span></span></code></pre></div>
<p>Git’s own help describes <code>-a</code> there as “commit all changed files”. It skips the staging step entirely: modified files go straight into the commit without you running <code>git add</code> at all. The usual shorthand squashes the flags together:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">git</span><span style="color:#9ECBFF"> commit</span><span style="color:#79B8FF"> -am</span><span style="color:#9ECBFF"> "Fix the login redirect"</span></span></code></pre></div>
<p>So if you half-remember <code>-a</code> meaning “all” in Git, you’re not imagining it. You’ve just attached it to <code>add</code> instead of <code>commit</code>.</p>
<p><strong>The catch, and it’s a big one:</strong> <code>git commit -a</code> only picks up files Git is <em>already tracking</em>. A brand new file you created five minutes ago is untracked, so it is silently left out of the commit. That is the classic “why isn’t my new component on GitHub?” moment, and it’s why plenty of people give up on <code>-am</code> and go back to <code>git add -A</code> followed by <code>git commit -m</code>.</p>
<h2 id="the-flag-nobody-mentions-git-add--u">The flag nobody mentions: <code>git add -u</code><a class="heading-anchor" href="#the-flag-nobody-mentions-git-add--u" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Sitting quietly between <code>git add .</code> and <code>git add -A</code> is <code>-u</code>, short for <code>--update</code>. It stages every change to <strong>tracked</strong> files — modifications and deletions — and ignores anything new.</p>
<p>Here’s the difference, run for real. Starting with one modified file (<code>a.txt</code>) and one brand new file (<code>b.txt</code>):</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">git</span><span style="color:#9ECBFF"> add</span><span style="color:#79B8FF"> -u</span></span>
<span class="line"><span style="color:#B392F0">git</span><span style="color:#9ECBFF"> status</span><span style="color:#79B8FF"> --short</span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>M  a.txt</span></span>
<span class="line"><span>?? b.txt</span></span></code></pre></div>
<p><code>a.txt</code> is staged. <code>b.txt</code> is still sitting there as untracked. That’s exactly what <code>git commit -a</code> does, just as a separate step you can inspect before committing.</p>
<p>It’s genuinely useful when a build has scattered new files around your working directory and you only want to commit edits to things that already existed.</p>
<h2 id="putting-all-four-side-by-side">Putting all four side by side<a class="heading-anchor" href="#putting-all-four-side-by-side" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<table>
<thead>
<tr>
<th scope="col">Command</th>
<th scope="col">Modified files</th>
<th align="right" scope="col">Deleted files</th>
<th align="right" scope="col">New (untracked) files</th>
<th scope="col">Scope</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row"><code>git add -A</code></th>
<td>✅</td>
<td align="right">✅</td>
<td align="right">✅</td>
<td>Whole repository</td>
</tr>
<tr>
<th scope="row"><code>git add .</code></th>
<td>✅</td>
<td align="right">✅</td>
<td align="right">✅</td>
<td>Current folder and below</td>
</tr>
<tr>
<th scope="row"><code>git add -u</code></th>
<td>✅</td>
<td align="right">✅</td>
<td align="right">❌</td>
<td>Whole repository</td>
</tr>
<tr>
<th scope="row"><code>git commit -a</code></th>
<td>✅</td>
<td align="right">✅</td>
<td align="right">❌</td>
<td>Whole repository, and commits immediately</td>
</tr>
</tbody>
</table>
<h2 id="stage-half-a-file-with-git-add--p-">Stage half a file with <code>git add -p</code> 🔪<a class="heading-anchor" href="#stage-half-a-file-with-git-add--p-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Once you’re past “stage everything”, this is the flag actually worth learning, and it’s the one that changes how you write commits.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">git</span><span style="color:#9ECBFF"> add</span><span style="color:#79B8FF"> -p</span></span></code></pre></div>
<p>Git walks you through your changes one chunk at a time and asks what to do with each. The answers you need on day one:</p>
<ul>
<li><strong><code>y</code></strong> — stage this chunk</li>
<li><strong><code>n</code></strong> — skip it</li>
<li><strong><code>s</code></strong> — split it into smaller chunks (use this a lot)</li>
<li><strong><code>q</code></strong> — quit, keeping what you’ve staged so far</li>
<li><strong><code>?</code></strong> — list every option, because there are more</li>
</ul>
<p>This is how you rescue a messy afternoon where you fixed a bug <em>and</em> renamed some variables <em>and</em> left a <code>console.log</code> behind. Instead of one incoherent commit, you stage the bug fix, commit it, then deal with the rest. Your future self reviewing that history will thank you — and so will anyone reading your <a href="/how-to-create-better-pull-requests-3-proven-tips/">pull requests</a>.</p>
<h2 id="staged-something-by-mistake-undo-it-">Staged something by mistake? Undo it 🔙<a class="heading-anchor" href="#staged-something-by-mistake-undo-it-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Nothing you’ve staged is committed yet, so nothing here is dangerous. Git even tells you the command — run <code>git status</code> after staging and it prints:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>Changes to be committed:</span></span>
<span class="line"><span>  (use "git restore --staged &#x3C;file>..." to unstage)</span></span></code></pre></div>
<p>So, to unstage one file:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">git</span><span style="color:#9ECBFF"> restore</span><span style="color:#79B8FF"> --staged</span><span style="color:#9ECBFF"> src/index.js</span></span></code></pre></div>
<p>Or everything you just staged:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">git</span><span style="color:#9ECBFF"> restore</span><span style="color:#79B8FF"> --staged</span><span style="color:#9ECBFF"> .</span></span></code></pre></div>
<p>Your edits are untouched — <code>--staged</code> only removes files from the staging area, it doesn’t revert anything you wrote. (<code>git reset HEAD &#x3C;file></code> does the same job and is what older tutorials use. <code>git restore</code> is the modern, clearer spelling.)</p>
<p>And if you want to see what a command <em>would</em> stage before committing to it, <code>-n</code> does a dry run:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">git</span><span style="color:#9ECBFF"> add</span><span style="color:#79B8FF"> -n</span><span style="color:#9ECBFF"> .</span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>add 'a.txt'</span></span></code></pre></div>
<h2 id="frequently-asked-questions-faq">Frequently Asked Questions (FAQ)<a class="heading-anchor" href="#frequently-asked-questions-faq" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<h3 id="is-git-add--a-a-valid-git-command">Is <code>git add -a</code> a valid Git command?<a class="heading-anchor" href="#is-git-add--a-a-valid-git-command" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>No — <code>git add -a</code> is <strong>not a valid command</strong>. Run it and Git replies:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>error: unknown switch `a'</span></span>
<span class="line"><span>usage: git add [&#x3C;options>] [--] &#x3C;pathspec>...</span></span></code></pre></div>
<p>The correct command to stage all changes is <code>git add -A</code>. If you wanted to stage and commit in one go, you wanted <code>git commit -a</code>.</p>
<h3 id="do-i-need-to-run-git-add--a-from-the-root-of-my-repository">Do I need to run <code>git add -A</code> from the root of my repository?<a class="heading-anchor" href="#do-i-need-to-run-git-add--a-from-the-root-of-my-repository" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>No, you can run <code>git add -A</code> from any directory inside your project, and it will always stage changes across the entire repository.</p>
<h3 id="does-git-add-save-or-commit-my-changes">Does <code>git add</code> save or commit my changes?<a class="heading-anchor" href="#does-git-add-save-or-commit-my-changes" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>No. <code>git add</code> only moves changes into the <strong>staging area</strong> — a holding space between your files and your history. Nothing enters the repository until <code>git commit</code> runs. That in-between step exists so you can choose what goes into a commit rather than being forced to commit everything you happened to touch.</p>
<h3 id="will-git-add--a-add-files-listed-in-gitignore">Will <code>git add -A</code> add files listed in <code>.gitignore</code>?<a class="heading-anchor" href="#will-git-add--a-add-files-listed-in-gitignore" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>No. Ignored files stay ignored no matter which of these commands you use. If you genuinely need to stage one, <code>git add -f path/to/file</code> forces it — but stop and ask why it was ignored first.</p>
<h3 id="how-do-i-stage-only-certain-file-types">How do I stage only certain file types?<a class="heading-anchor" href="#how-do-i-stage-only-certain-file-types" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Quote the pattern so your shell hands it to Git rather than expanding it itself:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">git</span><span style="color:#9ECBFF"> add</span><span style="color:#9ECBFF"> '*.js'</span></span></code></pre></div>
<p>That stages every <code>.js</code> file in the repository, from wherever you’re standing.</p>
<h3 id="what-if-git-add--a-stages-something-i-dont-want">What if <code>git add -A</code> stages something I don’t want?<a class="heading-anchor" href="#what-if-git-add--a-stages-something-i-dont-want" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Unstage it with <code>git restore --staged &#x3C;file></code>, as above. Better still, get in the habit of running <code>git status</code> before every commit — the two seconds it costs is how you avoid committing a <code>.env</code> file, and there is no comfortable way to un-commit one of those once it’s pushed.</p>
<p>Thanks for being here! 🙌 If you found this post helpful, giving it a like or share means a lot to us — it helps others find it too.</p>
<p>Got another Git command that’s confusing or unclear? Drop a comment below, and we’ll be happy to explain it in a future post or reply directly. We’re here to make Git simpler, one command at a time. 😊</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-install-git-on-mac-macos-for-beginners/">How to install Git on Mac – MacOS for beginners</a></li>
<li><a href="/how-to-create-better-pull-requests-3-proven-tips/">How to Improve Pull Requests: 3 Basic Rules</a></li>
<li><a href="/husky-hooks-the-easy-way-to-improve-your-project-workflow/">Husky Hooks: Improve Your Git Workflow</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Made Easy With Reusable Code – Why Classes Matter</title>
      <link>https://littlecodingthings.com/made-easy-with-reusable-code-why-classes-matter/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/made-easy-with-reusable-code-why-classes-matter/</guid>
      <pubDate>Fri, 11 Jul 2025 10:00:00 GMT</pubDate>
      <description>Style many elements at once with a single CSS class, then name it so it still makes sense in six months. With do and don't examples.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>When building 🏗 websites, it’s common to create reusable code. What about you? Have you ever wanted to style multiple elements consistently without repeating yourself? That’s where <a href="/coding-made-easy-with-css-selectors-an-ultimate-guide/">CSS classes</a> come in handy! They are flexible, well-structured, and designed to <strong>style multiple elements at once, giving them a consistent look</strong>. They assist you in reusing styles efficiently and also maintain your code organized and clean. 🧹 🧱</p>
<h2 id="reusing-styles-with-classes">Reusing styles with classes<a class="heading-anchor" href="#reusing-styles-with-classes" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>To highlight the value of reusable code with classes, consider the following simple example.</p>
<p><strong>Example</strong>
Let’s say we want to create <strong>several buttons that all match in style</strong> and look uniform across the page.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">button</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"custom-button"</span><span style="color:#E1E4E8">>Subscribe&#x3C;/</span><span style="color:#85E89D">button</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">button</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"custom-button"</span><span style="color:#E1E4E8">>Submit&#x3C;/</span><span style="color:#85E89D">button</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">button</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"custom-button"</span><span style="color:#E1E4E8">>Cancel&#x3C;/</span><span style="color:#85E89D">button</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.custom-button</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">140</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-weight</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">normal</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#e6e6e6</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* gray */</span></span>
<span class="line"><span style="color:#79B8FF">  text-align</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">none</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">8</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  padding</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">4</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 4</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">120</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">120</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">120</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.4</span><span style="color:#E1E4E8">); </span><span style="color:#6A737D">/* semi-transparent gray */</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inline-block</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  cursor</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pointer</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>As we can see below, <strong>all three buttons share the exact same characteristics</strong> by only sharing one class, the <code>.custom-button</code>. Whenever we want to restyle the buttons, we only need to make changes to this class, and the changes will take effect instantly on all buttons.
Incredibly impressive but made easy at the same time! 😎</p>
<p><img src="/reusable-code-btn-subscribe.webp" alt="Gray button with &#x27;subscribe&#x27; written on." style="max-width:36%" class="img-narrow"></p>
<p><img src="/reusable-code-btn-submit.webp" alt="Gray button with &#x27;submit&#x27; written on." style="max-width:36%" class="img-narrow"></p>
<p><img src="/reusable-code-btn-cancel.webp" alt="Gray button with &#x27;cancel" style="max-width:36%" class="img-narrow"></p>
<h2 id="the-importance-of-keeping-names-precise-and-descriptive">The importance of keeping names precise and descriptive<a class="heading-anchor" href="#the-importance-of-keeping-names-precise-and-descriptive" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>When creating class names, try to <strong>make them short yet meaningful. Do not use unclear and generic names</strong>. A name like <code>.custom-button</code> or <code>.card-header</code> gives a clear idea of what the class is for. Pick names that make sense at a glance. <strong>Descriptive names help you and others understand your code</strong> later, especially in larger projects.</p>
<p><strong>✔ DO</strong></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.profile-card</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">250</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">250</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">grey</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>❌ <strong>DON’T</strong></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.card</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">250</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">250</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">grey</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h2 id="add-concise-comments">Add Concise Comments<a class="heading-anchor" href="#add-concise-comments" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Last but not least, <strong>always accompany classes with comments</strong>. Comment with precision. Your comments should clearly <strong>explain why you are using</strong> a particular approach rather than simply describing what the code does.
Additionally, <strong>update comments</strong> as your code evolves. Outdated comments can be more harmful and misleading than having no comments at all. 😉</p>
<p>Below, I have included an example.
Remember, the correct way to declare a comment is:
<code>/* This is a comment in CSS */</code>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* limit width to improve readability on large screens */</span></span>
<span class="line"><span style="color:#B392F0">.container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  max-width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Using reusable classes in CSS saves time and keeps your code well-organized and maintainable. So, next time you catch yourself repeating the same styles again and again, try grouping 🧲 them into a class!</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/coding-made-easy-with-css-selectors-an-ultimate-guide/">CSS Selectors: A Complete Guide</a></li>
<li><a href="/how-to-use-important-in-css/">How to Use !important in CSS</a></li>
<li><a href="/practices-behind-clean-lines-of-code/">Practices Behind Clean Lines Of Code</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Express.js Middleware Interview Questions</title>
      <link>https://littlecodingthings.com/coding-interview-series-intro-to-express-js-middleware/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/coding-interview-series-intro-to-express-js-middleware/</guid>
      <pubDate>Thu, 03 Jul 2025 07:31:00 GMT</pubDate>
      <description>Express.js interview questions on middleware, routes and app.use, with clear answers on req.params vs req.query vs req.body and express.Router().</description>
      <category>Thoughts &amp; Theory</category>
      <content:encoded><![CDATA[<p>While preparing for a coding interview, I found myself feeling a bit rusty on theoretical questions and scenarios I haven’t dealt with recently in my everyday work. After all, a developer doesn’t have to remember everything, right? Based on experience, a developer usually just remembers <em>something</em> exists — or has to look it up if they’ve never built anything similar.</p>
<p>So what’s this post about? This — and others coming soon — will be part of a series covering questions I believe are important for any developer to know in order to feel confident going into an interview focused on Express.js. If you can answer these questions, you should feel pretty good. You won’t know everything, but you’ll be in solid shape to show your knowledge and tackle most of what comes your way.</p>
<p>For me, these are basically my notes from preparing for coding interviews, and I figured I’d share them in case they help you too.</p>
<p>We also plan to share a quiz app featuring these same questions in a simple, game-like environment. We’re building it now and will share it with you soon, so stay tuned!</p>
<p>Enough said! Let’s start with some simple questions and gradually go deeper. In each post, I’ll also include links to the next parts of the series.</p>
<p>Each answer in this series isn’t meant to be 100% complete or the final word. The goal is to show the interviewer that you understand the topic well and can explain it clearly. There’s always room for improvement or deeper discussion.</p>
<p>Some questions include additional context to strengthen your understanding or explore the topic more deeply — we’ve marked those with a 🧠 icon.</p>
<p>Others will point you to related resources for continued learning or best practices — those are marked with a 🚀 icon.</p>
<h2 id="introductory-coding-interview-questions">Introductory coding interview questions<a class="heading-anchor" href="#introductory-coding-interview-questions" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<h3 id="what-is-expressjs">What is Express.js?<a class="heading-anchor" href="#what-is-expressjs" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Express.js is a web application framework built on Node.js. It provides a higher-level API for handling HTTP requests. Express.js is commonly used to build REST APIs because it simplifies route handling compared to Node.js. (If you want to build one yourself first, here is <a href="/how-to-setup-an-express-js-server-using-typescript-2024/">how to set up an Express.js server with TypeScript</a>.)</p>
<h3 id="what-are-some-alternatives-to-expressjs">What are some alternatives to Express.js?<a class="heading-anchor" href="#what-are-some-alternatives-to-expressjs" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<ul>
<li>Koa.js – Created by the same team behind Express</li>
<li>Fastify – Focuses on <strong>speed and performance</strong></li>
<li>Nest.js – <strong>TypeScript-first</strong> framework</li>
</ul>
<h3 id="why-should-you-use-expressjs-over-nodes-built-in-http-module">Why should you use Express.js over Node’s built-in HTTP module?<a class="heading-anchor" href="#why-should-you-use-expressjs-over-nodes-built-in-http-module" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Node.js provides a low-level foundation, while Express abstracts common patterns, such as routing and middleware, making development faster and more maintainable.</p>
<h4 id="-deeper--compare-express-and-node-doing-the-same-thing">🧠 Deeper – Compare Express and Node Doing the Same Thing<a class="heading-anchor" href="#-deeper--compare-express-and-node-doing-the-same-thing" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p>It’s easy sometimes to say something is different, but it would be nice to have a quick glimpse at an actual example. Because of this, below is a simple <strong>GET / users</strong> route implemented first with <strong>Express.js</strong> and then with <strong>plain Node.js</strong> so you can see the practical difference in code size and readability.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">// Express.js</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> express</span><span style="color:#F97583"> =</span><span style="color:#B392F0"> require</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'express'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> app</span><span style="color:#F97583"> =</span><span style="color:#B392F0"> express</span><span style="color:#E1E4E8">();</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">app.</span><span style="color:#B392F0">get</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'/users'</span><span style="color:#E1E4E8">, (</span><span style="color:#FFAB70">req</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">res</span><span style="color:#E1E4E8">) </span><span style="color:#F97583">=></span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  res.</span><span style="color:#B392F0">json</span><span style="color:#E1E4E8">({ message: </span><span style="color:#9ECBFF">'Users list'</span><span style="color:#E1E4E8"> });</span></span>
<span class="line"><span style="color:#E1E4E8">});</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">app.</span><span style="color:#B392F0">listen</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">3000</span><span style="color:#E1E4E8">, () </span><span style="color:#F97583">=></span><span style="color:#E1E4E8"> console.</span><span style="color:#B392F0">log</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'Express server on port 3000'</span><span style="color:#E1E4E8">));</span></span></code></pre></div>
<p><em>In Express.js if you use <code>res.json()</code> (or pass an object/array to <code>res.send()</code>), Express automatically sets the <code>Content-Type</code> header to <code>application/json; charset=utf-8</code>. You don’t need to call <code>res.setHeader()</code> yourself.</em></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">// Node</span></span>
<span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> http</span><span style="color:#F97583"> =</span><span style="color:#B392F0"> require</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'http'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> server</span><span style="color:#F97583"> =</span><span style="color:#E1E4E8"> http.</span><span style="color:#B392F0">createServer</span><span style="color:#E1E4E8">((</span><span style="color:#FFAB70">req</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">res</span><span style="color:#E1E4E8">) </span><span style="color:#F97583">=></span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">  if</span><span style="color:#E1E4E8"> (req.method </span><span style="color:#F97583">===</span><span style="color:#9ECBFF"> 'GET'</span><span style="color:#F97583"> &#x26;&#x26;</span><span style="color:#E1E4E8"> req.url </span><span style="color:#F97583">===</span><span style="color:#9ECBFF"> '/users'</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#E1E4E8">    res.statusCode </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> 200</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    res.</span><span style="color:#B392F0">setHeader</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'Content-Type'</span><span style="color:#E1E4E8">, </span><span style="color:#9ECBFF">'application/json'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    res.</span><span style="color:#B392F0">end</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">JSON</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">stringify</span><span style="color:#E1E4E8">({ message: </span><span style="color:#9ECBFF">'Users list'</span><span style="color:#E1E4E8"> }));</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#F97583">else</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    res.statusCode </span><span style="color:#F97583">=</span><span style="color:#79B8FF"> 404</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    res.</span><span style="color:#B392F0">end</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'Not Found'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">});</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">server.</span><span style="color:#B392F0">listen</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">3000</span><span style="color:#E1E4E8">, () </span><span style="color:#F97583">=></span><span style="color:#E1E4E8"> console.</span><span style="color:#B392F0">log</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'Node server on port 3000'</span><span style="color:#E1E4E8">));</span></span></code></pre></div>
<h2 id="middlewares">Middlewares<a class="heading-anchor" href="#middlewares" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<h3 id="what-is-middleware-in-express">What is middleware in Express?<a class="heading-anchor" href="#what-is-middleware-in-express" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>A <a href="https://expressjs.com/en/guide/writing-middleware.html">middleware is a function</a>. It runs before the final route handler, and it has access to the request, response, and next callback.</p>
<p>An example of a middleware on a route level could be:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">// auth middleware</span></span>
<span class="line"><span style="color:#F97583">function</span><span style="color:#B392F0"> auth</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">req</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">res</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">next</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#F97583">  if</span><span style="color:#E1E4E8"> (</span><span style="color:#F97583">!</span><span style="color:#B392F0">checkAuthOfUserId</span><span style="color:#E1E4E8">(req.params.id)) {</span></span>
<span class="line"><span style="color:#F97583">    return</span><span style="color:#E1E4E8"> res.</span><span style="color:#B392F0">status</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">403</span><span style="color:#E1E4E8">).</span><span style="color:#B392F0">send</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'Access denied'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  next</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">app.</span><span style="color:#B392F0">get</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'/users/:id'</span><span style="color:#E1E4E8">, auth, (</span><span style="color:#FFAB70">req</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">res</span><span style="color:#E1E4E8">) </span><span style="color:#F97583">=></span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  res.</span><span style="color:#B392F0">send</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">`Access granted to user ${</span><span style="color:#E1E4E8">req</span><span style="color:#9ECBFF">.</span><span style="color:#E1E4E8">params</span><span style="color:#9ECBFF">.</span><span style="color:#E1E4E8">id</span><span style="color:#9ECBFF">}`</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">});</span></span></code></pre></div>
<h3 id="how-many-types-of-middleware-do-you-know">How many types of middleware do you know?<a class="heading-anchor" href="#how-many-types-of-middleware-do-you-know" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>There are types of middleware:</p>
<ul>
<li>Global</li>
<li>Path based</li>
<li>Route specific</li>
<li>Error handling</li>
</ul>
<p>Examples for each would be:</p>
<h4 id="global-type-middleware-example">Global type middleware example<a class="heading-anchor" href="#global-type-middleware-example" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> express</span><span style="color:#F97583"> =</span><span style="color:#B392F0"> require</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'express'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> app</span><span style="color:#F97583"> =</span><span style="color:#B392F0"> express</span><span style="color:#E1E4E8">();</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">app.</span><span style="color:#B392F0">use</span><span style="color:#E1E4E8">(express.</span><span style="color:#B392F0">json</span><span style="color:#E1E4E8">());</span></span></code></pre></div>
<p>This middleware will run <strong>for</strong> all incoming requests, regardless of <strong>route or method</strong>.</p>
<h4 id="path-specific-middleware-example">Path-specific middleware example<a class="heading-anchor" href="#path-specific-middleware-example" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">// middleware definition</span></span>
<span class="line"><span style="color:#F97583">function</span><span style="color:#B392F0"> adminLogger</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">req</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">res</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">next</span><span style="color:#E1E4E8">) { </span><span style="color:#F97583">...</span><span style="color:#E1E4E8"> }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">// Apply middleware to all /admin paths (any method)</span></span>
<span class="line"><span style="color:#E1E4E8">app.</span><span style="color:#B392F0">use</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'/admin'</span><span style="color:#E1E4E8">, adminLogger);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">app.</span><span style="color:#B392F0">get</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'/admin'</span><span style="color:#E1E4E8">, (</span><span style="color:#FFAB70">req</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">res</span><span style="color:#E1E4E8">) </span><span style="color:#F97583">=></span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  res.</span><span style="color:#B392F0">send</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'Admin Home'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">});</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">app.</span><span style="color:#B392F0">post</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'/admin'</span><span style="color:#E1E4E8">, (</span><span style="color:#FFAB70">req</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">res</span><span style="color:#E1E4E8">) </span><span style="color:#F97583">=></span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  res.</span><span style="color:#B392F0">send</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'Admin POST'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">});</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">app.</span><span style="color:#B392F0">get</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'/admin/settings'</span><span style="color:#E1E4E8">, (</span><span style="color:#FFAB70">req</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">res</span><span style="color:#E1E4E8">) </span><span style="color:#F97583">=></span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  res.</span><span style="color:#B392F0">send</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'Admin Settings'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">});</span></span></code></pre></div>
<p>A <strong>path-specific middleware</strong> will run on <strong>all HTTP methods</strong> for <strong>any route that starts with that path</strong>.</p>
<h4 id="route-based-middleware-example">Route-based middleware example<a class="heading-anchor" href="#route-based-middleware-example" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">function</span><span style="color:#B392F0"> requireAuth</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">req</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">res</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">next</span><span style="color:#E1E4E8">) { </span><span style="color:#F97583">...</span><span style="color:#E1E4E8"> }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">app.</span><span style="color:#B392F0">get</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'/profile'</span><span style="color:#E1E4E8">, requireAuth, (</span><span style="color:#FFAB70">req</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">res</span><span style="color:#E1E4E8">) </span><span style="color:#F97583">=></span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  res.</span><span style="color:#B392F0">send</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'Welcome to your profile!'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">});</span></span></code></pre></div>
<p>This middleware is applied only to a specific route and will run <strong>only</strong> when a <code>GET</code> request is made to the <code>/profile</code> endpoint.</p>
<h4 id="error-handling-middleware-example">Error-handling middleware example<a class="heading-anchor" href="#error-handling-middleware-example" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p>Error-handling middleware is a special feature in Express.js that catches errors and handles them in a single location. It has <strong>four parameters</strong>:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">function</span><span style="color:#B392F0"> errorHandler</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">err</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">req</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">res</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">next</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#6A737D">  // Custom error handling logic</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><strong>In Express 5</strong>, if a route handler or middleware returns a <strong>Promise</strong> that is either <strong>rejected</strong> or throws an exception, Express will automatically call <code>next(err)</code> for you.</p>
<h3 id="what-do-you-know-about-the-appuse-function">What do you know about the app.use function?<a class="heading-anchor" href="#what-do-you-know-about-the-appuse-function" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><code>app.use()</code> is a method in Express used to <strong>register middleware functions</strong>. These middleware run <strong>before any route handler</strong> and can modify the request or response, or end the response cycle.</p>
<h3 id="-further-reading--using-the-right-terms--path-route-or-handler">🚀 Further reading – Using the Right Terms — Path, Route, or Handler?<a class="heading-anchor" href="#-further-reading--using-the-right-terms--path-route-or-handler" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>When working with <strong>Express.js</strong>, you’ll frequently encounter the terms <strong>route</strong>, <strong>path</strong>, and <strong>handler</strong>. It’s important to understand the distinction between them, as each plays a different role in handling HTTP requests.</p>
<p>Let’s break it down using the following example:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>app.get('/users', (req, res) => { ... });</span></span></code></pre></div>
<p><strong>Path</strong>: The URL pattern that the server listens to — here, it’s <code>'/users'</code>.</p>
<p><strong>Route</strong>: The combination of an HTTP method (e.g., <code>GET</code>, <code>POST</code>) and a <strong>path</strong>. In this example, <code>GET /users</code> is the route.</p>
<p><strong>Handler</strong>: The callback function that is executed when a request matches the route. In this case, it’s the function <code>(req, res) => { ... }</code>.</p>
<h2 id="routes">Routes<a class="heading-anchor" href="#routes" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<h3 id="what-is-a-route-in-expressjs">What is a route in Express.js?<a class="heading-anchor" href="#what-is-a-route-in-expressjs" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>A <strong>route</strong> in Express defines a specific endpoint by combining an HTTP method (such as <code>GET</code>, <code>POST</code>, etc.) with a path, along with the logic (called a <strong>handler</strong>) that should execute when that request is received.</p>
<p>Example</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>app.get('/hello', (req, res) => {</span></span>
<span class="line"><span>  res.send('Hello this is route!')</span></span>
<span class="line"><span>})</span></span></code></pre></div>
<h3 id="whats-the-difference-between-appget-and-apppost">What’s the difference between <code>app.get</code> and <code>app.post</code>?<a class="heading-anchor" href="#whats-the-difference-between-appget-and-apppost" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Both <code>app.get</code> and <code>app.post</code> define routes.</p>
<ul>
<li><code>app.get()</code> handles <strong>GET</strong> requests for fetching data.</li>
<li><code>app.post()</code> handles <strong>POST</strong> requests for updating or creating data.</li>
</ul>
<h3 id="how-would-you-retrieve-a-route-param-from-a-url-like-usersid">How would you retrieve a route param from a URL like <code>/users/:id</code>?<a class="heading-anchor" href="#how-would-you-retrieve-a-route-param-from-a-url-like-usersid" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">app.</span><span style="color:#B392F0">get</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'/users/:id'</span><span style="color:#E1E4E8">, (</span><span style="color:#FFAB70">req</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">res</span><span style="color:#E1E4E8">) </span><span style="color:#F97583">=></span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">  const</span><span style="color:#E1E4E8"> { </span><span style="color:#79B8FF">id</span><span style="color:#E1E4E8"> } </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> req.params;</span></span>
<span class="line"><span style="color:#E1E4E8">  res.</span><span style="color:#B392F0">send</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">`User id is ${</span><span style="color:#E1E4E8">id</span><span style="color:#9ECBFF">}`</span><span style="color:#E1E4E8">)</span></span>
<span class="line"><span style="color:#E1E4E8">})</span></span></code></pre></div>
<h3 id="whats-the-difference-between-reqparams-reqquery-and-reqbody">What’s the difference between <code>req.params</code>, <code>req.query</code>, and <code>req.body</code>?<a class="heading-anchor" href="#whats-the-difference-between-reqparams-reqquery-and-reqbody" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<table>
<thead>
<tr>
<th scope="col">Property</th>
<th scope="col">Source</th>
<th scope="col">Example</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">req.params</th>
<td>Route parameters</td>
<td>/users/:id → req.params.id</td>
</tr>
<tr>
<th scope="row">req.query</th>
<td>URL query string</td>
<td>/search?q=test → req.query.q</td>
</tr>
<tr>
<th scope="row">req.body</th>
<td>POST/PUT body</td>
<td>req.body.name needs middleware like express.json()</td>
</tr>
</tbody>
</table>
<h3 id="can-a-route-have-multiple-middleware-functions-how">Can a route have multiple middleware functions? How?<a class="heading-anchor" href="#can-a-route-have-multiple-middleware-functions-how" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Yes, you could add middleware by adding it to the route before the handler.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>app.get('/secure', authMiddleware, loggingMiddleware, (req, res) => {</span></span>
<span class="line"><span>  res.send('Access granted');</span></span>
<span class="line"><span>});</span></span></code></pre></div>
<h3 id="what-is-expressrouter-and-why-would-you-use-it">What is <code>express.Router()</code> and why would you use it?<a class="heading-anchor" href="#what-is-expressrouter-and-why-would-you-use-it" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><code>express.Router()</code> creates a modular, mini Express app. It helps organize code by separating routes into files.</p>
<p>For example, you might organize all your user-related routes in a separate file, such as:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">// routes/users.js</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> express</span><span style="color:#F97583"> =</span><span style="color:#B392F0"> require</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'express'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> router</span><span style="color:#F97583"> =</span><span style="color:#E1E4E8"> express.</span><span style="color:#B392F0">Router</span><span style="color:#E1E4E8">();</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">// GET /users</span></span>
<span class="line"><span style="color:#E1E4E8">router.</span><span style="color:#B392F0">get</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'/'</span><span style="color:#E1E4E8">, (</span><span style="color:#FFAB70">req</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">res</span><span style="color:#E1E4E8">) </span><span style="color:#F97583">=></span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  res.</span><span style="color:#B392F0">send</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'User list'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">});</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">// GET /users/:id</span></span>
<span class="line"><span style="color:#E1E4E8">router.</span><span style="color:#B392F0">get</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'/:id'</span><span style="color:#E1E4E8">, (</span><span style="color:#FFAB70">req</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">res</span><span style="color:#E1E4E8">) </span><span style="color:#F97583">=></span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  res.</span><span style="color:#B392F0">send</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">`User ID: ${</span><span style="color:#E1E4E8">req</span><span style="color:#9ECBFF">.</span><span style="color:#E1E4E8">params</span><span style="color:#9ECBFF">.</span><span style="color:#E1E4E8">id</span><span style="color:#9ECBFF">}`</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">});</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">module</span><span style="color:#E1E4E8">.</span><span style="color:#79B8FF">exports</span><span style="color:#F97583"> =</span><span style="color:#E1E4E8"> router;</span></span></code></pre></div>
<p>and then import and register them in your main Express application file like this:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> express</span><span style="color:#F97583"> =</span><span style="color:#B392F0"> require</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'express'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> app</span><span style="color:#F97583"> =</span><span style="color:#B392F0"> express</span><span style="color:#E1E4E8">();</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> userRoutes</span><span style="color:#F97583"> =</span><span style="color:#B392F0"> require</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'./routes/users'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">// Mount user router at /users</span></span>
<span class="line"><span style="color:#E1E4E8">app.</span><span style="color:#B392F0">use</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'/users'</span><span style="color:#E1E4E8">, userRoutes);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">app.</span><span style="color:#B392F0">listen</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">3000</span><span style="color:#E1E4E8">, () </span><span style="color:#F97583">=></span><span style="color:#E1E4E8"> console.</span><span style="color:#B392F0">log</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'Server running'</span><span style="color:#E1E4E8">));</span></span></code></pre></div>
<h2 id="whats-next">What’s next?<a class="heading-anchor" href="#whats-next" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>In this post, we reviewed key Express.js concepts — from routing and middleware types to error handling. These are the kinds of topics that come up often in coding interviews.</p>
<p>In the next part of this series, we’ll shift gears toward <strong>project-level questions</strong>. Stay tuned!</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-setup-an-express-js-server-using-typescript-2024/">Express.js Server with TypeScript</a></li>
<li><a href="/most-common-typescript-errors-and-how-to-solve-them/">Common TypeScript Errors and Fixes</a></li>
<li><a href="/how-to-use-absolute-paths-in-a-node-project-2024/">Absolute Paths in a Node Project</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How CSS Became So Powerful with Animations</title>
      <link>https://littlecodingthings.com/how-css-became-powerful-with-animations/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-css-became-powerful-with-animations/</guid>
      <pubDate>Sat, 28 Jun 2025 14:24:00 GMT</pubDate>
      <description>How CSS went from decorating static pages to driving motion — and why animation is a way of communicating state, not just decoration.</description>
      <category>Thoughts &amp; Theory</category>
      <content:encoded><![CDATA[<p>Hi there! You’re aware that the web 🕸 wasn’t always like it is today? Websites were like digital 📰 posters – just text and images. A page loads, and no changes occur. Static design had the reins. No movement, no glow! 🤹‍♀️ ✨ Everything remained visually frozen. 🧊 🥶 CSS was only a tool to decorate that static content and make some improvements, such as selecting a font, changing colors, adding a border or a margin.</p>
<p>As time went on, browsers improved, and users began to expect more. That’s when <a href="/the-truth-about-css-is-it-really-a-programming-language/" title="CSS">CSS</a> started to shine and show the way from static pages to fluid experiences! With features like <strong>transition</strong>, <strong>transform</strong>, <strong>animation</strong>, and <a href="/keyframes-in-css-explained-make-your-animations-stand-out/"><strong>keyframes</strong></a>, the focus shifted from how things looked to how they can pulse and move in time. Dynamic design is finally here! CSS became a language capable of transforming static <a href="/html-formatting-elements-made-simple-with-easy-and-practical-examples/" title="HTML elements">HTML elements</a> into dynamic 🧨 ones.</p>
<p>Motion matters. It allows users to <strong>feel</strong> when something changes and witness how elements react. <strong>It’s a way of communication</strong>, 🔊 not just decoration. With only CSS, designers can craft these interactions. Creating animations that ‘<strong>rotate</strong>‘, ‘<strong>skew</strong>‘, ‘<strong>scale</strong>‘ or ‘<strong>shift</strong>‘ position suggests ongoing system activity. A sliding menu, like a ‘<em>hamburger icon</em>‘, reveals categories, indicating that navigation continues beyond the current view. A spinning icon, after a user clicks ‘Submit’ or ‘Save’ on a button, signals that a process is loading. A button that gently fades in and out on hover – labeled ‘<em>Sign Up</em>‘ – asks for interaction. A fading alert, such as ‘<em>Connection lost</em>‘ or ‘<em>Download has failed, retrying</em>‘, quietly suggests that the message is temporary. Even a ‘<em>scale-up</em>‘ focusing on an image can reveal that it is active. CSS became a must to represent progress and maintain users’ attention.</p>
<p>Of course, as with everything, setting boundaries is essential. Many times <strong>action can cause confusion</strong> and make users feel distracted or, even worse, rushed. <strong>Not every interface needs to include movement</strong>. Sometimes, picking stillness is the best choice. Valuable designs recognise when to pause!</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/static-vs-dynamic-design-with-css-from-stillness-to-action/">CSS Motion: transform, transition, animation</a></li>
<li><a href="/keyframes-in-css-explained-make-your-animations-stand-out/">CSS Keyframes Animation Explained</a></li>
<li><a href="/the-truth-about-css-is-it-really-a-programming-language/">Is CSS a Programming Language?</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How to Restart Your Node App Without Nodemon</title>
      <link>https://littlecodingthings.com/how-to-restart-your-node-apps-without-nodemon/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-restart-your-node-apps-without-nodemon/</guid>
      <pubDate>Sat, 14 Jun 2025 13:42:00 GMT</pubDate>
      <description>Node.js 18.11 added a built-in --watch flag that restarts your app when files change. No nodemon, no config, no extra dependency to install.</description>
      <category>Setup &amp; Tools</category>
      <content:encoded><![CDATA[<p>If you’ve built anything with Node.js, you’ve probably used <code>nodemon</code> to automatically restart your app when files change. It’s been a go-to developer tool for years — but did you know you no longer need it?</p>
<p>With <a href="https://nodejs.org/en/blog/release/v18.11.0">Node.js 18.11</a> and above, there’s a built-in <code>--watch</code> option. It tells Node to monitor your source files and automatically restart the process when changes are detected.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">node</span><span style="color:#79B8FF"> --watch</span><span style="color:#9ECBFF"> app.js</span></span></code></pre></div>
<p>That’s it. No configuration, no dependencies, no waiting for external tools to kick in.</p>
<p>It works great when:</p>
<ul>
<li>You’re building small or medium apps.</li>
<li>You don’t need advanced features like custom delay or file filters.</li>
<li>You want to keep your environment minimal and lean.</li>
</ul>
<p>Keep in mind that, large projects with complex file structures might still benefit from <code>nodemon</code> or more advanced tools.</p>
<h2 id="what-node-actually-watches-">What Node actually watches 👀<a class="heading-anchor" href="#what-node-actually-watches-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>This is the part nobody explains, and it’s the reason <code>--watch</code> sometimes looks broken.</p>
<p>Node doesn’t watch your folder. It watches <strong>your entry point and every file that entry point requires or imports</strong> — the module graph, in other words. <code>node_modules</code> is excluded by default, which is why the whole thing stays fast.</p>
<p>So this restarts:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">node</span><span style="color:#79B8FF"> --watch</span><span style="color:#9ECBFF"> app.js</span></span></code></pre></div>
<p>…when you edit <code>app.js</code>, or <code>routes/users.js</code>, or anything else your app actually pulls in.</p>
<p>While it’s running you’ll see Node narrating itself in the terminal:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>Completed running 'app.js'. Waiting for file changes before restarting...</span></span>
<span class="line"><span>Restarting 'app.js'</span></span></code></pre></div>
<p>What it does <strong>not</strong> restart on is a file nothing imports. Edit an HTML template, a <code>.sql</code> seed file, a JSON fixture you read with <code>fs.readFile</code> instead of <code>import</code>, and Node sits there doing nothing while you refresh the page and wonder what you broke. I lost a solid ten minutes to this before the penny dropped: the file was never part of the graph, so it was never being watched.</p>
<h2 id="watching-folders-node-cant-see---watch-path">Watching folders Node can’t see: <code>--watch-path</code><a class="heading-anchor" href="#watching-folders-node-cant-see---watch-path" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>That’s what <code>--watch-path</code> is for. It takes a path — pass the flag more than once for more than one path:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">node</span><span style="color:#79B8FF"> --watch</span><span style="color:#79B8FF"> --watch-path=./src</span><span style="color:#79B8FF"> --watch-path=./views</span><span style="color:#9ECBFF"> app.js</span></span></code></pre></div>
<p>Now edits inside <code>views/</code> restart the app even though nothing in your code imports them.</p>
<p>One thing to know: the entry point still has to be there. If you forget it, Node stops you with a refreshingly clear message:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>node: --watch requires specifying a file</span></span></code></pre></div>
<h2 id="bonus-you-can-probably-drop-dotenv-too">Bonus: you can probably drop <code>dotenv</code> too<a class="heading-anchor" href="#bonus-you-can-probably-drop-dotenv-too" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Since Node 20.6.0 there’s <code>--env-file</code>, which loads a <code>.env</code> file straight into <code>process.env</code> — no package, no <code>require('dotenv').config()</code> at the top of your file. It stopped being experimental in Node 22.21.0 and 24.10.0.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">node</span><span style="color:#79B8FF"> --watch</span><span style="color:#79B8FF"> --env-file=.env</span><span style="color:#9ECBFF"> app.js</span></span></code></pre></div>
<p>And here’s the nice part I only found by testing it: editing <code>.env</code> restarts the app too. The env file counts as a watched file, so your new value is live on the next boot without you touching anything.</p>
<p>If a variable exists both in your real shell environment and in the file, <strong>the shell wins</strong> — the file doesn’t override what’s already set. That’s deliberate, and it’s what you want on a server.</p>
<p>More on all of this in our <a href="/environment-variables-101-secure-your-secrets-like-a-pro/">guide to environment variables with dotenv</a>.</p>
<h2 id="node---watch-vs-nodemon-honestly-"><code>node --watch</code> vs nodemon, honestly 🥊<a class="heading-anchor" href="#node---watch-vs-nodemon-honestly-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<table>
<thead>
<tr>
<th scope="col"></th>
<th scope="col"><code>node --watch</code></th>
<th scope="col"><code>nodemon</code></th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Install</th>
<td>Built in since 18.11</td>
<td><code>npm install --save-dev nodemon</code></td>
</tr>
<tr>
<th scope="row">Watches by default</th>
<td>Entry point + imported modules</td>
<td><code>js</code>, <code>mjs</code>, <code>coffee</code>, <code>litcoffee</code>, <code>json</code> in the working directory</td>
</tr>
<tr>
<th scope="row">Extra folders</th>
<td><code>--watch-path</code></td>
<td><code>--watch</code></td>
</tr>
<tr>
<th scope="row">Ignore rules</th>
<td>—</td>
<td><code>--ignore lib/ --ignore tests/</code></td>
</tr>
<tr>
<th scope="row">Delay before restart</th>
<td>—</td>
<td><code>--delay 2500ms</code></td>
</tr>
<tr>
<th scope="row">Run something that isn’t Node</th>
<td>—</td>
<td><code>--exec "python -v" ./app.py</code></td>
</tr>
<tr>
<th scope="row">Manual restart</th>
<td>—</td>
<td>type <code>rs</code> and hit return</td>
</tr>
<tr>
<th scope="row">Config file</th>
<td>—</td>
<td><code>nodemon.json</code>, or <code>nodemonConfig</code> in <code>package.json</code></td>
</tr>
<tr>
<th scope="row">Keep old logs on restart</th>
<td><code>--watch-preserve-output</code></td>
<td>on by default</td>
</tr>
</tbody>
</table>
<p>That last row is worth a sentence. By default <code>--watch</code> clears your terminal on every restart, which is lovely until the error you needed to read scrolls into the void. <code>--watch-preserve-output</code> (available since 18.11, same release as <code>--watch</code> itself) turns that off:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">node</span><span style="color:#79B8FF"> --watch</span><span style="color:#79B8FF"> --watch-preserve-output</span><span style="color:#9ECBFF"> app.js</span></span></code></pre></div>
<h2 id="so-when-should-you-still-install-nodemon">So when should you still install nodemon?<a class="heading-anchor" href="#so-when-should-you-still-install-nodemon" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Be honest about which of these you actually need:</p>
<ul>
<li><strong>You’re not running Node.</strong> <code>nodemon --exec "python -v" ./app.py</code> watches files and restarts <em>anything</em>. <code>--watch</code> only restarts Node.</li>
<li><strong>Your files save in bursts.</strong> A build step that writes forty files triggers forty restarts. <code>--delay</code> debounces that; Node has no equivalent.</li>
<li><strong>You need to ignore things.</strong> Test folders, generated output, a <code>tmp/</code> directory your app writes to on every request. Without an ignore rule that last one is an infinite restart loop.</li>
<li><strong>You want the <code>rs</code> escape hatch.</strong> Typing <code>rs</code> to force a restart is a genuinely useful habit when a watcher gets confused.</li>
</ul>
<p>If none of those describe you — and for most small Express apps and scripts, none of them do — that’s one dependency you never have to install again.</p>
<h2 id="frequently-asked-questions">Frequently asked questions<a class="heading-anchor" href="#frequently-asked-questions" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<h3 id="what-node-version-do-i-need-for---watch">What Node version do I need for <code>--watch</code>?<a class="heading-anchor" href="#what-node-version-do-i-need-for---watch" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Node 18.11.0 or newer. It was experimental at first and is now marked stable, so anything on a current LTS release has it. Check with <code>node -v</code>.</p>
<h3 id="does---watch-work-with-typescript">Does <code>--watch</code> work with TypeScript?<a class="heading-anchor" href="#does---watch-work-with-typescript" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Not on its own — <code>--watch</code> restarts a Node process, it doesn’t compile anything. Recent Node versions can run TypeScript files by stripping the types, and for a full build step you still want <code>tsc --watch</code> alongside, or <code>nodemon --exec</code> driving your compiler. If you’re setting a project up from scratch, our <a href="/how-to-setup-an-express-js-server-using-typescript-2024/">Express.js server with TypeScript walkthrough</a> covers the setup.</p>
<h3 id="how-do-i-use---watch-in-an-npm-script">How do I use <code>--watch</code> in an npm script?<a class="heading-anchor" href="#how-do-i-use---watch-in-an-npm-script" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Exactly the same way, in <code>package.json</code>:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">{</span></span>
<span class="line"><span style="color:#79B8FF">  "scripts"</span><span style="color:#E1E4E8">: {</span></span>
<span class="line"><span style="color:#79B8FF">    "dev"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"node --watch --env-file=.env app.js"</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Then <code>npm run dev</code>. This is usually where nodemon lived, so it’s a one-line swap.</p>
<h3 id="why-does-my-app-restart-in-a-loop">Why does my app restart in a loop?<a class="heading-anchor" href="#why-does-my-app-restart-in-a-loop" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Something your app writes is inside what Node is watching — a log file, a cache, a generated file in <code>src/</code>. The app writes, the watcher fires, the app restarts, it writes again. Move the file out of the watched path, or switch to nodemon and add <code>--ignore</code> for it.</p>
<h3 id="can-i-still-use---watch-in-production">Can I still use <code>--watch</code> in production?<a class="heading-anchor" href="#can-i-still-use---watch-in-production" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Please don’t. Watch mode is a development convenience — it holds file handles open and restarts your process on disk activity, which is the last thing you want on a live server. Use a process manager there instead.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/docker-docker-compose-commands-i-keep-forgetting-cheat-sheet/">Docker &#x26; Docker Compose Commands I Keep Forgetting</a></li>
<li><a href="/do-you-still-need-to-use-save-on-npm-install/">Do You Still Need npm install --save?</a></li>
<li><a href="/how-to-use-absolute-paths-in-a-node-project-2024/">How To Use Absolute Paths In A Node Project</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Circular CSS Button with Shadow Effect</title>
      <link>https://littlecodingthings.com/how-to-make-a-circular-clickable-button-with-shadow-effect/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-make-a-circular-clickable-button-with-shadow-effect/</guid>
      <pubDate>Sat, 07 Jun 2025 08:42:00 GMT</pubDate>
      <description>Build a round push-button in CSS: inset shadows for the base, a gradient face, hover and active states, and a soft shadow underneath.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hey there! 😃 In today’s technology-obsessed world, it’s absolutely crucial to master the art of creating an amazing circular clickable button. A well-crafted button not only enhances the presentation but also elevates the user experience. Maximizing user attention is vital, and buttons are, most of the time, the key to achieving this goal. By utilizing the right tools and techniques, we can create a visually stunning and functionally efficient button that not only looks great but also delivers an unforgettable user experience. 🆙</p>
<p>Let’s collaborate to create a standout button that supports user-friendliness.</p>
<h2 id="html-basic-structure">HTML Basic Structure<a class="heading-anchor" href="#html-basic-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>To start building our button, we need to organize our <a href="/most-useful-html-elements-for-maximizing-better-results/" title="HTML">HTML</a> code snippet. The first step is to create a parent element that will act as the base of our button. We give this element the class name <code>.button-base</code>. Next, we need to add a child element within this parent element to serve as the clickable part of the button. We give this child element the class name <code>.clicable-part</code>. It’s important to nest these two elements within a <code>button</code> HTML element as it’s more <strong>semantic</strong>, better for <strong>accessibility</strong>, and behaves correctly in forms and interactive contexts by default.
Additionally, we need to create the shadow effect for our button, so we add one more HTML element with the class name <code>.button-shadow</code>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">button</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"button-base"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"clicable-part"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">button</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"button-shadow"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h2 id="css-foundation">CSS foundation<a class="heading-anchor" href="#css-foundation" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We move forward with <a href="/how-to-work-with-css-syntax-the-correct-way/" title="CSS">CSS</a> and make our button fresh and stylish! For this post, I am writing CSS using Sass syntax. If you would like to convert it to vanilla CSS and don’t already know how, I’d suggest you use an online Sass — CSS converter.</p>
<h3 id="prepare-the-body-for-the-clickable-button">Prepare the body for the clickable button<a class="heading-anchor" href="#prepare-the-body-for-the-clickable-button" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Firstly, we apply a color (<code>#f5f5f5</code> – off-white) to the body by setting the <code>background-color</code>. Additionally, we want to center our button. For that reason, we are using the <code>flex</code> method.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#f5f5f5</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h3 id="create-the-base-of-the-clickable-button">Create the base of the clickable button<a class="heading-anchor" href="#create-the-base-of-the-clickable-button" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>To create the base of our button, we start by making a square with a <code>width</code> and <code>height</code> of 200 pixels. Then, we make it rounded by adding a <code>border-radius</code> of 50%. We use a pale white color (<code>#f9f9f9</code>) for the button’s <code>background-color</code>. To give it a more stylish look, we add some shadows using the <a href="/how-box-shadow-works-made-simple/"><code>box-shadow</code> property</a>.</p>
<p>Finally, we add the <code>flex</code> method to prepare the space to position the clickable part of the button in the center of the base.</p>
<p>📍 As seen in the code snippet below, we need to include <code>border: none</code> and <code>background-color: transparent</code> properties in the button element to ensure it will display only <strong>the styles we define</strong>. These properties <strong>remove the browser’s default styles</strong> that typically come with. As a result, it provides us with a <strong>clean starting point</strong>, so the button appears exactly as we’ve styled it, with no unexpected borders or colors.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">button</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">none</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#B392F0">  .button-base</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#f9f9f9</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 6</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 8</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #eae8e8</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* top inset shadow */</span></span>
<span class="line"><span style="color:#79B8FF">      inset</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> -2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 15</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #ccc7c7</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* bottom inset shadow */</span></span>
<span class="line"><span style="color:#79B8FF">      0</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #d6d1d1</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* bottom shadow */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">    display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>In the image below, you can see the base of the button we just created.</p>
<p><img src="/circular-clicable-button1-create-the-base.webp" alt="An image showing the base of the circular clickable button" style="max-width:41%" class="img-narrow"></p>
<h3 id="create-the-clickable-part-of-the-button">Create the clickable part of the button<a class="heading-anchor" href="#create-the-clickable-part-of-the-button" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>To create the clickable part of our button, we first set the <code>height</code> and <code>width</code> to 80%. Then, we apply a <code>border-radius: inherit</code> to make it appear rounded and follow the shape of the base. For the <code>background</code> of the button, we use a <code>linear-gradient</code> that adds depth as it gives a bright orange color at the top that gradually becomes darker as it goes down. To add a more stylish look, we include shadows using the <code>box-shadow</code> property.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.clicable-part</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">80</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">80</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inherit</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#F97583">    to</span><span style="color:#79B8FF"> bottom</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    #f7eb13</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    #fd741b</span></span>
<span class="line"><span style="color:#E1E4E8">    );</span></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 6</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #ffa500</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* top inset shadow */</span></span>
<span class="line"><span style="color:#79B8FF">    0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #d05a05</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* bottom shadow */</span></span>
<span class="line"><span style="color:#79B8FF">    0</span><span style="color:#79B8FF"> 6</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 6</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #bcb8b8</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* bottom shadow */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>The following image shows the clickable part we just added on the top of the base.</p>
<p><img src="/circular-clicable-button2-create-the-clicable-part.webp" alt="An image showing the base of the circular clickable button. On it&#x27;s top it has the clickable part." style="max-width:41%" class="img-narrow"></p>
<h3 id="add-content-at-the-top-of-the-clickable-part">Add content at the top of the clickable part<a class="heading-anchor" href="#add-content-at-the-top-of-the-clickable-part" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>To add content at the top of the clickable part of a button, we can use a <code>::before</code> pseudo-element. Inside the pseudo-element, we can insert the desired symbol or text using the <code>content</code> property. For instance, in our case, a question mark emoticon <strong>(?)</strong> has been used, but you can use any symbol or text you prefer. It’s important to note that the <code>flex</code> method in the <code>.clickable-part</code> class is essential, as it centers the mark correctly.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.clicable-part</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">    content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"❔"</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>The image below displays the content we added on the top of the clickable part of the button.</p>
<p><img src="/circular-clicable-button3-adding-content-on-the-top-of-the-clicable-part.webp" alt="An image showing the base of the circular clickable button. On it&#x27;s top it has the clickable part. The clickable part it has a question mark on." style="max-width:41%" class="img-narrow"></p>
<h3 id="add-the-hover-effect-on-the-top-of-the-clickable-button">Add the hover effect on the top of the clickable button<a class="heading-anchor" href="#add-the-hover-effect-on-the-top-of-the-clickable-button" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>To add a hover effect, we set the <code>:hover</code> CSS property. For the <code>cursor</code>, I prefer using the value pointer (👆), but feel free to choose any other style from the plethora of options available <a href="https://www.w3schools.com/cssref/pr_class_cursor.php" title="CSS cursor values">in this list of CSS cursor values</a>. Finally, I apply the <code>filter: brightness</code> and increase it to 110%. This makes our button appear brighter whenever the mouse hovers over it. ✨</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.clicable-part</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ..</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">    cursor</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pointer</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">    filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">brightness</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">110</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>The gif below demonstrates how the hover effect (👆) appears.</p>
<h3 id="activate-the-clickable-part-of-the-button">Activate the clickable part of the button<a class="heading-anchor" href="#activate-the-clickable-part-of-the-button" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>To make your button fully functional, you need to activate its clickable part. We can achieve this by adding the <code>:active</code> property. Next, we give it a <code>background</code> with a <code>linear-gradient</code> that creates a sense of depth by providing a bright magenta color at the top that gradually becomes darker as it goes down. To make it more visually appealing, we include shadows using the <code>box-shadow</code> property.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.clicable-part</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ..</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:active</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#FFAB70">      to</span><span style="color:#79B8FF"> bottom</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">      #f767f7</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">      #df0361</span></span>
<span class="line"><span style="color:#E1E4E8">      );</span></span>
<span class="line"><span style="color:#79B8FF">      box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 6</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #df0361</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* top inset shadow */</span></span>
<span class="line"><span style="color:#79B8FF">      0</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #bcb8b8</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* bottom shadow */</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>The following gif displays the activated clickable area.</p>
<h3 id="update-the-buttons-content-when-it-is-activated">Update the button’s content when it is activated<a class="heading-anchor" href="#update-the-buttons-content-when-it-is-activated" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>To enhance the user experience, we can dynamically update the content displayed on the button when it’s clicked. This may be accomplished by adding a <code>::before</code> pseudo-element and inserting the desired content into the <code>content</code> property. In our case, we will display a white heart (🤍) when the button is clicked.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.clicable-part</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ..</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:active</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">      content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"🤍"</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>With just a single click, this button comes to life and reveals its beautiful new content in the following gif (🤍) – it’s an absolute must-see!! 😎</p>
<h3 id="add-the-shadow-effect-to-the-clickable-button">Add the shadow effect to the clickable button<a class="heading-anchor" href="#add-the-shadow-effect-to-the-clickable-button" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>The last thing we have to do is add the shadow effect. We create a rectangle with 140 pixels <code>width</code> and 15 pixels <code>height</code>. Next, we give it a rounded shape by setting the <code>border-radius</code> property to 50%. To create a background that looks like it becomes lighter as it goes toward outer space, we use the <code>radial-gradient</code> technique and make the center darker. To make the whole thing look smoother, we add <a href="/how-inset-works-in-box-shadow-made-simple/">inset and outer shadows</a> with the <code>box-shadow</code> property.</p>
<p>Finally, we utilize the <code>position: absolute</code> combined with the <code>top</code>, <code>left</code>, and <code>transform</code> properties to move it below the button and center it.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.button-shadow</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">140</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">15</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">radial-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">#a7aaaa</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#b2b7b7</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#eaeded</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #eaeded</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* shadow left side */</span></span>
<span class="line"><span style="color:#79B8FF">    5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #eaeded</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* shadow right side */</span></span>
<span class="line"><span style="color:#79B8FF">    inset</span><span style="color:#79B8FF"> -5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #eaeded</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* inset shadow right side */</span></span>
<span class="line"><span style="color:#79B8FF">    inset</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #eaeded</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* inset shadow left side */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">520</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>The button’s captivating shadow effect is truly impressive and adds to the overall appeal. Hope you find it enjoyable and engaging. Thank you for your attention. 🥳</p>
<p><img src="/circular-clicable-button7-adding-shadow.webp" alt="An image showing the base of the circular clickable button. On it&#x27;s top it has the clickable part. The clickable part it has a question mark on. Button also has a shadow below." style="max-width:41%" class="img-narrow"></p>
<h2 id="complete-code-solution">Complete code solution<a class="heading-anchor" href="#complete-code-solution" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Below is the full code referenced in this blog post. Feel free to copy and use it in your own projects. If you have any questions or encounter any issues, don’t hesitate to reach out for assistance. You can easily copy the desired code snippet by clicking on the copy icon, located in the top-right corner of each snippet.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">button</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"button-base"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"clicable-part"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">button</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"button-shadow"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">@mixin</span><span style="color:#B392F0"> flex-all-center</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#FFAB70">$body-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#f5f5f5</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$button-base-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#f9f9f9</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$button-base-inset-top-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#eae8e8</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$button-base-inset-bottom-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#ccc7c7</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$button-base-dark-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#d6d1d1</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$button-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">to</span><span style="color:#79B8FF"> bottom</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#f7eb13</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#fd741b</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#FFAB70">$button-inset-top-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#ffa500</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$button-inset-bottom-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#d05a05</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$button-dark-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#bcb8b8</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$button-active-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">to</span><span style="color:#79B8FF"> bottom</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#f767f7</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#df0361</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#FFAB70">$button-active-inset-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#df0361</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$button-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#eaeded</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">*</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  margin</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  padding</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-sizing</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">border-box</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">html</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">vh</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$body-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">  @include</span><span style="color:#B392F0"> flex-all-center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  min-width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">button</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">none</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#B392F0">  .button-base</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$button-base-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 6</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 8</span><span style="color:#F97583">px</span><span style="color:#FFAB70"> $button-base-inset-top-shadow</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* top inset shadow */</span></span>
<span class="line"><span style="color:#79B8FF">    inset</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> -2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 15</span><span style="color:#F97583">px</span><span style="color:#FFAB70"> $button-base-inset-bottom-shadow</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* bottom inset shadow */</span></span>
<span class="line"><span style="color:#79B8FF">    0</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#FFAB70"> $button-base-dark-shadow</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* bottom shadow */</span></span>
<span class="line"><span style="color:#F97583">    @include</span><span style="color:#B392F0"> flex-all-center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#B392F0">    .clicable-part</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">80</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">80</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inherit</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$button-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 6</span><span style="color:#F97583">px</span><span style="color:#FFAB70"> $button-inset-top-shadow</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* top inset shadow */</span></span>
<span class="line"><span style="color:#79B8FF">      0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#FFAB70"> $button-inset-bottom-shadow</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* bottom shadow */</span></span>
<span class="line"><span style="color:#79B8FF">      0</span><span style="color:#79B8FF"> 6</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 6</span><span style="color:#F97583">px</span><span style="color:#FFAB70"> $button-dark-shadow</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* bottom shadow */</span></span>
<span class="line"><span style="color:#F97583">      @include</span><span style="color:#B392F0"> flex-all-center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"❔"</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">        cursor</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pointer</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">        filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">brightness</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">110</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">:active</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        background</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$button-active-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 6</span><span style="color:#F97583">px</span><span style="color:#FFAB70"> $button-active-inset-shadow</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* top inset shadow */</span></span>
<span class="line"><span style="color:#79B8FF">          0</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#FFAB70"> $button-dark-shadow</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* bottom shadow */</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">          content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"🤍"</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">    } </span><span style="color:#6A737D">/* end of clicable-part */</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">/* end of button-base */</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">/* end of button */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.button-shadow</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">140</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">15</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">radial-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">#a7aaaa</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#b2b7b7</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#eaeded</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#FFAB70"> $button-shadow</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* shadow left side */</span></span>
<span class="line"><span style="color:#79B8FF">    5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#FFAB70"> $button-shadow</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* shadow right side */</span></span>
<span class="line"><span style="color:#79B8FF">    inset</span><span style="color:#79B8FF"> -5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#FFAB70"> $button-shadow</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* inset shadow right side */</span></span>
<span class="line"><span style="color:#79B8FF">    inset</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#FFAB70"> $button-shadow</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* inset shadow left side */</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">520</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">/* end of shadow */</span></span></code></pre></div>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-make-a-transparent-button-using-html-and-css/">Transparent Button in CSS</a></li>
<li><a href="/how-inset-works-in-box-shadow-made-simple/">How inset Works in box-shadow (Made Simple)</a></li>
<li><a href="/how-to-effectively-use-css-transform-scale-on-hover/">CSS Scale on Hover with transform</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How inset Works in box-shadow (Made Simple)</title>
      <link>https://littlecodingthings.com/how-inset-works-in-box-shadow-made-simple/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-inset-works-in-box-shadow-made-simple/</guid>
      <pubDate>Fri, 30 May 2025 07:38:00 GMT</pubDate>
      <description>The inset keyword draws a shadow inside the element instead of around it. Here is how to build a soft pressed-in effect with two shadows.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Shadows are a simple yet powerful way to add depth and dimension. In programming, the <a href="/how-box-shadow-works-made-simple/">box shadow CSS property</a> creates a sense of layering by simulating light or darkness on <a href="/most-useful-html-elements-for-maximizing-better-results/" title="HTML elements">HTML elements</a>. The <strong>inset box-shadow</strong>, which we will analyze in this post, creates a shadow <em>inside</em> the element, giving it a “pressed” or “embossed” effect that adds even more visual interest to your design.</p>
<p>📌 Always remember that inset shadows are drawn inside the box, hence they can reduce the space inside the element.</p>
<p>For better clarity, let’s begin by breaking down the box-shadow property as each value controls and affects a specific part of how the shadow appears.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* box-shadow: offset-X offset-Y blur-radius spread-radius color; */</span></span></code></pre></div>
<ul>
<li><strong>offset-X</strong> — moves the shadow horizontally. Positive values push it right, negative ones left.</li>
<li><strong>offset-Y</strong> — moves the shadow vertically. Positive values push it down, negative ones up.</li>
<li><strong>blur-radius</strong> — softens the edges. <code>0</code> keeps them sharp, larger values fade the shadow out.</li>
<li><strong>spread-radius</strong> — grows or shrinks the shadow before the blur is applied.</li>
<li><strong>color</strong> — sets the color and, through <code>rgba()</code>, how transparent the shadow is.</li>
</ul>
<p>Add the <code>inset</code> keyword to those same values and the shadow flips inwards: it is drawn from the edges of the box towards its center instead of spreading outwards.</p>
<h2 id="setting-up-the-layout">Setting up the layout<a class="heading-anchor" href="#setting-up-the-layout" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We begin by establishing the basic HTML and CSS structure. Our shadow will be housed within a gray ⬜ box, but for now, we need to adjust the body element so it can properly center and display our box.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"box"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#e0e0e0</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* Light Gray */</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  margin</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h2 id="creating-the-box">Creating the box<a class="heading-anchor" href="#creating-the-box" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Now it’s time to create a rounded box with a light gray background color to gently contrast with the body. This subtle color difference helps us clearly see the shadow effect in action.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#ece9e9</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* Very Light Gray */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/inset-box-shadow-effect-create-the-box.webp" alt="A gray box on a dark gray background." style="max-width:41%" class="img-narrow"></p>
<h2 id="creating-inner-shadows-using-box-shadow">Creating inner shadows using <code>box-shadow</code><a class="heading-anchor" href="#creating-inner-shadows-using-box-shadow" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We finalize our work with the shadow effect. Let’s break down our code to make it clear:</p>
<p><strong><code>inset -5px -5px 10px rgba(255, 255, 255, 0.8)</code></strong>
➤ It positions the shadow at the <strong>bottom-right</strong>, with a softly blurred, which makes the edges smooth rather than sharp. Also, the shadow is white and mostly visible.</p>
<p><strong><code>inset 5px 5px 10px rgba(50, 50, 50, 0.2)</code></strong>
➤ It positions the shadow at the <strong>top-left</strong>, we have again a softly blurred effect, and the shadow now is dark gray and very soft.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> -5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> -5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.8</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#79B8FF">    inset</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">50</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">50</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">50</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.2</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/inset-box-shadow-effect-adding-the-dark-shadow-1.webp" alt="A gray box with inset dark shadow at the top left sides and light shadow at the bottom right sides" style="max-width:41%" class="img-narrow"></p>
<p>If you use <code>spread-radius</code> with inset shadows, it can make the shadow spread too much, making it look too big or messy. By leaving it out, the shadow stays close to the edges, keeping the effect clean and focused.</p>
<p>Working with different shades of gray adds a touch of elegance and also elevates your work. Additionally, it maintains a clean and modern design. 🚀 ✨ So, what’s your take? Do you agree with me, or do you see it in a whole different way? 😄</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-box-shadow-works-made-simple/">How box-shadow Works (Made Simple)</a></li>
<li><a href="/how-to-make-a-circular-clickable-button-with-shadow-effect/">Circular CSS Button with Shadow Effect</a></li>
<li><a href="/how-to-create-a-stunning-gray-css-water-drop/">How To Create A Stunning Gray CSS Water Drop</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How box-shadow Works (Made Simple)</title>
      <link>https://littlecodingthings.com/how-box-shadow-works-made-simple/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-box-shadow-works-made-simple/</guid>
      <pubDate>Fri, 23 May 2025 08:17:00 GMT</pubDate>
      <description>What each box-shadow value actually does — offset, blur, spread and color — built up step by step on one simple box you can copy.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hello there! Want to make your <a href="/most-useful-html-elements-for-maximizing-better-results/" title="HTML elements">HTML elements</a> stand out a bit more? The <code>box-shadow</code> property in CSS lets you add depth by creating a shadow around elements — almost like they’re floating off the page.</p>
<p>To get a better idea of how <code>box-shadow</code> works, let’s look at the different values it takes. Each one controls a part of how the shadow shows up on the page:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* box-shadow: offset-X offset-Y blur-radius spread-radius color; */</span></span></code></pre></div>
<p>🔸 <strong>position</strong>
  • <strong>offset-X</strong>: moves the shadow horizontally
  • <strong>offset-Y</strong>: moves the shadow vertically</p>
<p>🔸 <strong>blur-radius</strong>
  • Makes the shadow’s edges smoother</p>
<p>🔸 <strong>spread-radius</strong>
  • Expands the size of the shadow</p>
<p>🔸 <strong>color</strong>
  • Sets the color and transparency using <code>rgba()</code></p>
<p>Setting <code>spread-radius</code> to <code>0</code> keeps the shadow tightly within the blur area. This helps control how far the shadow extends, making it feel like it’s coming from a specific direction — useful when you want the shadow to appear only on certain sides.</p>
<h2 id="setting-up-the-layout">Setting up the layout<a class="heading-anchor" href="#setting-up-the-layout" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We begin by creating the basic HTML and CSS structure. We will work with a light gray ⬜ box and adjust the layout to perfectly center it within the body element.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"box"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#e0e0e0</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* Light gray */</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  margin</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h2 id="creating-the-box">Creating the box<a class="heading-anchor" href="#creating-the-box" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We create a simple, rounded box that will hold our shadow effect. It has a very light gray background color to contrast with the body, and helps us visualize the effect.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#f0f0f0</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* Very Light Gray */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/box-shadow-effect-create-the-box.webp" alt="A gray box on a dark gray background." style="max-width:41%" class="img-narrow"></p>
<h2 id="adding-the-box-shadow-effect">Adding the box-shadow effect<a class="heading-anchor" href="#adding-the-box-shadow-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We finalize our work with the shadow effect. First, we shift the shadow bottom and to the right (<code>8px 8px</code>), then we give a nice soft blur of <code>20px</code> and a semi-transparent gray (<code>rgba(120, 120, 120, 0.4)</code>). And just like that, this simple line of code makes our box look 3D. How amazing! 😃</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#6A737D">  /* offset-X | offset-Y | blur-radius | spread-radius | color */</span></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">8</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 8</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">120</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">120</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">120</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.4</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/box-shadow-effect-create-the-shadow.webp" alt="A light gray box with gray shadow effect at the bottom right sides" style="max-width:41%" class="img-narrow"></p>
<p>Now your box stands out! ✨ Try it yourself or try something different! Want the shadow above the box and to the left? Use negative values. Want it sharper? Decrease the blur. Maybe with a little bit of color? 🎨 Play with the <code>rgba()</code> values.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* Alternative shadow example */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#6A737D">  /* offset-X | offset-Y | blur-radius | spread-radius | color */</span></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> -5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">220</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">100</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">180</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.3</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/box-shadow-effect-adding-color.webp" alt="A gray box with a pink shadow at the top left sides" style="max-width:41%" class="img-narrow"></p>
<p>Box shadows do more than just enhance appearance — they help direct attention and add gentle emphasis where it counts. Utilizing this small detail intentionally can have a significant impact on your overall design. ✨ 😃</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-inset-works-in-box-shadow-made-simple/">How inset Works in box-shadow (Made Simple)</a></li>
<li><a href="/drop-shadow-vs-box-shadow-what-is-the-difference/">Drop-shadow VS Box-shadow: What is the difference?</a></li>
<li><a href="/enhance-your-content-utilizing-the-css-text-shadow-property/">The CSS text-shadow Property</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>CSS Water Drop Effect on Text</title>
      <link>https://littlecodingthings.com/css-water-drop-effect-how-to-make-text-look-wet-and-glossy-a-step-by-step-guide/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/css-water-drop-effect-how-to-make-text-look-wet-and-glossy-a-step-by-step-guide/</guid>
      <pubDate>Thu, 15 May 2025 09:46:00 GMT</pubDate>
      <description>Sit a glossy CSS water drop on top of a heading using border-radius, layered box-shadows and two pseudo-element highlights.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>😃 In this post, we are beyond excited to show you how to create a breathtaking water drop effect that stands on top of a text using only the power of CSS.</p>
<p>We will confidently guide you through every single step of the process, from the initial design phase to the final finishing touches.</p>
<p>In addition, we will share expert tips on how to masterfully experiment with CSS properties to achieve the perfect shape and reflection effects. So, let’s jump right in and create something fantastic together!</p>
<h2 id="setting-up-the-html-structure-for-the-water-drop-effect">Setting up the HTML structure for the water drop effect<a class="heading-anchor" href="#setting-up-the-html-structure-for-the-water-drop-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We begin with the <a href="/most-useful-html-elements-for-maximizing-better-results/" title="HTML">HTML</a> structure. We need to create an element with the class name <code>.wrapper</code>. This element will have two child elements. The first child element will be dedicated to the text, so we give a suitable class name, such as <code>.text</code>. Similarly, we should name the second child element with a class name that reflects its purpose, such as <code>.drop</code>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"wrapper"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"text"</span><span style="color:#E1E4E8">>drop&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"drop"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p>Our top priority right now is to work on the second child element, which is our amazing drop. 💦 🤓 Once we’re done with that, we’ll move on to the text.</p>
<h2 id="styling-the-water-drop-effect-with-css">Styling the water drop effect with CSS<a class="heading-anchor" href="#styling-the-water-drop-effect-with-css" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We move forward with the <a href="/how-to-work-with-css-syntax-the-correct-way/" title="CSS">CSS</a> structure. To create a flexible layout for our project, we set the <code>flex</code> property on the element with the class <code>.wrapper</code>. This will allow us to easily adjust the size and position of its child elements.</p>
<p>Additionally, we added the <code>position: relative</code> property to the wrapper to establish a reference point for any absolutely positioned child elements later on in the project. By doing this, we have prepared the necessary space and layout for easier and more precise positioning of elements.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.wrapper</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h3 id="how-to-create-a-realistic-water-drop-effect-in-css">How to create a realistic water drop effect in CSS<a class="heading-anchor" href="#how-to-create-a-realistic-water-drop-effect-in-css" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Firstly, we must select a color for the body, setting the <code>background-color</code>. Keep in mind that the same color must be used for the drop. Therefore, it is crucial to choose the <a href="/what-you-need-to-know-about-css-color-methods/">color</a> carefully. 🌈</p>
<p>Then, we need to establish the dimensions and <a href="/how-to-be-creative-with-different-css-border-styles/">borders</a>. Thus, we will set the <code>width</code> and <code>height</code> and then adjust the <code>border-radius</code> property to create a slightly rounded shape.</p>
<p>Next, we maintain the body’s <code>background-color</code> by adjusting the transparency of the drop. In that way, our drop inherits the color of the body.</p>
<p>Additionally, we add the <code>box-shadow</code> property which is the most crucial part as it is responsible for creating a realistic-looking drop that appears three-dimensional. Without it, the element may appear flat and lacking in depth. 😉 So, don’t be afraid to experiment with different shadow settings until you find the right combination that works for you. It’s truly amazing how much of a difference a small tweak-change can make!</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#5fc8e8</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* a light shade of blue */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.wrapper</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.drop</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">210</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">220</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">45</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 45</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 55</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> -2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #0f9dc4</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* all around */</span></span>
<span class="line"><span style="color:#79B8FF">  5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #0796c1</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* bottom &#x26; right */</span></span>
<span class="line"><span style="color:#79B8FF">  inset</span><span style="color:#79B8FF"> 15</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 15</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 30</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #0796c1</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* inset top &#x26; left */</span></span>
<span class="line"><span style="color:#79B8FF">  inset</span><span style="color:#79B8FF"> -29</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> -20</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #f2f4f7</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* inset bottom &#x26; right */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>This is what is rendered on the screen. For now, we continue to ignore the text and focus on our almost-ready 🙃 amazing drop!</p>
<p><img src="/blue-water-drop-1-create-the-drop.webp" alt="CSS Water drop effect: An image showing a text at the left side and a blue water drop at the right side. We create the water drop using border-radius, background-color and box-shadow CSS properties." style="max-width:55%" class="img-narrow"></p>
<h3 id="adding-shine-to-the-water-drop">Adding shine to the water drop<a class="heading-anchor" href="#adding-shine-to-the-water-drop" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>By utilizing the <code>::before</code> and <code>::after</code> <a href="/coding-made-easy-with-css-selectors-an-ultimate-guide/#pseudo-classes-and-pseudo-elements">pseudo-elements</a> without the need for additional HTML markup. This technique can be used to create a glancing effect. Both pseudo-elements have the same properties but with different values, which helps to differentiate them from each other and create a unique look.</p>
<p>We can effortlessly position those glances within the drop element by using the CSS property <code>position: absolute</code>.</p>
<p>Then, we specify their dimensions and the color by setting the <code>width</code>, <code>height</code> and <code>background-color</code>.</p>
<p>Next, we modify the shadows and their shape by setting the <code>box-shadow</code> and <code>border-radius</code> .</p>
<p>After that, we use the <code>top</code> and <code>left</code> properties to position them. Finally, to make them look even more realistic, we can add some rotation by using the <code>transform: rotate()</code> property.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.drop</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.drop::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">14</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">7</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#f5f5f5</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #f5f5f5</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 45</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">/</span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 45</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">15</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">140</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.drop::after</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#fff</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #fff</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 45</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 45</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">/</span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 40</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 55</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">25</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-45</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>After adding these glances, we can see our final drop. 💦 ✨ It’s pretty cool, isn’t it?</p>
<p><img src="/blue-water-drop-2-adding-glance.webp" alt="CSS Water drop effect: An image showing a text behind a blue water drop. This water drop has two glances at the top right side. We made them using the :before and :after pseudoelements" style="max-width:55%" class="img-narrow"></p>
<h3 id="adjusting-text-appearance-beneath-the-water-drop-effect">Adjusting text appearance beneath the water drop effect<a class="heading-anchor" href="#adjusting-text-appearance-beneath-the-water-drop-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>We are moving forward by adjusting our text and making it more visually appealing. I have selected the “Lobster” font-family with a font size of <code>140</code> pixels, a warm dark orange, and a black <code>2px</code> <code>text-shadow</code>.</p>
<p>In case we wish to use another font-family than the usual ones, we need to insert it into our CSS. We do so by setting the <code>@import url(...)</code>. Ensure this statement is placed at the beginning of your CSS code snippet, just like I did. Check below. 👇</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">@import</span><span style="color:#79B8FF"> url</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'https://fonts.googleapis.com/css?family=Lobster'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.text</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  font-family</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"Lobster"</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">sans-serif</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">140</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#e85a5a</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* a shade of warm dark orange */</span></span>
<span class="line"><span style="color:#79B8FF">  text-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Take a closer look now. The text appears so different behind the water drop. It’s quite impressive, don’t you think? 😎</p>
<p><img src="/blue-water-drop-3-manipulate-text.webp" alt="Water drop effect: An image showing a perfectly centered text behind a blue water drop. This water drop has two glances at the top right side." style="max-width:55%" class="img-narrow"></p>
<p>One last step, and we are ready! We are free to place our text wherever we want by setting the <code>position: absolute</code> , <code>top</code> and <code>left</code> CSS properties in order to move it.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.text</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-45</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-35</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>The final step is complete! Congratulations! 🥳 You have the option to either keep the original design or create your own. Please remember that the most important thing is to combine the appropriate colors 🌈 and shadows; this is necessary for our drop to look realistic.</p>
<p><img src="/blue-water-drop-4-with-text-underneath.webp" alt="Water drop effect: An image showing a text behind a blue water drop. This water drop has two glances at the top right side." style="max-width:55%" class="img-narrow"></p>
<h2 id="full-css-water-drop-effect-code-copy--paste-ready">Full CSS water drop effect code (copy &#x26; paste ready)<a class="heading-anchor" href="#full-css-water-drop-effect-code-copy--paste-ready" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Below is the full code referenced in this blog post. Feel free to copy and use it in your own projects. If you have any questions or encounter any issues, don’t hesitate to reach out for assistance. You can easily copy the desired code snippet by clicking on the copy icon, located in the top-right corner of each snippet.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"wrapper"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"text"</span><span style="color:#E1E4E8">>drop&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"drop"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">@import</span><span style="color:#79B8FF"> url</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'https://fonts.googleapis.com/css?family=Lobster'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">*</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  margin</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  padding</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-sizing</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">border-box</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">html</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">vh</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#5fc8e8</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.wrapper</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.text</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-family</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"Lobster"</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">sans-serif</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">140</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#e85a5a</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  text-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-45</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-35</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.drop</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">210</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">220</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">45</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 45</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 55</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> -2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #0f9dc4</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* all around */</span></span>
<span class="line"><span style="color:#79B8FF">  5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #0796c1</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* bottom &#x26; right */</span></span>
<span class="line"><span style="color:#79B8FF">  inset</span><span style="color:#79B8FF"> 15</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 15</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 30</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #0796c1</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* inset top &#x26; left */</span></span>
<span class="line"><span style="color:#79B8FF">  inset</span><span style="color:#79B8FF"> -29</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> -20</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #f2f4f7</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* inset bottom &#x26; right */</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.drop::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">14</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">7</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#f5f5f5</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #f5f5f5</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 45</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">/</span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 45</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">15</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">140</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.drop::after</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#fff</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #fff</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 45</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 45</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">/</span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 40</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 55</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">25</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-45</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-create-a-stunning-gray-css-water-drop/">How To Create A Stunning Gray CSS Water Drop</a></li>
<li><a href="/how-inset-works-in-box-shadow-made-simple/">How inset Works in box-shadow (Made Simple)</a></li>
<li><a href="/transform-your-text-black-and-white-css-stripes-made-easy/">Striped Text Effect in CSS</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>CSS Neon Text Effect</title>
      <link>https://littlecodingthings.com/how-to-create-stunning-vibrant-neon-effect-css-only/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-create-stunning-vibrant-neon-effect-css-only/</guid>
      <pubDate>Wed, 07 May 2025 08:00:00 GMT</pubDate>
      <description>Build a glowing neon sign with nothing but layered box-shadow and text-shadow — outer glow, inset glow and a matching text halo.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>The <strong>neon effect</strong> in web design brings that bold, electric vibe that grabs attention right away. ⚡🌈 Inspired by real-life neon signs, which I’m sure you have seen outside bars, arcades, or glowing up city streets, it mixes retro charm with a modern twist. It adds personality and mood, turning plain text or shapes into glowing, eye-catching pieces. That soft glow, the depth, those bright color fades — they take a simple design and make it feel alive, as if you have just travelled back in time. 🌟 And the best part? You can pull it off with just <a href="/is-html-a-programming-language-find-out-now/">HTML</a> and <a href="/the-truth-about-css-is-it-really-a-programming-language/" title="CSS">CSS</a>. No images, no JavaScript. 🥳</p>
<h2 id="setting-the-stage-basic-html-structure">Setting the stage: Basic HTML structure<a class="heading-anchor" href="#setting-the-stage-basic-html-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>To begin creating this effect, we’ll start with a basic <a href="/most-useful-html-elements-for-maximizing-better-results/">HTML</a> structure and add custom CSS later. Think of the HTML <code>&#x3C;div></code> we are using, as the frame for a neon sign, and the text as the glowing message inside it.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"neon-effect"</span><span style="color:#E1E4E8">>Neon Vibes Simple Css&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p>From there, we move to <a href="/how-to-work-with-css-syntax-the-correct-way/">CSS</a> structure. We import a Google font named “Orbitron”, a futuristic style text, that fits perfectly for our neon effect.</p>
<p>Then we lay the foundation: we structure the page by setting the body to fill the entire viewport and using <code>display: flex</code> <a href="/how-to-center-in-css-using-different-ways/">to center our neon box both vertically and horizontally</a>. Finally, we add a solid black background — it doesn’t look like much yet, but it sets the perfect stage for the neon glow we’ll add soon, creating strong contrast just like a real sign glowing in the dark.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">@import</span><span style="color:#79B8FF"> url</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'https://fonts.googleapis.com/css?family=Orbitron'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  max-width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">vh</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#000</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h2 id="building-the-neon-sign-base">Building the neon sign base<a class="heading-anchor" href="#building-the-neon-sign-base" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The <code>.neon-effect</code> class is used to create the main structure of the glowing sign. It defines a rectangular box with a width of <code>700px</code> and a height of <code>300px</code>, along with a soft, <a href="/how-to-be-creative-with-different-css-border-styles/">rounded border</a> in light violet (#f4cbf8).</p>
<p>The box uses <code>display: flex</code> to perfectly center the text both vertically and horizontally. The font is set to <strong>Orbitron</strong>, giving the text a bold, futuristic style, and its size is large (<code>80px</code>) to make it stand out.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.neon-effect</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#6A737D">  /* Frame */</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">700</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> #f4cbf8</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* light violet */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">  /* Fonts */</span></span>
<span class="line"><span style="color:#79B8FF">  font-family</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">'Orbitron'</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">Arial</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">80</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  text-align</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#faf0fb</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* light pink */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/neon-text-effect-creat-base.webp" alt="Building the neon sign base (frame and text) to create the neon effect." style="max-width:42%" class="img-narrow"></p>
<p>The text color is a very light pink (#faf0fb), which will work beautifully once we add glowing shadow effects around it. For now, this creates a clean and centered base — the canvas for our neon sign.</p>
<h2 id="glowing-borders-neon-frame-with-box-shadow">Glowing borders: Neon frame with box-shadow<a class="heading-anchor" href="#glowing-borders-neon-frame-with-box-shadow" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>To create the glowing neon frame around the box, we use layered <a href="/how-box-shadow-works-made-simple/"><code>box-shadow</code></a> effects. The <strong>outer shadows</strong> softly expand in multiple directions, starting with white and transitioning through vivid shades of pink, magenta, and purple. This gives the impression of light softly spreading from the edges.</p>
<p>We also include a subtle touch of <strong>yellow-gold</strong> hue, blending into the glow. This not only adds visual warmth but also gives a nostalgic nod to vintage neon signs, bringing up the charm of the old days while keeping the overall look fresh and vibrant.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.neon-effect</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">:</span></span>
<span class="line"><span style="color:#6A737D">    /* outer glow */</span></span>
<span class="line"><span style="color:#79B8FF">    0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #fff</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* white */</span></span>
<span class="line"><span style="color:#79B8FF">    0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 6</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #ff99ff</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* light pink */</span></span>
<span class="line"><span style="color:#79B8FF">    0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 12</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #ff33ff</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* magenta */</span></span>
<span class="line"><span style="color:#79B8FF">    0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #cc00ff</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* violet */</span></span>
<span class="line"><span style="color:#79B8FF">    0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 28</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #9900cc</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* deep purple */</span></span>
<span class="line"><span style="color:#79B8FF">    0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 36</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #660066</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* dark purple */</span></span>
<span class="line"><span style="color:#79B8FF">    0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 40</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #ffe187</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* light yellow - soft gold */</span></span>
<span class="line"><span style="color:#6A737D">    /* inner glow */</span></span>
<span class="line"><span style="color:#79B8FF">    inset</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 4</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #ff99ff</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* light pink */</span></span>
<span class="line"><span style="color:#79B8FF">    inset</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 8</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #ff33ff</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* magenta */</span></span>
<span class="line"><span style="color:#79B8FF">    inset</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 14</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #cc00ff</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* violet */</span></span>
<span class="line"><span style="color:#79B8FF">    inset</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 18</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #9900cc</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* deep purple */</span></span>
<span class="line"><span style="color:#79B8FF">    inset</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 24</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #660066</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* dark purple */</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span></code></pre></div>
<p>Equally important is the second group, which uses the <code>inset</code> keyword and adds an inner glow that shines inside the box. These <strong>inset shadows</strong> create depth and give the illusion that the light is not only around the sign, but also glowing from within. The combination of outer and inset shadows is essential for achieving a rich, realistic neon effect.</p>
<p><img src="/neon-text-effect-creat-style-frame.webp" alt="Styling the neon frame with pink, magenta, purple and yellow-gold hues setting the box shadow CSS property." style="max-width:42%" class="img-narrow"></p>
<h2 id="illuminated-text-neon-glow-with-text-shadow">Illuminated Text: Neon Glow with Text-Shadow<a class="heading-anchor" href="#illuminated-text-neon-glow-with-text-shadow" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>To create the glowing effect around the text, we use the same method, multiple layers of <a href="/enhance-your-content-utilizing-the-css-text-shadow-property/"><code>text-shadow</code></a>. Each shadow in your code adds a soft light in a different shade: from white and light pink to vibrant magenta and deep purple.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.neon-effect</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  text-shadow</span><span style="color:#E1E4E8">:</span></span>
<span class="line"><span style="color:#79B8FF">    0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #fff</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* white */</span></span>
<span class="line"><span style="color:#79B8FF">    0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #ff99ff</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* light pink */</span></span>
<span class="line"><span style="color:#79B8FF">    0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #ff33ff</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* magenta */</span></span>
<span class="line"><span style="color:#79B8FF">    0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 26</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #cc00ff</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* violet */</span></span>
<span class="line"><span style="color:#79B8FF">    0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 24</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #9900cc</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* deep purple */</span></span>
<span class="line"><span style="color:#79B8FF">    0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 32</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #660066</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* dark purple */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>These layered shadows build a rich glow around each letter, giving it a strong, radiant presence against the dark background. The variation in color and blur size creates depth, making the text appear as if it’s lit from within, just like real neon tubing.</p>
<p><img src="/neon-text-effect-creat-style-text.webp" alt="Styling the neon text with pink, magenta and purple hues setting the text shadow CSS property." style="max-width:42%" class="img-narrow"></p>
<p>Neon effects in web design are a powerful way to grab attention. ✨ They combine vivid colors, glowing shadows, and sharp contrast to mimic the iconic look of neon signs. Whether you’re aiming for a modern tech vibe or a nostalgic retro feel, neon brings style and energy. Using CSS alone, we can recreate this classic visual with precision and creativity — no electricity needed! 💡😎</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/enhance-your-content-utilizing-the-css-text-shadow-property/">The CSS text-shadow Property</a></li>
<li><a href="/how-inset-works-in-box-shadow-made-simple/">How inset Works in box-shadow (Made Simple)</a></li>
<li><a href="/how-to-make-a-css-shine-effect-animation/">How To Make a CSS Shine Effect Animation</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>CSS Grayscale Filter – A Complete Guide</title>
      <link>https://littlecodingthings.com/awesome-css-grayscale-filter-how-to-upgrade-images/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/awesome-css-grayscale-filter-how-to-upgrade-images/</guid>
      <pubDate>Mon, 28 Apr 2025 10:24:00 GMT</pubDate>
      <description>Apply filter: grayscale() to text, backgrounds, photos, SVG, Font Awesome icons and emoji — with a before-and-after for every case.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hello everybody! 😃 In the vibrant world of web design, the CSS grayscale filter stands as a powerful tool for transforming the visual appearance of images and elements on a webpage. The CSS filter: grayscale(%) works like a magic wand. 🪄 It takes colorful images or elements and converts them into grayscale shades. This effect is great for creating different aesthetics, whether you’re aiming for a vintage charm or a sleek, modern look. The CSS grayscale filter can be applied to various elements, including images, SVGs, emojis, font icons, and even <a href="/most-useful-html-elements-for-maximizing-better-results/">HTML elements</a>.</p>
<p>Let’s explore what makes this filter so enchanting! 🧙‍♀️</p>
<h2 id="grayscale-on-html-elements">Grayscale on HTML elements<a class="heading-anchor" href="#grayscale-on-html-elements" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>First of all, it’s important to note that the CSS grayscale filter may not be noticeable on <strong>black</strong> and <strong>white</strong> elements. Since grayscale shifts colors toward shades of gray, and black is already the darkest shade, while white stays the lightest one. Secondly, always keep in mind that the <code>filter: grayscale(100%)</code> can make text completely dark, which may not be ideal when placed on black or very dark backgrounds.</p>
<h3 id="using-the-css-grayscale-filter-on-fonts">Using the CSS grayscale filter on fonts<a class="heading-anchor" href="#using-the-css-grayscale-filter-on-fonts" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>We will begin by applying grayscale to fonts. In the following example, I used blue text, instead of the default black to emphasize the contrast and make the transition to shades of gray more noticeable.</p>
<p>This reinforces an important point we discussed earlier—this effect stands out most when applied to bright, colored elements rather than dark, black, or near-black ones. 😉</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">>The grayscale filter&#x3C;/</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">h1</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">blue</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">grayscale</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>With the <a href="/most-useful-html-elements-for-maximizing-better-results/">HTML</a> code, we define an <code>&#x3C;h1></code> heading element, then <a href="/how-to-work-with-css-syntax-the-correct-way/">CSS</a> sets its text color to blue and applies a grayscale filter to it. Initially, we use 50% intensity, creating a visual effect where the blue text is converted to grayscale while still retaining a subtle hint of its original blue color.</p>
<p>To clarify, there is another example where we use the filter at 90%, resulting in the title appearing in different shades of gray. This time, it’s very close to being completely dark gray—almost black, we could say.</p>
<figure><img src="/greyscale-filter-fonts1.webp" alt="This image shows a blue text." style="max-width:42%" class="img-narrow"><figcaption>without grayscale(%)</figcaption></figure>
<figure><img src="/greyscale-filter-fonts2.webp" alt="This image displays blue text with the CSS grayscale filter set to 50%, partially desaturating the blue color into varying shades of gray." style="max-width:42%" class="img-narrow"><figcaption>with grayscale(50%)</figcaption></figure>
<figure><img src="/greyscale-filter-fonts3.webp" alt="This image displays blue text with the CSS grayscale filter set to 90%, turning it into grayish shades while retaining 10% of the original blue color." style="max-width:42%" class="img-narrow"><figcaption>with grayscale(90%)</figcaption></figure>
<h3 id="grayscale-on-background-color">Grayscale on background color<a class="heading-anchor" href="#grayscale-on-background-color" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>In this case, instead of setting the text color, we will set the <code>background-color</code>. Now, take a look at the orange. In the first image, we see a bright orange, while in the second, the color appears slightly darker (grayish) due to the <code>filter: grayscale(40%)</code> property.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">>The grayscale filter&#x3C;/</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">h1</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">grayscale</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">40</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<figure><img src="/grayscale-filter-background-color1.webp" alt="This image displays black text on an orange background color." style="max-width:42%" class="img-narrow"><figcaption>without grayscale(%)</figcaption></figure>
<figure><img src="/grayscale-filter-background-color2.webp" alt="This image displays black text on an orange background with the CSS grayscale filter set to 40%, converting the background into grayish shades while reducing its original color intensity." style="max-width:42%" class="img-narrow"><figcaption>with grayscale(40%)</figcaption></figure>
<h2 id="grayscale-on-other-html-elements">Grayscale on other HTML elements<a class="heading-anchor" href="#grayscale-on-other-html-elements" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We can also apply the grayscale filter to various HTML elements, such as <code>&#x3C;span></code>, <code>&#x3C;li></code>, and more. Below, I’ve provided two examples for clarity: the first applies the filter to the content of two <code>&#x3C;span></code> elements, while the second applies it to the bullets of an <code>&#x3C;li></code>.</p>
<h3 id="example-using-a-span">Example using a span<a class="heading-anchor" href="#example-using-a-span" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"grayscale-elements"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">>"&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">> Happy Coding! &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">>"&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.grayscale-elements</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.grayscale-elements</span><span style="color:#85E89D"> span</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">grayscale</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">80</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>In the HTML snippet, we create a <code>&#x3C;div></code> element with the class <code>.grayscale-elements</code>. Inside this <code>&#x3C;div></code>, we add two <code>&#x3C;span></code> elements, each containing a double quote to frame the text <strong>“Happy Coding!”</strong> These <code>&#x3C;span></code> elements allow us to style the quotes differently from the rest of the text.</p>
<p>In the associated CSS code, <code>.grayscale-elements</code> is targeting elements with this class. The text color of the elements with this class is set to orange. Additionally, the CSS rules target the <code>&#x3C;span></code> elements inside and apply an 80% grayscale filter to them, rendering the quotes in shades of gray while retaining the orange color for the rest of the content.</p>
<figure><img src="/grayscale-filter-html-elements-span1.webp" alt="This image displays orange text enclosed in quotation marks." style="max-width:42%" class="img-narrow"><figcaption>without grayscale(%)</figcaption></figure>
<figure><img src="/grayscale-filter-html-elements-span2.webp" alt="This image displays orange text enclosed in quotes, with the quotes inside <span> elements. The spans have the CSS grayscale filter set to 80%, converting the orange color into grayish shades while retaining 20% of its original hue." style="max-width:42%" class="img-narrow"><figcaption>with grayscale(80%)</figcaption></figure>
<h3 id="example-using-a-ul">Example using a ul<a class="heading-anchor" href="#example-using-a-ul" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">ul</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>HTML&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>CSS&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Javascript&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">ul</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">ul</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  list-style</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">none</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* remove the default bullets */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">li</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* change lists default (black) color */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">li</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"•"</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* add new bullets and now can be manipulated */</span></span>
<span class="line"><span style="color:#79B8FF">  margin-right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* add distance between the bullet and the text */</span></span>
<span class="line"><span style="color:#79B8FF">  filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">grayscale</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">); </span><span style="color:#6A737D">/* one of our examples */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>In the HTML snippet, we create an unordered list (<code>&#x3C;ul></code>) containing three list items (<code>&#x3C;li></code>).</p>
<p>In the associated CSS, we target the <code>&#x3C;ul></code> element and remove the default bullets using <code>list-style: none</code>. Then, we style the list items (<code>&#x3C;li></code>), setting their text color to magenta.</p>
<p>The <code>::before</code> <a href="/coding-made-easy-with-css-selectors-an-ultimate-guide/" title="pseudo-element">pseudo-element</a> is used to add custom bullets before each list item. In this case, the bullet is a solid circle (•) created using the <code>content</code> property. The <code>margin-right</code> property adds spacing between the bullet and the text.</p>
<p>Additionally, a grayscale effect is applied to the bullets using <code>filter: grayscale(50%)</code>, reducing their original color intensity by 50%. This results in bullets appearing in varying shades of gray while still retaining some color.</p>
<p>For an even more pronounced effect, I also applied a 90% grayscale filter (<code>filter: grayscale(90%)</code>), making the bullets appear even closer to a true gray. 😃</p>
<figure><img src="/grayscale-filter-html-elements-li1.webp" alt="This image displays an unordered list with three list items, all styled in magenta color." style="max-width:32%" class="img-narrow"><figcaption>without grayscale(%)</figcaption></figure>
<figure><img src="/grayscale-filter-html-elements-li2.webp" alt="This image shows an unordered list with three list items inside. The list items have color magenta while a grayscale effect is applied to the bullets using filter: grayscale(50%), rendering them with a 50% intensity of grayscale." style="max-width:32%" class="img-narrow"><figcaption>with grayscale(50%)</figcaption></figure>
<figure><img src="/grayscale-filter-html-elements-li3.webp" alt="This image displays an unordered list with three magenta-colored list items. The bullets have the CSS grayscale filter set to 90%, making them appear in grayish shades." style="max-width:32%" class="img-narrow"><figcaption>with grayscale(90%)</figcaption></figure>
<h2 id="css-grayscale-on-images">CSS Grayscale on images<a class="heading-anchor" href="#css-grayscale-on-images" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Another way to take advantage of this CSS property is by applying the <code>filter: grayscale</code> to images, transforming their colors into shades of gray. This is particularly useful for making pictures look old-fashioned or monochromatic when they create a black and white effect.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"grayscale-image"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.grayscale-image</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">url</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">&#x3C;your-image></span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  background-repeat</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">no-repeat</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">cover</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">400</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">grayscale</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">70</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>The given code creates an HTML <code>div</code> element with the class <code>.grayscale-image</code>.</p>
<p>This class is styled using CSS to display a grayscale image. The background of the <code>div</code> is set to an image from the provided URL using the <code>background-image</code> property. The image is styled to not repeat (<code>background-repeat: no-repeat</code>) and to cover the entire area (<code>background-size: cover</code>). Its dimensions are set to <code>width</code> of 300 pixels and <code>height</code> of 400 pixels. Finally, a grayscale filter is applied to the image using the <code>filter</code> property, with a 70% level of grayscale.</p>
<figure><img src="/grayscale-filter-image1.webp" alt="This image displays a photo with vibrant colors, including shades of pink, gold, and green." style="max-width:32%" class="img-narrow"><figcaption>without grayscale(%) – Original photo by <a href="https://unsplash.com/@kharp?utm_content=creditCopyText&#x26;utm_medium=referral&#x26;utm_source=unsplash">Katie Harp</a> on <a href="https://unsplash.com/photos/pink-and-white-book-on-white-and-green-floral-textile-mhx-T3pOHm4?utm_content=creditCopyText&#x26;utm_medium=referral&#x26;utm_source=unsplash">Unsplash</a></figcaption></figure>
<figure><img src="/grayscale-filter-image2.webp" alt="This image displays a photo with colors close to pink, gold, and green, with the CSS grayscale filter set to 70%, partially desaturating the colors into grayish tones." style="max-width:42%" class="img-narrow"><figcaption>with grayscale(70%)</figcaption></figure>
<p>I did something similar for the following image but set the <code>grayscale</code> to 100%, which transformed the image entirely into shades of gray. Impressive, isn’t it? 🙃</p>
<figure><img src="/grayscale-filter-image1-building-without-grayscale.webp" alt="This image displays a photo of a brown building with the sky in the background and an airplane flying overhead." style="max-width:32%" class="img-narrow"><figcaption>without grayscale – Original photo by <a href="https://unsplash.com/@boontohhgraphy?utm_content=creditCopyText&#x26;utm_medium=referral&#x26;utm_source=unsplash">Sorasak</a> on <a href="https://unsplash.com/photos/bottom-view-shot-of-airplane-flying-above-high-rise-building-KxCJXXGsv9I?utm_content=creditCopyText&#x26;utm_medium=referral&#x26;utm_source=unsplash">Unsplash</a></figcaption></figure>
<figure><img src="/grayscale-filter-image2-building-with-grayscale.webp" alt="This image displays a photo of a brown building and the sky with an airplane. The CSS grayscale filter is set to 100%, converting the entire photo into grayscale shades." style="max-width:32%" class="img-narrow"><figcaption>grayscale(100%)</figcaption></figure>
<h2 id="css-grayscale-on-svg">CSS Grayscale on SVG<a class="heading-anchor" href="#css-grayscale-on-svg" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The grayscale filter can be applied to SVG elements too, making them appear in varying shades of gray. This is often used to achieve a specific artistic or design effect. For instance, we applied this filter to an <strong>SVG of a moon</strong>, which was originally yellow, transforming it into a soft gray and adding a unique visual dimension. Awesome, right?</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">svg</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">grayscale</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">80</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>In our CSS code, we apply a filter with a specified grayscale percentage of 80%. This effect transforms the originally yellow image into varying shades of gray while preserving a subtle hint of its original color.</p>
<p>🔖 Remember that directly targeting the <code>&#x3C;svg></code> element may cause conflicts 🌩 ⚡ if multiple SVGs exist in the document.</p>
<figure><img src="/grayscale-filter-svg1.webp" alt="This image displays a yellow moon against a dark background." style="max-width:25%" class="img-narrow"><figcaption>without grayscale(%)</figcaption></figure>
<figure><img src="/grayscale-filter-svg2.webp" alt="This image displays a yellow moon with the CSS grayscale filter set to 80%, partially desaturating the colors into grayish shades while retaining 20% of the original hue." style="max-width:25%" class="img-narrow"><figcaption>with grayscale(80%)</figcaption></figure>
<h2 id="css-grayscale-in-font-awesome">CSS Grayscale in Font Awesome<a class="heading-anchor" href="#css-grayscale-in-font-awesome" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Another way to use this CSS trick is with <strong>Font Awesome</strong> icons. In the example below, we will see how to do it the correct way. Since Font Awesome icons start off as black, it’s important to apply color before adding the grayscale effect.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">i</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"fa-solid fa-camera-retro"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">i</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.fa-camera-retro</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">grayscale</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">70</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/* OR - if you want a more generic rule */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">i</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">grayscale</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">70</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>In this HTML snippet, we have an <code>&#x3C;i></code> element with the class <code>.fa-solid .fa-camera-retro</code> from the Font Awesome library.</p>
<p>The corresponding <strong>CSS</strong> styles <code>.fa-camera-retro</code>, setting the icon’s color to <strong>red</strong> and applying a <strong>70% grayscale effect</strong>. Additionally, we can also target the <code>&#x3C;i></code> element directly for a more generic customization.</p>
<p>🔖 Remember, if you use the <strong>Font Awesome</strong> <code>.fa-solid</code> class for multiple icons or style them via <code>&#x3C;i></code>, all instances will inherit the same appearance, affecting every <code>&#x3C;i></code> element in the document.</p>
<figure><img src="/grayscale-filter-fontawesome1.webp" alt="This image displays a red retro camera icon from Font Awesome." style="max-width:25%" class="img-narrow"><figcaption>without grayscale</figcaption></figure>
<figure><img src="/grayscale-filter-fontawesome2.webp" alt="This image displays a red retro camera icon from Font Awesome with the CSS grayscale filter set to 70%, making the red appear much darker, almost brown." style="max-width:25%" class="img-narrow"><figcaption>with grayscale(70%)</figcaption></figure>
<h2 id="css-grayscale-on-emoticons-using-pseudo-elements">CSS Grayscale on emoticons using pseudo-elements<a class="heading-anchor" href="#css-grayscale-on-emoticons-using-pseudo-elements" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Next, we move on to the beloved <strong>emoticons</strong> (like 🤗, 😇, etc.). It’s a cool way to make them look a bit different! Below I crafted an example to give a clearer explanation. I chose two of my favorite emoticons 👩‍🎤 🧚‍♀️. Feel free to choose your personal favorite and enjoy the experience!! Always remember that the more vivid the colors, the stronger and more noticeable the effect will be! Good luck! 🌟 🥳</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"grayscale-emoticons"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.grayscale-emoticons::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"👩‍🎤 🧚‍♀️"</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">grayscale</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">40</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>The HTML snippet creates a <code>div</code> element with the class <code>.grayscale-emoticons</code>.</p>
<p>The linked CSS code, <code>.grayscale-emoticons</code> uses the <code>::before</code> pseudo-element to insert content. The inserted content consists of two emojis: “👩‍🎤” and “🧚‍♀️.” Additionally, a grayscale <code>filter</code> of 40% is applied, giving the emojis a subtle grayscale effect, displaying them in varying shades of gray while retaining some of their original colors.</p>
<p>I also included another example with a <strong>100% grayscale filter</strong>, which completely removes all colors, rendering the emojis entirely in grayscale.</p>
<figure><img src="/greyscale-filter-emoticons1.webp" alt="This image shows two colorful emoticons." style="max-width:42%" class="img-narrow"><figcaption>without grayscale</figcaption></figure>
<figure><img src="/greyscale-filter-emoticons2.webp" alt="This image shows two colorful emoticons with a grayscale filter of 40%. As a result the emoticons are now displayed in varying shades of gray with 40% intensity of the original colors." style="max-width:42%" class="img-narrow"><figcaption>with grayscale(40%)</figcaption></figure>
<figure><img src="/greyscale-filter-emoticons3.webp" alt="This image shows two colorful emoticons with a grayscale filter of 100%. As a result the emoticons are now displayed only in shades of gray." style="max-width:42%" class="img-narrow"><figcaption>with grayscale(100%)</figcaption></figure>
<p>Using shades of gray adds a nice touch, but if you want to go the extra mile 🏃‍♀️, try adding shadows to elements for a more realistic look. Building on our previous example, I’ve incorporated the fantastic <a href="/drop-shadow-vs-box-shadow-what-is-the-difference/">drop-shadow CSS property</a> to achieve this. Pretty cool, right! 😃</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.grayscale-emoticons::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"👩‍🎤 🧚‍♀️"</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">grayscale</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">40</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">drop-shadow</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> -1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #1d1e22</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<figure><img src="/grayscale-filter-emoticons2-add-shadow.webp" alt="This image displays two colorful emoticons with the CSS grayscale filter set to 40%, partially desaturating their colors. They also feature a 2px -1px 1px gray shadow." style="max-width:42%" class="img-narrow"><figcaption>filter: grayscale(40%) drop-shadow(2px -1px 1px #1d1e22);</figcaption></figure>
<figure><img src="/grayscale-filter-emoticons3-add-shadow.webp" alt="This image shows two colorful emoticons with a grayscale filter of 100%. As a result the emoticons are now displayed in various shades of gray. They also have a 2px -2px 2px gray shadow." style="max-width:42%" class="img-narrow"><figcaption>filter: grayscale(100%) drop-shadow(2px -2px 2px #1d1e22);</figcaption></figure>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/css-grayscale-filter-how-to-upgrade-images/">How to Make Grayscale Images with CSS</a></li>
<li><a href="/grayscale-backdrop-filter-a-useful-tool-to-make-grayish-backgrounds/">CSS backdrop-filter: grayscale()</a></li>
<li><a href="/the-css-sepia-filter-learn-how-to-make-vintage-images/">The CSS Sepia Filter Explained</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>CSS Conic Gradient Made Easy</title>
      <link>https://littlecodingthings.com/css-conic-gradient-technique-how-to-make-stunning-visual-effects/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/css-conic-gradient-technique-how-to-make-stunning-visual-effects/</guid>
      <pubDate>Thu, 17 Apr 2025 08:49:00 GMT</pubDate>
      <description>Sweep colors around a point with conic-gradient. Move the center, set the start angle, add color stops and build pie-chart style wedges.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hello! 😃 CSS conic gradient techniques are a fantastic way to add colorful, creative flair to your designs. Today, we’re diving into the enchanting world of <code>conic-gradient</code> in CSS — a type of gradient where <a href="/what-you-need-to-know-about-css-color-methods/" title="colors">colors</a> transition in a circular or conical pattern around a central point (either the default center or one you define within the element).</p>
<p>This powerful technique allows you to blend and combine colors in unique ways, creating artistic and visually striking effects. Plus, it’s perfect for building things like <strong>pie charts</strong> for presentations — no extra libraries needed!</p>
<p>In addition to <code>conic-gradient</code> CSS also offers <a href="/css-linear-gradient-techniques-how-to-make-colorful-line-drawings/">linear-gradient</a> and <a href="/css-radial-gradient-techniques-how-to-make-colorful-infinite-loops/" title="radial-gradient">radial-gradient</a> techniques. 🌈✨ They all have a starting and an ending point, giving us the flexibility to control the direction and flow of the gradient. It is essential to blend at least two colors, but we can blend even more, creating smooth transitions or distinct shifts between them based on our needs.</p>
<p>Ready to unlock 🗝 the art and practical uses of conical gradients? Let’s jump into this creative adventure! 💻</p>
<h2 id="what-is-a-conic-gradient">What is a conic gradient?<a class="heading-anchor" href="#what-is-a-conic-gradient" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>A CSS conic gradient is a styling technique used in CSS to create a color transition that radiates from a central point in a circular or conical pattern. It allows you to specify different color stops and angles, leading to a visually pleasing gradient effect for backgrounds or other elements on a webpage.</p>
<p>There are many variations and creative ways to use conic gradients — and we’ll be exploring them in the next sections!</p>
<h2 id="understanding-the-default-direction-of-a-css-conic-gradient">Understanding the default direction of a CSS conic gradient<a class="heading-anchor" href="#understanding-the-default-direction-of-a-css-conic-gradient" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>So, let’s begin with the <strong>default</strong> direction, which is clockwise. To create a conic gradient, we need at least two colors. Below, I’ve prepared some examples to show exactly what I mean.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* blend two colors */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.conic-two-colors</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/conic1a-default-two-colors.webp" alt="Default CSS conic gradient with two colors, red and green" style="max-width:32%" class="img-narrow"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* blend many colors */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.conic-multiple-colors</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">yellow</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/conic1b-default-many-colors.webp" alt="Default conic gradient with many colors." style="max-width:32%" class="img-narrow"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* blend black and white */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.conic-black-white</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/conic1c-default-black-and-white-colors.webp" alt="Default conic gradient with only black and white." style="max-width:32%" class="img-narrow"></p>
<p>🔖 Keep in mind that if we want to achieve a <strong>seamless transition between the last and first color</strong>, we have two ways to achieve this:</p>
<ul>
<li>First, we can choose <strong>intermediate colors between the starting and ending colors</strong>. For example, in our case, we can pick colors from <code>#FF4C00</code> (orange) to <code>#FF6E00</code> (a reddish shade), creating a smooth blend from orange to red.</li>
<li>The second option, which is simpler, involves <strong>repeating the same color</strong> at both ends. In this example, we’ll use <code>red</code> as the repeated color.</li>
</ul>
<p>Here’s a simple code snippet to help illustrate this.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* using specific colors when blending */</span></span>
<span class="line"><span style="color:#B392F0">.conic-smooth-option-a</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">yellow</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#FF4C00</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#FF6E00</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/* using the same color at both ends */</span></span>
<span class="line"><span style="color:#B392F0">.conic-smooth-option-b</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">yellow</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/conic1b-smooth.webp" alt="" style="max-width:28%" class="img-narrow"></p>
<h2 id="positioning-the-center-of-a-css-conic-gradient">Positioning the center of a CSS conic gradient<a class="heading-anchor" href="#positioning-the-center-of-a-css-conic-gradient" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<h3 id="move-the-center-to-the-sides">Move the center to the sides<a class="heading-anchor" href="#move-the-center-to-the-sides" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>In CSS, conic gradients provide the flexibility to reposition the gradient’s center anywhere within the container. This enables precise alignment with a specific side, whether or not you use percentage values (%) or define specific color stops.</p>
<p>In the following examples, we’ll focus on positioning the gradient center along different sides of the container.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* Gradient starting from the left */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.conic-left-point</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">at</span><span style="color:#79B8FF"> left</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/conic2-at-left.webp" alt="Conic gradient with many colors. The center is at the left side of the square." style="max-width:32%" class="img-narrow"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* Starting point at 75% from the left */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.conic-using-percentage</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">at</span><span style="color:#79B8FF"> left</span><span style="color:#79B8FF"> 75</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/conic3-at-left75.webp" alt="Conic gradient with many colors. The center is at the 75% of the left side of the square." style="max-width:32%" class="img-narrow"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* Gradient starting at 75% left with defined color stops */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.conic-specific-stops</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">at</span><span style="color:#79B8FF"> left</span><span style="color:#79B8FF"> 75</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">red</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#79B8FF"> 15</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">purple</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#79B8FF"> 25</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/conic3-at-left75-with-specific-color-stops.webp" alt="Conic gradient with many colors and specific color stops. The center is at the 75% of the left side of the square." style="max-width:32%" class="img-narrow"></p>
<h3 id="move-the-center-to-the-corners">Move the center to the corners<a class="heading-anchor" href="#move-the-center-to-the-corners" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Building on the previous section, we can also move the gradient’s center to the corners of the container. Conic gradients in CSS allow this kind of precise positioning, with or without using color stops, giving you even more layout control.</p>
<h4 id="without-color-stops">Without color stops<a class="heading-anchor" href="#without-color-stops" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p>The following code snippet shows a gradient that <strong>starts from the center point of our element</strong> with red color, transitions to green, then blue, followed by purple, ending with orange, creating a smooth, circular gradient effect.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.conic-default</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/conic-5-final.webp" alt="" style="max-width:28%" class="img-narrow"></p>
<p>Below we can see how the previous gradient can break into different pieces the position we choose for the gradient’s center.</p>
<p>The CSS code snippet <code>.conic-bottom-right-corner</code> <strong>starts at the bottom right corner of our element</strong> and smoothly transitions through red, green, blue, purple, and orange creating a visually appealing color blend.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.conic-bottom-right-corner</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">at</span><span style="color:#79B8FF"> bottom</span><span style="color:#79B8FF"> right</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/conic5a-at-bottom-right.webp" alt="CSS Conic-gradient where the center is at the bottom right corner." style="max-width:32%" class="img-narrow"></p>
<p>The reason you’re only seeing the purple and orange colors is due to the angle of the gradient in relation to the element.</p>
<p>I followed the same steps with <code>.conic-bottom-left-corner</code>, and as the angle changes, the red and green colors become visible. The same goes for <code>.conic-top-right-corner</code>, where we can now see shades of blue and purple. Finally, by setting the center to the top left using <code>.conic-top-left-corner</code>, green and blue come into view. How cool is that! 🥳</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.conic-bottom-left-corner</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">at</span><span style="color:#79B8FF"> bottom</span><span style="color:#79B8FF"> left</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/conic5b-at-bottom-left.webp" alt="CSS Conic-gradient where the center is at the bottom left corner." style="max-width:32%" class="img-narrow"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.conic-top-right-corner</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">at</span><span style="color:#79B8FF"> top</span><span style="color:#79B8FF"> right</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/conic5c-at-top-right.webp" alt="Conic-gradient where the center is at the top right corner." style="max-width:32%" class="img-narrow"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.conic-top-left-corner</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">at</span><span style="color:#79B8FF"> top</span><span style="color:#79B8FF"> left</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/conic5d-at-top-left.webp" alt="Conic-gradient where the center is at the top left corner." style="max-width:32%" class="img-narrow"></p>
<p>Imagine that changing the center position and adjusting the angle is like zooming in on the gradient — revealing each quarter of the circle more closely, one at a time. 🔍 It’s like examining the gradient through a magnifying glass as you explore each corner!</p>
<h4 id="with-color-stops">With color stops<a class="heading-anchor" href="#with-color-stops" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p>Let’s take a look at the following example, where color stops are used to better control how and where each color appears within the conic gradient.</p>
<p>Color stops let you define specific points along the gradient circle where a color should begin or end. This gives you greater precision over the flow of colors, rather than relying on an even, automatic blend. For example:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.conic-color-stops</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">red</span><span style="color:#79B8FF"> 75</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#79B8FF"> 80</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#79B8FF"> 90</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">purple</span><span style="color:#79B8FF"> 95</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/conic-5-with-color-stops.webp" alt="CSS conic-gradient with color stops — red to 75%, then green, blue, purple, and orange up to 100%, creating sharp transitions in a circular layout." style="max-width:32%" class="img-narrow"></p>
<p>In this case, red takes up the majority of the gradient — up to 75% — and the remaining colors (green, blue, purple, and orange) appear in quicker succession toward the end.</p>
<p>We can also combine color stops with center positioning to control not only <em>when</em> colors appear but also <em>where</em> they start. For instance:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.conic-bottom-right-stops</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">at</span><span style="color:#79B8FF"> bottom</span><span style="color:#79B8FF"> right</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">red</span><span style="color:#79B8FF"> 75</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#79B8FF"> 80</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#79B8FF"> 90</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">purple</span><span style="color:#79B8FF"> 95</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/conic5a-at-bottom-right-with-color-stops.webp" alt="Conic-gradient with many colors and specific color stops. The center is at the bottom right corner." style="max-width:32%" class="img-narrow"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.conic-bottom-left-stops</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">at</span><span style="color:#79B8FF"> bottom</span><span style="color:#79B8FF"> left</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">red</span><span style="color:#79B8FF"> 75</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#79B8FF"> 80</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#79B8FF"> 90</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">purple</span><span style="color:#79B8FF"> 95</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/conic5b-at-bottom-left-with-color-stops.webp" alt="Conic-gradient with many colors and specific color stops. The center is at the bottom left corner." style="max-width:32%" class="img-narrow"></p>
<p>These examples show how positioning the gradient center at different corners—while using color stops—can dramatically affect which parts of the gradient are visible. You’ll notice that the dominant red still takes the lead, but the visibility of the other colors shifts depending on the corner you choose.</p>
<h3 id="moving-the-center-inside-the-element">Moving the center inside the element<a class="heading-anchor" href="#moving-the-center-inside-the-element" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>We continue with a really powerful feature of conic gradients: the ability to position the center <em>anywhere</em> inside the element. This opens up even more creative possibilities — and of course, you’re free to use color stops with these custom center positions as well.</p>
<p>Below, I’ve prepared two examples.</p>
<p>In the first one, the gradient starts from a point located 30% across and 55% down the element. It then <strong>smoothly transitions</strong> through different colors: red, green, purple, magenta, yellow, and orange. Imagine a color wheel starting from red and going around in order, stopping at each of these colors along the way.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.conic-center-30-55</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">at</span><span style="color:#79B8FF"> 30</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 55</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  red</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">yellow</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/conic7-at-30-55.webp" alt="Conic-gradient with many colors where the center is at 30% across and 55% down." style="max-width:32%" class="img-narrow"></p>
<p>In the second one, the gradient starts from a point 30% across and 55% down the element — but this time, it uses <strong>color stops</strong> to control exactly where each color appears.</p>
<p>Then it <strong>transitions through different color stops</strong>: red 15%, green 30%, purple 45%, magenta 60%, yellow 90%, and finally orange at 100%. You can use my example or you are free to create your own. I chose these values based on what felt right to me—but feel free to experiment and create your own version. It’s totally up to you</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.conic-center-30-55-stops</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">at</span><span style="color:#79B8FF"> 30</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 55</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  red</span><span style="color:#79B8FF"> 15</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#79B8FF"> 30</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">purple</span><span style="color:#79B8FF"> 45</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">magenta</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">yellow</span><span style="color:#79B8FF"> 90</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/conic7b-at-30-55-with-specific-color-stops.webp" alt="Conic-gradient with many colors and specific color stops. The center is at 30% across and 55% down." style="max-width:32%" class="img-narrow"></p>
<h2 id="changing-the-starting-angle-of-a-css-conic-gradient">Changing the starting angle of a CSS conic gradient<a class="heading-anchor" href="#changing-the-starting-angle-of-a-css-conic-gradient" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Let’s move forward and explore another option available with conic gradients, as we are free to start the gradient from different points.</p>
<p>In our example the gradient <strong>starts at 45 degrees to the right</strong>, moving from red to blue. This means the colors change smoothly in a circular motion, like a slice of pie with red at the starting edge and blue at the finishing point.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.conic-angle-45</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">from</span><span style="color:#79B8FF"> 45</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/conic6-from-45deg.webp" alt="" style="max-width:28%" class="img-narrow"></p>
<h2 id="css-conic-gradient-without-blending">CSS conic gradient without blending<a class="heading-anchor" href="#css-conic-gradient-without-blending" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Another option is to use a <strong>non-blend</strong> gradient technique. In the following code snippet, the gradient starts with the color red at the top of the circle and makes sharp, sudden transitions to the next colors — green, blue, purple, and finally orange. Each color occupies a distinct 20% slice of the circle, creating a step-like, segmented pattern with no smooth blending between sections. It’s like a colorful pie chart made of equal parts.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.conic-no-blending</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#79B8FF">  red</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">red</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  green</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#79B8FF"> 40</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  blue</span><span style="color:#79B8FF"> 40</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  purple</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">purple</span><span style="color:#79B8FF"> 80</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  orange</span><span style="color:#79B8FF"> 80</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">%</span></span>
<span class="line"><span style="color:#E1E4E8">  );</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/conic8-equal-no-gradient.webp" alt="" style="max-width:28%" class="img-narrow"></p>
<h2 id="creating-repeating-css-conic-gradients">Creating repeating CSS conic gradients<a class="heading-anchor" href="#creating-repeating-css-conic-gradients" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The <code>repeating-conic-gradient</code> is a function that is used to repeat the conic gradient. Below are two examples that show just how flexible and creative conic gradients can be.</p>
<p>1. <strong>Repeating every 10%</strong>: The gradient originates from the center of the element. It begins with red at the center, then transitions to green at 5%, and to blue at that same 5% mark, which gives a hard edge rather than a blend. At 10%, it shifts to a specific pinkish-red color defined by the hex code <code>#ff1064</code>. These color transitions repeat every 10% of the circle, creating a series of concentric slices that cycle outward in a continuous, colorful loop.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.conic-repeat-10</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">repeating-conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#ff1064</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/conic9-repeating.webp" alt="" style="max-width:28%" class="img-narrow"></p>
<p>2. <strong>Repeating every 25%</strong>: In this example, the gradient is centered within the element and begins with green at the starting point. As it radiates outward, it shifts to black at 8%, then to orange at 18%, and finally to a vibrant pinkish-red at 25% (using the hex code <code>#ff1064</code>). These defined color stops repeat every 25% of the circle, creating a looping, segmented pattern that spirals out from the center in consistent, colorful sections.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.conic-repeat-25</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">repeating-conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> 8</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#79B8FF"> 18</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#ff1064</span><span style="color:#79B8FF"> 25</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/conic10-repeating.webp" alt="" style="max-width:28%" class="img-narrow"></p>
<h2 id="what-to-avoid-when-creating-css-conic-gradients">What to avoid when creating CSS conic gradients<a class="heading-anchor" href="#what-to-avoid-when-creating-css-conic-gradients" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Always bear in mind that, to create a harmonious and uniform repeating conic gradient, it’s important to maintain consistent spacing and carefully planned distances between color stops.</p>
<p>In the image below, we can observe that green, black, and orange are each repeated <strong>three times</strong>, while the color <code>#ff1064</code> (a shade of pinkish-red) appears only <strong>twice</strong>. This happens because the total space occupied by all the defined color stops—green, black, orange, and <code>#ff1064</code>—adds up to <strong>40%</strong> of the conic gradient.</p>
<p>This setup ensures that the entire pattern repeats in a balanced way: the specified colors take up 40% of the gradient, and the remaining 60% of the circle is evenly distributed across the repeated pattern. The result is a visually pleasing and consistent circular repetition.</p>
<p>The following code snippet defines the color stops and their positions for this repeating conic gradient:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.conic-avoid-repeating</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">repeating-conic-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> 8</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#79B8FF"> 18</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#ff1064</span><span style="color:#79B8FF"> 40</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Here’s what each part means:</p>
<ul>
<li><strong>green</strong>: This is the starting color of the gradient. It begins right at the 0% mark.</li>
<li><strong>black 8%</strong>: The next color in the gradient is black, and it starts at 8%.</li>
<li><strong>orange 18%</strong>: Orange follows next, starting at 18% of the circle.</li>
<li><strong>#ff1064 40%</strong>: Finally, the last color in the gradient is a shade of pinkish-red specified by the hexadecimal color code <code>#ff1064</code>, and it starts at 40% of the circle’s circumference.</li>
</ul>
<p>After that, the pattern repeats, starting again from green and continuing through the same sequence.</p>
<p><img src="/conic11-repeating-avoid.webp" alt="" style="max-width:28%" class="img-narrow"></p>
<h2 id="creating-amazing-pie-charts-with-css-conic-gradient">Creating amazing pie charts with CSS conic gradient<a class="heading-anchor" href="#creating-amazing-pie-charts-with-css-conic-gradient" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The CSS conic function is used to create conic gradient backgrounds. A <strong>conic gradient</strong> creates a circular gradient, much like a pie chart, with or without different color stops defining different sections of the circle.</p>
<p>And here’s the fun part: we’re completely free to shape our gradients into perfect circles using CSS! Just apply a <code>border-radius</code> of <code>50%</code>, and you can create stunning <strong>pie-style visuals</strong>. 😃</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.pie-chart</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">conic-gradient</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#79B8FF">  red</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">red</span><span style="color:#79B8FF"> 12</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  orange</span><span style="color:#79B8FF"> 12</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#79B8FF"> 30</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  yellow</span><span style="color:#79B8FF"> 30</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">yellow</span><span style="color:#79B8FF"> 48</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  green</span><span style="color:#79B8FF"> 48</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#79B8FF"> 65</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  blue</span><span style="color:#79B8FF"> 65</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#79B8FF"> 82</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  purple</span><span style="color:#79B8FF"> 82</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">purple</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">%</span></span>
<span class="line"><span style="color:#E1E4E8">  );</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.circle</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">240</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">240</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h3 id="breakdown-of-the-color-segments">Breakdown of the color segments:<a class="heading-anchor" href="#breakdown-of-the-color-segments" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<ul>
<li><code>red 0%, red 12%</code> This pair defines a red segment that starts at 0% and ends at 12% of the circle. This represents the first segment of the conic gradient.</li>
<li><code>orange 12%, orange 30%</code>: Starts right after red and continues to 30%, forming the orange slice.</li>
<li><strong>yellow 30%, yellow 48%</strong>, <strong>green 48%, green 65%</strong>, and <strong>blue 65%, blue 82%</strong> each define their own slices.</li>
<li>The last segment, <code>purple 82%, purple 100%</code>, defines the purple segment that starts at 82% and goes all the way to 100% of the circle. This represents the last segment of the conic gradient.</li>
</ul>
<p>Each pair of color stops defines a slice of the <strong>CSS conic gradient</strong>, making it easy to visualize proportions — just like a pie chart!</p>
<p><img src="/conic15-chart-pie.webp" alt="" style="max-width:28%" class="img-narrow"></p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/css-linear-gradient-techniques-how-to-make-colorful-line-drawings/">CSS Linear Gradient: A Practical Guide</a></li>
<li><a href="/css-radial-gradient-techniques-how-to-make-colorful-infinite-loops/">CSS Radial Gradient: A Practical Guide</a></li>
<li><a href="/create-playful-border-effects-combining-css-gradients-with-the-border-image-slice-css-property/">CSS Gradient Borders with border-image</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How To Create A Stunning Gray CSS Water Drop</title>
      <link>https://littlecodingthings.com/how-to-create-a-stunning-gray-css-water-drop/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-create-a-stunning-gray-css-water-drop/</guid>
      <pubDate>Mon, 07 Apr 2025 10:10:00 GMT</pubDate>
      <description>Draw a water drop in pure CSS: an uneven border-radius, four stacked box-shadows for volume, and two pseudo-elements for the highlights.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hello there! 😃 In this post, we will guide you drop-by-drop ☔ on how to make a beautiful gray CSS water drop using only CSS. We will take you through the entire process, from the initial design to the final touches, and provide useful tips on how to adjust CSS properties to achieve the perfect shape and reflection effects. By the end, you will have created stunning water drops that will capture everyone’s attention.</p>
<p>So, let’s begin this adventure and dive in! 🤿</p>
<h2 id="html-structure-for-water-drop">HTML Structure for water drop<a class="heading-anchor" href="#html-structure-for-water-drop" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>First, we create an <a href="/most-useful-html-elements-for-maximizing-better-results/" title="HTML element">HTML element</a> with a class name that reflects the intended purpose and makes it easily identifiable. In our example, we will use the class name <code>.drop</code> 💦✨.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"drop"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h2 id="css-structure-for-a-water-drop">CSS Structure for a water drop<a class="heading-anchor" href="#css-structure-for-a-water-drop" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We continue working on our <a href="/how-to-work-with-css-syntax-the-correct-way/" title="CSS">CSS</a> code. First, we have to create our drop, then we will add some shine as a way to look more natural, and finally, we will add two more drops with different sizes. Let the game begin! ⏳</p>
<h3 id="create-thewater-drop">Create the water drop<a class="heading-anchor" href="#create-thewater-drop" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>We begin by setting the <code>background-color</code> for our body, giving it a light shade of grayish blue (<code>#c9c9db</code>). As drops are transparent, picking the appropriate color as their background is essential.</p>
<p>Then we define the dimensions and borders of our drop, setting the <code>width</code> and <code>height</code> and adjusting the <code>border-radius</code> property to create a slightly rounded shape. (It’s important to note that nothing will be rendered on the screen at this stage as our drop does not have any color yet. 💬 )</p>
<p>Next, we work on creating the drop effect using only shadows, which can be quite challenging. To achieve this, we have to make sure that the drop’s <code>background-color</code> is set to transparent.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#c9c9db</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* a light shade of grayish blue */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.drop</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 45</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">/</span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 45</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>We finalize by adding the <code>box-shadow</code> property to create the CSS water drop effect. We have to play somehow 🎨 🖌 with our color shades till we manage 🤯 to create the perfect result. 💪</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#c9c9db</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* a light shade of grayish blue */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.drop</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #8a8a8e</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* top-right-left-bottom */</span></span>
<span class="line"><span style="color:#79B8FF">  5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #929297</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* right &#x26; bottom */</span></span>
<span class="line"><span style="color:#79B8FF">  inset</span><span style="color:#79B8FF"> 8</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 8</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 25</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #71717a</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* inset top &#x26; left */</span></span>
<span class="line"><span style="color:#79B8FF">  inset</span><span style="color:#79B8FF"> -8</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> -8</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 25</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #f2f2f2</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* inset bottom &#x26; right */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Below, we can see what has been displayed on the screen up to this point.</p>
<p><img src="/water-drops-gray-color-create-drop.webp" alt="An image showing a gray CSS water drop create using border-radius, background-color and box-shadow CSS properties." style="max-width:56%" class="img-narrow"></p>
<h3 id="adding-shine-to-thecss-water-drop">Adding shine to the CSS water drop<a class="heading-anchor" href="#adding-shine-to-thecss-water-drop" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>With the power of CSS, we can bring to life unique and captivating shine ✨ effects using the <code>::before</code> and <code>::after</code> pseudo-elements. By setting different values for the same properties, we can create a distinctive and inspiring look that will leave a lasting impression on our audience.</p>
<p>To position the shine inside the drop element, we utilize the <code>position: relative</code> to our class and then the <code>position: absolute</code> to our pseudo-elements.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.drop</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.drop::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">14</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#f5f5f5</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #fff</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 45</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">/</span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 45</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">25</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-40</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.drop::after</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#f5f5f5</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #fff</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 45</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">/</span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 45</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">35</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">15</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Then, we specify the dimensions and colors for the shine by setting the <code>width</code>, <code>height</code> and <code>background-color</code>.</p>
<p>Next, we add the <code>box-shadow</code> and <code>border-radius</code> properties that allow us to create smooth and rounded corners on the shiny elements. This can give the design a softer look.</p>
<p>After that, we use the <code>top</code> and <code>left</code> properties to position them.</p>
<p>Finally, to make them look even more realistic, we can add some rotation by using the <code>transform: rotate()</code> property.</p>
<p>In the following image, you can see the changes applied: a shiny, grey water drop!</p>
<p><img src="/water-drops-gray-color-adding-shine.webp" alt="An image showing a CSS gray water drop with two small, almost white oval shapes like shiny effects." style="max-width:56%" class="img-narrow"></p>
<h2 id="create-the-restof-the-water-drops">Create the rest of the water drops<a class="heading-anchor" href="#create-the-restof-the-water-drops" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We will complete our work by adding two more drops. Each drop will have a different class, depending on its size.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"drop"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"drop drop--medium"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"drop drop--small"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p>First of all, we add a small <code>margin</code> of 30 pixels between the drops. Then, we continue with adding the drop’s size based on our preferences.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.drop</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  margin</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">30</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"><span style="color:#B392F0">.drop--medium</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">120</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">120</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.drop--small</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Here we are! Our stunning water drops are displayed on the screen! Nice, isn’t it? 😎
<em>(We added some extra styling, not included in our code snippets, to center our drops, in case you are wondering about the last screenshot)</em></p>
<p>Hope you found it useful. Utilize these techniques to create stunning water drops that will impress your audience. Have fun experimenting with different colors, shades, and shapes to produce your own unique designs! 💦 ✨ Happy coding!</p>
<p><img src="/water-drops-gray-color-final-design-three-drops.webp" alt="An image showing three different  gray CSS water drops with two small, almost white oval shapes like shiny effects in each." style="max-width:56%" class="img-narrow"></p>
<h2 id="complete-code-solution">Complete code solution<a class="heading-anchor" href="#complete-code-solution" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Below is the full code referenced in this blog post, along with some extra stylings to enhance our final result. Feel free to copy and use it in your own projects. If you have any questions or encounter any issues, don’t hesitate to reach out for assistance in the comments section. You can easily copy the desired code snippet by clicking on the copy icon located in the top-right corner of each snippet.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"drop"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"drop drop--medium"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"drop drop--small"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">*</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  margin</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  padding</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-sizing</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">border-box</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">html</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">vh</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#c9c9db</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.drop</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 45</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">/</span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 45</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #8a8a8e</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* top-right-left-bottom */</span></span>
<span class="line"><span style="color:#79B8FF">  5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #929297</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* right &#x26; bottom */</span></span>
<span class="line"><span style="color:#79B8FF">  inset</span><span style="color:#79B8FF"> 8</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 8</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 25</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #71717a</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* inset top &#x26; left */</span></span>
<span class="line"><span style="color:#79B8FF">  inset</span><span style="color:#79B8FF"> -8</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> -8</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 25</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #f2f2f2</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* inset bottom &#x26; right */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  margin</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">30</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.drop::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">14</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#f5f5f5</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #fff</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 45</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">/</span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 45</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">25</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-40</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.drop::after</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#f5f5f5</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #fff</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 45</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">/</span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 45</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">35</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">15</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.drop--medium</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">120</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">120</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.drop--small</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/css-water-drop-effect-how-to-make-text-look-wet-and-glossy-a-step-by-step-guide/">CSS Water Drop Effect on Text</a></li>
<li><a href="/how-inset-works-in-box-shadow-made-simple/">How inset Works in box-shadow (Made Simple)</a></li>
<li><a href="/how-to-make-a-css-reflection-effect/">How To Make A CSS Reflection Effect</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>CSS Folded Corner Effect with clip-path</title>
      <link>https://littlecodingthings.com/make-a-unique-folded-corner-effect-utilizing-the-clip-path-css-property/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/make-a-unique-folded-corner-effect-utilizing-the-clip-path-css-property/</guid>
      <pubDate>Mon, 31 Mar 2025 00:58:00 GMT</pubDate>
      <description>Build a folded paper corner with clip-path and a ::before pseudo-element — no images, and a drop-shadow trick that clipped boxes allow.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hello everybody! I’m excited to share a cool folded corner effect I created using just <a href="/most-useful-html-elements-for-maximizing-better-results/">HTML</a> and <a href="/how-to-work-with-css-syntax-the-correct-way/">CSS</a>. This eye-catching design adds a dynamic flair, creating a realistic illusion that enhances your webpage’s visual appeal —no images, extra scripts, or complex code required. How awesome is that? 😎</p>
<p>Elements with <code>clip-path</code> do not take shadows directly. Instead, they must be nested within a container to inherit its shadows.</p>
<h2 id="creating-the-folded-corner-effect-using-pseudo-element">Creating the folded corner effect using pseudo-element<a class="heading-anchor" href="#creating-the-folded-corner-effect-using-pseudo-element" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We’ll start by using the <code>::before</code> pseudo-element combined with the <code>clip-path</code> property to create the folded corner effect. The main element, which contains the pseudo-element, is styled with a <code>filter</code> property to apply a shadow. This shadow is then inherited by the pseudo-element, allowing the folded corner to display a subtle, realistic shadow as well. This technique keeps the design lightweight and visually appealing.</p>
<h3 id="basic-html-structure-for-the-folded-corner-effect">Basic HTML structure for the folded corner effect<a class="heading-anchor" href="#basic-html-structure-for-the-folded-corner-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>The HTML code snippet creates a card layout. We have a parent element with the class <code>.card</code>, housing two child elements: the first with the class <code>.title</code> for the card’s title, and the second with the class <code>.folded-corner</code> to apply the folded corner effect via CSS.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"card"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"title"</span><span style="color:#E1E4E8">>Folded Corner Effect&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"folded-corner"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h3 id="css-structure-creating-the-paper-and-cut-corner">CSS structure: creating the paper and cut corner<a class="heading-anchor" href="#css-structure-creating-the-paper-and-cut-corner" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Starting with the CSS, we define a horizontal rectangle by setting the width to <code>450px</code> and the height to <code>300px</code>, along with a subtle <code>2px border-radius</code> for slightly rounded corners. The background color is set to <code>#228a90</code>, a rich teal with greenish-blue tones that gives the card a fresh, modern look.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.card</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">450</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#228a90</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/folded-corner-create-the-paper.webp" alt="Initial paper design before applying folded corner effect" style="max-width:62%" class="img-narrow"></p>
<p>Then we use the <a href="https://caniuse.com/?search=clip-path">clip-path property</a> to shape the desired paper corner for the folded effect. I chose the <strong>top-left</strong> corner, but you can select any one you prefer by adjusting the corresponding points in the <code>clip-path: polygon()</code> function.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.card</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">450</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#228a90</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">polygon</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 30</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">30</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Think of the corners in this order: <strong>top-left, top-right, bottom-right, bottom-left</strong> (clockwise).</p>
<p>Remember to split each selected corner into two coordinates to get the right look (watch those 👇 magenta measurements! 😉)
<em>Take into account that the top-left corner has both Axis-X and Axis-Y on 0%.</em></p>
<p><img src="/folded-corner-create-the-cutting-corner-outline.webp" alt="Axis coordinates of card showing top-left corner cut, preparing the folded corner effect"></p>
<p>Finally, adding <code>position:relative</code> does not change something in our effect but prepares us for future positioning adjustments. As for centering our elements using flexbox—it’s purely for aesthetic purposes, helping keep everything visually balanced and neat.
Below, we can see what is rendered on the screen for now. Pretty cool, right!? 😃</p>
<p><img src="/folded-corner-create-the-cutting-corner.webp" alt="Progress so far: paper with cut corner created using HTML and CSS folded corner effect" style="max-width:56%" class="img-narrow"></p>
<h3 id="css-structure-how-to-create-the-folded-corner-effect">CSS structure: how to create the folded corner effect<a class="heading-anchor" href="#css-structure-how-to-create-the-folded-corner-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>To continue building our effect, we’ll use the <code>folded-corner</code> child element to create a second rectangle within the parent <code>card</code> element. This element will act as the folded piece of paper. We’ll give it a width of <code>70px</code> and a height of <code>160px</code>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.card</span><span style="color:#B392F0"> .folded-corner</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">70</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">160</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>For now, we’ll use a <strong>red background color</strong> to help us visualize its position and behavior more clearly—this will be updated to its final color later. We’ll also apply <code>position: absolute</code> to enable precise positioning.</p>
<p><img src="/folded-corner-create-the-effect-step1.webp" alt="Initial red-colored container element for folded corner effect" style="max-width:56%" class="img-narrow"></p>
<p>Next, we continue with positioning. We use the <code>top</code> and <code>left</code> properties to move the <code>.folded-corner</code> element closer to the clipped corner, then apply the <code>transform</code> property to rotate it into place.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.card</span><span style="color:#B392F0"> .folded-corner</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-7</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">52</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">56</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<figure><img src="/folded-corner-position-the-container-add-shadow-step2-top1-1.webp" alt="Positioning folded-corner element at top -7px in folded corner effect layout" style="max-width:62%" class="img-narrow"><figcaption>top: -7px;</figcaption></figure>
<figure><img src="/folded-corner-position-the-container-add-shadow-step2-left2.webp" alt="Positioning folded-corner element at left 52px to align with cut corner" style="max-width:62%" class="img-narrow"><figcaption>left: 52px;</figcaption></figure>
<figure><img src="/folded-corner-position-the-container-add-shadow-step2.webp" alt="Rotating folded-corner element by 56 degrees using CSS transform property" style="max-width:62%" class="img-narrow"><figcaption>transform: rotate(56deg);</figcaption></figure>
<p>Finally, adding the <code>filter</code> property is essential for completing our effect. As mentioned earlier, applying a shadow directly to an element with a <code>clip-path</code> isn’t possible — so the solution is to create an additional element that can hold the shadow.</p>
<p>To do this, we’ll add a <code>::before</code> pseudo-element with the <strong>same dimensions</strong> as our folded corner. This allows us to recreate the folded shape and apply the shadow to it — adding depth and realism to the folded corner effect. 😎</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.card</span><span style="color:#B392F0"> .folded-corner</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-7</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">52</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">56</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">drop-shadow</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 4</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.4</span><span style="color:#E1E4E8">));</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<figure><img src="/folded-corner-position-the-container-add-shadow-step2-rotate3.webp" alt="Initial red-colored container element for folded corner effect" style="max-width:56%" class="img-narrow"><figcaption>filter: drop-shadow(6px 4px 5px rgba(0, 0, 0, 0.4));</figcaption></figure>
<p>Next, we move forward by using the <code>::before</code> <a href="/coding-made-easy-with-css-selectors-an-ultimate-guide/#before-and-after">pseudo-element</a> with the <code>content</code> property and set its <code>position</code> to <code>absolute</code> for precise placement within the parent.
We want this pseudo-element to have the exact dimensions as the parent, so we set both its <code>width</code> and <code>height</code> to <code>100%</code>, something that allows it to inherit the parent’s size.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.card</span><span style="color:#B392F0"> .folded-corner::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>For now, we apply a pink <code>background</code> to help visualize the structure. Finally, we add a <code>border-radius</code> of <code>10%</code> to the bottom corner, which softens the edge and creates a smoother, more realistic folded appearance.</p>
<p><img src="/folded-corner-adding-before-rounded-edge-step3.webp" alt="Adding the ::before pseudo-element" style="max-width:56%" class="img-narrow"></p>
<p>Next, we replace the pink <code>background</code> with a smooth <a href="/css-linear-gradient-techniques-how-to-make-colorful-line-drawings/">linear gradient</a>. We choose colors similar to the main hue but make them darker towards the edges and lighter in the center. This gradient effect enhances the appearance by making the center appear brighter and polish. ✨</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.card</span><span style="color:#B392F0"> .folded-corner::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">to</span><span style="color:#79B8FF"> right</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#277c7f</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#5abcbc</span><span style="color:#79B8FF"> 30</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#63c5c6</span><span style="color:#79B8FF"> 40</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#5abcbc</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#277c7f</span><span style="color:#79B8FF"> 90</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#0d4749</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/folded-corner-adding-linear-gradient-step4.webp" alt="Adding a linear-gradient to the ::before pseudo-element" style="max-width:56%" class="img-narrow"></p>
<p>To complete the shape, we apply the <code>clip-path: polygon(0% -2%, 0% 100%, 100% 100%)</code> property. This is essential for transforming the <code>::before</code> pseudo-element —which starts as a rectangle, just like its parent—into a triangle.</p>
<p>In simple words, this clipping path reshapes the element into the desired triangular form. 🥳</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.card</span><span style="color:#B392F0"> .folded-corner::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">polygon</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> -2</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/folded-corner-adding-gradient-to-before-step5.webp" alt="Adding clip-path to the ::before pseudo-element" style="max-width:56%" class="img-narrow"></p>
<p>The last step is to turn back to the parent element with the class <code>.folded-corner</code> and “remove” the red rectangle from view by simply replacing the red <code>background-color</code> with a transparent value.
As we can see, the <code>::before</code> pseudo-element inherits its parent shadow effect while the parent becomes invisible.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.card</span><span style="color:#B392F0"> .folded-corner</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">70</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">160</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-7</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">52</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">56</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">drop-shadow</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 4</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.4</span><span style="color:#E1E4E8">));</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/folded-corner-effect-step6.webp" alt="Finalize the folded corner effect" style="max-width:56%" class="img-narrow"></p>
<p>We can enhance the title to have a more eye-cathing result. Applying a white <code>background-color</code>, increasing the <code>font-size</code>, and adding a subtle black <code>text-shadow</code> will make the title stand out beautifully, elevating the overall design. 📄 ✨</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.card</span><span style="color:#B392F0"> .title</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  font-family</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">sans-serif</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-weight</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">bold</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  text-align</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  padding</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  text-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/folded-corner-styling-title-step7.webp" alt="Stylling paper&#x27;s title" style="max-width:56%" class="img-narrow"></p>
<h2 id="complete-code-example">Complete code example<a class="heading-anchor" href="#complete-code-example" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"card"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"title"</span><span style="color:#E1E4E8">>Folded Corner Effect&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"folded-corner"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.card</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">450</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#228a90</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">polygon</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 30</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">30</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.card</span><span style="color:#B392F0"> .folded-corner</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">70</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">160</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-7</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">52</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">56</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">drop-shadow</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 4</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.4</span><span style="color:#E1E4E8">));</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.card</span><span style="color:#B392F0"> .folded-corner::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">to</span><span style="color:#79B8FF"> right</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#277c7f</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#5abcbc</span><span style="color:#79B8FF"> 30</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#63c5c6</span><span style="color:#79B8FF"> 40</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#5abcbc</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#277c7f</span><span style="color:#79B8FF"> 90</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#0d4749</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  clip-path</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">polygon</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> -2</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.card</span><span style="color:#B392F0"> .title</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  font-family</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">sans-serif</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-weight</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">bold</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  text-align</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  padding</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  text-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>If you have any questions or run into any issues, don’t hesitate to reach out in the comments below — I’m happy to help. You can easily copy any code snippet by clicking the <strong>copy icon</strong> in the top-right corner of each block.</p>
<h2 id="summary">Summary<a class="heading-anchor" href="#summary" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We started by creating the paper and cutting its corner. Then, we set the <code>clip-path</code> property to define the shape and positioned the folded-corner element precisely over the clipped area. After that, we enhanced the styling with background gradients that match the paper’s tone, and wrapped up by polishing the effect for a clean, realistic look. 📄 ✨</p>
<p>Wishing you the best of luck in all your creative endeavors! 😃</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/easy-made-circles-a-simple-guide-to-clip-path-css-property/">clip-path: circle() Explained</a></li>
<li><a href="/clip-path-for-simplified-triangles-ready-code-to-copy/">CSS Triangles with clip-path</a></li>
<li><a href="/drop-shadow-vs-box-shadow-what-is-the-difference/">Drop-shadow VS Box-shadow: What is the difference?</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>CSS Keyframes Animation Explained</title>
      <link>https://littlecodingthings.com/keyframes-in-css-explained-make-your-animations-stand-out/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/keyframes-in-css-explained-make-your-animations-stand-out/</guid>
      <pubDate>Sat, 22 Mar 2025 13:35:00 GMT</pubDate>
      <description>Build a @keyframes animation one layer at a time — color, shape, position, rotation and delay — on a single box, with the shorthand at the end.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hi there! 😃 In today’s post, we will analyze the amazing CSS <code>@keyframes</code> rule, an incredibly powerful tool for creating complex and visually stunning animations on web pages.</p>
<h2 id="understanding-keyframes-in-css">Understanding keyframes in CSS<a class="heading-anchor" href="#understanding-keyframes-in-css" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>In simple terms, keyframes define the animation’s behavior through a series of <code>@keyframes</code> which describes how the animation should change over time.
Each keyframe represents a specific point in time, and CSS smoothly transitions between these keyframes to create fluid motion.</p>
<p>With CSS keyframes, you can create various animations, from simple color changes to complex effects like movements and transformations. By combining keyframes with other CSS properties, we can control timing and duration and create dynamic and visually engaging websites.</p>
<p>I will provide you with an example that will make this <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_syntax/At-rule" title="at-rule">at-rule</a> crystal clear. 🧐 Let’s grab a ☕ and move forward. 🚀 We’ve got this!</p>
<h2 id="example-of-keyframes-in-css-the-theory-behind-it">Example of keyframes in CSS: The theory behind it<a class="heading-anchor" href="#example-of-keyframes-in-css-the-theory-behind-it" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The details of the animation will depend on the specific effect we want to achieve. Let’s say we want to create an animation where a square ⬛ transforms into a circle ⚫ and then back into a square ⬛ again. Additionally, the color 🌈 of the shape changes during the animation, and there are some movements and transitions involved. It might seem massive and confusing, 😰 but we can deal with it step by step together! 🛠</p>
<p>For our animation to be smooth and realistic, we need to define the <code>@keyframes</code>. The first keyframe serves as the starting point (<code>0%</code>), followed by intermediate points and the final keyframe (<code>100%</code>) that marks the end of the animation and returns to the starting point.</p>
<p>😃The following code snippet provides a quick example of a keyframes structure in action.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">@keyframes</span><span style="color:#FFAB70"> name-of-keyframe</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#B392F0">  0%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ... </span><span style="color:#6A737D">/* this is the starting point */</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  50%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ... </span><span style="color:#6A737D">/* this is one intermediate point */</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  100%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ... </span><span style="color:#6A737D">/* this is the ending point */</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>To create these keyframes, you’ll need to use CSS animation properties, such as <code>animation-name</code>, <code>animation-duration</code>, <code>animation-iteration-count</code> and <code>animation-delay</code>. <strong>The</strong> <code>animation-name</code> <strong>property connects the animation to its keyframes</strong>, while the other properties control how long it should last, how it should behave over time, and whether it has a delay before starting.</p>
<p>Once you’ve defined your keyframes and animation properties, CSS will automatically insert transitions between the keyframes to create smooth changes. This means you don’t need to worry about manual calculations. CSS takes care of it for you. Cool huh!? 😎 ✨</p>
<h2 id="example-of-keyframes-in-css-practical-implementation">Example of keyframes in CSS: Practical implementation<a class="heading-anchor" href="#example-of-keyframes-in-css-practical-implementation" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>As we already mentioned, we will work with a box. We need to start with the <a href="/most-useful-html-elements-for-maximizing-better-results/" title="HTML">HTML</a> code and create a <code>&#x3C;div></code> element that has the class name <code>.box</code>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"box"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p>Then, in our <a href="/how-to-work-with-css-syntax-the-correct-way/" title="CSS">CSS</a> code, we define the basic properties. It should be a square with a <code>width</code> and <code>height</code> of 200 pixels, and we’ll keep the <code>background-color</code> simple by using black for now.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>This is what is rendered on the screen for now. A simple black box.</p>
<p><img src="/css-keyframes-infinite-create-box.webp" alt="Keyframes in CSS: image shows a black box." style="max-width:28%" class="img-narrow"></p>
<h3 id="applying-animation-effects-to-the-elements">Applying animation effects to the elements<a class="heading-anchor" href="#applying-animation-effects-to-the-elements" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>To add animation effects to our <code>&#x3C;div></code> element, we need to define the animation properties of our class <code>.box</code>. We set the <code>animation-name</code>, which is the animation’s name, then the <code>animation-duration</code>, which is the time the animation takes to complete, and finally, the <code>animation-iteration-count</code> which declares how many times the animation should repeat.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  animation-name</span><span style="color:#E1E4E8">: my-animation;</span></span>
<span class="line"><span style="color:#79B8FF">  animation-duration</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">s</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  animation-iteration-count</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">infinite</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/* ----- MY ANIMATION ----- */</span></span>
<span class="line"><span style="color:#F97583">@keyframes</span><span style="color:#FFAB70"> my-animation</span><span style="color:#E1E4E8"> {}</span></span></code></pre></div>
<p>Then, we create our animation using the <code>@keyframes</code> rule, where we can specify the values of the CSS properties at different points during the animation. <strong>The most crucial step is to link the animation to our element</strong>. We do this by using the <code>animation-name</code> property and assigning it to the same name we defined earlier. In our case <code>my-animation</code>.</p>
<h3 id="transforming-colors-and-shapes-with-animation">Transforming colors and shapes with animation<a class="heading-anchor" href="#transforming-colors-and-shapes-with-animation" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>We will start our transformations by working with colors and shapes using the <code>background-color</code> and <code>border-radius</code> properties.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* ----- MY ANIMATION ----- */</span></span>
<span class="line"><span style="color:#F97583">@keyframes</span><span style="color:#FFAB70"> my-animation</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#B392F0">  0%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  25%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  50%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  75%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  100%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>As we can see, it begins with a pink square at starting point: <code>0%</code>. Then, it transitions to purple (<code>25%</code>) where it starts becoming cyclic. After that, it turns to black (<code>50%</code>) and remains a full circle. Then (<code>75%</code>) shifts to purple again, where it starts transitioning back to a square. Finally (ending point: <code>100%</code>) turns to a pink square.</p>
<p><img src="/css-keyframes-infinite-changing-colors-and-shape.webp" alt="Keyframes in CSS: A pink square transitions into a purple circle, then a black circle, and back to a pink square using CSS @keyframes, background-color, and border-radius properties." style="max-width:45%" class="img-narrow"></p>
<h3 id="animating-element-position">Animating Element Position<a class="heading-anchor" href="#animating-element-position" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>The next step is adjusting the position of our box. To do this, we need to adjust the positioning of the HTML element associated with our <code>.box</code> class and set it to <code>position: relative</code>, allowing it to move within its container.</p>
<p>Now, let’s animate its movement:</p>
<ul>
<li>The animation starts at the top-left corner <code>0%</code>.</li>
<li>At <strong><code>25%</code></strong>, it moves diagonally by changing both the <code>top</code> and <code>left</code> values.</li>
<li>At <strong><code>50%</code></strong>, it continues moving horizontally to the right.</li>
<li>At <strong><code>75%</code></strong>, it moves diagonally back by adjusting <code>top</code> and <code>left</code> again.</li>
<li>Finally, at <strong><code>100%</code></strong>, it returns to its original position at the top-left corner.</li>
</ul>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/* ----- MY ANIMATION ----- */</span></span>
<span class="line"><span style="color:#F97583">@keyframes</span><span style="color:#FFAB70"> my-animation</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#B392F0">  0%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  25%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  50%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  75%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  100%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-keyframes-infinite-move.webp" alt="CSS animations: A pink square moves from the top left while transforming into a purple circle, then shifts left and becomes a black circle, before returning to the top left as a pink square using CSS @keyframes, top, and left properties." style="max-width:74%" class="img-narrow"></p>
<h3 id="animating-element-rotation">Animating Element Rotation<a class="heading-anchor" href="#animating-element-rotation" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>We can also make our box a little bit playful! 🤹‍♀️ We will add some extra moves with the amazing <a href="/how-to-effectively-use-css-transform-scale-on-hover/"><code>transform</code> CSS property</a>.</p>
<p>We will apply a rotation <strong>only between 25% and 75%</strong>.</p>
<ul>
<li>The animation starts with no rotation at <code>0%</code>.</li>
<li>At <code>25%</code>, the element remains unrotated with <code>transform: rotateY(0deg)</code>.</li>
<li>At <code>50%</code>, it completes a full rotation with <code>transform: rotateY(360deg)</code></li>
<li>At <code>75%</code>, it returns to its original position with <code>transform: rotateY(0deg)</code>.</li>
<li>Finally, at <code>100%</code>, the cycle resets, ready to repeat.</li>
</ul>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* ----- MY ANIMATION ----- */</span></span>
<span class="line"><span style="color:#F97583">@keyframes</span><span style="color:#FFAB70"> my-animation</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#B392F0">  0%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  25%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateY</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  50%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateY</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">360</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  75%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateY</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  100%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-keyframes-infinite-adding-rotation-axisy.webp" alt="CSS animations with @keyframes: This image shows a pink square moving from top left and turning to a purple circle, then moving only to left by rotating at axis-Y and turning to a black circle and then again moving back to top left and turning to a pink square using the CSS @keyframes property and the css transform: rotateY() property." style="max-width:74%" class="img-narrow"></p>
<p>Now, let’s try to make it even more impressive by enriching the starting and ending phases.</p>
<ul>
<li>At <code>0%</code>, we add <code>transform: rotateX(360deg)</code>.</li>
<li>At <code>25%</code>, it resets with <code>transform: rotateX(0deg)</code>, creating a rotation along the X-axis from 0% to 25%.</li>
<li>At <code>50%</code> and <code>75%</code>, we maintain a non-rotating phase with <code>transform: rotateX(0deg)</code>.</li>
<li>Finally, at <code>100%</code>, we add <code>transform: rotateX(360deg)</code>, creating another rotation from <code>75%</code> to <code>100%</code>.</li>
</ul>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* ----- MY ANIMATION ----- */</span></span>
<span class="line"><span style="color:#F97583">@keyframes</span><span style="color:#FFAB70"> my-animation</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#B392F0">  0%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">360</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  25%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  50%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  75%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  100%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">360</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-keyframes-infinite-adding-rotation-axisx.webp" alt="CSS Keyframes: This image shows a pink square that rotating to axis-X from top left and turning to a purple circle, then moving only to left by rotating at axis-Y and turning to a black circle and then again rotating to axis-X going back to top left and turning to a pink square using the CSS @keyframes property and the css transform: rotateY() property." style="max-width:74%" class="img-narrow"></p>
<h3 id="inserting-content-into-the-animated-element">Inserting content into the animated element<a class="heading-anchor" href="#inserting-content-into-the-animated-element" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>We can also add any content we want (text, image, emoticon, etc.) inside our HTML element. For our example, I use an emoticon and set its <code>font-size</code> to <code>100px</code>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"box"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"emoticon"</span><span style="color:#E1E4E8">>🪐&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#B392F0"> .emoticon</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-keyframes-inifinite-adding-content.webp" alt="CSS keyframes: This image shows a pink square with a perfectrly centered emoticon (Ringed planet) inside it, that rotating to axis-X from top left and turning to a purple circle, then moving only to left by rotating at axis-Y and turning to a black circle and then again rotating to axis-X going back to top left and turning to a pink square using the CSS @keyframes property. We create this animation setting the CSS animation-name, CSS animation-duration and CSS animation-iteration-count properties." style="max-width:74%" class="img-narrow"></p>
<h3 id="delaying-the-animation-start">Delaying the animation start<a class="heading-anchor" href="#delaying-the-animation-start" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>We can add a delay to our animation by setting the <code>animation-delay</code> CSS property. This delay momentarily pauses the animation before it begins, creating a smoother and more controlled start.</p>
<p>For instance, if we set the delay to <code>2s</code>, the animation will start after 2 seconds. However, please note that this <strong>delay occurs only once</strong> when we first see the animation. To observe the effect again, we may need to refresh the page. </p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  animation-delay</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">s</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>You can see the animation with the delay effect below. It starts with its initial black <code>background-color</code> and after the 2s it starts the transitions we created with the <code>@keyframes</code>. 😉</p>
<p><img src="/css-keyframes-infinite-adding-the-delay.webp" alt="CSS Keyframes: This image shows a pink square with a perfectrly centered emoticon (Ringed planet) inside it, that rotating to axis-X from top left and turning to a purple circle, then moving only to left by rotating at axis-Y and turning to a black circle and then again rotating to axis-X going back to top left and turning to a pink square using the CSS @keyframes property. This animation has a starting delay of 2 seconds. We do so using the CSS animation-delay property." style="max-width:74%" class="img-narrow"></p>
<h2 id="using-the-animation-shorthand">Using the animation shorthand<a class="heading-anchor" href="#using-the-animation-shorthand" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>By using shorthand, you can save space and time while improving your code’s readability. Instead of writing multiple properties separately, you can define them all using just the <code>animation</code> shorthand.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  animation-name</span><span style="color:#E1E4E8">: my-animation;</span></span>
<span class="line"><span style="color:#79B8FF">  animation-duration</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">s</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  animation-iteration-count</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">infinite</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  animation-delay</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">s</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">  /* Here’s the shorthand version */</span></span>
<span class="line"><span style="color:#79B8FF">  animation</span><span style="color:#E1E4E8">: my-animation </span><span style="color:#79B8FF">10</span><span style="color:#F97583">s</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">s</span><span style="color:#79B8FF"> infinite</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h2 id="complete-css-animation-code-copy--paste-ready">Complete CSS animation code (copy &#x26; paste ready)<a class="heading-anchor" href="#complete-css-animation-code-copy--paste-ready" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Below is the full code referenced in this blog post. Feel free to copy and use it in your own projects.</p>
<p>If you have any questions or encounter any issues, don’t hesitate to ask for help. You can easily copy the desired code snippet by clicking on the copy icon, located in the top-right corner of each snippet.</p>
<p>We’d love to hear your thoughts! If you have feedback or questions, drop a comment below.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"box"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"emoticon"</span><span style="color:#E1E4E8">>🪐&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">*</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  margin</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  padding</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-sizing</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">border-box</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">html</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">vh</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  animation</span><span style="color:#E1E4E8">: my-animation </span><span style="color:#79B8FF">10</span><span style="color:#F97583">s</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">s</span><span style="color:#79B8FF"> infinite</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.box</span><span style="color:#B392F0"> .emoticon</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/* ----- MY ANIMATION ----- */</span></span>
<span class="line"><span style="color:#F97583">@keyframes</span><span style="color:#FFAB70"> my-animation</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#B392F0">  0%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">360</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  25%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateY</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">rotateX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  50%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateY</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">360</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">rotateX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">    visibility</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">visible</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  75%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateY</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">rotateX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  100%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">360</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-css-became-powerful-with-animations/">How CSS Became So Powerful with Animations</a></li>
<li><a href="/static-vs-dynamic-design-with-css-from-stillness-to-action/">CSS Motion: transform, transition, animation</a></li>
<li><a href="/how-to-make-a-blinking-animation-using-css/">How to Make A Blinking Animation Using CSS</a></li>
<li><a href="/html-for-blinking-text-simple-copy-paste-code/">HTML for Blinking Text – Simple Copy &#x26; Paste Code</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>The CSS last-child Selector</title>
      <link>https://littlecodingthings.com/css-last-child-selector-the-most-valuable-selector/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/css-last-child-selector-the-most-valuable-selector/</guid>
      <pubDate>Mon, 10 Mar 2025 09:53:00 GMT</pubDate>
      <description>:last-child targets the final element inside its parent. Worked examples on lists and paragraphs, plus the :nth-last-child(1) equivalent.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hello everyone! In this post, we will explore the CSS last child selector, one of the <a href="/coding-made-easy-with-css-selectors-an-ultimate-guide/" title="most useful selectors in CSS">most useful selectors in CSS</a>. We use the CSS <code>last-child</code> selector when we want to <strong>target and modify only the last element</strong> of the same type. By types of elements, we mean <a href="/most-useful-html-elements-for-maximizing-better-results/" title="HTML tags">HTML tags</a> like paragraphs (<code>&#x3C;p></code>), headings (<code>&#x3C;h1></code>, <code>&#x3C;h2></code> …), lists (<code>&#x3C;li></code>) and others.</p>
<p>Typically, we use the CSS last-child selector with list items <code>&#x3C;li></code>, but it can be applied to any type of element. I have prepared some examples to help you understand how to use the selector based on your needs.</p>
<h2 id="how-to-use-the-css-last-child-selector-for-list-elements">How to use the CSS last child selector for list elements<a class="heading-anchor" href="#how-to-use-the-css-last-child-selector-for-list-elements" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>In the example below, the HTML structure includes an ordered list (<code>&#x3C;ol></code>) with three list items (<code>&#x3C;li></code>), all colored <strong>indigo</strong>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">ol</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>First item&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Second item&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Last item&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">ol</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/last-child-selector-li-without.webp" alt="An ordered list with three items all colored indigo." style="max-width:32%" class="img-narrow"></p>
<p>We continue by adding the CSS rule, which selects only the last item and applies a red color to it.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* Applies indigo color to all list items */</span></span>
<span class="line"><span style="color:#85E89D">li</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">indigo</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/* Applies red color only to the last list item */</span></span>
<span class="line"><span style="color:#85E89D">li</span><span style="color:#B392F0">:last-child</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/*       OR       */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">li</span><span style="color:#B392F0">:nth-last-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/last-child-selector-li.webp" alt="An ordered list with three items all colored indigo apart from the last one which has color red as we used the: CSS last child selector. :last-child OR :nth-last-child(1)" style="max-width:32%" class="img-narrow"></p>
<p>When using the <code>:last-child</code> selector in CSS, it targets the last element within its parent. When we add a new item to the end of the list, this new item becomes the last child of the list, and the previous last item now becomes the second one from the end. This change causes the <code>:last-child</code> selector to now <strong>target</strong> <strong>the</strong> <strong>newly</strong> <strong>added</strong> <strong>item</strong> instead.</p>
<h2 id="applying-the-css-last-child-selector-to-non-list-elements">Applying the CSS last child selector to non-list elements<a class="heading-anchor" href="#applying-the-css-last-child-selector-to-non-list-elements" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>In the following example, we will use the last child selector for paragraphs. The HTML structure contains a <code>&#x3C;div></code> which encloses three paragraph (<code>&#x3C;p></code>) elements. By default, all HTML elements have black text color, so paragraphs will appear in black.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>First paragraph&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>Second paragraph&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>Last paragraph&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/first-child-selector-html-element-without.webp" alt="Three paragraphs all colored by default black." style="max-width:52%" class="img-narrow"></p>
<p>By setting the CSS last child selector, it selects the last <code>&#x3C;p></code> element and applies the text color <code>red</code> to a <code>white</code> background. As a result, the last paragraph appears in <code>red</code> with a <code>white</code> background, while the preceding paragraphs keep their default styling.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* Applies red color and background white</span></span>
<span class="line"><span style="color:#6A737D">   to the last paragraph</span></span>
<span class="line"><span style="color:#6A737D">*/</span></span>
<span class="line"><span style="color:#85E89D">p</span><span style="color:#B392F0">:last-child</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/*       OR       */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">p</span><span style="color:#B392F0">:nth-last-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/last-child-selector-html-element.webp" alt="Three paragraphs all colored by default black, apart from the last one which has color red and background color white as we used the last child css selector." style="max-width:53%" class="img-narrow"></p>
<h2 id="using-the-last-child-selector-across-multiple-parent-containers">Using the last child selector across multiple parent containers<a class="heading-anchor" href="#using-the-last-child-selector-across-multiple-parent-containers" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>In this example, we will examine another case, as many times, we have multiple HTML elements to work with within a document. Here, we have two <code>div</code> elements, each containing two paragraph (<code>&#x3C;p></code>) elements colored black.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>First paragraph inside the first div&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>Last paragraph inside the first div&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>First paragraph inside the second div&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>Last paragraph inside the second div&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/last-child-selector-html-multiple-elements-without.webp" alt="Four paragraphs all colored black" style="max-width:52%" class="img-narrow"></p>
<p>The CSS rule <code>div p:last-child</code> selects the last <code>&#x3C;p></code> element within any <code>&#x3C;div></code> and applies the specified styles to it.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* Applies red color and white background</span></span>
<span class="line"><span style="color:#6A737D">   to the last paragraph inside each div</span></span>
<span class="line"><span style="color:#6A737D">*/</span></span>
<span class="line"><span style="color:#85E89D">div</span><span style="color:#85E89D"> p</span><span style="color:#B392F0">:last-child</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/*       OR       */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">div</span><span style="color:#85E89D"> p</span><span style="color:#B392F0">:nth-last-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>As a result, the last paragraph of each <code>&#x3C;div></code> will display in <code>red</code> with a <code>white</code> background.</p>
<p><img src="/last-child-selector-html-multiple-elements-selects-all-last-children.webp" alt="Four paragraphs all colored by default black, apart from the second and last one which has color red and background color white." style="max-width:52%" class="img-narrow"></p>
<p>Meanwhile, the remaining paragraphs will keep their default styles. This demonstrates how the <code>:last-child</code> selector can be used to style the last element within several parent containers. 😉</p>
<h2 id="selecting-the-last-child-inside-the-first-parent-element">Selecting the last child inside the first parent element<a class="heading-anchor" href="#selecting-the-last-child-inside-the-first-parent-element" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>In this example, we have two <code>&#x3C;div></code> elements, each containing two paragraph <code>&#x3C;p></code> elements colored black as in the previous one, but this time, we will examine how we can <strong>select only the</strong> <strong>last paragraph inside the first div</strong>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>First paragraph in the first div&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>Second paragraph in the first div&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>First paragraph in the second div&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>Second paragraph in the second div&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/last-child-selector-html-multiple-elements-without.webp" alt="Four paragraphs all colored black" style="max-width:52%" class="img-narrow"></p>
<p>The CSS rule <code>div:first-child p:last-child</code> <strong>selects only the first paragraph <code>&#x3C;p></code> within the first</strong> <code>div</code> and applies the specified styles to it.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* Applies red color and white background</span></span>
<span class="line"><span style="color:#6A737D">   to the last paragraph of the first div</span></span>
<span class="line"><span style="color:#6A737D">*/</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">div</span><span style="color:#B392F0">:first-child</span><span style="color:#85E89D"> p</span><span style="color:#B392F0">:last-child</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/*       OR       */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">div</span><span style="color:#B392F0">:nth-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">) </span><span style="color:#85E89D">p</span><span style="color:#B392F0">:nth-last-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Therefore, the last paragraph in the first <code>div</code> will be shown in red with a white background, while the second paragraph will remain in its default black color.</p>
<p><img src="/last-child-selector-html-multiple-elements.webp" alt="Four paragraphs all colored by default black, apart from the second one which has color red and background color white." style="max-width:52%" class="img-narrow"></p>
<p><strong>The second <code>div</code>, is not influenced at all</strong> by the styles applied to the first <code>div</code>, demonstrating selective styling implementation. 😉 This method is particularly useful for assigning specific styles to elements in complex layouts.</p>
<h2 id="avoiding-the-last-child-with-the-notlast-child-selector">Avoiding the last child with the <code>:not(:last-child)</code> selector<a class="heading-anchor" href="#avoiding-the-last-child-with-the-notlast-child-selector" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Finally, we will examine the opposite case and how <strong>to avoid selecting the last child</strong> <strong>element</strong>. In this example, the HTML structure consists of an ordered list <code>&#x3C;ol></code> housing three list <code>&#x3C;li></code> elements.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">ol</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>First item&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Second item&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Last item&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">ol</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/not-last-child-selector-li-without.webp" alt="An ordered list with three items all colored by default, black." style="max-width:42%" class="img-narrow"></p>
<p>The CSS rule <strong><code>ol li:not(:last-child)</code> selects all <code>&#x3C;li></code> elements within the <code>ol</code> apart from the last one</strong> and apply the specified styles to them.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* Applies red color to all paragraphs</span></span>
<span class="line"><span style="color:#6A737D">   except for the last one</span></span>
<span class="line"><span style="color:#6A737D">*/</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">ol</span><span style="color:#85E89D"> li</span><span style="color:#B392F0">:not</span><span style="color:#E1E4E8">(</span><span style="color:#B392F0">:last-child</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>As a result, <em>all list items except for the last</em> one will be pictured in red, while the last list item will retain its default color, black.</p>
<p><img src="/not-last-child-selector-li.webp" alt="An ordered list with three items. The last item has by default color black while the other two items have color red as we used the css  not last child selector." style="max-width:42%" class="img-narrow"></p>
<p>Alternatively, we can use the CSS <a href="/what-you-need-to-know-about-css-nth-child-selector-a-practical-guide/#styling-only-the-last-element-with-nth-last-child1">nth-last-child selector</a> like this</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">ol</span><span style="color:#85E89D"> li</span><span style="color:#B392F0">:not</span><span style="color:#E1E4E8">(</span><span style="color:#B392F0">:nth-last-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">)) {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>This selector serves a similar purpose, but it is more flexible as it allows for the selection of <strong>any child based on its position</strong>.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/learn-how-to-select-only-the-css-first-child/">Learn How to Select Only the CSS First Child</a></li>
<li><a href="/the-css-nth-of-type-selector-how-to-target-elements-by-type/">The CSS nth-of-type Selector Explained</a></li>
<li><a href="/coding-made-easy-with-css-selectors-an-ultimate-guide/">CSS Selectors: A Complete Guide</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>What Does span Do in HTML?</title>
      <link>https://littlecodingthings.com/what-does-span-do-in-html-unlocking-its-full-potential/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/what-does-span-do-in-html-unlocking-its-full-potential/</guid>
      <pubDate>Sat, 01 Mar 2025 10:55:00 GMT</pubDate>
      <description>What the HTML span tag is for, how it differs from div, and how to style a single word — or a single letter — without breaking the line.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>The <code>&#x3C;span></code> tag is a powerful yet often overlooked element in <a href="/is-html-a-programming-language-find-out-now/">HTML</a>. It’s commonly used for adding style and interactivity, but what does span do in HTML exactly? In this guide, we’ll explore its full potential and show you how to use it effectively on your web pages.</p>
<h2 id="what-is-a-span-tag">What is a span tag?<a class="heading-anchor" href="#what-is-a-span-tag" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We use HTML <code>&#x3C;span></code> tag to target and manipulate specific 🍰 parts within an HTML 🎂 element <strong>without affecting</strong> the layout of surrounding elements. In simple terms, it acts as an inline container for styling small portions 🍰🍰 of text.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">>....&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h2 id="why-and-when-to-use-span-in-html">Why and when to use span in HTML?<a class="heading-anchor" href="#why-and-when-to-use-span-in-html" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Since <code>&#x3C;span></code> does not introduce additional structure or spacing, it is ideal for <strong>precise</strong>, <strong>targeted styling</strong> such as:</p>
<ul>
<li>Highlighting text, changing colors, or formatting specific letters, words, or even a small paragraph.</li>
<li>Wrapping text for <strong>CSS animations</strong> or visual effects.</li>
</ul>
<h2 id="the-difference-between-span-and-div">The difference between span and div<a class="heading-anchor" href="#the-difference-between-span-and-div" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>While both <code>&#x3C;div></code> and <code>&#x3C;span></code> are used for grouping and styling elements, they behave differently in terms of layout and structure. The table below highlights their key differences:</p>
<table>
<thead>
<tr>
<th scope="col">span</th>
<th scope="col">div</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">inline element</th>
<td>block element</td>
</tr>
<tr>
<th scope="row">stays within same line</th>
<td>starts new line and takes full width</td>
</tr>
<tr>
<th scope="row">does not affect layout</th>
<td>breaks the normal text flow</td>
</tr>
</tbody>
</table>
<h2 id="html-span-using-inline-styling">HTML span using inline styling<a class="heading-anchor" href="#html-span-using-inline-styling" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Below, I’ve prepared an example to illustrate how we use <code>&#x3C;span></code>, along with an image to help you visualize it better. 🤓
In this example, we use <code>&#x3C;span></code> to change the style of multiple parts of the text within a <code>&#x3C;p></code> element. The <code>&#x3C;span></code> tag wraps around specific words we want to highlight or style differently without affecting the entire line.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  My sandwich has</span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> style</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"color:yellow"</span><span style="color:#E1E4E8">>yellow&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">> cheese,</span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> style</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"color:red"</span><span style="color:#E1E4E8">>red&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">> tomatoes and</span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> style</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"color:green"</span><span style="color:#E1E4E8">>green&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">> fresh lettuce!!</span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/span-example-text.webp" alt="What does span do in HTML: Text displaying &#x22;My sandwich has yellow cheese, red tomatoes and green fresh lettuce&#x22;. Each color word is written with its color as we set the span HTML tag." style="max-width:75%" class="img-narrow"></p>
<h2 id="styling-span-in-css-best-practices">Styling span in CSS: Best practices<a class="heading-anchor" href="#styling-span-in-css-best-practices" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We can also style <code>&#x3C;span></code> elements beyond <a href="/how-to-work-with-css-syntax-the-correct-way/" title="CSS">CSS</a> inline styling. Below, I include an example and an image to picture it.
In this example, we place the <code>&#x3C;span></code> element within a <code>&#x3C;div></code> element. The CSS code applies specific styling (<a href="/what-you-need-to-know-about-css-color-methods/">color</a>, font style, and text-decoration) only to the text inside the <code>&#x3C;span></code> tag, allowing us to highlight or change the look of a selected part without affecting the rest of the text.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  My sandwich is &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">>amazing!!&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">div</span><span style="color:#F97583"> ></span><span style="color:#85E89D"> span</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-style</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">italic</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  text-decoration</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">underline</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/span-html.webp" alt="What does span do in HTML: Text displaying  &#x22;My sandwich is amazing&#x22;. The word amazing is styling differently than the rest sentence as we set the span HTML tag." style="max-width:75%" class="img-narrow"></p>
<p>🔖 Here’s a trick: With <code>div > span</code>, we’re styling only <code>&#x3C;span></code> elements that are <strong>direct children</strong> of a <code>&#x3C;div></code>. This way, we target <em>only this specific span</em>, without affecting other <code>&#x3C;span></code> elements in the code! 🔴</p>
<p>Curious to learn more about how to focus on the exact elements you want? Look at my <a href="/coding-made-easy-with-css-selectors-an-ultimate-guide/">CSS selectors</a> post — it’s all about precision! 🎯</p>
<h2 id="targeting-letters-one-by-one-using-span-in-css">Targeting letters one by one using span in CSS<a class="heading-anchor" href="#targeting-letters-one-by-one-using-span-in-css" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Want to take it a step further? We can make it even more impressive by styling each letter of one word individually!! 🧨 ✨</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  My sandwich is</span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"letter-a"</span><span style="color:#E1E4E8">>a&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"letter-m"</span><span style="color:#E1E4E8">>m&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"letter-a"</span><span style="color:#E1E4E8">>a&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"letter-z"</span><span style="color:#E1E4E8">>z&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"letter-i"</span><span style="color:#E1E4E8">>i&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"letter-n"</span><span style="color:#E1E4E8">>n&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"letter-g"</span><span style="color:#E1E4E8">>g&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"exclamation-mark"</span><span style="color:#E1E4E8">>!!&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.letter-a</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">deeppink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.letter-m</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.letter-z</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">indigo</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.letter-i</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.letter-n</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">blue</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.letter-g</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">darkorchid</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.exclamation-mark</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/span-example-text-css-many-classes.webp" alt="What does span do in HTML: Text displaying  &#x22;My sandwich is amazing&#x22;. The word amazing is styling differently than the rest sentence as we set the span HTML tag." style="max-width:45%" class="img-narrow"></p>
<h2 id="learn-how-to-use-html-span--the-fun-way">Learn how to use HTML span – the fun way<a class="heading-anchor" href="#learn-how-to-use-html-span--the-fun-way" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>What about making our learning more fun and using the metaphor of a sandwich to represent how the <code>&#x3C;span></code> elements are surrounded by their container element (<a href="/most-useful-html-elements-for-maximizing-better-results/">HTML opening and closing tags</a>)!</p>
<p>Here’s the idea 💡</p>
<h3 id="sandwich-with-span-as-the-filling-">Sandwich with span as the filling 🍔<a class="heading-anchor" href="#sandwich-with-span-as-the-filling-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Imagine an illustration where a slice of text is styled like a sandwich with:</p>
<ul>
<li><strong>Bread Slices</strong>: Representing HTML tags surrounding the <code>&#x3C;span></code> element.</li>
<li><strong>Fillings (cheese, tomato, lettuce)</strong>: Representing the words or phrases wrapped in the <code>&#x3C;span></code> elements, styled differently to stand out, just like all these fillings inside a sandwich.</li>
</ul>
<p>This metaphor will show the positioning of <code>&#x3C;span></code> clearly! 🥳</p>
<p><img src="/span-post-cover.webp" alt="A cheeseburger with cheese, tomato and lettuce inside." style="max-width:55%" class="img-narrow"></p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/most-useful-html-elements-for-maximizing-better-results/">The Most Useful HTML Elements</a></li>
<li><a href="/html-formatting-elements-made-simple-with-easy-and-practical-examples/">HTML Text Formatting Elements</a></li>
<li><a href="/coding-made-easy-with-css-selectors-an-ultimate-guide/">CSS Selectors: A Complete Guide</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Is CSS a Programming Language?</title>
      <link>https://littlecodingthings.com/the-truth-about-css-is-it-really-a-programming-language/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/the-truth-about-css-is-it-really-a-programming-language/</guid>
      <pubDate>Thu, 20 Feb 2025 11:41:00 GMT</pubDate>
      <description>No — CSS is a style sheet language, not a programming language. What separates the two, and what CSS does instead, with an example.</description>
      <category>Thoughts &amp; Theory</category>
      <content:encoded><![CDATA[<p>Is CSS a programming language? If you’ve ever wondered, read the following post and discover 🔎 why you might reconsider asking that question!</p>
<p>A programming language is a tool 🛠 that enables developers to instruct computers to perform tasks or calculations. Developers achieve this by writing code that tells the computer what to do step-by-step, much like giving commands to execute specific outcomes. It consists of rules that a computer can understand and execute. 😎</p>
<p>CSS (Cascading Style Sheets) is not considered a programming language. It is a style sheet language that defines how <a href="/most-useful-html-elements-for-maximizing-better-results/" title="HTML elements">HTML elements</a> should be displayed on a webpage and controls their layout, colors, fonts, and spacing.</p>
<p>Below, I have prepared an example to help you better understand what CSS does. Also, you’ll see an image displaying the HTML and CSS code snippet used in the example.</p>
<p>As we already said, CSS contains rules. Each rule typically includes a <a href="/coding-made-easy-with-css-selectors-an-ultimate-guide/" title="selector">selector</a> (which identifies the HTML element to style) and the declaration block <code>{...}</code> (which specifies the styling properties and their values). In our example, <code>h1</code> is the selector, and <code>background-color: pink;</code> , <code>color: indigo;</code> and <code>font-size: 25px;</code> are declarations.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">>Enjoy working with CSS!!&#x3C;/</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">h1</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">indigo</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">25</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-programming-language-example.webp" alt="Is CSS a programming language - Text writing: Enjoy working with CSS" style="max-width:42%" class="img-narrow"></p>
<p>Remember that if you want to include interactive functionality in your projects, programming languages are invaluable tools you can leverage. 🧨 ✨</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/is-html-a-programming-language-find-out-now/">Is HTML a Programming Language? Find Out Now!</a></li>
<li><a href="/how-to-work-with-css-syntax-the-correct-way/">How To Work With CSS Syntax: The Correct Way!</a></li>
<li><a href="/how-css-became-powerful-with-animations/">How CSS Became So Powerful with Animations</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>CSS Filters: Opacity and Saturate</title>
      <link>https://littlecodingthings.com/opacity-and-saturate-empower-css-filter-for-unique-images/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/opacity-and-saturate-empower-css-filter-for-unique-images/</guid>
      <pubDate>Mon, 20 Jan 2025 09:03:00 GMT</pubDate>
      <description>Use filter: opacity() to fade an image into its background and filter: saturate() to dial its colors up or down. Side-by-side examples.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Welcome to a practical guide on using the CSS filter to modify how your images 📸 look. In this post, we’ll work on how to adjust the <code>opacity</code> and <code>saturate</code> (color intensity) CSS filters. These two methods will help us handle how images are rendered on our website, particularly concerning their colors and transparency.</p>
<p>Let’s get into the world of CSS 👩‍💻 and customize the images to suit our needs.</p>
<h2 id="css-filter-opacity">CSS filter: opacity<a class="heading-anchor" href="#css-filter-opacity" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The CSS property <code>filter: opacity()</code> helps you control how transparent an image is against its background. You can set it anywhere between 0% and 100%. At 0%, the image is fully transparent, so only the background behind it shows. If you set it to 100%, the image displays its true, unaltered colors. Values in between let more or less of the background show through.</p>
<p>🔖 For setting CSS opacity, you can use either a percentage of 0% and 100% or a decimal value between 0 and 1, both options ending up in the same outcome. 🫧😃</p>
<h3 id="example">Example<a class="heading-anchor" href="#example" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Starting with the <a href="/most-useful-html-elements-for-maximizing-better-results/">HTML</a> code which includes three <code>&#x3C;img></code> elements. All images share the same <code>.image</code> class. Additionally, the second image includes one more class the <code>.opacity-image2</code> while the third image includes the <code>.opacity-image3</code> class.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">body</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">img</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"image"</span><span style="color:#E1E4E8">/></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">img</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"image opacity-image2"</span><span style="color:#E1E4E8">/></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">img</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"image opacity-image3"</span><span style="color:#E1E4E8">/></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">body</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p>In the <a href="/how-to-work-with-css-syntax-the-correct-way/">CSS</a> code the <code>.image</code> class introduces a non-repeated image that covers the entire background area of the element. Its dimensions are 300 pixels in width and 500 pixels in height.</p>
<p>We move forward with the other two classes. The <code>.opacity-image2</code> class targets the second image and applies a visual effect controlling transparency. An opacity of 80% means the element will be slightly transparent, allowing some background to show through.</p>
<p>The <code>.opacity-image3</code> class is meant for the third image, ensuring the same visual change happens there too. In this case, an opacity of 20% means the element will be mostly transparent, allowing more background to show through.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.image</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">url</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">https://images.unsplash.com/photo-1501829385782-9841539fa6bf?ixlib=rb-4.0.3&#x26;ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&#x26;auto=format&#x26;fit=crop&#x26;w=3024&#x26;q=80</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  background-repeat</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">no-repeat</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">cover</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">500</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.opacity-image2</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">opacity</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">80</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.opacity-image3</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">opacity</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>* In this case, the background is black, so our effect turns to dark shades.</p>
<figure><img src="/filter-opacity-with-black-background.webp" alt="Three identical photos of a red car with old buildings in Verona city, Italy. The first photo displays original colors. The second has opacity set to 80%, and the third has opacity set to 20%. The white background affects the opacity."><figcaption>Original Photo by <a href="https://unsplash.com/@jonatanhernandez?utm_content=creditCopyText&#x26;utm_medium=referral&#x26;utm_source=unsplash">Jonatan Hernandez</a> on <a href="https://unsplash.com/photos/AWkEp5ap-vw?utm_content=creditCopyText&#x26;utm_medium=referral&#x26;utm_source=unsplash">Unsplash</a> – opacity(80%) – opacity(20%)</figcaption></figure>
<p>* In this case, the background is white, so our effect turns to bright shades.</p>
<figure><img src="/filter-opacity-with-white-background.webp" alt="This image shows three identical photos. All photos shown a red car with old buildings as a background.This photo was captured in Verona city Italy. The first photo has the original colors. The second has set the filter: opacity(80%); CSS property while the third has set the filter: opacity(20%);. Additionally the background has color white which affects the opacity."><figcaption>Original photo by <a href="https://unsplash.com/@jonatanhernandez?utm_content=creditCopyText&#x26;utm_medium=referral&#x26;utm_source=unsplash">Jonatan Hernandez</a> on <a href="https://unsplash.com/photos/AWkEp5ap-vw?utm_content=creditCopyText&#x26;utm_medium=referral&#x26;utm_source=unsplash">Unsplash</a> – opacity(80%) – opacity(20%)</figcaption></figure>
<p>* In this case, the background is purple (a random color for this specific example, as you can pick any color you prefer), so our effect will blend the original element’s colors and the purple background color, influenced by the 80% opacity.</p>
<figure><img src="/filter-opacity-with-purple-background.webp" alt="Red car with old buildings in Verona city, Italy, demonstrating CSS opacity filter effects. Three photos: original colors, 80% opacity, and 20% opacity against a purple background."><figcaption>Original photo by <a href="https://unsplash.com/@jonatanhernandez?utm_content=creditCopyText&#x26;utm_medium=referral&#x26;utm_source=unsplash">Jonatan Hernandez</a> on <a href="https://unsplash.com/photos/AWkEp5ap-vw?utm_content=creditCopyText&#x26;utm_medium=referral&#x26;utm_source=unsplash">Unsplash</a> – opacity(80%) – opacity(20%)</figcaption></figure>
<h2 id="css-filter-saturate">CSS filter: saturate<a class="heading-anchor" href="#css-filter-saturate" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Saturation is about how bright and vivid colors are in a picture. The CSS property <code>filter: saturate()</code> helps you adjust this. The values vary from 0% to 100%. If you choose 0%, the colors disappear and become black and white (<a href="/awesome-css-grayscale-filter-how-to-upgrade-images/">grayscale</a>). With a value of 100%, it stays as colorful as it was.</p>
<p>Keep in mind that going over 100% makes colors appear highly vibrant. Specifying a saturation of 200% is technically allowed, but that’s not the usual way.</p>
<p>🔖 To specify a percentage for saturation, you can use values like 10% or 0.1, they mean the same thing. It’s up to you. 🫧😃</p>
<h3 id="example-1">Example<a class="heading-anchor" href="#example-1" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Starting with the HTML code which includes three <code>&#x3C;img></code> elements. All images share the same <code>.image</code> class. Additionally, the second image includes one more class the <code>.saturate-image2</code> while the third image includes the <code>.saturate-image3</code> class.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">img</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"image"</span><span style="color:#E1E4E8">/></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">img</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"image saturate-image2"</span><span style="color:#E1E4E8">/></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">img</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"image saturate-image3"</span><span style="color:#E1E4E8">/></span></span></code></pre></div>
<p>In the CSS code, the <code>.image</code> class introduces a non-repeated image that covers the entire background area of the element. Its dimensions are 300 pixels in width and 500 pixels in height.</p>
<p>We continue with the other two classes. The <code>.saturate-image2</code> class targets the second image and applies a visual effect controlling saturation. A saturation of 200% will be doubled compared to the original colors of the image, resulting in a sharp visual effect.</p>
<p>The <code>.saturate-image3</code> class focuses on the third image and applies the same visual effect. In this case, a saturation of 20% means the image will have its colors slightly desaturated, resulting in a toned-down appearance compared to the original colors. The saturation level will be reduced to one-fifth of the original, giving a less intense color effect.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.image</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">url</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">https://images.unsplash.com/photo-1501829385782-9841539fa6bf?ixlib=rb-4.0.3&#x26;ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&#x26;auto=format&#x26;fit=crop&#x26;w=3024&#x26;q=80</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  background-repeat</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">no-repeat</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">cover</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">500</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.saturate-image2</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">saturate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">200</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.saturate-image3</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">saturate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>The results are shown in the images below.</p>
<figure><img src="/filter-saturate-origin-photo.webp" alt="Red car with old buildings in Verona city, Italy" style="max-width:28%" class="img-narrow"><figcaption>default-saturate(100%) Original photo by <a href="https://unsplash.com/@jonatanhernandez?utm_content=creditCopyText&#x26;utm_medium=referral&#x26;utm_source=unsplash">Jonatan Hernandez</a> on <a href="https://unsplash.com/photos/AWkEp5ap-vw?utm_content=creditCopyText&#x26;utm_medium=referral&#x26;utm_source=unsplash">Unsplash</a></figcaption></figure>
<figure><img src="/filter-saturate-200.webp" alt="Vibrant red car against old buildings in Verona city, Italy, with CSS saturate filter set to 200%." style="max-width:28%" class="img-narrow"><figcaption>saturate(200%)</figcaption></figure>
<figure><img src="/filter-saturate-20.webp" alt="Red car against old buildings in Verona city, Italy, with CSS saturate filter set to 20%, resulting in a more grayish appearance compared to the original photo." style="max-width:28%" class="img-narrow"><figcaption>saturate(20%)</figcaption></figure>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/the-unique-css-opacity-check-out-this-amazing-property/">Using CSS Opacity for Transparency</a></li>
<li><a href="/contrast-and-brightness-empower-css-filter-for-powerful-images/">CSS Filters: Adjust Contrast and Brightness</a></li>
<li><a href="/grayscale-backdrop-filter-a-useful-tool-to-make-grayish-backgrounds/">CSS backdrop-filter: grayscale()</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>CSS Filters: Adjust Contrast and Brightness</title>
      <link>https://littlecodingthings.com/contrast-and-brightness-empower-css-filter-for-powerful-images/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/contrast-and-brightness-empower-css-filter-for-powerful-images/</guid>
      <pubDate>Mon, 13 Jan 2025 11:00:00 GMT</pubDate>
      <description>Control light and dark in an image with filter: contrast() and filter: brightness(). What each percentage does, with side-by-side photos.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Welcome to a practical guide on using CSS <code>filter</code> to modify the appearance of your 📸 images. In this post, we’ll focus on adjusting the <code>contrast</code> and <code>brightness</code> CSS filters. These techniques will allow us to control how images are displayed, specifically regarding their levels of light and darkness.</p>
<p>Let’s dive into the world of CSS 👩‍💻 and customize the images to suit our preferences.</p>
<h2 id="css-property-filter-contrast">CSS property filter: contrast<a class="heading-anchor" href="#css-property-filter-contrast" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The CSS property <code>filter: contrast()</code> is used to control the difference between the <strong>light and dark parts</strong> of an image. The <code>contrast</code> property accepts values from 0% to infinity. A value of 100% (or 1) is normal contrast. A higher value, increases the difference between light and dark areas, making the image appear more vivid and clearer. On the contrary, a lower value decreases the distinction, resulting in a softer and more blended appearance.</p>
<p>Always remember, if you want your picture to be clear and detailed, you can try using higher contrast values. This way, you find the right mix between making the picture softer and keeping it sharp and clear. But if you set the contrast too low, the picture might not show the different parts or details well. It might look a bit boring or like it has a gray layer on top. 🙁</p>
<p>🔖 You can express contrast either as a percentage (10%) or in decimal form (0.1) – both methods produce identical results. The choice between the two is entirely based on your personal liking. 🫧😃</p>
<h3 id="css-contrast-filter-example">CSS Contrast filter example<a class="heading-anchor" href="#css-contrast-filter-example" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>I crafted an example for you.</p>
<p>Starting with the <a href="/most-useful-html-elements-for-maximizing-better-results/">HTML</a> code which includes three <code>&#x3C;img></code> elements. All images share the same <code>.image</code> class. Additionally, the second image includes one more class the <code>.contrast-image2</code> while the third image includes the <code>.contrast-image3</code> class.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">img</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"image"</span><span style="color:#E1E4E8">/></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">img</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"image contrast-image2"</span><span style="color:#E1E4E8">/></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">img</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"image contrast-image3"</span><span style="color:#E1E4E8">/></span></span></code></pre></div>
<p>In the <a href="/how-to-work-with-css-syntax-the-correct-way/">CSS</a> code the <code>.image</code> class introduces a non-repeated image that covers the entire background area of the element. Its dimensions are 300 pixels in width and 500 pixels in height.</p>
<p>We move forward with the other two classes. The <code>.contrast-image2</code> class targets the second image and applies a visual effect that controls the contrast. A value of 150% would make the differences between light and dark elements in the image more pronounced, resulting in a sharper and more defined visual appearance.</p>
<p>The <code>.contrast-image3</code> class targets the third image and applies the same visual effect. In this case, a value of 20% reduces the contrast, making it less distinct and blending the light and dark areas.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.image</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">url</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">https://images.unsplash.com/photo-1501829385782-9841539fa6bf?ixlib=rb-4.0.3&#x26;ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&#x26;auto=format&#x26;fit=crop&#x26;w=3024&#x26;q=80</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  background-repeat</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">no-repeat</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">cover</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">500</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.contrast-image2</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">contrast</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">150</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.contrast-image3</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">contrast</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>In the images below we can see the results.</p>
<figure><img src="/filter-origin-photo.webp" alt="A red car is parked in front of old buildings in Verona, Italy. The historic architecture in the background contrasts with the vibrant color of the modern car." style="max-width:28%" class="img-narrow"><figcaption>default-contrast(100%) Original photo by <a href="https://unsplash.com/@jonatanhernandez?utm_content=creditCopyText&#x26;utm_medium=referral&#x26;utm_source=unsplash">Jonatan Hernandez</a> on <a href="https://unsplash.com/photos/AWkEp5ap-vw?utm_content=creditCopyText&#x26;utm_medium=referral&#x26;utm_source=unsplash">Unsplash</a></figcaption></figure>
<figure><img src="/filter-contast-150.webp" alt="A photo of a red car with old buildings in the background, captured in Verona, Italy. The image has a CSS filter with 150% contrast, making it sharper and more vivid than the original." style="max-width:28%" class="img-narrow"><figcaption>contrast(150%)</figcaption></figure>
<figure><img src="/filter-contast-20.webp" alt="A photo of a red car with old buildings in the background, captured in Verona, Italy. The image has a CSS filter with 20% contrast, giving it a softer, more grayish look compared to the original." style="max-width:28%" class="img-narrow"><figcaption>contrast(20%)</figcaption></figure>
<h2 id="css-property-filter-brightness">CSS property filter: brightness<a class="heading-anchor" href="#css-property-filter-brightness" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The CSS <code>filter: brightness</code> is a property that adjusts the intensity of light in an image. It influences <strong>how bright or dark</strong> the visual element appears to the viewer. A value of 100% (or 1) represents the origin brightness. Values less than 100% darken the element, while values greater than 100% brighten it. For example, 50% would make the element half as bright, and 200% would make it twice as bright while a brightness of 0% gives only a black color.</p>
<p>🔖 You have the choice to indicate brightness using percentages, such as 10%, or in decimal form like 0.1, both have the same results. It’s completely up to your preference. 🫧😃</p>
<h3 id="css-brightness-filter-example">CSS Brightness filter example<a class="heading-anchor" href="#css-brightness-filter-example" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Here is an example for you.</p>
<p>Starting with the HTML code which includes three <code>&#x3C;img></code> elements. All images share the same <code>.image</code> class. Additionally, the second image includes one more class the <code>.brightness-image2</code> while the third image includes the <code>.brightness-image3</code> class.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">img</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"image"</span><span style="color:#E1E4E8">/></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">img</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"image brightness-image2"</span><span style="color:#E1E4E8">/></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">img</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"image brightness-image3"</span><span style="color:#E1E4E8">/></span></span></code></pre></div>
<p>In the CSS code the <code>.image</code> class introduces a non-repeated image that covers the entire background area of the element. Its dimensions are 300 pixels in width and 500 pixels in height.</p>
<p>We proceed with the other two classes. The <code>.brightness-image2</code> class targets the second image and applies a visual effect that controls the brightness making the element 1.5 times brighter than its normal appearance.</p>
<p>The <code>.brightness-image3</code> class targets the third image and applies the same visual effect. In this case, a brightness of 20% means the element will be darkened, making it one-fifth as bright as its original state.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.image</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">url</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">https://images.unsplash.com/photo-1501829385782-9841539fa6bf?ixlib=rb-4.0.3&#x26;ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&#x26;auto=format&#x26;fit=crop&#x26;w=3024&#x26;q=80</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  background-repeat</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">no-repeat</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">cover</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">500</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.brightness-image2</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">brightness</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">150</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.brightness-image3</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">brightness</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>In the images below we can see the results.</p>
<figure><img src="/filter-origin-photo.webp" alt="A photo of a red car with old buildings as a background.This photo was captured in Verona city Italy." style="max-width:28%" class="img-narrow"><figcaption>default-brightness(100%) Original photo by <a href="https://unsplash.com/@jonatanhernandez?utm_content=creditCopyText&#x26;utm_medium=referral&#x26;utm_source=unsplash">Jonatan Hernandez</a> on <a href="https://unsplash.com/photos/AWkEp5ap-vw?utm_content=creditCopyText&#x26;utm_medium=referral&#x26;utm_source=unsplash">Unsplash</a></figcaption></figure>
<figure><img src="/filter-brightness-150.webp" alt="A photo of a red car with old buildings in the background, captured in Verona, Italy. The image has a CSS filter with 150% brightness, making it brighter than the original." style="max-width:28%" class="img-narrow"><figcaption>brightness(150%)</figcaption></figure>
<figure><img src="/filter-brightness-20.webp" alt="A photo of a red car with old buildings in the background, captured in Verona, Italy. The image has a CSS filter with 20% brightness, making it significantly less bright, almost black, compared to the original." style="max-width:28%" class="img-narrow"><figcaption>brightness(20%)</figcaption></figure>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/opacity-and-saturate-empower-css-filter-for-unique-images/">CSS Filters: Opacity and Saturate</a></li>
<li><a href="/awesome-css-grayscale-filter-how-to-upgrade-images/">CSS Grayscale Filter – A Complete Guide</a></li>
<li><a href="/the-css-sepia-filter-learn-how-to-make-vintage-images/">The CSS Sepia Filter Explained</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Using CSS Opacity for Transparency</title>
      <link>https://littlecodingthings.com/the-unique-css-opacity-check-out-this-amazing-property/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/the-unique-css-opacity-check-out-this-amazing-property/</guid>
      <pubDate>Mon, 06 Jan 2025 10:44:00 GMT</pubDate>
      <description>How the CSS opacity property works from 0 to 1, how to fade it smoothly on hover, and why a parent background tints its children.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>The CSS <code>opacity</code> property allows you to adjust the transparency of an element on a website. Opacity values range from <code>0.0</code> to <code>1</code> (default), where <code>opacity: 0.0</code> indicates complete transparency and <code>opacity: 1</code> indicates complete intransparency (opaqueness). 👻💻</p>
<h2 id="how-to-change-opacity-on-hover">How to change opacity on hover?<a class="heading-anchor" href="#how-to-change-opacity-on-hover" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>You can create visually appealing effects by overlapping the elements’ colors. Moreover, you can make it more dynamic 💥 by animating it with CSS transitions. For instance, you can create an effect when an element is clicked or hovered over.</p>
<p>Let’s say, for example, we have a red box like this</p>
<p><img src="/magenta-box.webp" alt="A magenta box on an orange background" style="max-width:42%" class="img-narrow"></p>
<p>and would like to change its opacity on hover. How would we do that? We would add the following code:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  opacity</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0.5</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>As a result, when hovering over our element, it would change its opacity like this</p>
<p>See the Pen<a href="https://codepen.io/GeorgeLin/pen/vYoBYBP">
Opacity box no transition</a> by George (<a href="https://codepen.io/GeorgeLin">@GeorgeLin</a>)
on <a href="https://codepen.io">CodePen</a>.</p>
<p>(Embedding a live pen like that in your own posts is worth knowing — we wrote up <a href="/how-to-embed-codepen-in-a-wordpress-blog/">how to embed CodePen in a blog</a> after running into the referer error.)</p>
<p>Some may think this is not ideal; changing the opacity is cool, but it feels like we can do better. A straightforward way to improve the opacity change is just to add a transition effect and make it look much cooler:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  transition</span><span style="color:#E1E4E8">: opacity </span><span style="color:#79B8FF">0.5</span><span style="color:#F97583">s</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"><span style="color:#B392F0">.box:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  opacity</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0.5</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  transition</span><span style="color:#E1E4E8">: opacity </span><span style="color:#79B8FF">0.5</span><span style="color:#F97583">s</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>We apply the same transition to both the <code>.box</code> class and its hover state to ensure a consistent effect when hovering on or off the element. This approach produces the following result:</p>
<p>See the Pen<a href="https://codepen.io/GeorgeLin/pen/bGXbGvg">
Opacity box with transition</a> by George (<a href="https://codepen.io/GeorgeLin">@GeorgeLin</a>)
on <a href="https://codepen.io">CodePen</a>.</p>
<p>Pretty cool, right?</p>
<h2 id="exploring-css-opacity-and-its-impact-on-background-colors-in-html">Exploring CSS Opacity and Its Impact on Background Colors in HTML<a class="heading-anchor" href="#exploring-css-opacity-and-its-impact-on-background-colors-in-html" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Depending on the opacity value, the child’s hues are influenced by the parent’s colors. <strong>Hues become more vibrant as the opacity value increases.</strong> If the child element has a low opacity value, its colors will be more similar to the parent’s <code>background-color</code>. Conversely, if the child element has a high opacity value, its colors will be less similar to the parent’s color.</p>
<p>In the following examples I prepared, we can see how this CSS property works. 🧐 So, let’s take a closer look.</p>
<p>Each example has a pair of HTML elements, one with <code>.parent</code> class and one with the <code>.child</code> class. Child elements have the same colors (<code>color: black</code> and  <code>background-color: white</code>) while parent elements have different <code>background-color</code> each time (gray and orange).</p>
<h3 id="css-opacity-effects-on-html-elements-with-gray-backgrounds"><strong>CSS Opacity: Effects on HTML Elements with Gray Backgrounds</strong><a class="heading-anchor" href="#css-opacity-effects-on-html-elements-with-gray-backgrounds" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>As we can see, the resulting color of our child element will be a mix of white, influenced by the grey ⬜ background color.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.parent</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">grey</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.child</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  opacity</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0.1</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* depending on the value */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-opacity-filter-parent-background-grey.webp" alt="An image showing a table with 10 blocks. Each block shows the CSS opacity filter starting from 0.1 to 1"></p>
<h3 id="css-opacity-effects-on-html-elements-with-orange-backgrounds">CSS Opacity: Effects on HTML Elements with Orange Backgrounds<a class="heading-anchor" href="#css-opacity-effects-on-html-elements-with-orange-backgrounds" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>As observed, the child’s resulting color will be a blend of white, affected by the orange 🟧 background color.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.parent</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.child</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  opacity</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0.1</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* depending on the value */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-opacity-filter-parent-background-orange.webp" alt="An image showing a table with 10 blocks. Each block shows the CSS opacity filter starting from 0.1 to 1."></p>
<p>CSS opacity offers a powerful way to control transparency, influencing how the background colors of parent elements interact with those of child elements. Understanding these interactions can help create visually appealing designs where colors harmoniously blend across different layers. 🌈 ✨</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/opacity-and-saturate-empower-css-filter-for-unique-images/">CSS Filters: Opacity and Saturate</a></li>
<li><a href="/simple-ways-to-create-a-css-overlay-effect/">Simple Ways to Create a CSS Overlay Effect</a></li>
<li><a href="/what-you-need-to-know-about-css-color-methods/">What You Need to Know About CSS Color Methods</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>CSS Word Spacing – How to Do It Right</title>
      <link>https://littlecodingthings.com/css-word-spacing-how-to-do-it-right/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/css-word-spacing-how-to-do-it-right/</guid>
      <pubDate>Mon, 23 Dec 2024 10:00:00 GMT</pubDate>
      <description>word-spacing controls the gap between words. Three headings compared — normal, widened and negative — and the values worth avoiding.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hey everyone! 😃 In this post, we’ll take a look at the CSS property called word spacing. It controls the <strong>horizontal distance between words</strong> in a text. By default, the CSS word spacing is set to 0px, which is known as normal (<code>word-spacing: normal</code>). If you increase the spacing value, the distance between words will get bigger, while decreasing it will make the spacing smaller.</p>
<p>Let’s take a closer look at this simple yet useful CSS property to gain a better understanding of it.</p>
<h2 id="html-structure-for-css-word-spacing">HTML structure for CSS word spacing<a class="heading-anchor" href="#html-structure-for-css-word-spacing" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Let’s begin by creating an <a href="/most-useful-html-elements-for-maximizing-better-results/">HTML</a> document. In it, we include three headings <code>&#x3C;h1></code> that display the text “Hello World”. The first heading has the class <code>.spacing-normal</code>, the second heading has the class <code>.spacing-big</code>, and the third heading has the class <code>.spacing-small</code>. All headings contain the same text, as it allows an easy comparison. 👌</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">h1</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"spacing-normal"</span><span style="color:#E1E4E8">>Hello World&#x3C;/</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">h1</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"spacing-big"</span><span style="color:#E1E4E8">>Hello World&#x3C;/</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">h1</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"spacing-small"</span><span style="color:#E1E4E8">>Hello World&#x3C;/</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h2 id="css-structure-for-css-word-spacing">CSS structure for CSS word spacing<a class="heading-anchor" href="#css-structure-for-css-word-spacing" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>For our CSS structure, we set the <code>word-spacing</code> property for all three classes and differentiate them by assigning different values.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.spacing-normal</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  word-spacing</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">normal</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.spacing-big</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  word-spacing</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.spacing-small</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  word-spacing</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>The image below illustrates the effect of varying word spacing values on each of our headings. The first heading has normal word spacing, while the second has a larger distance between words due to the increased word spacing value. Similarly, the third heading has a narrower spacing resulting from the decreased value.</p>
<p>🔖 It is important to avoid using word spacing values that are either too large or too small.</p>
<p><img src="/css-word-spacing.webp" alt="An example of the CSS word spacing property" style="max-width:56%" class="img-narrow"></p>
<p>In summary, this image illustrates how adjusting the spacing between words can affect the appearance of text. It’s amazing how even small changes can have a significant impact. Isn’t it? 😎</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/css-letter-spacing-working-on-the-correct-way/">CSS Letter Spacing – Working on The Correct Way</a></li>
<li><a href="/how-to-calculate-css-line-height/">How To Calculate CSS Line Height</a></li>
<li><a href="/css-text-decoration-explained-with-examples/">CSS Text Decoration Explained with Examples</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How to install Git on Mac – MacOS for beginners</title>
      <link>https://littlecodingthings.com/how-to-install-git-on-mac-macos-for-beginners/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-install-git-on-mac-macos-for-beginners/</guid>
      <pubDate>Mon, 16 Dec 2024 10:00:00 GMT</pubDate>
      <description>Install Git on macOS with Xcode Command Line Tools or Homebrew, set your commit identity, and learn the handful of commands you’ll use every day.</description>
      <category>Setup &amp; Tools</category>
      <content:encoded><![CDATA[<p>So, you’re new to macOS and ready to set up Git? Great choice! Git is one of the essential tools for developers, and installing it should be one of the first steps in your journey. Don’t worry—it’s easier than you think. Let’s get started!</p>
<p>If you’ve never worked with Git before, think of it as a timeline for your files. It’s a tool used to keep track of every change you make, so you can jump backward in time if you break something or experiment freely without losing your original work.</p>
<p>It’s not just for programmers — writers, researchers, and designers also use Git to track versions of their work. Installing Git on your Mac now will save you a lot of headaches later.</p>
<p>Although there’s a small learning curve at first, you’ll quickly find that once you’ve used Git for a while, you can’t imagine working without it — you’ll wonder how you ever managed before.</p>
<h2 id="check-if-git-is-already-installed">Check if Git is already installed<a class="heading-anchor" href="#check-if-git-is-already-installed" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>If you’re just setting up your Mac, it’s unlikely that Git is already installed. macOS doesn’t come with a fully functional Git by default. Instead, it includes a placeholder located at <code>/usr/bin/git</code>. This placeholder acts as a link to the actual Git version, which gets installed with Xcode or the Command Line Tools.</p>
<p>To check, open your terminal and type:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">git</span><span style="color:#79B8FF"> --version</span></span></code></pre></div>
<p>If you see something like:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>No developer tools were found, requesting install</span></span></code></pre></div>
<p>it means that macOS detected that you tried to use a command-line developer tool – <code>git</code> in this case – but the <strong>Xcode Command Line Tools</strong> are not installed on your system.</p>
<p>From here, you have two main choices for installing Git on your Mac — Apple’s Xcode Command Line Tools or the Homebrew package manager. Both will get the job done, but they have different strengths.</p>
<ul>
<li><strong>Xcode Command Line Tools</strong> is quick and easy if you just want to start using Git right away, but the version it installs is maintained by Apple and might not always be the latest.</li>
<li><strong>Homebrew</strong>, on the other hand, gives you more control and makes it simple to update Git whenever a new release comes out. If you plan to keep working with Git regularly, I suggest going with Homebrew for its flexibility and ease of maintenance.</li>
</ul>
<h2 id="install-git-on-mac-using-xcode">Install Git on Mac using Xcode<a class="heading-anchor" href="#install-git-on-mac-using-xcode" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Xcode is one of the quickest ways to install Git on your system. Since Xcode Command Line tools include Git in the package, to use Git all you need to do is type the following command in your terminal</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>xcode-select --install</span></span></code></pre></div>
<p>When the pop-up appears, click <strong>Install</strong>. Make sure you’re connected to the internet.</p>
<p>Once the installation finishes, confirm it by typing:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">git</span><span style="color:#79B8FF"> --version</span></span></code></pre></div>
<p>You should now see something like:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">git</span><span style="color:#9ECBFF"> version</span><span style="color:#79B8FF"> 2.39.5</span><span style="color:#E1E4E8"> (Apple </span><span style="color:#9ECBFF">Git-154</span><span style="color:#E1E4E8">)</span></span></code></pre></div>
<h2 id="install-git-on-mac-using-homebrew">Install Git on Mac using Homebrew<a class="heading-anchor" href="#install-git-on-mac-using-homebrew" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Another popular way to install Git on macOS, apart from using Xcode Command Line Tools, is by <a href="/how-to-install-homebrew-macos-for-beginners/">using Homebrew</a>.</p>
<p>This method is often preferred by developers who want more control over the Git version or are already using Homebrew for managing other software.</p>
<p>To install Git using Homebrew, run the following command</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">brew</span><span style="color:#9ECBFF"> install</span><span style="color:#9ECBFF"> git</span></span></code></pre></div>
<p>Running this command will display some logs related to the Git installation, such as:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">...</span><span style="color:#E1E4E8">.</span></span>
<span class="line"><span style="color:#F97583">==></span><span style="color:#E1E4E8"> Installing git</span></span>
<span class="line"><span style="color:#F97583">==></span><span style="color:#E1E4E8"> Pouring git</span><span style="color:#F97583">--</span><span style="color:#79B8FF">2.47</span><span style="color:#E1E4E8">.1.arm64_sequoia.bottle.tar.gz</span></span>
<span class="line"><span style="color:#F97583">==></span><span style="color:#E1E4E8"> Caveats</span></span>
<span class="line"><span style="color:#E1E4E8">The Tcl</span><span style="color:#F97583">/</span><span style="color:#E1E4E8">Tk </span><span style="color:#B392F0">GUIs</span><span style="color:#E1E4E8"> (e.g. gitk, git</span><span style="color:#F97583">-</span><span style="color:#E1E4E8">gui) are now </span><span style="color:#F97583">in</span><span style="color:#E1E4E8"> the </span><span style="color:#9ECBFF">`git-gui`</span><span style="color:#E1E4E8"> formula.</span></span>
<span class="line"><span style="color:#E1E4E8">Subversion </span><span style="color:#B392F0">interoperability</span><span style="color:#E1E4E8"> (git</span><span style="color:#F97583">-</span><span style="color:#E1E4E8">svn) is now </span><span style="color:#F97583">in</span><span style="color:#E1E4E8"> the </span><span style="color:#9ECBFF">`git-svn`</span><span style="color:#E1E4E8"> formula.</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">zsh completions and functions have been installed </span><span style="color:#B392F0">to</span><span style="color:#E1E4E8">:</span></span>
<span class="line"><span style="color:#F97583">  /</span><span style="color:#E1E4E8">opt</span><span style="color:#F97583">/</span><span style="color:#E1E4E8">homebrew</span><span style="color:#F97583">/</span><span style="color:#E1E4E8">share</span><span style="color:#F97583">/</span><span style="color:#E1E4E8">zsh</span><span style="color:#F97583">/</span><span style="color:#E1E4E8">site</span><span style="color:#F97583">-</span><span style="color:#E1E4E8">functions</span></span>
<span class="line"><span style="color:#F97583">==></span><span style="color:#E1E4E8"> Summary</span></span>
<span class="line"><span style="color:#E1E4E8">🍺  </span><span style="color:#F97583">/</span><span style="color:#E1E4E8">opt</span><span style="color:#F97583">/</span><span style="color:#E1E4E8">homebrew</span><span style="color:#F97583">/</span><span style="color:#E1E4E8">Cellar</span><span style="color:#F97583">/</span><span style="color:#E1E4E8">git</span><span style="color:#F97583">/</span><span style="color:#79B8FF">2.47</span><span style="color:#E1E4E8">.</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">,</span><span style="color:#79B8FF">685</span><span style="color:#E1E4E8"> files, 54.4</span><span style="color:#79B8FF">MB</span></span>
<span class="line"><span style="color:#F97583">==></span><span style="color:#E1E4E8"> Running </span><span style="color:#9ECBFF">`brew cleanup git`</span><span style="color:#F97583">...</span></span>
<span class="line"><span style="color:#F97583">...</span><span style="color:#E1E4E8">.</span></span></code></pre></div>
<p>Once the installation process is complete, you can verify that Git was installed successfully by typing:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">git</span><span style="color:#79B8FF"> --version</span></span></code></pre></div>
<p>You should see</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">git</span><span style="color:#9ECBFF"> version</span><span style="color:#79B8FF"> 2.39.5</span><span style="color:#E1E4E8"> (Apple </span><span style="color:#9ECBFF">Git-154</span><span style="color:#E1E4E8">)</span></span></code></pre></div>
<p>With Git successfully installed, you’re now ready to dive into your development journey and take full control of your projects!</p>
<p><strong>🛠 Extra Tip:</strong> When installing via Homebrew, you can easily update Git later by running:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">brew</span><span style="color:#9ECBFF"> update</span><span style="color:#E1E4E8"> &#x26;&#x26; </span><span style="color:#B392F0">brew</span><span style="color:#9ECBFF"> upgrade</span><span style="color:#9ECBFF"> git</span></span></code></pre></div>
<p>This ensures you’re always on the latest stable release without waiting for Apple updates. It also makes switching between different Git versions simple, which is useful for testing or specific project needs.</p>
<h2 id="verify-git-configuration">Verify Git configuration<a class="heading-anchor" href="#verify-git-configuration" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>After installing Git, it’s a good idea to configure your identity so your commits are linked to the right name and email address. Run the following commands in your terminal:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">git</span><span style="color:#9ECBFF"> config</span><span style="color:#79B8FF"> --global</span><span style="color:#9ECBFF"> user.name</span><span style="color:#9ECBFF"> "Your Name"</span></span>
<span class="line"><span style="color:#B392F0">git</span><span style="color:#9ECBFF"> config</span><span style="color:#79B8FF"> --global</span><span style="color:#9ECBFF"> user.email</span><span style="color:#9ECBFF"> "you@example.com"</span></span></code></pre></div>
<p>You can check your saved settings with:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">git</span><span style="color:#9ECBFF"> config</span><span style="color:#79B8FF"> --list</span></span></code></pre></div>
<p>This will show your username, email, and other configuration details. These can be changed at any time if you switch accounts or need to adjust your settings.</p>
<h2 id="next-steps-with-git"><strong>Next Steps with Git</strong><a class="heading-anchor" href="#next-steps-with-git" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Installing Git is just the beginning. The next step is learning a few key commands that will make you productive right away. Start with:</p>
<ul>
<li><code>git init</code> – Create a new repository in the current folder.</li>
<li><code>git add &#x3C;filename></code> – Stage files you want to include in your next commit. (There is also <code>git add -A</code> for everything at once — see <a href="/what-does-git-add-a-do/">what <code>git add -a</code> actually does</a>.)</li>
<li><code>git commit -m "message"</code> – Save your staged changes with a short description.</li>
<li><code>git status</code> – Check what’s been modified, staged, or committed.</li>
<li><code>git log</code> – View a history of all commits in the repository.</li>
</ul>
<p>Once you’re comfortable with these, try creating a branch with <code>git branch &#x3C;branchname></code> and switching to it using <code>git checkout &#x3C;branchname></code>. Branching is one of Git’s most powerful features, letting you work on new ideas without touching your main project until you’re ready.</p>
<p>As you explore these commands, remember that consistent practice is the fastest way to build confidence and skill with Git. And if you want to take things a step further, tools like <a href="/husky-hooks-the-easy-way-to-improve-your-project-workflow/">Husky pre-commit hooks</a> can help automate checks and streamline your workflow as you grow.</p>]]></content:encoded>
    </item>
    <item>
      <title>Is HTML a Programming Language? Find Out Now!</title>
      <link>https://littlecodingthings.com/is-html-a-programming-language-find-out-now/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/is-html-a-programming-language-find-out-now/</guid>
      <pubDate>Mon, 09 Dec 2024 09:00:00 GMT</pubDate>
      <description>No — HTML is a markup language, not a programming language. Here is what that distinction actually means, and why it matters.</description>
      <category>Thoughts &amp; Theory</category>
      <content:encoded><![CDATA[<p>Understanding the role of a programming language is the key 🗝 to answering the question “Is HTML a programming language?”. 🧐</p>
<p>To put it simply, the answer is <strong>no, HTML is not a programming language</strong>.</p>
<p>HTML stands for <strong>H</strong>yper<strong>T</strong>ext <strong>M</strong>arkup <strong>L</strong>anguage, a type of <strong>markup language</strong> used for creating structured content. But what does that even mean? Let’s break it down a bit.</p>
<h2 id="markup-language">Markup Language<a class="heading-anchor" href="#markup-language" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>A markup language is a system for creating <strong>structured</strong> <strong>text</strong> in a way that both humans and machines can read. It consists of <a href="/most-useful-html-elements-for-maximizing-better-results/" title="tags">tags</a> or elements known as building blocks. These tags are responsible for the structure of the web page defining how its content is organized and formatted. Some examples of such elements would be <code>&#x3C;h1></code> for headers, <code>&#x3C;a></code> for links, <code>&#x3C;p></code> for paragraphs, <code>&#x3C;footer></code> for footers.</p>
<h2 id="hypertext">HyperText<a class="heading-anchor" href="#hypertext" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The term “hypertext” is part of the name because it allows text to include links – called <strong>hyperlinks</strong> – to connect to other pages. Turning text into a hyperlink makes it easy to navigate between web pages.</p>
<p>By combining hypertext and markup, we get HTML, which is a language that structures web pages while also adding links to make them somewhat dynamic by connecting to other resources.</p>
<p>That’s pretty cool, but even though we have defined a “smart” language, the question still remains: Is HTML a programming language?</p>
<h2 id="getting-to-the-answer-is-html-a-programming-language">Getting to the answer: Is HTML a programming language?<a class="heading-anchor" href="#getting-to-the-answer-is-html-a-programming-language" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We can undoubtedly say that a programming language <strong>gives precise instructions</strong> to a computer or other devices to perform specific tasks, process data and create interactivity. Programming languages can build everything from simple scripts to complex applications, empowering developers to create tools and software that automate and enhance systems.</p>
<p>While HTML structures and displays content, <strong>it lacks the ability to process logic or perform tasks like a true programming language</strong>.</p>
<h2 id="a-quick-glimpse-at-how-html-is-written">A quick glimpse at how HTML is written<a class="heading-anchor" href="#a-quick-glimpse-at-how-html-is-written" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Below, I’ve included a simple HTML code snippet with an image to illustrate how the HTML actually works. In this case, it only defines the structure of a heading, a paragraph, a link, and a footer. It doesn’t involve processing, which is the role of programming languages. 😉</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">>I am the Heading&#x3C;/</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>I am a paragraph with text.&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">a</span><span style="color:#B392F0"> href</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"https://example.com"</span><span style="color:#E1E4E8">>This is a link&#x3C;/</span><span style="color:#85E89D">a</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">footer</span><span style="color:#E1E4E8">>I am the Footer&#x3C;/</span><span style="color:#85E89D">footer</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/html-programming-language.webp" alt="Is HTML a programming language?
An image with a heading tag, a paragraph tag, a link tag and a footer tag." style="max-width:56%" class="img-narrow"></p>
<p>To make websites dynamic or interactive, we have to combine <a href="/most-useful-html-elements-for-maximizing-better-results/" title="HTML">HTML</a> (for structure) with <a href="/how-to-work-with-css-syntax-the-correct-way/" title="CSS">CSS</a> (for styling) and <a href="/javascript-array-methods-easy-examples-that-make-learning-a-blast/" title="JavaScript">Javascript</a> (for functionality and behavior). The last one is an actual programming language. 😃 ✨</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/the-truth-about-css-is-it-really-a-programming-language/">Is CSS a Programming Language?</a></li>
<li><a href="/most-useful-html-elements-for-maximizing-better-results/">The Most Useful HTML Elements</a></li>
<li><a href="/html-formatting-elements-made-simple-with-easy-and-practical-examples/">HTML Text Formatting Elements</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How to install Homebrew – MacOS for beginners</title>
      <link>https://littlecodingthings.com/how-to-install-homebrew-macos-for-beginners/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-install-homebrew-macos-for-beginners/</guid>
      <pubDate>Mon, 02 Dec 2024 08:58:00 GMT</pubDate>
      <description>Homebrew is the package manager macOS is missing. Install it with one terminal command, verify it worked, and fix the PATH error that catches beginners.</description>
      <category>Setup &amp; Tools</category>
      <content:encoded><![CDATA[<p>If you are making your first steps on macOS, you may have never heard of Homebrew before. <strong>Homebrew</strong> is a <strong>powerful package manager</strong>, similar to <strong>npm</strong> if you’ve worked with it before. It allows you to easily install, update, and remove software packages directly from your terminal, making it an incredibly handy tool for developers. In this post, you’ll find a step-by-step guide to install Homebrew on MacOS.</p>
<h2 id="why-is-it-essential-to-install-homebrew">Why is it essential to install Homebrew?<a class="heading-anchor" href="#why-is-it-essential-to-install-homebrew" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Homebrew is widely regarded as <strong>the most popular</strong> package manager for macOS. It’s the go-to choice for developers and power users because of its simplicity and active community support.</p>
<p>Homebrew lets you easily get the tools and libraries you need for development or daily tasks, from developer tools like <a href="/how-to-install-git-on-mac-macos-for-beginners/">Git</a> and <a href="/how-to-install-npm-on-macos/">Node.js</a> to simple everyday utilities. It saves time by skipping the trouble of manual downloads and setup. It’s simple, fast, and perfect for customizing your Mac.</p>
<p>If you haven’t used a tool like Homebrew before, don’t overlook it – it could completely transform the way you manage software on your Mac.</p>
<h2 id="check-if-homebrew-is-already-installed">Check if Homebrew is already installed<a class="heading-anchor" href="#check-if-homebrew-is-already-installed" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Just to make sure you haven’t already installed Homebrew in the past, let’s check it out. Open your terminal and type:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">brew</span><span style="color:#9ECBFF"> help</span></span></code></pre></div>
<p>If you have it installed, you should see something like</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">Example</span><span style="color:#9ECBFF"> usage:</span></span>
<span class="line"><span style="color:#B392F0">  brew</span><span style="color:#9ECBFF"> search</span><span style="color:#9ECBFF"> TEXT</span><span style="color:#F97583">|</span><span style="color:#B392F0">/REGEX/</span></span>
<span class="line"><span style="color:#B392F0">  brew</span><span style="color:#9ECBFF"> info</span><span style="color:#E1E4E8"> [FORMULA</span><span style="color:#F97583">|</span><span style="color:#B392F0">CASK...]</span></span>
<span class="line"><span style="color:#B392F0">  brew</span><span style="color:#9ECBFF"> install</span><span style="color:#9ECBFF"> FORMULA</span><span style="color:#F97583">|</span><span style="color:#B392F0">CASK...</span></span>
<span class="line"><span style="color:#B392F0">  brew</span><span style="color:#9ECBFF"> update</span></span>
<span class="line"><span style="color:#B392F0">  brew</span><span style="color:#9ECBFF"> upgrade</span><span style="color:#E1E4E8"> [FORMULA</span><span style="color:#F97583">|</span><span style="color:#B392F0">CASK...</span></span>
<span class="line"><span style="color:#79B8FF">  ....</span></span></code></pre></div>
<p>otherwise, you will get the following result</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>command not found: brew</span></span></code></pre></div>
<h2 id="how-to-install-homebrew">How to install Homebrew<a class="heading-anchor" href="#how-to-install-homebrew" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Ready to install Homebrew? Here’s everything you need to know. Open your terminal (<em>Cmd + Space and type</em> “<em>Terminal</em>“) and type</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"</span></span></code></pre></div>
<p>Oh, you say! What is this command? Let me explain. This command asks <a href="https://www.gnu.org/software/bash/manual/bash.html#What-is-Bash_003f">bash</a> (<em>which is a command-line shell language commonly used in macOS and Linux</em>) to execute a script.</p>
<p>Here’s how it works:</p>
<ul>
<li><strong><code>/bin/bash</code></strong>: specifies the bash shell, ensuring the command is executed using bash, even if your default shell is something else (<em>like zsh</em>).</li>
<li><strong><code>-c</code></strong>: This flag tells bash to execute the command provided in quotes.</li>
<li><strong><code>$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)</code></strong>: This part fetches the Homebrew installation script directly from GitHub using <a href="/why-every-developer-should-still-know-curl-in-2026/"><code>curl</code></a> (<em>a tool for transferring data over the network — worth learning properly, since it turns up in install instructions like this one constantly</em>).</li>
</ul>
<p>In simple terms, this command downloads the <a href="https://github.com/Homebrew/install">Homebrew installer script from GitHub</a> and immediately runs it using bash to set up Homebrew on your system.</p>
<p>You will be asked for your super user password:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"</span></span>
<span class="line"><span></span></span>
<span class="line"><span>Checking for `sudo` access (which may request your password)...</span></span>
<span class="line"><span></span></span>
<span class="line"><span>Password:</span></span></code></pre></div>
<p>After typing your password, you’ll see a message prompting you to press <strong>ENTER</strong> to proceed with the installation. Simply press <strong>ENTER</strong>, and the installation will continue.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"</span></span>
<span class="line"><span></span></span>
<span class="line"><span>Checking for `sudo` access (which may request your password)...</span></span>
<span class="line"><span></span></span>
<span class="line"><span>Password:</span></span>
<span class="line"><span></span></span>
<span class="line"><span>==> This script will install:</span></span>
<span class="line"><span>/opt/homebrew/bin/brew</span></span>
<span class="line"><span>/opt/homebrew/share/doc/homebrew</span></span>
<span class="line"><span>....</span></span>
<span class="line"><span>/opt/homebrew</span></span>
<span class="line"><span>==> The following new directories will be created:</span></span>
<span class="line"><span>/opt/homebrew/bin</span></span>
<span class="line"><span>/opt/homebrew/etc</span></span>
<span class="line"><span>/opt/homebrew/include</span></span>
<span class="line"><span>....</span></span>
<span class="line"><span>/opt/homebrew/Frameworks</span></span>
<span class="line"><span></span></span>
<span class="line"><span>Press RETURN/ENTER to continue or any other key to abort:</span></span></code></pre></div>
<p>Wait for the installation process to complete—it may take a few minutes. Once it’s done, you’ll see the message <strong>“Installation successful!”</strong>. However, to ensure everything was installed correctly, let’s verify it by typing the following command in the terminal:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">brew</span><span style="color:#9ECBFF"> help</span></span></code></pre></div>
<p>If it was successfully installed, you should see the following response.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">Example</span><span style="color:#9ECBFF"> usage:</span></span>
<span class="line"><span style="color:#B392F0">  brew</span><span style="color:#9ECBFF"> search</span><span style="color:#9ECBFF"> TEXT</span><span style="color:#F97583">|</span><span style="color:#B392F0">/REGEX/</span></span>
<span class="line"><span style="color:#B392F0">  brew</span><span style="color:#9ECBFF"> info</span><span style="color:#E1E4E8"> [FORMULA</span><span style="color:#F97583">|</span><span style="color:#B392F0">CASK...]</span></span>
<span class="line"><span style="color:#B392F0">  brew</span><span style="color:#9ECBFF"> install</span><span style="color:#9ECBFF"> FORMULA</span><span style="color:#F97583">|</span><span style="color:#B392F0">CASK...</span></span>
<span class="line"><span style="color:#79B8FF">  ....</span></span></code></pre></div>
<h2 id="homebrew-doesnt-work-after-installing-it">Homebrew doesn’t work after installing it<a class="heading-anchor" href="#homebrew-doesnt-work-after-installing-it" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>If you’ve already followed all the steps described to install Homebrew but see a “command not found” error when running, e.g., <code>brew help</code> it typically means that the Homebrew binary is not properly added to your system’s PATH.</p>
<p>To resolve the issue, revisit the logs from the Homebrew installation script. At the end of the script, you’ll typically find specific instructions for finalizing the installation.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>Warning: /opt/homebrew/bin is not in your PATH.</span></span>
<span class="line"><span>  Instructions on how to configure your shell for Homebrew</span></span>
<span class="line"><span>  can be found in the 'Next steps' section below.</span></span>
<span class="line"><span>==> Installation successful!</span></span>
<span class="line"><span>...</span></span>
<span class="line"><span>...</span></span>
<span class="line"><span>...</span></span>
<span class="line"><span>==> Next steps:</span></span>
<span class="line"><span>- Run these commands in your terminal to add Homebrew to your PATH:</span></span>
<span class="line"><span>    echo >> /Users/&#x3C;your username>/.zprofile</span></span>
<span class="line"><span>    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/&#x3C;your username>/.zprofile</span></span>
<span class="line"><span>    eval "$(/opt/homebrew/bin/brew shellenv)"</span></span></code></pre></div>
<p>copy the last part of the Homebrew installation instructions —starting from the command that begins with <code>echo</code> — and paste it into your terminal. This command typically adds Homebrew to your system’s PATH.</p>
<h2 id="what-homebrew-actually-did-to-your-mac-">What Homebrew actually did to your Mac 🔍<a class="heading-anchor" href="#what-homebrew-actually-did-to-your-mac-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Worth thirty seconds, because it explains most of the confusion that follows.</p>
<p>Homebrew installs everything into a single directory it owns:</p>
<ul>
<li><strong><code>/opt/homebrew</code></strong> on Apple Silicon Macs (M1 and later)</li>
<li><strong><code>/usr/local</code></strong> on older Intel Macs</li>
</ul>
<p>Not sure which you have? Ask it:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">brew</span><span style="color:#79B8FF"> --prefix</span></span></code></pre></div>
<p>That difference is behind a genuinely large share of “this guide doesn’t work for me” moments — a tutorial written on an Intel Mac points at <code>/usr/local</code>, you paste the path on an M-series machine, and nothing is there.</p>
<p>Inside that directory, each package lives in its own folder, and Homebrew creates symlinks from <code>bin</code> into your <code>PATH</code>. That’s the whole trick: install once, get a command you can type, remove it cleanly later because nothing was scattered across your system.</p>
<p>It also explains why you don’t need <code>sudo</code> for day-to-day use. The prefix belongs to <strong>your user account</strong>, not to root. <strong>Never run <code>sudo brew install</code></strong> — it creates root-owned files inside a directory Homebrew expects to own, and every later command spends its time complaining about permissions. The installer asks for your password once, at the start, to create that directory. After that, <code>brew</code> on its own is correct.</p>
<h2 id="formulae-and-casks-two-kinds-of-thing-">Formulae and casks: two kinds of thing 🍺<a class="heading-anchor" href="#formulae-and-casks-two-kinds-of-thing-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Homebrew installs two different categories of software, and knowing the words saves you a search:</p>
<ul>
<li>
<p><strong>Formulae</strong> are command-line tools and libraries — <code>git</code>, <code>node</code>, <code>postgresql</code>, <code>wget</code>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">brew</span><span style="color:#9ECBFF"> install</span><span style="color:#9ECBFF"> git</span></span></code></pre></div>
</li>
<li>
<p><strong>Casks</strong> are ordinary Mac apps with a window and an icon, the ones you’d normally download as a <code>.dmg</code> and drag into Applications.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">brew</span><span style="color:#9ECBFF"> install</span><span style="color:#79B8FF"> --cask</span><span style="color:#9ECBFF"> visual-studio-code</span></span></code></pre></div>
</li>
</ul>
<p>That second one is the part people miss for months. VS Code, Docker Desktop, Firefox — no download page, no drag-and-drop. And when you set up your next Mac, a handful of <code>brew install --cask</code> lines rebuild your whole toolkit while you make coffee.</p>
<h2 id="the-commands-youll-actually-use">The commands you’ll actually use<a class="heading-anchor" href="#the-commands-youll-actually-use" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<table>
<thead>
<tr>
<th scope="col">Command</th>
<th scope="col">What it does</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row"><code>brew search TEXT</code></th>
<td>Find out whether a package exists</td>
</tr>
<tr>
<th scope="row"><code>brew info FORMULA</code></th>
<td>Version, dependencies and any caveats — <strong>read this one</strong></td>
</tr>
<tr>
<th scope="row"><code>brew install FORMULA</code></th>
<td>Install it</td>
</tr>
<tr>
<th scope="row"><code>brew uninstall FORMULA</code></th>
<td>Remove it</td>
</tr>
<tr>
<th scope="row"><code>brew list</code></th>
<td>Everything you’ve installed</td>
</tr>
<tr>
<th scope="row"><code>brew outdated</code></th>
<td>What has a newer version available</td>
</tr>
<tr>
<th scope="row"><code>brew update</code></th>
<td>Update <strong>Homebrew itself</strong> and its catalogue</td>
</tr>
<tr>
<th scope="row"><code>brew upgrade</code></th>
<td>Update <strong>your installed packages</strong></td>
</tr>
<tr>
<th scope="row"><code>brew cleanup</code></th>
<td>Delete old versions and reclaim disk space</td>
</tr>
<tr>
<th scope="row"><code>brew doctor</code></th>
<td>Check your setup for problems</td>
</tr>
</tbody>
</table>
<h3 id="brew-update-vs-brew-upgrade-"><code>brew update</code> vs <code>brew upgrade</code> 🤯<a class="heading-anchor" href="#brew-update-vs-brew-upgrade-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>These two names are the single most confusing thing about Homebrew, so let’s be blunt about it:</p>
<ul>
<li><strong><code>brew update</code></strong> refreshes Homebrew’s list of available software. Nothing you installed changes.</li>
<li><strong><code>brew upgrade</code></strong> installs newer versions of the packages you actually have.</li>
</ul>
<p>Run <code>update</code> first, then <code>outdated</code> to see what’s coming, then <code>upgrade</code>:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">brew</span><span style="color:#9ECBFF"> update</span></span>
<span class="line"><span style="color:#B392F0">brew</span><span style="color:#9ECBFF"> outdated</span></span>
<span class="line"><span style="color:#B392F0">brew</span><span style="color:#9ECBFF"> upgrade</span></span></code></pre></div>
<p>Skipping straight to <code>brew upgrade</code> still works — it updates the catalogue itself first — but you’ll have upgraded things without ever seeing what was about to change.</p>
<p>One habit worth forming: <code>brew info</code> before you install anything. That’s where a formula tells you it’s keg-only, or that it needs a line added to your shell config, or that it just created a database cluster somewhere. Those caveats are the difference between a tool that works and an hour of troubleshooting — the <a href="/how-to-install-postgres-on-macos/">Postgres install</a> is the classic example, since it prints exactly the <code>brew services</code> command you’ll need next.</p>
<h2 id="frequently-asked-questions">Frequently asked questions<a class="heading-anchor" href="#frequently-asked-questions" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<h3 id="do-i-need-xcode-to-use-homebrew">Do I need Xcode to use Homebrew?<a class="heading-anchor" href="#do-i-need-xcode-to-use-homebrew" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Not the full Xcode, but you do need Apple’s <strong>Command Line Tools</strong>, which are a few gigabytes of compilers and developer utilities. The good news is the Homebrew installer handles this for you — if that step in your install took a suspiciously long time, that’s what it was doing.</p>
<h3 id="how-do-i-uninstall-homebrew">How do I uninstall Homebrew?<a class="heading-anchor" href="#how-do-i-uninstall-homebrew" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>The project publishes an uninstall script alongside the installer:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">/bin/bash</span><span style="color:#79B8FF"> -c</span><span style="color:#9ECBFF"> "$(</span><span style="color:#B392F0">curl</span><span style="color:#79B8FF"> -fsSL</span><span style="color:#9ECBFF"> https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"</span></span></code></pre></div>
<p>Same shape as the install command, different filename. It removes Homebrew and everything it installed, so read what it prints before confirming.</p>
<h3 id="why-does-homebrew-say-a-package-is-keg-only">Why does Homebrew say a package is “keg-only”?<a class="heading-anchor" href="#why-does-homebrew-say-a-package-is-keg-only" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>It means the package was installed but deliberately not linked into your <code>PATH</code>, usually because it’s a specific version of something that could conflict with another version. It isn’t an error. <code>brew info</code> on that package prints the <code>export PATH</code> line you need to use it.</p>
<h3 id="what-if-brew-doctor-reports-warnings">What if <code>brew doctor</code> reports warnings?<a class="heading-anchor" href="#what-if-brew-doctor-reports-warnings" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Don’t panic — <code>brew doctor</code> is thorough to the point of pessimism, and “Your system is ready to brew” is genuinely rare on a machine that’s seen some use. Read the warnings, fix anything mentioning permissions or an unexpected file in the prefix, and ignore the rest unless something is actually broken.</p>
<p>By now, you should have Homebrew installed on your system successfully. <strong>Congratulations</strong>! This is just the first small step on your exciting journey to mastering powerful tools and workflows as you grow your skills. If you’re exploring ways to automate parts of your development workflow next, you might find Git tools like <a href="/husky-hooks-the-easy-way-to-improve-your-project-workflow/">Husky pre-commit hooks</a> especially helpful.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-install-git-on-mac-macos-for-beginners/">How to install Git on Mac – MacOS for beginners</a></li>
<li><a href="/how-to-install-postgres-on-macos/">How to Install Postgres on MacOS</a></li>
<li><a href="/how-to-install-java-on-mac-step-by-step-guide/">How to Install Java on Mac: Step-by-Step Guide</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How to Add Sass to A Create-React-App Project</title>
      <link>https://littlecodingthings.com/how-to-add-sass-to-a-create-react-app-project/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-add-sass-to-a-create-react-app-project/</guid>
      <pubDate>Mon, 25 Nov 2024 10:00:00 GMT</pubDate>
      <description>Add Sass to a Create React App project with one npm install, plus the real difference between Sass and SCSS syntax and how to remove CRA later.</description>
      <category>Setup &amp; Tools</category>
      <content:encoded><![CDATA[<p>In this post, we’ll be sharing all the steps you need to follow to learn how to add Sass to a Create-React-App project. We’ll take it step by step and make it crystal clear for you! Let’s do it!</p>
<h2 id="setup-a-create-react-app-project">Setup a Create-React-App project<a class="heading-anchor" href="#setup-a-create-react-app-project" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>To build your initial project structure, you have two options, either install <code>create-react-app</code> (CRA) package globally and use that, or use <code>npx</code> and avoid installing <code>create-react-app</code> in your system.</p>
<p>To check if you already have CRA installed, type in your terminal:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">create-react-app</span><span style="color:#79B8FF"> --version</span></span></code></pre></div>
<p>If you see a version logged, something like <code>5.0.1</code> then you are just fine and can start the project initialization process. Otherwise, you need to decide whether to proceed by installing CRA or not. Both decisions are valid and it depends on your coding style and whether you like to keep global packages or not.</p>
<h3 id="installing-create-react-app">Installing Create-React-App<a class="heading-anchor" href="#installing-create-react-app" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>If you want to install <code>create-react-app</code> in your terminal type:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">npm</span><span style="color:#9ECBFF"> install</span><span style="color:#9ECBFF"> create-react-app</span><span style="color:#79B8FF"> --global</span></span></code></pre></div>
<p>After installing the package, check its version to verify the installation by typing <code>create-react-app --version</code>.</p>
<p>Now that you have installed CRA, you can create your project by typing</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>create-react-app my-project</span></span></code></pre></div>
<h3 id="using-npx--avoid-installing-create-react-app">Using npx – Avoid installing Create-React-App<a class="heading-anchor" href="#using-npx--avoid-installing-create-react-app" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>If you want to avoid installing <code>create-react-app</code> and just use npx, you can just type</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">npx</span><span style="color:#9ECBFF"> create-react-app</span><span style="color:#9ECBFF"> my-project</span></span></code></pre></div>
<p>Basic difference between <code>npx</code> and <code>npm</code> is that <code>npm</code> is a package <strong>manager</strong> and <code>npx</code> is a package <strong>executor</strong>.</p>
<p>Using <code>npx</code> doesn’t install the package you want permanently but rather temporarily so that it gets the job done. That’s why if you check the version of the package used after using npx, you will get nothing back, compared to the classic installation with <code>npm</code> in which you’ll get the installed package’s version. Try it out!</p>
<p>You may ask how <code>npx</code> was added to my system. Since <code>npm</code> <a href="https://github.com/npm/npm/releases/tag/v5.2.0" title="version 5.2.0">version 5.2.0</a>, <code>npx</code> is pre-bundled with <code>npm</code>.</p>
<h2 id="add-sass-to-create-react-app">Add Sass to Create-React-App<a class="heading-anchor" href="#add-sass-to-create-react-app" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Now that we have our project’s basic structure, let’s start adding some Sass code. Our first step is installing Sass:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">npm</span><span style="color:#9ECBFF"> install</span><span style="color:#9ECBFF"> sass</span></span></code></pre></div>
<p>Now that we have the Sass package installed, the next step would be to rename our <code>App.css</code> file to <code>App.scss</code> and add some Sass styling there like so:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> { </span><span style="color:#79B8FF">background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">; }</span></span></code></pre></div>
<p>Now I know what you are thinking, and yes, this is not solid styling for our app; it’s just to verify our changes are applied as expected. One final step before verifying everything works. We have renamed our <code>App.css</code> to <code>App.scss</code> so we will be getting an error if we run our app because the importing in the <code>App.js</code> file is using the previous extension <code>import './App.css';</code>.</p>
<p>Let’s change that too by making it <code>import './App.scss';</code></p>
<p>Now, check out your browser, and you should see the applied changes! Keep in mind, though, that based on your already applied stylings, you may not actually see our styles on the browser because they will probably get overridden by yours. You can still see if everything worked as expected and if our style was “passed” to the browser either by checking your browser’s dev tools or by increasing your style’s specificity.</p>
<h2 id="sass-vs-scss--whats-the-difference">Sass VS SCSS – What’s the difference?<a class="heading-anchor" href="#sass-vs-scss--whats-the-difference" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>For those of you who are paying extra attention, you may have already seen that we have installed a Sass package to handle new code styling, but we have used <code>.scss</code> file extension. What’s with that?</p>
<p>Well, first of all, <code>sass</code> package encompasses both the Sass and SCSS syntax, so we are fine with that regardless of the style we want to use, Sass or SCSS.</p>
<p>The difference between Sass and SCSS is basically their syntax. Sass is more concise and doesn’t use curly braces, whereas SCSS (Sassy CSS) has a more CSS-like syntax.</p>
<p>Both serve the same purpose of allowing maintainability and efficient CSS usage, however <code>.scss</code> extension is more popular in the Sass community, and that’s why we have chosen in this post to use the <code>.scss</code> file extension.</p>
<h2 id="remove-create-react-app">Remove Create-React-App<a class="heading-anchor" href="#remove-create-react-app" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>If, after finishing your project, you’d like to remove CRA from your system, you can just type</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">npm</span><span style="color:#9ECBFF"> uninstall</span><span style="color:#79B8FF"> --global</span><span style="color:#9ECBFF"> create-react-app</span></span></code></pre></div>
<p>Remember, if you have used <code>npx</code> for your project’s initialization, nothing was installed, so you’ll be just fine, no reason for uninstalling anything.</p>
<h2 id="one-important-update-cra-is-deprecated-️">One important update: CRA is deprecated ⚠️<a class="heading-anchor" href="#one-important-update-cra-is-deprecated-️" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Since this post was written, the React team <a href="https://react.dev/blog/2025/02/14/sunsetting-create-react-app">deprecated Create React App</a> — on 14 February 2025 — and now points people at a framework like Next.js, or a build tool like <strong>Vite</strong>, Parcel or Rsbuild. CRA still works and is in maintenance mode, so an existing project isn’t going to stop building tomorrow. But it’s no longer what you should reach for on a new one.</p>
<p>The good news for this particular post: Sass is even easier in Vite. Install the same <code>sass</code> package and import a <code>.scss</code> file — Vite handles it with no extra configuration and no <code>react-scripts</code> in the middle.</p>
<p>If you’re keeping a CRA project going, our guide to <a href="/how-to-change-the-default-port-in-a-create-react-app-project/">changing the default port in a Create React App project</a> covers the other setting people usually want next.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-change-the-default-port-in-a-create-react-app-project/">Change the Default Port in Create React App</a></li>
<li><a href="/naming-conventions-how-to-name-your-components-without-fighting-your-ui-library/">Component Naming Conventions in React</a></li>
<li><a href="/coding-made-easy-with-css-selectors-an-ultimate-guide/">CSS Selectors: A Complete Guide</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>nth-child vs nth-of-type in CSS</title>
      <link>https://littlecodingthings.com/css-selectors-nth-child-vs-nth-of-type-and-how-to-use-them-correctly/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/css-selectors-nth-child-vs-nth-of-type-and-how-to-use-them-correctly/</guid>
      <pubDate>Mon, 18 Nov 2024 09:26:00 GMT</pubDate>
      <description>:nth-child() counts every sibling; :nth-of-type() counts only elements of that tag. The same markup styled both ways, side by side.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>The amazing <a href="/coding-made-easy-with-css-selectors-an-ultimate-guide/" title="CSS selectors">CSS selectors</a> family! One of the most helpful tools we can use when styling our website. In today’s post, 😃 we’ll examine the unstoppable battle of <code>nth-child()</code> VS <code>nth-of-type()</code> selectors. They both allow you to target <a href="/most-useful-html-elements-for-maximizing-better-results/" title="HTML elements">HTML elements</a> based on their position within a parent, but they achieve that differently.</p>
<p>The moment to clarify the key difference between them and how to use each effectively to get the styling we want has finally come! 🤓</p>
<p>So, let’s proceed by analyzing and comparing these amazing pseudo-classes! 💻 ✨</p>
<h2 id="preparing-our-html-structure">Preparing our HTML structure<a class="heading-anchor" href="#preparing-our-html-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We begin with an HTML code snippet by creating a <code>&#x3C;section></code> element as the parent, which contains some <code>&#x3C;p></code> and <code>&#x3C;div></code> children.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">section</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>I'm the first paragraph&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>I'm the first div&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>I'm the second paragraph&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>I'm the second div&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>I'm the third paragraph&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>I'm the third div&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">section</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p>Below, we can see what is rendered on the screen for now. Three paragraphs and three div elements. Note that I have kept the default styling: black text on a white background.</p>
<p><img src="/css-selectors-nth-child-vs-nth-of-type-example-outlet.webp" alt="CSS nth child VS nth of type selectors. This image shows <p> and <div> as children inside a <section> element" style="max-width:42%" class="img-narrow"></p>
<h2 id="the-nth-child-selector">The nth-child selector<a class="heading-anchor" href="#the-nth-child-selector" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The <a href="/what-you-need-to-know-about-css-nth-child-selector-a-practical-guide/" title=":nth-child() selector"><code>:nth-child()</code> selector</a> <strong>targets the HTML element declared inside the parentheses, regardless of its type</strong>. In the code snippet below, we pick the second child (which happens to be a div) by placing the number 2 inside the parentheses.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">section</span><span style="color:#B392F0"> :nth-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">2</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>The image below shows that the second child takes on our attributes.</p>
<p><img src="/css-selectors-nth-child-vs-nth-of-type-example-selects-nth-child.webp" alt="This image shows <p> and <div> sibling elements, with the second element styled differently using the nth-child(2) CSS selector" style="max-width:42%" class="img-narrow"></p>
<h2 id="the-nth-of-type-selector">The nth-of-type selector<a class="heading-anchor" href="#the-nth-of-type-selector" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The <code>:nth-of-type()</code> selector <strong>targets HTML elements based on their type</strong>. In the following code snippet, we pick the second <code>&#x3C;p></code> element by placing the number 2 inside the parentheses <code>()</code> and specifying the type <code>p</code> before the selector.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">section</span><span style="color:#85E89D"> p</span><span style="color:#B392F0">:nth-of-type</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">2</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">    color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>The image below shows that the styling is now applied to the second paragraph instead of the second child.</p>
<p><img src="/css-selectors-nth-child-vs-nth-of-type-example-selects-nth-of-type-second-paragraph.webp" alt="This image shows sibling <p> and <div> elements. The second <p> element is styled differently using the p:nth-of-type(2) CSS selector, with 2 inside the parentheses and p preceding the selector" style="max-width:42%" class="img-narrow"></p>
<p>We can also try to do the same with our <code>&#x3C;div></code> elements. Let’s change the type, in front of our selector, from <code>p</code> to <code>div</code>. What would happen then?</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">section</span><span style="color:#85E89D"> div</span><span style="color:#B392F0">:nth-of-type</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">2</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">    color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>We now notice that the styling is removed from the second paragraph and applied to the second div. Cool huh? 😎</p>
<p><img src="/css-selectors-nth-child-vs-nth-of-type-example-selects-nth-of-type-second-div.webp" alt="This image shows sibling <p> and <div> elements. The second <div> element is styled differently using the div:nth-of-type(2) CSS selector, with 2 inside the parentheses and div preceding the selector." style="max-width:42%" class="img-narrow"></p>
<p>By learning correctly when and how to use each selector, we can ensure that our CSS targets exactly the elements we intend and help us achieve more precise and effective styling. Happy coding! 🎉 👩‍💻</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/what-you-need-to-know-about-css-nth-child-selector-a-practical-guide/">The CSS nth-child Selector Explained</a></li>
<li><a href="/the-css-nth-of-type-selector-how-to-target-elements-by-type/">The CSS nth-of-type Selector Explained</a></li>
<li><a href="/learn-how-to-select-only-the-css-first-child/">Learn How to Select Only the CSS First Child</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How to Install npm on MacOS</title>
      <link>https://littlecodingthings.com/how-to-install-npm-on-macos/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-install-npm-on-macos/</guid>
      <pubDate>Fri, 15 Nov 2024 14:06:00 GMT</pubDate>
      <description>Install Node.js and npm on macOS with Homebrew in four steps: check what you already have, install, verify the versions, then update npm to the latest.</description>
      <category>Setup &amp; Tools</category>
      <content:encoded><![CDATA[<p>Installing <strong>Node.js</strong> and <strong>npm</strong> (Node Package Manager) on your Mac is super simple. With these tools, you can manage Javascript packages, create powerful web applications, and dive deep into modern web development. Start by following these steps:</p>
<h2 id="step-1-verify-that-npm-is-installed">Step 1: Verify that npm is installed<a class="heading-anchor" href="#step-1-verify-that-npm-is-installed" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Open your terminal and type</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">node</span><span style="color:#79B8FF"> -v</span></span>
<span class="line"><span style="color:#B392F0">npm</span><span style="color:#79B8FF"> -v</span></span></code></pre></div>
<ul>
<li>If you see version numbers (e.g., <code>v16.13.0</code> for Node.js and <code>8.1.0</code> for npm), they’re already installed.</li>
<li>If you see errors or no versions, continue to the next step.</li>
</ul>
<h2 id="step-2-install-nodejs-includes-npm">Step 2: Install Node.js (includes npm)<a class="heading-anchor" href="#step-2-install-nodejs-includes-npm" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The easiest way to install Node.js and npm is by using <strong>Homebrew</strong>. If you don’t have Homebrew installed, <a href="/how-to-install-homebrew-macos-for-beginners/">install it first</a>.</p>
<p>Then run:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">brew</span><span style="color:#9ECBFF"> install</span><span style="color:#9ECBFF"> node</span></span></code></pre></div>
<h2 id="step-3-verify-the-installation">Step 3: Verify the Installation<a class="heading-anchor" href="#step-3-verify-the-installation" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>After the installation completes, type the following command to check the versions and ensure everything is installed properly:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">node</span><span style="color:#79B8FF"> -v</span></span>
<span class="line"><span style="color:#B392F0">npm</span><span style="color:#79B8FF"> -v</span></span></code></pre></div>
<p>You should see version numbers for both. 🎉</p>
<h2 id="step-4-update-npm-optional">Step 4: Update npm (Optional)<a class="heading-anchor" href="#step-4-update-npm-optional" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>npm updates frequently, so ensure you have the latest version:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">npm</span><span style="color:#9ECBFF"> install</span><span style="color:#79B8FF"> -g</span><span style="color:#9ECBFF"> npm@latest</span></span></code></pre></div>
<p>🎉 <strong>You’re all set!</strong> Now, you can use Node.js and npm to manage and build amazing projects. Happy coding! 😊</p>
<p><strong>Why Use Node.js and npm?</strong></p>
<ul>
<li><strong>Fast &#x26; Scalable</strong>: Node.js enables fast, scalable network applications with non-blocking I/O.</li>
<li><strong>Massive Ecosystem</strong>: npm offers access to over 1 million open-source packages.</li>
<li><strong>Cross-Platform</strong>: Develop once and deploy anywhere.</li>
</ul>
<p>These tools are essential for any web developer aiming to build modern, high-performance applications.</p>
<h2 id="hold-on--why-didnt-we-install-npm-">Hold on — why didn’t we install npm? 🤔<a class="heading-anchor" href="#hold-on--why-didnt-we-install-npm-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Because you can’t, and you don’t need to. <strong>npm ships inside Node.js.</strong> One download, two commands on your machine. That’s why Step 2 only installs <code>node</code> and Step 3 checks both versions.</p>
<p>The two do completely different jobs, which is worth getting straight early:</p>
<ul>
<li><strong>Node.js</strong> is the runtime. It’s the thing that runs your Javascript outside a browser.</li>
<li><strong>npm</strong> is the package manager. It downloads other people’s code into <code>node_modules</code> and records it in your <code>package.json</code>.</li>
</ul>
<p>There’s a third command you also just got for free: <strong>npx</strong>, which runs a package without installing it. <code>npx create-next-app@latest</code> is the everyday example — you use it once and you don’t want it living on your machine forever.</p>
<h2 id="the-mistake-almost-everyone-makes-brew-install-node-isnt-the-lts-">The mistake almost everyone makes: <code>brew install node</code> isn’t the LTS 😬<a class="heading-anchor" href="#the-mistake-almost-everyone-makes-brew-install-node-isnt-the-lts-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>This one bites people weeks later, so it’s worth thirty seconds now.</p>
<p>The Homebrew formula called <code>node</code> tracks the <strong>newest</strong> Node release, not the Long Term Support one. Node’s release policy is that even-numbered major versions become LTS and odd-numbered versions never do — so depending on the month, plain <code>brew install node</code> can hand you a release that hosting providers and CI images don’t support yet.</p>
<p>Check what you got:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">node</span><span style="color:#79B8FF"> -v</span></span></code></pre></div>
<p>If that’s an odd major number (or just newer than you want), install a specific line instead:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">brew</span><span style="color:#9ECBFF"> install</span><span style="color:#9ECBFF"> node@22</span></span></code></pre></div>
<p>The versioned formulas are <strong>keg-only</strong>, which is Homebrew’s way of saying “installed, but deliberately not wired into your <code>PATH</code>”, so two Node versions can coexist without fighting. Homebrew prints the exact <code>export PATH</code> line to add to your <code>~/.zshrc</code> when the install finishes — read that output instead of guessing, because the path differs between Apple Silicon (<code>/opt/homebrew</code>) and Intel (<code>/usr/local</code>) Macs.</p>
<p>If you juggle Node versions per project all day, a version manager like <strong>nvm</strong> or <strong>fnm</strong> is the better tool and Homebrew is the wrong one. If you have one machine and one Node, Homebrew is genuinely fine.</p>
<h2 id="zsh-command-not-found-npm-after-a-successful-install">“zsh: command not found: npm” after a successful install<a class="heading-anchor" href="#zsh-command-not-found-npm-after-a-successful-install" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The install worked. Your shell just doesn’t know where to look yet.</p>
<p>First, find out what your shell is actually finding:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#79B8FF">which</span><span style="color:#79B8FF"> -a</span><span style="color:#9ECBFF"> node</span></span>
<span class="line"><span style="color:#B392F0">brew</span><span style="color:#79B8FF"> --prefix</span></span></code></pre></div>
<p>Nearly every time, it’s one of three things:</p>
<ol>
<li><strong>You never opened a new terminal.</strong> <code>PATH</code> is read when the shell starts. Quit Terminal and reopen it, or run <code>source ~/.zshrc</code>.</li>
<li><strong>You’re on an Apple Silicon Mac and Homebrew isn’t on your <code>PATH</code> at all.</strong> Homebrew installs to <code>/opt/homebrew</code> on M-series Macs, and older setup guides written for Intel Macs point at <code>/usr/local</code>. If <code>brew --prefix</code> says <code>/opt/homebrew</code> but nothing from Homebrew works, this is your problem — our <a href="/how-to-install-homebrew-macos-for-beginners/">Homebrew install guide</a> has the shell config step.</li>
<li><strong>You installed a keg-only version</strong> like <code>node@22</code> and skipped the <code>export PATH</code> line.</li>
</ol>
<h2 id="never-run-sudo-npm-install--g-">Never run <code>sudo npm install -g</code> 🚫<a class="heading-anchor" href="#never-run-sudo-npm-install--g-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>When a global install fails, the first search result always says to put <code>sudo</code> in front of it. Don’t.</p>
<p>The error looks like this:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>npm error code EACCES</span></span>
<span class="line"><span>npm error syscall mkdir</span></span>
<span class="line"><span>npm error path /usr/local/lib/node_modules</span></span></code></pre></div>
<p><code>sudo</code> does make it go away — by creating root-owned folders inside your npm directory. Every later install as your normal user then fails on those folders, and you’re stuck reaching for <code>sudo</code> forever to dig out of a hole <code>sudo</code> dug.</p>
<p>Installed through Homebrew, you shouldn’t hit this at all: Homebrew’s prefix belongs to your user account, so global installs just work. If you are hitting it, you have a leftover Node from a <code>.pkg</code> installer or an old guide, and the real fix is to remove that one rather than escalate around it.</p>
<h2 id="frequently-asked-questions">Frequently asked questions<a class="heading-anchor" href="#frequently-asked-questions" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<h3 id="how-do-i-update-nodejs-and-npm-on-a-mac">How do I update Node.js and npm on a Mac?<a class="heading-anchor" href="#how-do-i-update-nodejs-and-npm-on-a-mac" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Two separate things. For Node, use Homebrew:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">brew</span><span style="color:#9ECBFF"> update</span></span>
<span class="line"><span style="color:#B392F0">brew</span><span style="color:#9ECBFF"> upgrade</span><span style="color:#9ECBFF"> node</span></span></code></pre></div>
<p>npm updates on its own schedule, faster than Node does, so bump it directly when you need to:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">npm</span><span style="color:#9ECBFF"> install</span><span style="color:#79B8FF"> -g</span><span style="color:#9ECBFF"> npm@latest</span></span></code></pre></div>
<h3 id="do-i-need-nodejs-if-i-only-want-npm">Do I need Node.js if I only want npm?<a class="heading-anchor" href="#do-i-need-nodejs-if-i-only-want-npm" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Yes. npm is written in Javascript and runs on Node — there is no npm without it. That’s also why <code>npm -v</code> and <code>node -v</code> report completely unrelated version numbers.</p>
<h3 id="how-do-i-uninstall-nodejs-installed-with-homebrew">How do I uninstall Node.js installed with Homebrew?<a class="heading-anchor" href="#how-do-i-uninstall-nodejs-installed-with-homebrew" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">brew</span><span style="color:#9ECBFF"> uninstall</span><span style="color:#9ECBFF"> node</span></span></code></pre></div>
<p>If you previously installed Node from the <code>.pkg</code> file on nodejs.org, Homebrew can’t remove that one — it lives in <code>/usr/local/bin</code> and has to be deleted by hand. Running <code>which -a node</code> will show you every copy on your machine, which is the fastest way to spot a duplicate.</p>
<h3 id="whats-the-difference-between-npm-install-and-npm-install--g">What’s the difference between <code>npm install</code> and <code>npm install -g</code>?<a class="heading-anchor" href="#whats-the-difference-between-npm-install-and-npm-install--g" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Without <code>-g</code>, packages land in the <code>node_modules</code> folder of the project you’re standing in, and get written to that project’s <code>package.json</code>. With <code>-g</code>, they install once for your whole user account and become terminal commands. Project dependencies should almost never be global — if you want to know why the <code>--save</code> flag disappeared from that first command, we covered it in <a href="/do-you-still-need-to-use-save-on-npm-install/">do you still need npm install --save?</a>.</p>
<h3 id="why-does-npm-install-create-a-package-lockjson">Why does <code>npm install</code> create a <code>package-lock.json</code>?<a class="heading-anchor" href="#why-does-npm-install-create-a-package-lockjson" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>It records the exact version of every package installed, including your dependencies’ dependencies, so that your teammate and your CI server get byte-for-byte the same tree you did. Commit it. Deleting it to “fix” an install is a habit worth not picking up.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-install-homebrew-macos-for-beginners/">How to install Homebrew – MacOS for beginners</a></li>
<li><a href="/do-you-still-need-to-use-save-on-npm-install/">Do You Still Need To Use npm install –save?</a></li>
<li><a href="/how-to-restart-your-node-apps-without-nodemon/">How to Restart Your Node App Without Nodemon</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How To Make CSS Reflection – The Easy Way</title>
      <link>https://littlecodingthings.com/how-to-make-css-reflection-the-easy-way/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-make-css-reflection-the-easy-way/</guid>
      <pubDate>Mon, 11 Nov 2024 14:51:00 GMT</pubDate>
      <description>Mirror any element with a single declaration: -webkit-box-reflect. Direction, distance, and a linear-gradient fade-out, with examples.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hello there! Today, we will explore a simple yet valuable topic. How do you create a CSS reflection using only one property? Let’s unlock the amazing <code>-webkit-box-reflect</code> property and effortlessly craft repeatable elements with minimal 😉 code! 🥳</p>
<h2 id="simple-css-reflection">Simple CSS Reflection<a class="heading-anchor" href="#simple-css-reflection" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We will start by creating two identical boxes. We set 200 pixels <code>width</code> and 100 pixels <code>height</code> and also add a solid black 2 pixel <code>border</code>. Continuing, we give our boxes an indigo <code>background-color</code>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"box box--adjacent"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"box box--spaced"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p>Next, we proceed with our <code>-webkit-box-reflect</code> where we create the reflection of each box, ensuring that their direction remains the same (<code>right</code> direction). However, the second reflection is located 150 pixels from the original box. That way, we can explore both direction and distance.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">indigo</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#FFAB70">--adjacent</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    -webkit-box-reflect</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">right</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#FFAB70">--spaced</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    -webkit-box-reflect</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">right</span><span style="color:#79B8FF"> 150</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>In the images provided, we can see two boxes along with their corresponding reflections. In the first image, the box’s reflection is located exactly on the right-hand side, adjacent to the original box, while in the second image, the box also has a reflection on the right-hand side but is positioned 150 pixels away from the original box.</p>
<figure><img src="/css-box-reflection-outlet-with-side-1.webp" alt="CSS reflection. An image showing a box reflection on the right-hand side of the origin box." style="max-width:43%" class="img-narrow"><figcaption>-webkit-box-reflect: right</figcaption></figure>
<figure><img src="/css-box-reflection-outlet-with-side-and-distance.webp" alt="CSS reflection. An image showing a box reflection on the right-hand side positioned 150 pixels away from the original box." style="max-width:42%" class="img-narrow"><figcaption>-webkit-box-reflect: right 150px</figcaption></figure>
<h2 id="css-reflection-with-fade-out-effect">CSS Reflection With Fade-Out Effect<a class="heading-anchor" href="#css-reflection-with-fade-out-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>It is essential to know that we can use the <code>-webkit-box-reflect</code> CSS property to create a reflection effect that accurately mirrors the original element’s appearance and style. We can further improve this effect and make it seem more authentic by using the <a href="/css-linear-gradient-techniques-how-to-make-colorful-line-drawings/" title="linear-gradient CSS property">linear-gradient CSS property</a>, which gives us the impression of a gradual fade-out. This technique is pretty cool! 😎</p>
<p>We will start with our HTML code snippet, creating again two boxes with identical characteristics. We set 200 pixels <code>width</code> and 100 pixels <code>height</code>. Next, we give both boxes an indigo <code>background-color</code>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"box box--simple-reflection"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"box box--fade-out-reflection"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p>Next, we proceed with our <code>-webkit-box-reflect</code> where we create the reflections of each box, ensuring that they have the same direction (<code>below</code>). However, the second reflection has a <code>linear-gradient</code> that creates a fade-out effect from top to bottom.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">indigo</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#FFAB70">--simple-reflection</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    -webkit-box-reflect</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">below</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#FFAB70">--fade-out-reflection</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    -webkit-box-reflect</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">below</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span></span>
<span class="line"><span style="color:#79B8FF">    linear-gradient</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#79B8FF">      rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">,</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">,</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">,</span><span style="color:#79B8FF">0.0</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#79B8FF">      rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">,</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">,</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">,</span><span style="color:#79B8FF">0.2</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#79B8FF">      rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">,</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">,</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">,</span><span style="color:#79B8FF">0.4</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#79B8FF">      rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">,</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">,</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">,</span><span style="color:#79B8FF">0.6</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#79B8FF">      rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">,</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">,</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">,</span><span style="color:#79B8FF">0.8</span><span style="color:#E1E4E8">)</span></span>
<span class="line"><span style="color:#E1E4E8">    );</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>When adjusting the reflection vertically, we need to use <code>above</code> and <code>below</code> instead of <code>top</code> and <code>bottom</code>.</p>
<p>Below, you can observe two boxes along with their related reflections. In the first image, the box’s reflection is located 10 pixels below the original box. In the second image, the reflection stands again 10 pixels below the origin box, but this time has the fade-out effect. It looks nice, doesn’t it?</p>
<figure><img src="/css-box-reflection-outlet-with-distance-and-side-below.webp" alt="CSS reflection. An image showing a box reflection 10 pixels below the original box." style="max-width:40%" class="img-narrow"><figcaption>-webkit-box-reflect: below 10px</figcaption></figure>
<figure><img src="/css-box-reflection-fade-out-outlet-distance-and-side-below.webp" alt="CSS reflection. An image showing a box reflection positioned 10 pixels below the original box. It has a linear-gradient(
rgba(0,0,0,0.0),
rgba(0,0,0,0.2),
rgba(0,0,0,0.4),
rgba(0,0,0,0.6),
rgba(0,0,0,0.8)) that creates the fade-out effect." style="max-width:42%" class="img-narrow"><figcaption>-webkit-box-reflect: below 10px linear-gradient(rgba(…))</figcaption></figure>
<p>If you are interested in diving deeper, there is an amazing post about <strong><a href="/how-to-make-a-css-text-reflection-effect/" title="CSS text reflection">CSS text reflection</a></strong> that you might enjoy reading!</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-make-a-css-reflection-effect/">How To Make A CSS Reflection Effect</a></li>
<li><a href="/how-to-make-a-css-text-reflection-effect/">How To Make A CSS Text Reflection Effect</a></li>
<li><a href="/css-linear-gradient-techniques-how-to-make-colorful-line-drawings/">CSS Linear Gradient: A Practical Guide</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Make Your Work Easier by Using Variables in CSS</title>
      <link>https://littlecodingthings.com/make-your-work-easier-by-using-variables-in-css/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/make-your-work-easier-by-using-variables-in-css/</guid>
      <pubDate>Mon, 04 Nov 2024 09:00:00 GMT</pubDate>
      <description>CSS custom properties from scratch: declaring them in :root, global vs local scope, combining them, and how var() fallbacks really work.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hello there! Today, we will analyze the amazing variables in CSS, also known as <strong>custom properties</strong> or <strong>cascading variables</strong>. It is a powerful technique that allows us to <strong>store reusable values</strong> for colors, sizes, fonts, and even animations. These values can be set once and used as many times as we want throughout our project.</p>
<p>Simply put, if we want to update a value throughout our <a href="/the-truth-about-css-is-it-really-a-programming-language/">CSS</a> code, we only need to change it in one place instead of searching and modifying multiple CSS rules. This keeps our code clean and organized and our work more flexible, especially in larger projects. 😎</p>
<h2 id="how-to-declare-css-variables">How to declare CSS variables<a class="heading-anchor" href="#how-to-declare-css-variables" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>CSS variables are defined using the <code>--</code> prefix and are typically declared in the <code>:root</code> pseudo-class. Below, we can see an example with two declared variables. The first one refers to the <code>--primary-color</code> (main color) of our project, while the second one concerns the <code>--text-font-size</code> (text’s font size).</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">:root</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#FFAB70">  --primary-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">  --text-font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">16</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>By defining variables in the <code>:root</code> pseudo-class, we make them accessible globally. To limit a variable’s scope, we can define it locally, within a specific selector, like a class or ID.</p>
<h2 id="how-to-use-css-variables">How to use CSS Variables<a class="heading-anchor" href="#how-to-use-css-variables" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We connect these two variables with our <a href="/how-to-work-with-css-syntax-the-correct-way/">CSS</a> styles, using the <code>var()</code> function. This step is crucial for ensuring our variables will work correctly. Simple but super useful! 🤓 ✨</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--primary-color</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--text-font-size</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h2 id="global-vs-local-scope">Global VS local scope<a class="heading-anchor" href="#global-vs-local-scope" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Now, let’s examine what we mean by global and local variables and how knowing the difference between these two types of variables can help us write more flexible, organized, and efficient code.</p>
<p>Global and local variables in CSS are essential for keeping styles easily managed. <strong>Global</strong> variables, defined in the <code>:root</code> selector, can be used in any CSS rule in the entire stylesheet, creating consistent layouts. In contrast, <strong>local</strong> variables, declared inside a class or ID selector, are scoped only to specific elements and their children, allowing for a more customized styling.</p>
<h3 id="understanding-variable-scope-with-an-example">Understanding variable scope with an example<a class="heading-anchor" href="#understanding-variable-scope-with-an-example" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong>Global type</strong></p>
<p>We create two global variables named <code>--primary-color</code> and <code>--secondary-color</code> that can be applied everywhere in the stylesheet.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* Anything inside :root is accessible globally */</span></span>
<span class="line"><span style="color:#B392F0">:root</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#FFAB70">  --primary-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">  --secondary-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">gray</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--primary-color</span><span style="color:#E1E4E8">); </span><span style="color:#6A737D">/* Accessible here */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">header</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--secondary-color</span><span style="color:#E1E4E8">); </span><span style="color:#6A737D">/* Accessible here as well */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><strong>Local type</strong></p>
<p>We create a local variable named <code>--header-bg</code> located inside the <code>.header</code> class. This specific variable can be applied only to the header and its descendants.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.header</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#FFAB70">  --header-bg</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">gray</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* Local variable */</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--header-bg</span><span style="color:#E1E4E8">); </span><span style="color:#6A737D">/* Accessible here */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.header</span><span style="color:#85E89D"> h1</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--header-bg</span><span style="color:#E1E4E8">); </span><span style="color:#6A737D">/* Accessible here */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.footer</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--header-bg</span><span style="color:#E1E4E8">); </span><span style="color:#6A737D">/* Not accessible here, will not work */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h2 id="advanced-css-variable-usage-example">Advanced CSS variable usage example<a class="heading-anchor" href="#advanced-css-variable-usage-example" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>For better understanding, I’ve prepared a more detailed example of CSS variables, showing how to apply them in a stylesheet and an image to help visualize the results. We intend to create three identical boxes side by side within a container, all styled using CSS variables.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"container"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"box"</span><span style="color:#E1E4E8">>Box 1&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"box"</span><span style="color:#E1E4E8">>Box 2&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"box"</span><span style="color:#E1E4E8">>Box 3&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* Container characteristics */</span></span>
<span class="line"><span style="color:#B392F0">:root</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#FFAB70">  --container-width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">600</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">  --container-height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">  --container-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#3ab7b7</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* A shade of teal */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/* Box characteristics */</span></span>
<span class="line"><span style="color:#B392F0">:root</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#FFAB70">  --box-width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">150</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">  --box-height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">150</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">  --box-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#fec0ca</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* A light shade of pink */</span></span>
<span class="line"><span style="color:#FFAB70">  --box-title-weight</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">800</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">  --box-title-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">25</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/* Box &#x26; Container border */</span></span>
<span class="line"><span style="color:#B392F0">:root</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#FFAB70">  --border-all-around</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">vh</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--container-width</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--container-height</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--container-color</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--border-all-around</span><span style="color:#E1E4E8">);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">space-around</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--box-width</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--box-height</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--box-color</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--box-title-size</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  font-weight</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--box-title-weight</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--border-all-around</span><span style="color:#E1E4E8">);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>In the following image, we can see the layout we just created.</p>
<p><img src="/css-variables-example.webp" alt="variables in css: A container with three identical boxes inside." style="max-width:65%" class="img-narrow"></p>
<p>If we want to modify the height of our boxes, we can easily do it by changing only the <code>--box-height</code> variable. For example, let’s change it from <code>150px</code> to <code>50px</code>.</p>
<p>In the image below, we can notice the difference.</p>
<p><img src="/css-variables-example-b.webp" alt="css variable: A container with three identical rectangles inside." style="max-width:65%" class="img-narrow"></p>
<p>Naming variables can be a really demanding task! Keep names simple, but ensure they are clear and meaningful.</p>
<h2 id="combining-multiple-css-variables">Combining multiple CSS variables<a class="heading-anchor" href="#combining-multiple-css-variables" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>When working with variables, we have the flexibility to add many values inside a CSS property. Let’s try to create a rainbow effect. We have to define variables for each rainbow color (<code>--color-red</code>, <code>--color-orange</code>, <code>--color-yellow</code>, <code>--color-green</code>, <code>--color-blue</code>, <code>--color-indigo</code>, <code>--color-violet</code>). Then, we’ll apply them in <code>linear-gradient</code> to <a href="/css-rainbow-text-how-to-make-astonishing-and-vibrant-fonts/" title="create the rainbow effect.">create the rainbow effect.</a> 🌈 🎉</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"box"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">:root</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#FFAB70">  --box-width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">800</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">  --box-height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">  --color-red</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#ff0000</span><span style="color:#E1E4E8">;     </span><span style="color:#6A737D">/* Red */</span></span>
<span class="line"><span style="color:#FFAB70">  --color-orange</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#ffa500</span><span style="color:#E1E4E8">;  </span><span style="color:#6A737D">/* Orange */</span></span>
<span class="line"><span style="color:#FFAB70">  --color-yellow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#ffff00</span><span style="color:#E1E4E8">;  </span><span style="color:#6A737D">/* Yellow */</span></span>
<span class="line"><span style="color:#FFAB70">  --color-green</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#008000</span><span style="color:#E1E4E8">;   </span><span style="color:#6A737D">/* Green */</span></span>
<span class="line"><span style="color:#FFAB70">  --color-blue</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#0000ff</span><span style="color:#E1E4E8">;    </span><span style="color:#6A737D">/* Blue */</span></span>
<span class="line"><span style="color:#FFAB70">  --color-indigo</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#4b0082</span><span style="color:#E1E4E8">;  </span><span style="color:#6A737D">/* Indigo */</span></span>
<span class="line"><span style="color:#FFAB70">  --color-violet</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#ee82ee</span><span style="color:#E1E4E8">;  </span><span style="color:#6A737D">/* Violet */</span></span>
<span class="line"><span style="color:#FFAB70">  --border-all-around</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--box-width</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--box-height</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#F97583">    to</span><span style="color:#79B8FF"> right</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--color-red</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#79B8FF">    var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--color-orange</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#79B8FF">    var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--color-yellow</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#79B8FF">    var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--color-green</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#79B8FF">    var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--color-blue</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#79B8FF">    var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--color-indigo</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#79B8FF">    var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--color-violet</span><span style="color:#E1E4E8">)</span></span>
<span class="line"><span style="color:#E1E4E8">  );</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--border-all-around</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>In the following image, we can see the effect! Nice, isn’t it!?</p>
<p><img src="/css-variables-combine-multiple-variables.webp" alt="CSS variable fallback: A rectangle with rainbow effect." style="max-width:55%" class="img-narrow"></p>
<h2 id="css-variable-fallback">CSS Variable Fallback<a class="heading-anchor" href="#css-variable-fallback" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We also have the flexibility to use fallbacks. But what is a fallback? 🤔
A fallback acts as a <strong>default value</strong> when:</p>
<ol>
<li>A variable is not defined, or</li>
<li>the value of a variable is not valid.</li>
</ol>
<p>Below are examples for each case to help you better understand it. 🧐
<strong>Case 1 –</strong> <strong>A variable is not defined</strong>
In the following example, the box will feature a dark gray background since <code>--bg-color</code> is not defined, resulting in the use of the fallback color.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"box"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">:root</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#FFAB70">  --box-width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">  --box-height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#6A737D">  /* --bg-color is not defined */</span></span>
<span class="line"><span style="color:#FFAB70">  --border-all-around</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--box-width</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--box-height</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--bg-color</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">darkgray</span><span style="color:#E1E4E8">); </span><span style="color:#6A737D">/* Fallback to darkgray */</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--border-all-around</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>The image below displays the results.</p>
<p><img src="/css-variables-with-fallbacks.webp" alt="css variables: A box with darkgray background color and a title with 40 pixels font size." style="max-width:31%" class="img-narrow"></p>
<p><strong>Case 2 – the value of a variable is not valid</strong>
This case is the one that trips people up. <code>--bg-color: pinky</code> is not a valid <strong>color</strong>, but it <em>is</em> a perfectly valid custom property — custom properties accept almost any value. So <code>var(--bg-color, darkgray)</code> still substitutes <code>pinky</code>, the fallback is <strong>skipped</strong>, and <code>background-color: pinky</code> then becomes invalid at computed-value time. The property falls back to its own initial value (<code>transparent</code> for <code>background-color</code>), <strong>not</strong> to <code>darkgray</code>.</p>
<p>🔖 In other words, the <code>var()</code> fallback only kicks in when the custom property is genuinely <strong>not defined</strong>, as in Case 1 above — never because its value turned out to be nonsense.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">:root</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#FFAB70">  --box-width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">  --box-height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">  --bg-color</span><span style="color:#E1E4E8">: pinky; </span><span style="color:#6A737D">/* --bg-color is invalid */</span></span>
<span class="line"><span style="color:#FFAB70">  --border-all-around</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--box-width</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--box-height</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--bg-color</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">darkgray</span><span style="color:#E1E4E8">); </span><span style="color:#6A737D">/* Fallback to darkgray */</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--border-all-around</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-variables-with-fallbacks.webp" alt="css variables: A box with darkgray background color and a title with 40 pixels font size." style="max-width:31%" class="img-narrow"></p>
<h2 id="frequently-asked-questions-">Frequently Asked Questions 🤔<a class="heading-anchor" href="#frequently-asked-questions-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><strong>Are spaces allowed in css variable names?​</strong></p>
<p>No, spaces are not allowed in CSS variable names. You can use hyphens (<code>-</code>), underscores (<code>_</code>), or camelCase instead.</p>
<p><strong>What are the valid characters for css variable names​?</strong></p>
<p>CSS variable names can include letters, numbers, underscores (<code>_</code>), hyphens (<code>-</code>), and must start with two dashes (<code>--</code>). They cannot contain spaces or special characters.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-work-with-css-syntax-the-correct-way/">How To Work With CSS Syntax: The Correct Way!</a></li>
<li><a href="/how-to-use-important-in-css/">How to Use !important in CSS</a></li>
<li><a href="/made-easy-with-reusable-code-why-classes-matter/">Made Easy With Reusable Code – Why Classes Matter</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Javascript Double Question Mark (??)</title>
      <link>https://littlecodingthings.com/how-to-use-a-javascript-double-question-mark/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-use-a-javascript-double-question-mark/</guid>
      <pubDate>Wed, 30 Oct 2024 15:15:00 GMT</pubDate>
      <description>The Javascript double question mark (??) is the nullish coalescing operator. How it works, how it differs from ||, and how to chain it safely.</description>
      <category>Thoughts &amp; Theory</category>
      <content:encoded><![CDATA[<p>The Javascript double question mark​ <code>??</code> is known as the <strong>nullish coalescing operator</strong>. It is a logical operator useful for checking whether a value is <code>undefined</code> or <code>null</code>, allowing us to provide a default value based on that check.</p>
<h2 id="how-does-the-javascript-nullish-coalescing-operator-work-">How does the Javascript <strong>nullish coalescing operator</strong> work? 🧁<a class="heading-anchor" href="#how-does-the-javascript-nullish-coalescing-operator-work-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Suppose we want to decide on a party treat based on whether a cupcake is available. If the cupcake is missing (i.e. it’s <code>undefined</code> or <code>null</code>), we’ll go with the brownie instead.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> partyTreat</span><span style="color:#F97583"> =</span><span style="color:#E1E4E8"> cupcake </span><span style="color:#F97583">??</span><span style="color:#E1E4E8"> brownie;</span></span></code></pre></div>
<p>The operator <code>??</code> in this snippet returns the right-hand operand – <code>brownie</code> – when the left one – <code>cupcake</code> – is <code>null</code> or <code>undefined</code>.</p>
<p><em>For those of you who immediately jumped, shouting that this is the same as the logical OR operator <code>||</code>, hang in there, I’ll get to you soon.</em></p>
<p>So, to make this crystal clear, let’s see the possible scenarios:</p>
<ul>
<li>If the cupcake is <code>null</code> or <code>undefined</code>, then our <code>partyTreat</code> will be a <code>brownie</code>.</li>
<li>If the cupcake is anything other than <code>null</code> or <code>undefined</code>, then our <code>partyTreat</code> will be the <code>cupcake</code>.
<em>I just hope they actually bring a real cupcake, not a truthy version of it…</em> 🥶 <em>(A cold programmer’s joke</em> 🤣_)_.</li>
</ul>
<figure><img src="/nullish-operator-flow.webp" alt="javascript double question mark​ flow diagram"><figcaption>Flowchart of the <code>??</code> operator: how JavaScript handles nullish values</figcaption></figure>
<h2 id="choosing-the-right-operator--or-">Choosing the Right Operator: <code>??</code> or <code>||</code>?<a class="heading-anchor" href="#choosing-the-right-operator--or-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>When it comes to handling default values in JavaScript, understanding the difference between the nullish coalescing operator (<code>??</code>) and the logical OR operator (<code>||</code>) is essential.</p>
<p>While both operators can provide fallback values, they behave differently with certain inputs.</p>
<p>The nullish coalescing operator returns the right-hand operand only if the left-hand operand is <code>null</code> or <code>undefined</code>, making it ideal for cases where you want to avoid falsy values like <code>0</code> or <code>''</code>.</p>
<p>In contrast, the logical OR operator returns the right-hand operand for <strong>any falsy value</strong>, including <code>0</code>, <code>NaN</code>, or an empty string.</p>
<p>By now, I am sure you understand that the nullish coalescing operator is a special case of a logical <code>||</code> operator, right?</p>
<p>So, they are different, but what would be a use case where one operator is preferable over the other?</p>
<p>Let’s assume we have a function that gets us a user’s score</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">// Logical operator || example</span></span>
<span class="line"><span style="color:#F97583">function</span><span style="color:#B392F0"> getUserScore</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">score</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#F97583">  const</span><span style="color:#79B8FF"> finalScore</span><span style="color:#F97583"> =</span><span style="color:#E1E4E8"> score </span><span style="color:#F97583">||</span><span style="color:#79B8FF"> 100</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">  return</span><span style="color:#E1E4E8"> finalScore;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">// Nullish coalescing operator ?? example</span></span>
<span class="line"><span style="color:#F97583">function</span><span style="color:#B392F0"> getUserScore</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">score</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#F97583">  const</span><span style="color:#79B8FF"> finalScore</span><span style="color:#F97583"> =</span><span style="color:#E1E4E8"> score </span><span style="color:#F97583">??</span><span style="color:#79B8FF"> 100</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">  return</span><span style="color:#E1E4E8"> finalScore;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>In the first case, if the score is <code>0</code>, which is falsy, then the <code>finalScore</code> ends up being assigned the default value of <code>100</code>, even though <code>0</code> might be a legitimate score.</p>
<p>In the second case, that won’t happen. <code>0</code> is neither <code>null</code> or <code>undefined</code>, so the <code>finalScore</code> will end being <code>0</code>, which is indeed a valid score.</p>
<p>The same trap shows up everywhere once you start looking for it, and always with values that are legitimately falsy:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> quantity</span><span style="color:#F97583"> =</span><span style="color:#E1E4E8"> cartItem.quantity </span><span style="color:#F97583">||</span><span style="color:#79B8FF"> 1</span><span style="color:#E1E4E8">;   </span><span style="color:#6A737D">// 0 items becomes 1 item 😬</span></span>
<span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> nickname</span><span style="color:#F97583"> =</span><span style="color:#E1E4E8"> user.nickname </span><span style="color:#F97583">||</span><span style="color:#9ECBFF"> "Anon"</span><span style="color:#E1E4E8">;  </span><span style="color:#6A737D">// "" becomes "Anon"</span></span>
<span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> isPublic</span><span style="color:#F97583"> =</span><span style="color:#E1E4E8"> settings.public </span><span style="color:#F97583">||</span><span style="color:#79B8FF"> true</span><span style="color:#E1E4E8">;  </span><span style="color:#6A737D">// false becomes true — always true, in fact</span></span></code></pre></div>
<p>Swap each <code>||</code> for <code>??</code> and all three behave the way the person who wrote them expected. My rule of thumb: <strong>if the value could sensibly be <code>0</code>, <code>""</code> or <code>false</code>, you want <code>??</code>.</strong> Otherwise the two are interchangeable and <code>||</code> is fine.</p>
<h2 id="the-syntaxerror-that-catches-everyone-">The SyntaxError that catches everyone 💥<a class="heading-anchor" href="#the-syntaxerror-that-catches-everyone-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Try to mix <code>??</code> with <code>&#x26;&#x26;</code> or <code>||</code> in the same expression and Javascript refuses to run the file at all:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> value</span><span style="color:#F97583"> =</span><span style="color:#E1E4E8"> a </span><span style="color:#F97583">||</span><span style="color:#E1E4E8"> b </span><span style="color:#F97583">??</span><span style="color:#9ECBFF"> "fallback"</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">// 🚫 SyntaxError</span></span></code></pre></div>
<p>Chrome puts it like this:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>SyntaxError: cannot use ?? unparenthesized within || and &#x26;&#x26; expressions</span></span></code></pre></div>
<p>This is not a bug you have to work around — it’s the language deliberately not guessing. <code>a || (b ?? c)</code> and <code>(a || b) ?? c</code> can return different values, and rather than pick a precedence you’d have to memorise, the spec makes you say which one you meant:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> value</span><span style="color:#F97583"> =</span><span style="color:#E1E4E8"> (a </span><span style="color:#F97583">||</span><span style="color:#E1E4E8"> b) </span><span style="color:#F97583">??</span><span style="color:#9ECBFF"> "fallback"</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">// ✅ fine</span></span>
<span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> other</span><span style="color:#F97583"> =</span><span style="color:#E1E4E8"> a </span><span style="color:#F97583">||</span><span style="color:#E1E4E8"> (b </span><span style="color:#F97583">??</span><span style="color:#9ECBFF"> "fallback"</span><span style="color:#E1E4E8">); </span><span style="color:#6A737D">// ✅ also fine, different result</span></span></code></pre></div>
<p>Add the parentheses. The error disappears and your intent is on the page for the next person reading it.</p>
<h2 id="-with-optional-chaining---the-combo-youll-actually-use-daily"><code>??</code> with optional chaining <code>?.</code> — the combo you’ll actually use daily<a class="heading-anchor" href="#-with-optional-chaining---the-combo-youll-actually-use-daily" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>On its own, <code>??</code> is a nice-to-have. Paired with optional chaining it becomes the standard way to read anything out of an API response:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> city</span><span style="color:#F97583"> =</span><span style="color:#E1E4E8"> response?.user?.address?.city </span><span style="color:#F97583">??</span><span style="color:#9ECBFF"> "Unknown"</span><span style="color:#E1E4E8">;</span></span></code></pre></div>
<p><code>?.</code> stops the moment it meets <code>null</code> or <code>undefined</code> and hands back <code>undefined</code> instead of throwing <code>TypeError: Cannot read properties of undefined</code>. <code>??</code> then catches that <code>undefined</code> and gives you a default. They’re designed as a pair — both treat <code>null</code> and <code>undefined</code> as the special cases and ignore everything else.</p>
<h2 id="the-lazy-cousin-">The lazy cousin: <code>??=</code><a class="heading-anchor" href="#the-lazy-cousin-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>If all you want is “set this if it isn’t already set”, there’s a dedicated operator for it — logical nullish assignment:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> config</span><span style="color:#F97583"> =</span><span style="color:#E1E4E8"> { retries: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8"> };</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">config.retries </span><span style="color:#F97583">??=</span><span style="color:#79B8FF"> 3</span><span style="color:#E1E4E8">;  </span><span style="color:#6A737D">// stays 0, because 0 isn't nullish</span></span>
<span class="line"><span style="color:#E1E4E8">config.timeout </span><span style="color:#F97583">??=</span><span style="color:#79B8FF"> 5000</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">// becomes 5000, because it was undefined</span></span></code></pre></div>
<p><code>config.timeout ??= 5000</code> is shorthand for <code>config.timeout = config.timeout ?? 5000</code>, and it’s handy for filling in defaults on an options object without clobbering what the caller passed you.</p>
<h2 id="-doesnt-evaluate-the-right-hand-side-unless-it-has-to"><code>??</code> doesn’t evaluate the right-hand side unless it has to<a class="heading-anchor" href="#-doesnt-evaluate-the-right-hand-side-unless-it-has-to" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Worth knowing, because it stops being trivia the moment the right-hand side is a function call:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> settings</span><span style="color:#F97583"> =</span><span style="color:#E1E4E8"> cached </span><span style="color:#F97583">??</span><span style="color:#B392F0"> loadSettingsFromDisk</span><span style="color:#E1E4E8">();</span></span></code></pre></div>
<p>If <code>cached</code> holds anything other than <code>null</code> or <code>undefined</code>, <code>loadSettingsFromDisk()</code> <strong>never runs</strong>. That’s called short-circuiting, and it’s the same behaviour <code>||</code> and <code>&#x26;&#x26;</code> have. It means you can safely put an expensive call on the right without paying for it every time — and it also means you shouldn’t put anything there with side effects you were counting on happening.</p>
<h2 id="frequently-asked-questions">Frequently Asked Questions<a class="heading-anchor" href="#frequently-asked-questions" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<h3 id="can-i-combine-the-nullish-coalescing-operator-with-other-operators-in-javascript">Can I combine the nullish coalescing operator with other operators in Javascript?<a class="heading-anchor" href="#can-i-combine-the-nullish-coalescing-operator-with-other-operators-in-javascript" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Yes, you can combine the Javascript nullish coalescing operator (<code>??</code>) with other operators to create more complex logic in your code. For example, by writing something like</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> result</span><span style="color:#F97583"> =</span><span style="color:#E1E4E8"> userInput </span><span style="color:#F97583">??</span><span style="color:#E1E4E8"> (isAdmin </span><span style="color:#F97583">&#x26;&#x26;</span><span style="color:#E1E4E8"> fallbackValue);</span></span></code></pre></div>
<p>we first evaluate if the user has entered a value (such as in a form). If <code>userInput</code> is <code>null</code> or <code>undefined</code>, we then evaluate whether the user is an admin.</p>
<p>If the user is an admin, <code>result</code> will be assigned the <code>fallbackValue</code>. If the user is not an admin, <code>result</code> will be <code>false</code> instead.</p>
<p>Note the parentheses around the <code>&#x26;&#x26;</code> part — as we saw above, they aren’t optional styling. Without them this line is a <code>SyntaxError</code>.</p>
<h3 id="how-can-i-chain-multiple-nullish-coalescing-operators-together">How can I chain multiple nullish coalescing operators together?<a class="heading-anchor" href="#how-can-i-chain-multiple-nullish-coalescing-operators-together" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>You can chain multiple nullish coalescing operators to evaluate different variables. For example, if you have several fallback options, the operator will return the first defined value it encounters:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> partyTreat</span><span style="color:#F97583"> =</span><span style="color:#E1E4E8"> cupcake </span><span style="color:#F97583">??</span><span style="color:#E1E4E8"> brownie </span><span style="color:#F97583">??</span><span style="color:#E1E4E8"> defaultTreat;</span></span></code></pre></div>
<p>Chaining <code>??</code> with itself is allowed and needs no parentheses — it’s only mixing it with <code>&#x26;&#x26;</code> or <code>||</code> that the parser objects to.</p>
<h3 id="is--the-same-as--in-javascript">Is <code>??</code> the same as <code>||</code> in Javascript?<a class="heading-anchor" href="#is--the-same-as--in-javascript" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>No, and this is the whole point of the operator. <code>||</code> falls back on <strong>any</strong> falsy value — <code>0</code>, <code>""</code>, <code>NaN</code>, <code>false</code>, <code>null</code>, <code>undefined</code>. <code>??</code> falls back on <strong>only</strong> <code>null</code> and <code>undefined</code>. Every other value, falsy or not, passes straight through.</p>
<h3 id="can-i-use--with-an-empty-string">Can I use <code>??</code> with an empty string?<a class="heading-anchor" href="#can-i-use--with-an-empty-string" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>You can, and it will keep the empty string. <code>"" ?? "fallback"</code> gives you <code>""</code>, because an empty string is a real value — just a falsy one. If you actually want to treat empty strings as missing, <code>??</code> is the wrong tool and <code>||</code> is the right one.</p>
<h3 id="what-browsers-support-the-double-question-mark">What browsers support the double question mark?<a class="heading-anchor" href="#what-browsers-support-the-double-question-mark" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>All of them. <code>??</code> landed in ES2020 and has been available across every major browser since July 2020, plus Node.js 14 and up. Unless you’re supporting Internet Explorer, you don’t need Babel or a polyfill for it — and a polyfill wouldn’t be possible anyway, since this is syntax rather than a function.</p>
<h3 id="does--work-in-typescript">Does <code>??</code> work in TypeScript?<a class="heading-anchor" href="#does--work-in-typescript" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Yes, and it plays especially nicely there. TypeScript narrows the type for you: if <code>score</code> is typed <code>number | undefined</code>, then <code>score ?? 100</code> is just <code>number</code>, and the “possibly undefined” complaint goes away. That makes it one of the tidiest fixes for a whole family of type errors — we listed a few more in our roundup of <a href="/most-common-typescript-errors-and-how-to-solve-them/">common TypeScript errors and how to fix them</a>.</p>
<p>Have you encountered any situations where one operator has significantly impacted your coding experience? If so, please share your examples in the comments below. We’d love to hear your insights!</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/javascript-array-methods-easy-examples-that-make-learning-a-blast/">Javascript Array Methods Explained</a></li>
<li><a href="/most-common-typescript-errors-and-how-to-solve-them/">Common TypeScript Errors and Fixes</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Best Job Sites for Web Developers</title>
      <link>https://littlecodingthings.com/best-job-sites-for-web-developers/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/best-job-sites-for-web-developers/</guid>
      <pubDate>Fri, 25 Oct 2024 09:58:00 GMT</pubDate>
      <description>The best job sites for web developers: remote boards, junior-friendly listings, freelance platforms, and the filters worth using on each one.</description>
      <category>Thoughts &amp; Theory</category>
      <content:encoded><![CDATA[<p>If you feel like you’re the only one struggling to <strong>find remote web developer jobs</strong>, let’s clear that up — <strong>you’re not alone</strong>! We’ve been in your shoes, and we might still be there right now. During our search, we realized that while some remote job sites are easy to find, others are buried deep (thanks, SEO), and some lists of remote job sites are hidden behind paywalls (we won’t name names).</p>
<p>To make things easier for everyone, we compiled a list of websites offering remote web developer jobs – and more – for anyone seeking remote work, <strong>regardless of the field</strong>.</p>
<p>We hope this helps you reach your goal!</p>
<p><em>If you manage a site that showcases remote developer jobs, we’d love to hear from you! Contact us to be added to our list. Reach out in the comments or visit our <a href="/contact-us/">Contact Us</a> page</em>.</p>
<h2 id="general-boards-for-remote-jobs">General boards for remote jobs<a class="heading-anchor" href="#general-boards-for-remote-jobs" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>General remote job boards are fantastic resources for discovering flexible work opportunities across various industries! These platforms showcase a diverse range of listings in fields like tech, marketing, and customer service, making it super easy to find and apply for remote positions that suit your style. Below, you’ll find a curated list of the best remote job boards to kickstart your remote career!</p>
<h3 id="eu-remote-jobs">EU Remote Jobs<a class="heading-anchor" href="#eu-remote-jobs" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><a href="https://euremotejobs.com/">EU Remote Jobs</a> is a frequently updated job board focused on remote opportunities within Europe. It’s a great resource for web developers, offering a wide variety of roles across frontend, backend, and full-stack development.</p>
<p>The site is easy to navigate, with clear categories and filters that help you quickly find positions that match your skills. <strong>New jobs are posted regularly</strong>—sometimes multiple times a day—so there’s always fresh opportunities to explore.</p>
<p>While the focus is on roles available to candidates based in Europe, many listings are open to international applicants as well. Whether you’re looking for a full-time position or freelance gigs, EU Remote Jobs is a solid place to find consistent, high-quality leads.</p>
<h3 id="we-work-remotely">We Work Remotely<a class="heading-anchor" href="#we-work-remotely" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong><a href="https://weworkremotely.com/">We Work Remotely</a></strong> is an excellent website for finding remote web developer jobs in tech, programming, design, and startups. It has a clean and easy-to-use layout, making it simple to browse different job categories. According to their site, “<em>For over a decade, WWR has been the number one destination to find and list incredible remote jobs. We’re home to the largest remote work community in the world with 4.5M visitors.</em>”</p>
<p>The site offers various jobs in programming, DevOps, design, product, customer support, and sales, clearly showing whether they are full-time or contract roles.</p>
<h3 id="gunio">Gun.io<a class="heading-anchor" href="#gunio" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong><a href="https://gun.io/" title="Gun.io">Gun.io</a></strong> is a platform designed for developers to connect with remote job opportunities while keeping 100% of their set rate. You start by creating a comprehensive profile highlighting your work history and preferred languages, which helps the team match you with roles that suit your skills.</p>
<p>Once your profile is complete, senior-level developers review it to ensure you’re a great fit for potential positions. Gun.io also provides support throughout your freelance journey, making it easier to focus on your work while ensuring you get paid what you deserve.</p>
<h3 id="4-day-week">4 day week<a class="heading-anchor" href="#4-day-week" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><a href="https://4dayweek.io"><strong>4 Day Week</strong></a> is a fantastic platform that promotes the four-day workweek and one you should not ignore! Here, you’ll find various remote job listings that embrace this innovative work model, allowing you to enjoy a better work-life balance while still achieving your career goals. Dive into a world where you can maximize productivity and enjoy your long weekends!</p>
<h3 id="remote-ok">Remote OK<a class="heading-anchor" href="#remote-ok" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong><a href="https://remoteok.com/" title="Remote OK">Remote OK</a></strong> is one of our top picks for finding remote jobs, offering roles for developers, designers, copywriters, and customer support representatives. Its beautiful user interface and simple, easy-to-use filters make it easy to find full-time remote work or remote part time jobs that fit your needs.</p>
<p>Trusted by major companies like Microsoft, IBM, and Amazon, the site also highlights that you can reach up to 1.9 million remote workers when hiring, making it a go-to resource for companies and job seekers alike. Whether you’re looking for tech or non-tech positions, Remote OK is a fantastic platform to explore!</p>
<h3 id="jobspresso">Jobspresso<a class="heading-anchor" href="#jobspresso" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><a href="https://jobspresso.co/" title="Jobspresso"><strong>Jobspresso</strong></a> is a trusted platform for finding remote jobs in fields like tech, marketing, customer support, and more. Each listing is carefully selected and reviewed to ensure top-quality job opportunities. From software development and AI roles to content writing and sales, Jobspresso offers various remote work options.</p>
<h3 id="remotive">Remotive<a class="heading-anchor" href="#remotive" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><a href="https://remotive.com/" title="Remotive"><strong>Remotive</strong></a> stands out as a remote jobs platform with a unique focus on community and flexibility. Created in 2014 by Rodolphe Dutel, Remotive has attracted over 500,000 followers across social networks.</p>
<p>It’s perfect for people who want to work remotely, whether you’re looking to ditch the commute, need a career-focused part-time role, or want a more flexible schedule. As their site says, Remotive is great for “anyone who wants to work remotely,” including parents seeking better work-life balance or professionals looking for alternative schedules.</p>
<h3 id="flexjobs">FlexJobs<a class="heading-anchor" href="#flexjobs" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><a href="https://www.flexjobs.com/"><strong>Flexjobs</strong></a> is a platform established in 2007 by Sara Sutton to simplify the search for reliable remote and flexible job options. After facing frustrations with misleading job ads, she created a site that features thoroughly vetted job listings in more than 50 industries, catering to everyone from entry-level applicants to executives.</p>
<p>With a commitment to quality, FlexJobs offers valuable resources and insights to help job seekers make informed decisions while providing a satisfaction guarantee to ensure a positive experience.</p>
<h3 id="jobrack">JobRack<a class="heading-anchor" href="#jobrack" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><a href="https://jobrack.eu/"><strong>JobRack</strong></a> is a valuable platform connecting skilled professionals in Eastern Europe and South Africa with remote job opportunities. It features a variety of roles across multiple industries, making it easier for job seekers to find positions that match their skills and preferences.</p>
<p>Whether you’re seeking full-time or part-time work, JobRack helps you connect with employers who appreciate talent and flexibility.</p>
<h3 id="justremote">JustRemote<a class="heading-anchor" href="#justremote" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong><a href="https://justremote.co/" title="JustRemote">JustRemote</a></strong> is a platform dedicated to helping individuals find authentic remote job opportunities across various fields. Their mission is to connect job seekers with reputable employers and make remote work accessible to everyone.</p>
<p>The site features carefully curated job listings in categories such as business, customer service, development, design, and marketing. While it primarily caters to U.S. residents, Just Remote also provides remote positions for applicants in numerous countries worldwide.</p>
<p>By simplifying the job search process, Just Remote empowers people to discover fulfilling remote work.</p>
<h3 id="working-nomads">Working Nomads<a class="heading-anchor" href="#working-nomads" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong><a href="https://www.workingnomads.com/jobs" title="Working nomads">Working nomads</a></strong> is a job board that connects remote workers with quality opportunities across various fields, including administration, development, marketing, and writing.</p>
<p>Their listings also include remote part-time jobs and contract positions from trusted companies. When this was written, their premium package provided access to over 30,000 remote jobs, making it easier for job seekers to find the right fit. Working Nomads helps seasoned professionals and newcomers discover their ideal remote role with daily or weekly job alerts.</p>
<h3 id="remoteco">Remote.co<a class="heading-anchor" href="#remoteco" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong><a href="https://remote.co/" title="Remote.co">Remote.co</a></strong> is a great platform for finding high-quality <strong>remote work</strong> opportunities in fields like tech, marketing, and customer support. Featured in Forbes and CNBC, it offers a wide range of job listings to help job seekers. With helpful resources and articles about remote work trends, Remote.co is a valuable tool for anyone looking for a remote job.</p>
<h3 id="arc">Arc<a class="heading-anchor" href="#arc" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong><a href="https://arc.dev/">Arc</a></strong> is a platform that connects top tech talent with remote opportunities, focusing on high-quality job matches for developers and other tech professionals to thrive in a remote work environment.</p>
<h3 id="pangian">Pangian<a class="heading-anchor" href="#pangian" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><a href="https://pangian.com"><strong>Pangian</strong></a> is a global remote job board that specializes in connecting job seekers with remote roles in various fields, promoting a diverse and inclusive work culture for professionals worldwide.</p>
<h3 id="honorable-mentions">Honorable mentions<a class="heading-anchor" href="#honorable-mentions" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Here are some honorable mentions—additional job boards that serve as exceptional resources for finding remote work opportunities.</p>
<h4 id="wellfound">Wellfound<a class="heading-anchor" href="#wellfound" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><strong><a href="https://wellfound.com">Wellfound</a></strong> – A platform for connecting startups with talented professionals seeking remote and flexible job opportunities.</p>
<h4 id="jobgether">Jobgether<a class="heading-anchor" href="#jobgether" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><strong><a href="https://jobgether.com">Jobgether</a></strong> – A user-friendly site that lists remote jobs across various industries, making it easy to find your next opportunity.</p>
<h4 id="himalayas">Himalayas<a class="heading-anchor" href="#himalayas" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><strong><a href="https://himalayas.app">Himalayas</a></strong> – A curated job board for remote jobs at innovative companies focusing on technology and startups.</p>
<h4 id="remote4me">Remote4me<a class="heading-anchor" href="#remote4me" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><strong><a href="https://remote4me.com">Remote4me</a></strong> – A platform that aggregates remote job listings from various sources to simplify your job search.</p>
<h4 id="remote-woman">Remote Woman<a class="heading-anchor" href="#remote-woman" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><a href="https://remotewoman.com"><strong>Remote Woman</strong></a> is job board specifically for women seeking remote work opportunities in tech and other fields.</p>
<h4 id="euro-remote-jobs">Euro Remote Jobs<a class="heading-anchor" href="#euro-remote-jobs" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><a href="https://euroremotejobs.com"><strong>Euro Remote Jobs</strong></a> is a job board dedicated to remote jobs in Europe, featuring a wide range of positions from various companies.</p>
<h4 id="lemonio">Lemon.io<a class="heading-anchor" href="#lemonio" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><a href="https://lemon.io"><strong>Lemon.io</strong></a> is a platform that connects companies with skilled developers, focusing on providing high-quality remote tech talent while ensuring a smooth hiring process.</p>
<h4 id="ruby-on-remote">Ruby on Remote<a class="heading-anchor" href="#ruby-on-remote" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><a href="https://rubyonremote.com"><strong>Ruby on Remote</strong></a> is a dedicated job board for Ruby developers featuring a curated list of remote job opportunities specifically tailored for professionals with Ruby skills across various industries.</p>
<blockquote>
<p>Don’t give up. The right <strong>remote job</strong> is out there!</p>
</blockquote>
<h2 id="remote-junior-developer-jobs">Remote junior developer jobs<a class="heading-anchor" href="#remote-junior-developer-jobs" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Yes! You saw that right! This section is for remote jobs for juniors. So many people are trying to get remote jobs as juniors and struggle to find them. Well, the market has listened… well, actually some developers did, but hopefully the market heard your voices too! As I was saying…some developers have created job boards just for junior developers. Here you go! Enjoy the ride, newcomers!</p>
<h3 id="remote-rocketship">Remote Rocketship<a class="heading-anchor" href="#remote-rocketship" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong><a href="https://www.remoterocketship.com/entry-level-jobs">Remote Rocketship</a></strong> offers a collection of entry-level remote jobs across various fields, making it easier for newcomers to kickstart their careers.</p>
<h3 id="entry-level-remote-job">Entry Level Remote Job<a class="heading-anchor" href="#entry-level-remote-job" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong><a href="https://entrylevelremotejob.com/">Entry Level Remote Job</a></strong> is a dedicated platform that connects job seekers with remote opportunities specifically designed for those starting their careers.</p>
<h2 id="best-freelancer-websites">Best freelancer websites<a class="heading-anchor" href="#best-freelancer-websites" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>If you don’t want to focus all your energy on one client and prefer to find gigs or part-time projects, this section is for you. Below, you’ll find a list of platforms where you can discover multiple freelance opportunities.</p>
<h3 id="toptal">Toptal<a class="heading-anchor" href="#toptal" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong><a href="https://www.toptal.com/" title="Toptal">Toptal</a></strong> is a freelance platform that connects top professionals with companies needing remote talent. It’s famous for its tough selection process, accepting only the top 3% of applicants, so it’s not for the faint-hearted.</p>
<p>With opportunities in software development, design, and finance, Toptal is trusted by companies like Airbnb and Shopify. It’s a great option for freelancers seeking high-quality projects and businesses looking for the best talent.</p>
<h3 id="upwork">Upwork<a class="heading-anchor" href="#upwork" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong><a href="https://www.upwork.com/" title="Upwork">Upwork</a></strong> is one of the largest and most popular freelance marketplaces, offering a wide variety of remote job opportunities in fields like web development, design, writing, and marketing.</p>
<p>Freelancers can create profiles, bid on projects, and connect with clients from around the world. Upwork has remote jobs for all experience levels, from beginners to experts, making it an excellent platform for anyone who wants to start or grow their freelance career.</p>
<h3 id="fiverr">Fiverr<a class="heading-anchor" href="#fiverr" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong><a href="https://www.fiverr.com/" title="Fiverr">Fiverr</a></strong> is a popular freelance platform where professionals can offer services starting at $5, covering everything from graphic design and writing to voiceovers and web development.</p>
<p>Freelancers create “gigs”, and clients can easily browse and purchase services. With its straightforward interface and wide range of categories, Fiverr is an excellent choice for freelancers seeking specialized services and clients needing quick, affordable solutions.</p>
<h3 id="freelancer">Freelancer<a class="heading-anchor" href="#freelancer" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong><a href="https://www.freelancer.com/" title="Freelancer">Freelancer</a></strong> is a global freelance marketplace where businesses can post projects, and freelancers can bid to get hired. Covering a wide range of categories like software development, writing, accounting, design, translation, data entry, and much more, it’s a platform suitable for all skill levels.</p>
<p>With contests and time-tracking features, Freelancer helps beginners and experienced professionals find remote work opportunities quickly and efficiently.</p>
<h3 id="peopleperhour">PeoplePerHour<a class="heading-anchor" href="#peopleperhour" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong><a href="https://www.peopleperhour.com/" title="PeoplePerHour">PeoplePerHour</a></strong> connects freelancers with clients seeking specific skills, particularly in tech, marketing, and design. Freelancers can apply for posted jobs or offer services in their own “Hourlies” — pre-packaged services at set prices.</p>
<p>Known for its ease of use and quality listings, <strong>PeoplePerHour</strong> is a solid choice for freelancers wanting flexible projects and clients looking for skilled professionals.</p>
<h3 id="turing">Turing<a class="heading-anchor" href="#turing" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong><a href="https://www.turing.com/" title="Turing">Turing</a></strong> is a platform designed to simplify the hiring process for global talent. Founded by Jonathan Siddharth and Vijay Krishnan, who faced challenges in sourcing high-quality talent in their previous venture, Turing combines comprehensive candidate profiles with a strict vetting process.</p>
<p>Launched in 2018, Turing has become a leading provider of AI-driven solutions, matching companies with skilled professionals for product development and engineering projects. With its innovative approach, Turing has earned the trust of numerous companies for their AI deployment, large language model training, and custom engineering requirements.</p>
<h3 id="x-team">X-Team<a class="heading-anchor" href="#x-team" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong><a href="https://x-team.com/" title="X-Team">X-Team</a></strong> is a unique platform that connects companies with top developers from around the world. Founded on the belief that work should be fulfilling, X-Team empowers its developers by providing them with opportunities to work remotely while continuously honing their skills. With a rigorous selection process, X-Team ensures that only the best talent joins its ranks, allowing companies to tap into a diverse pool of skilled professionals. Their emphasis on team culture, support, and ongoing learning has made X-Team a preferred choice for businesses looking for dedicated developers to drive their projects forward.</p>
<h3 id="codeable">Codeable<a class="heading-anchor" href="#codeable" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong><a href="https://codeable.io">Codeable</a></strong> is a platform that connects clients with expert WordPress developers. With a focus on quality, Codeable vets its developers to ensure only top-tier talent is available for hire.</p>
<h2 id="job-boards-with-remote-filters">Job boards with remote filters<a class="heading-anchor" href="#job-boards-with-remote-filters" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>While not solely focused on remote work, popular job boards like <strong>Indeed</strong> and <strong>LinkedIn</strong> offer filters to help you find flexible remote work opportunities. Here are a few top sites where you can search for remote positions:</p>
<h3 id="linkedin">Linkedin<a class="heading-anchor" href="#linkedin" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><a href="https://www.linkedin.com/" title="Linkedin"><strong>Linkedin</strong></a> is a professional networking site with a filter for remote web developer jobs, allowing you to search within your field.</p>
<h3 id="glassdoor">Glassdoor<a class="heading-anchor" href="#glassdoor" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><a href="https://www.glassdoor.com/index.htm" title="Glassdoor"><strong>Glassdoor</strong></a> although primarily known for company reviews, it also provides options to filter remote job listings.</p>
<h3 id="monstercom">Monster.com<a class="heading-anchor" href="#monstercom" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><a href="https://www.monster.com"><strong>Monster.com</strong></a> – A well-known job board that features filters to help you find remote job opportunities.</p>
<p>We’ll continue to update this post whenever we discover new remote job websites, so be sure to <strong>bookmark this page</strong> for future reference!</p>
<h2 id="how-to-get-the-most-out-of-remote-job-boards">How to get the most out of remote job boards<a class="heading-anchor" href="#how-to-get-the-most-out-of-remote-job-boards" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Finding remote web developer jobs isn’t just about knowing where to look — it’s also about <em>how</em> you use these platforms. Before applying, make sure your resume and portfolio clearly highlight your remote experience, communication skills, and ability to work independently. Many companies hiring remotely care just as much about collaboration and reliability as they do about technical skills.</p>
<p>If you’re a <strong>junior developer</strong>, focus on job boards that explicitly mention entry-level or junior-friendly roles, and don’t be discouraged by listings that ask for “experience” — many are flexible if you can show strong fundamentals and real projects. And if the current noise has you wondering whether these roles are disappearing altogether, we argued the opposite in <a href="/will-ai-replace-junior-developers-i-think-were-asking-the-wrong-question/">will AI replace junior developers?</a></p>
<p>For <strong>freelancers</strong>, platforms like Toptal, Upwork, and Codeable reward specialization. Niching down (for example, “React performance optimization” or “WordPress security”) can significantly improve your chances of landing consistent remote work.</p>
<p>Remote work opportunities change fast, so checking these job boards regularly, setting up alerts, and staying active will dramatically increase your chances. This list is updated often to help you stay ahead of the curve.</p>
<h2 id="common-mistakes-when-applying-for-remote-web-developer-jobs">Common mistakes when applying for remote web developer jobs<a class="heading-anchor" href="#common-mistakes-when-applying-for-remote-web-developer-jobs" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>One of the biggest mistakes developers make when applying for remote roles is sending the same generic application everywhere. Remote-first companies often receive hundreds of applications, so small details matter. Tailor your resume to highlight relevant skills, real-world projects, and tools mentioned in the job description.</p>
<p>Another common issue is ignoring time zone and availability requirements. Even fully remote teams often expect some overlap in working hours, so make sure you’re clear about your location and schedule upfront to avoid wasted applications.</p>
<p>Finally, don’t underestimate the importance of your online presence. A well-maintained GitHub profile, live demos, or case studies can make a big difference — especially for junior developers or career switchers who may not have extensive work experience yet.</p>
<p>Happy job hunting! 🚀</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/am-i-too-old-to-learn-coding/">Am I Too Old to Learn Coding?</a></li>
<li><a href="/will-ai-replace-junior-developers-i-think-were-asking-the-wrong-question/">Will AI Replace Junior Developers?</a></li>
<li><a href="/what-is-scrum-101-guide-for-new-developers/">What is Scrum? 101 Guide For New Developers</a> — the vocabulary your first job assumes</li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>HTML Lists: ol, ul and dl Explained</title>
      <link>https://littlecodingthings.com/html-lists-made-easy-ordered-unordered-and-special-lists/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/html-lists-made-easy-ordered-unordered-and-special-lists/</guid>
      <pubDate>Wed, 23 Oct 2024 09:10:00 GMT</pubDate>
      <description>Ordered, unordered and description lists in HTML — nesting them, swapping the marker for an image or emoji, and going horizontal.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Is our life surrounded by lists ✔ or do we live in a perfect world where taking care of things is unnecessary? Are we able to deal with our problems without organizing them? Are we ready to work on something difficult or, even worse, build something from scratch without using a list of steps? Do lists improve our life balance and make us more methodical? In this post, we will see how to create HTML lists and make our work and, by extension, our lives easier. 😃 ✨</p>
<p>Do lists improve our life balance and make us more methodical?</p>
<h2 id="html-lists">HTML Lists<a class="heading-anchor" href="#html-lists" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>A list is defined as <strong>a</strong> <strong>group of matching items</strong>. By default, the list’s direction is vertical. There are three categories of <a href="/most-useful-html-elements-for-maximizing-better-results/">HTML</a> lists: ordered, unordered, and description lists.</p>
<h3 id="ordered-list">Ordered list<a class="heading-anchor" href="#ordered-list" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>An <strong>ordered</strong> list, by default, uses numbers as markers for each list item. We have the ability to manipulate the <code>list-style-type</code> property and select the desired style.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">ol</span><span style="color:#B392F0"> style</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"list-style-type:decimal;"</span><span style="color:#E1E4E8">> </span><span style="color:#6A737D">&#x3C;!-- decimal is for example, you can choose any list-style-type you prefer --></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>France&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Germany&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Poland&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">ol</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p>Below, you can see the types of the ordered list.</p>
<p><img src="/ordered-list.webp" alt="Examples of ordered lists" style="max-width:69%" class="img-narrow"></p>
<h3 id="unordered-list">Unordered list<a class="heading-anchor" href="#unordered-list" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>An <strong>unordered</strong> list, by default, uses a small filled circle as its marker (<code>list-style-type: disc;</code>). We can manipulate the <code>list-style-type</code> property and choose the willing style.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">ul</span><span style="color:#B392F0"> style</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"list-style-type:disc;"</span><span style="color:#E1E4E8">> </span><span style="color:#6A737D">&#x3C;!-- disc is for example, you can choose any list-style-type you prefer --></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Greece&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Italy&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Spain&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">ul</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/unordered-list-1.webp" alt="Examples of unordered lists" style="max-width:69%" class="img-narrow"></p>
<h4 id="combination-of-lists">💡<strong>Combination of lists</strong><a class="heading-anchor" href="#combination-of-lists" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p>Combine <strong>ordered</strong> <strong>&#x26;</strong> <strong>unordered</strong> lists and make them more <strong><em>POWERFUL</em></strong>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">ol</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>France</span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">ul</span><span style="color:#B392F0"> style</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"list-style-type:circle"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Paris</span></span>
<span class="line"><span style="color:#E1E4E8">        &#x3C;</span><span style="color:#85E89D">ul</span><span style="color:#B392F0"> style</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"list-style-type:square"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">          &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Eiffel Tower&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">          &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Louvre Museum&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">        &#x3C;/</span><span style="color:#85E89D">ul</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Lyon&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Marseille&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;/</span><span style="color:#85E89D">ul</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Germany&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Poland</span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">ol</span><span style="color:#B392F0"> style</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"list-style-type:lower-alpha"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Krakow&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Gdansk&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;/</span><span style="color:#85E89D">ol</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Belgium</span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">ol</span><span style="color:#B392F0"> style</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"list-style-type:decimal-leading-zero"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Brussels&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Bruges</span></span>
<span class="line"><span style="color:#E1E4E8">        &#x3C;</span><span style="color:#85E89D">ul</span><span style="color:#B392F0"> style</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"list-style-type:square"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">          &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Canals&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">          &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>City Hall&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">        &#x3C;/</span><span style="color:#85E89D">ul</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Lier&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;/</span><span style="color:#85E89D">ol</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">ol</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/list-with-combinations.webp" alt="Example of combinations of unordered and ordered lists" style="max-width:28%" class="img-narrow"></p>
<h3 id="description-list">Description list<a class="heading-anchor" href="#description-list" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Description lists are used when we want to show terms followed by their descriptions. It consists of <code>&#x3C;dl></code> tag (a description list) which requires two elements. The first one is a <code>&#x3C;dt></code> tag, the description term element, and the second one is the <code>&#x3C;dd></code> tag, the description element.
Keep in mind, that the <code>&#x3C;dd></code> element has some <code>margin-left</code> set by default.</p>
<p>📝 We must pay attention to the <strong>correct order</strong>, as <code>&#x3C;dt></code> tag always comes before <code>&#x3C;dd></code> tag.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">dl</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">dt</span><span style="color:#E1E4E8">>&#x3C;</span><span style="color:#85E89D">b</span><span style="color:#E1E4E8">>HTML&#x3C;/</span><span style="color:#85E89D">b</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">dt</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">dd</span><span style="color:#E1E4E8">>The HyperText Markup Language or HTML is the standard markup language for documents designed to be displayed in a web browser.&#x3C;/</span><span style="color:#85E89D">dd</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">dt</span><span style="color:#E1E4E8">>&#x3C;</span><span style="color:#85E89D">b</span><span style="color:#E1E4E8">>CSS&#x3C;/</span><span style="color:#85E89D">b</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">dt</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">dd</span><span style="color:#E1E4E8">>Cascading Style Sheets is a style sheet language used for describing the presentation of a document written in a markup language such as HTML or XML.&#x3C;/</span><span style="color:#85E89D">dd</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">dl</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/discription-list.webp" alt="Example of a description list" style="max-width:49%" class="img-narrow"></p>
<h3 id="-special-lists">💎 Special lists<a class="heading-anchor" href="#-special-lists" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<h4 id="image-list">Image list<a class="heading-anchor" href="#image-list" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p>In HTML lists, instead of marks, we can also use an image. Although it is really demanding, if we choose the appropriate image and do all the necessary modifications we can achieve a really amazing result. We have to replace the marks and create a list by adding the image’s <code>URL</code> to the <code>list-style-image</code> property.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">ul</span></span>
<span class="line"><span style="color:#B392F0"> style</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"list-style-image:url('https://images.unsplash.com/photo-1464820453369-31d2c0b651af?ixlib=rb-4.0.3&#x26;ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&#x26;auto=format&#x26;fit=crop&#x26;w=20&#x26;q=80');"</span></span>
<span class="line"><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Choose&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>the&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>appropriate&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>image :-)&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">ul</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/image-list.webp" alt="Example of a list with images" style="max-width:25%" class="img-narrow"></p>
<h4 id="list-with-one-emoticon">List with one emoticon<a class="heading-anchor" href="#list-with-one-emoticon" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p>We can also make HTML lists using the same emoticon by adding it to the <code>content</code> property.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">ol</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"emoticon-face"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>HTML&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>CSS&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>JAVASCRIPT&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">ol</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.emoticon-face</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  list-style</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">none</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">  li</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">    content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"🥰"</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    margin-right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#85E89D"> li</span><span style="color:#B392F0">:not</span><span style="color:#E1E4E8">(</span><span style="color:#B392F0">:last-child</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">    margin-bottom</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">/* end of emoticon-face */</span></span></code></pre></div>
<p><img src="/emoticon-list-with-same-emoticon.webp" alt="Example of an emoticons list" style="max-width:35%" class="img-narrow"></p>
<h4 id="list-with-different-emoticons">List with different emoticons<a class="heading-anchor" href="#list-with-different-emoticons" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p>We can use more than one emoticon by setting the <a href="/what-you-need-to-know-about-css-nth-child-selector-a-practical-guide/"><code>nth-child</code></a> pseudo-class and thus utilize different emoticons to <code>content</code> property each time.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">ul</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"emoticons-weather"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Sunny days&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Cloudy days&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Rainy days&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Snowy days&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">ul</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.emoticons-weather</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  list-style</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">none</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"><span style="color:#6A737D">/* We use :not(:last-child) selector because we want to add distance</span></span>
<span class="line"><span style="color:#6A737D">*  between all list items apart from the last one.</span></span>
<span class="line"><span style="color:#6A737D">*/</span></span>
<span class="line"><span style="color:#85E89D">li</span><span style="color:#B392F0">:not</span><span style="color:#E1E4E8">(</span><span style="color:#B392F0">:last-child</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  margin-bottom</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">4</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"><span style="color:#B392F0">.emoticons-weather</span><span style="color:#85E89D"> li</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    margin-right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">8</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:nth-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">)</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">    content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"🌞"</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:nth-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">2</span><span style="color:#E1E4E8">)</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">    content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"🌥"</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:nth-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">3</span><span style="color:#E1E4E8">)</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">    content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"☔"</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:nth-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">4</span><span style="color:#E1E4E8">)</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">    content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"⛄"</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">/* end of emoticons-weather li */</span></span></code></pre></div>
<p><img src="/emoticon-list-with-different-emoticons.webp" alt="Example of a list with different weather emoticons" style="max-width:35%" class="img-narrow"></p>
<p>🤗 I chose these lovely emoticons above for my examples, but you can <a href="https://www.freecodecamp.org/news/all-emojis-emoji-list-for-copy-and-paste/" title="select any emoticon you want">select any emoticon you want</a>! All you have to do is copy and paste them into the <code>content</code> property.</p>
<h2 id="horizontal-list">Horizontal list<a class="heading-anchor" href="#horizontal-list" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>By default, HTML lists are vertical &#x26; list items have <code>display: block;</code>. Because of their blocked display, each list item takes up the available screen width and starts in a new line. In order to use them in a horizontal direction, we must implement them by changing the list-style property to none <code>list-style: none;</code> and setting the display property to inline-block <code>display: inline-block;</code>. This way, they occupy the same space as their size, and we can put them, side by side, on the same line.</p>
<p>💡 It is common to use horizontal lists in order to make navbars.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">ul</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"horizontal-direction"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Home&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Our work&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>About us&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Contact&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">ul</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.horizontal-direction</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  max-width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">350</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  list-style</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">none</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#85E89D"> li</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inline-block</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#85E89D"> li</span><span style="color:#B392F0">:not</span><span style="color:#E1E4E8">(</span><span style="color:#B392F0">:last-child</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">    padding-right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">/* end of horizontal-direction */</span></span></code></pre></div>
<p><img src="/horizontal-list.webp" alt="Example of a horizontal list" style="max-width:56%" class="img-narrow"></p>
<p><img src="/custom-list.webp" alt="A cloud with a list of three items, each with a different bullet shape (heart, smiling face, star). The list reads: &#x22;1. Love with all your heart, 2. Smile no matter what, 3. Shine all the way.&#x22;" style="max-width:28%" class="img-narrow"></p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/most-useful-html-elements-for-maximizing-better-results/">The Most Useful HTML Elements</a></li>
<li><a href="/html-formatting-elements-made-simple-with-easy-and-practical-examples/">HTML Text Formatting Elements</a></li>
<li><a href="/learn-how-to-select-only-the-css-first-child/">Learn How to Select Only the CSS First Child</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Is CSS Case-Sensitive?</title>
      <link>https://littlecodingthings.com/capitalizing-css-property-values-what-is-the-right-way/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/capitalizing-css-property-values-what-is-the-right-way/</guid>
      <pubDate>Fri, 18 Oct 2024 09:05:00 GMT</pubDate>
      <description>Property names and keyword values in CSS are case-insensitive, so GREEN and green are the same. Class and id names are not — here is why.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>When capitalizing CSS property values, a key advantage is that CSS property names and keyword values are not case-sensitive. 🪶 (Class and id names in your selectors are the exception — those <strong>are</strong> case-sensitive.) This means that no matter how you choose to capitalize your CSS values, either by using different letter cases, including lowercase, uppercase, or a combination of both, the browser will still understand all of them correctly.</p>
<blockquote>
<p>The letter case used for color names in CSS does not impact how the browser interprets them</p>
</blockquote>
<p>Here are some examples of this, using color properties:</p>
<ul>
<li><strong>Lowercase</strong>: You may use all lowercase letters for color names. For example, “red”, “green”, “blue”, “orange”, and “yellow” are all valid.</li>
</ul>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.element</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<ul>
<li><strong>Uppercase</strong>: Uppercase letters are also valid, so “RED”, “GREEN”, “BLUE”, “ORANGE” and “YELLOW” will be just fine.</li>
</ul>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.element</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">GREEN</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><strong>Combinations of both</strong>: You have the flexibility to use both uppercase and lowercase letters in color names. This lets you style color names according to your coding preferences or highlight specific parts of the color name.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.element</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  border-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">LightGreen</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><strong>No Impact on Interpretation</strong>: Regardless of the letter case used, the browser will correctly understand and apply the specified color. The choice of letter case is purely a matter of personal or coding style preference.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.element</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">LiGhtgreeN</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>To sum it up, the letter case used for color names in CSS does not impact how the browser interprets them. 😃</p>
<p>Whether you opt for all lowercase, uppercase, or a combination of both, it’s up to your coding style or your development team’s coding standards. The important thing to remember is that the browser will understand and apply the specified color, regardless of the letter casing used.</p>
<p>That said, developers still often follow conventions. While browsers are forgiving of capitalization, one common standard practice is to use all lowercase for CSS property values. The same goes for <a href="/what-you-need-to-know-about-css-color-methods/">color names, hex codes and the rest of the color methods</a>.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-work-with-css-syntax-the-correct-way/">How To Work With CSS Syntax: The Correct Way!</a></li>
<li><a href="/gray-vs-grey-in-css-what-is-the-right-choice/">Gray vs Grey in CSS. What Is the Right Choice?</a></li>
<li><a href="/what-you-need-to-know-about-css-color-methods/">What You Need to Know About CSS Color Methods</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Integration vs Unit Tests: How to Choose</title>
      <link>https://littlecodingthings.com/integration-and-unit-tests-how-to-choose-the-right-one/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/integration-and-unit-tests-how-to-choose-the-right-one/</guid>
      <pubDate>Mon, 14 Oct 2024 09:30:00 GMT</pubDate>
      <description>What separates a unit test from an integration test, when each one is worth writing, and why mocking an external provider can give you false confidence.</description>
      <category>Setup &amp; Tools</category>
      <content:encoded><![CDATA[<p>If you are making your first steps in code testing, I want to start by congratulating you on walking that path! 🥳 This is a crucial decision and a great addition to your skill set. Before writing some tests, it’s vital to grasp the difference between two fundamental testing methods regarding integration and unit tests. In this post, we’ll dive into these testing types and explore their differences.</p>
<p>If you’re new to testing in general and want a broader overview before comparing testing types, <a href="/javascript-testing-for-beginners-a-simple-practical-introduction/">this introduction to Javascript testing for beginners</a> explains the core ideas in simple terms.</p>
<h2 id="testing-scenario-for-our-comparison">Testing scenario for our comparison<a class="heading-anchor" href="#testing-scenario-for-our-comparison" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>To understand the difference between integration and unit tests, let’s use an example of a function that calculates a user’s daily budget. We’ll name our function <code>determineUserBudget</code> and have the following flow:</p>
<ul>
<li>Takes a <code>userId</code> parameter to perform a search for a user.</li>
<li>Uses the provided  <code>userId</code> to search for the corresponding user in the <code>Users</code> table of our database.</li>
<li>If we call the function without passing a <code>userId</code>, it will throw an <code>Error</code> to indicate the missing parameter.</li>
<li>Furthermore, if no user is found, it will also throw an <code>Error</code> to signify the absence of a matching user.</li>
<li>However, if a user is found, it will use the user’s info and call our <code>Budget</code> service.</li>
<li>Subsequently, it will perform budget calculations based on the retrieved data.</li>
<li>Lastly, the function will return the budget as its final output.</li>
</ul>
<p>Let’s see what was just described through the following diagram so that it is easier to understand the function flow:</p>
<p><img src="/integration-unit-test-diagram-start.webp" alt="Difference between unit tests and integration tests: Flow diagram showing an example of the possible flows of a function that fetches a user and calculates their budget." style="max-width:83%" class="img-narrow"></p>
<p>To differentiate between the internal workings of the function and the external connections that need to be made, I am using a dotted border.</p>
<p>Now that we have our testing scenario, let’s see what’s the difference between these two types of testing, and how we would test our function in each method.</p>
<p>(<em>We won’t be writing any code in this post</em>).</p>
<h2 id="what-is-a-unit-test">What is a unit test?<a class="heading-anchor" href="#what-is-a-unit-test" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>When writing a unit test we want to isolate the part of the code we are testing from the rest of the system.</p>
<blockquote>
<p>This Is The Main Characteristic Of Unit Tests, Isolation!</p>
</blockquote>
<p>Consider it as if you are focusing all your energy <strong>only</strong> on what’s happening <strong>inside</strong> a function without any regard for the function’s calls/interactions with the database, services, or any other invoked functions.</p>
<p>In our scenario, to unit test <code>determineUserBudget</code> , we’ll ignore the call to our database and the call to the money service. Our focus will solely be on testing if all potential function flows (<em>see green arrows</em>) are followed as expected.</p>
<p><img src="/integration-unit-test-diagram-isolated.webp" alt="Integration and unit tests: Flow diagram showing all possible flows of a function that fetches a user and calculates their budget in isolation to external calls" style="max-width:83%" class="img-narrow"></p>
<p>So, for the unit testing methodology, here are some testing scenarios we could write regardless of the testing suite, to ensure comprehensive coverage of your function:</p>
<ul>
<li>it should throw an error if no userId is passed.</li>
<li>it should make a call to the database if the correct userId is passed.</li>
<li>it should throw an error if no user is found.</li>
<li>it should contact the Money service if a user is found.</li>
<li>it should return the calculated user’s budget</li>
</ul>
<p>However, what about the two calls in the database and service? How can we isolate our function from these calls?</p>
<p>When writing unit tests we need to substitute the external calls with mock functions so that we can simulate the call without actually making it.</p>
<p><strong><strong>A</strong> mock</strong> function is a function that replaces the behavior of an actual function during the testing.</p>
<p>To create an effective mock function, it’s essential to understand the response type and structure of the function being replaced. Understanding the response type and structure allows us to mimic the behavior of the original function and ensure that the mocked function provides the expected data during our testing.</p>
<p>After replacing the external calls with mocked ones we can safely focus on testing the function without any interactions with the external environment. This isolation allows us to concentrate on the internal workings of the function and successfully unit test it.</p>
<h2 id="what-is-an-integration-test">What is an integration test?<a class="heading-anchor" href="#what-is-an-integration-test" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>In contrast with unit tests, the keyword on integration tests is not isolation but interaction. Through integration tests, we are testing how different parts of our code interact with each other.</p>
<blockquote>
<p><em>The Key Word On Integration Tests Is Interaction!</em></p>
</blockquote>
<p>In our testing scenario, we will test much more! We will test our function’s results, including the interaction with the database and the correctness of the budget returned. <strong>The difference with the unit test is that we will pass “real” data and receive back “real” data to test.</strong></p>
<p>In the integration testing methodology, the following testing scenarios could be some examples you could use based on our use case:</p>
<ul>
<li>it should return X budget when a user is approved.</li>
<li>it should return Y budget when user is new.</li>
<li>it should follow Z budget calculation methodology when user is pending confirmation.</li>
<li>it should calculate the budget correctly for a user with a positive income and no expenses.</li>
</ul>
<p>As you can see, the nature of our tests changed; we shifted our focus from testing the internal flow, to verifying our function produces the desired results, data, and budget.</p>
<p>Writing integration tests can be challenging because they require proper data preparation before executing the actual test. It’s quite common to spend more time during the initial steps to understand the required data and set up the necessary test environment before successfully executing the test.</p>
<h2 id="trusting-external-package-providers">Trusting external package providers<a class="heading-anchor" href="#trusting-external-package-providers" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>See that I didn’t mention testing the connection with the service? Well even if these are integration tests, they still don’t test connections with external services/providers.</p>
<p>Through integration tests, we are testing the way our functions interact with each other, not how they interact with external service functions. These functions are expected to have been tested by the service provider.</p>
<p>So, if for example you like using <a href="https://lodash.com/">lodash</a> and have used <code>isEmpty</code> in your function, you should not write unit tests about lodash <code>isEmpty</code>. It should be taken for granted that <code>isEmpty</code> is a black box for you that has been thoroughly tested by lodash’s developers.</p>
<h2 id="caution-when-using-real-data">Caution when using real data<a class="heading-anchor" href="#caution-when-using-real-data" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>It’s important to note that when I mention using real data, I am not referring to the same data used on the production site. Using production data in testing can lead to serious issues, like GDPR compliance and the leak of sensitive data.</p>
<p>Instead, by “real” data, I mean <strong>realistic</strong>/<strong>similar</strong> data, that the testing suite will use based on the testing environment. For example, when testing locally, the test would use data from the local database. When testing on a staging environment, the test would use data from the staging database.</p>
<p><strong>A staging environment</strong> is an environment we use for testing features and <a href="/the-unique-origin-of-the-term-bug-in-software-development/">bug</a> fixes before deploying them on production. A safe simulation of a site or software used in production.</p>
<p>You should anticipate that these databases will be populated with data that is structured similarly to your production database, but not identical.</p>
<h2 id="which-testing-method-to-choose">Which testing method to choose?<a class="heading-anchor" href="#which-testing-method-to-choose" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>While there isn’t a definitive answer to this question if I had to answer that, I’d say, “It depends.” And yes I know you probably don’t like that answer. In that case, if I had to choose one answer, I would say that you always need to choose both types.</p>
<p>Unit tests are awesome for checking function flows, but integration tests are the best so that you may have a good night’s sleep! 😴 What I usually do is follow an approach that combines both. For complex functions, I write at least one integration test and multiple unit tests for each individual function the complex function relies on.</p>
<p>I consider writing tests a form of art, and while it may take time to master, incorporating it into your workflow will bring immense value. Once it becomes an integral part of your everyday workflow, you’ll experience a remarkable mind-shift that will not only enhance your testing skills but will also change the way you implement a feature. You’ll begin wearing two hats, the developer and the tester. By doing so, you’ll be able to proactively think about edge cases, error conditions, and much more while implementing your features!</p>
<p>I can assure you it’s a mind-blowing and life-changing process. So what are you waiting for? Go for it!!</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/javascript-testing-tools-explained-what-beginners-really-need-to-know/">Javascript Testing Tools Explained</a></li>
<li><a href="/husky-hooks-the-easy-way-to-improve-your-project-workflow/">Husky Hooks: Improve Your Git Workflow</a> — run your tests automatically on every commit</li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Common TypeScript Errors and Fixes</title>
      <link>https://littlecodingthings.com/most-common-typescript-errors-and-how-to-solve-them/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/most-common-typescript-errors-and-how-to-solve-them/</guid>
      <pubDate>Fri, 11 Oct 2024 12:56:00 GMT</pubDate>
      <description>Fixes for the TypeScript errors beginners hit most: TS2307, TS2580, TS7006, TS7016 and TS18003 — what each one means and how to solve it.</description>
      <category>Server Side</category>
      <content:encoded><![CDATA[<p>While learning Typescript, I encountered many issues that were either recurring or difficult to solve. Because of this, I decided to share them in this post so that I could have access to the most common Typescript errors and their solutions. Since these are my first steps in learning TypeScript, feel free to share your insights and correct me if you see a solution applied incorrectly.</p>
<p>I will occasionally add more typescript errors to this post, hoping to save time and spare at least one of you the frustration and effort of dealing with them!</p>
<h2 id="ts2307--cannot-find-module-x-or-its-corresponding-type-declarations">TS2307 – Cannot find module ‘X’ or its corresponding type declarations<a class="heading-anchor" href="#ts2307--cannot-find-module-x-or-its-corresponding-type-declarations" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><strong>Error</strong> 🆘</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>error TS2307: Cannot find module './utils' or its corresponding type declarations.</span></span></code></pre></div>
<p><strong>Reason</strong> 🔬</p>
<p>This error can occur for several reasons:</p>
<p>You’re using path aliases that TypeScript doesn’t recognize — if you set up <a href="/how-to-use-absolute-paths-in-a-node-project-2024/">absolute paths in your Node project</a> and only told your bundler about them, TypeScript still needs the matching <code>paths</code> entry in <code>tsconfig.json</code>.</p>
<ul>
<li>
<p>The module doesn’t exist.</p>
</li>
<li>
<p>The import path is incorrect.</p>
</li>
<li>
<p>The file extension is wrong.</p>
</li>
<li>
<p>The file isn’t included in your <code>tsconfig.json</code>.</p>
</li>
</ul>
<p><strong>Solution</strong> ✅</p>
<p>Start by checking the obvious:</p>
<ul>
<li>Is the file in the correct location?</li>
<li>Is the import path correct?</li>
<li>Did you rename the file?</li>
</ul>
<p>If you’re using path aliases such as:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>"paths": {</span></span>
<span class="line"><span>  "@/*": ["src/*"]</span></span>
<span class="line"><span>}</span></span></code></pre></div>
<p>make sure they’re also configured correctly in your bundler or runtime.</p>
<p>If the package exists but TypeScript still complains, installing its type definitions may solve the issue:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">npm</span><span style="color:#9ECBFF"> install</span><span style="color:#79B8FF"> --save-dev</span><span style="color:#9ECBFF"> @types/package-name</span></span></code></pre></div>
<h2 id="ts2580--cannot-find-name-require">TS2580 – Cannot find name ‘require’<a class="heading-anchor" href="#ts2580--cannot-find-name-require" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><strong>Error</strong> 🆘</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>error TS2580: Cannot find name 'require'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node`.</span></span></code></pre></div>
<p><strong>Reason</strong> 🔬</p>
<p>As the error description clearly suggests, Typescript needed <code>@types/node</code> to successfully finish the compilation.</p>
<p><strong>Solution</strong> ✅</p>
<p>Running <code>npm i --save-dev @types/node</code> solves this issue</p>
<h2 id="ts7006--parameter-res-implicitly-has-an-any-type">TS7006 – Parameter ‘res’ implicitly has an ‘any’ type.<a class="heading-anchor" href="#ts7006--parameter-res-implicitly-has-an-any-type" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><strong>Error</strong> 🆘</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>error TS7006: Parameter 'res' implicitly has an 'any' type.6 app.get('/', (req, res) => {</span></span></code></pre></div>
<p><strong>Reason</strong> 🔬</p>
<p>I was building a project and had the following boilerplate code included</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> express</span><span style="color:#F97583"> =</span><span style="color:#B392F0"> require</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'express'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> app</span><span style="color:#F97583"> =</span><span style="color:#B392F0"> express</span><span style="color:#E1E4E8">();</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">app.</span><span style="color:#B392F0">get</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'/'</span><span style="color:#E1E4E8">, (</span><span style="color:#FFAB70">req</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">res</span><span style="color:#E1E4E8">) </span><span style="color:#F97583">=></span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  res.</span><span style="color:#B392F0">send</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'Hello World!'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">})</span></span></code></pre></div>
<p>My <code>tsconfig.json</code> file had <code>compilerOptions: {"strict": true }</code> set, so it was basically telling TS not to accept type <code>any</code> for its parameters. <code>strict: true</code> is <a href="https://www.typescriptlang.org/tsconfig/#strict">a shortcut for applying strict rules</a>, including the <a href="https://www.typescriptlang.org/tsconfig/#noImplicitAny" title="noImplicitAny">noImplicitAny</a> rule.</p>
<p>If you’re running into this error while setting up a backend project, it usually means Express is working but TypeScript isn’t fully configured yet. In that case, you might find it helpful to follow a complete walkthrough on <a href="/how-to-setup-an-express-js-server-using-typescript-2024/">setting up an Express.js server with Typescript</a> from scratch, including the correct typings and project structure.</p>
<p><strong>Solution</strong> ✅</p>
<p>To solve this issue, we need to install <code>@types/express</code> by running</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">npm</span><span style="color:#9ECBFF"> install</span><span style="color:#79B8FF"> --save-dev</span><span style="color:#9ECBFF"> @types/express</span></span></code></pre></div>
<p>In addition, we will refactor our code to use explicit types for our function parameters and constants.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">import</span><span style="color:#E1E4E8"> express, { Express, Request, Response } </span><span style="color:#F97583">from</span><span style="color:#9ECBFF"> 'express'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> app</span><span style="color:#F97583">:</span><span style="color:#B392F0"> Express</span><span style="color:#F97583"> =</span><span style="color:#B392F0"> express</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> port</span><span style="color:#F97583"> =</span><span style="color:#79B8FF"> 3004</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">app.</span><span style="color:#B392F0">get</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'/'</span><span style="color:#E1E4E8">, (</span><span style="color:#FFAB70">req</span><span style="color:#F97583">:</span><span style="color:#B392F0"> Request</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">res</span><span style="color:#F97583">:</span><span style="color:#B392F0"> Response</span><span style="color:#E1E4E8">) </span><span style="color:#F97583">=></span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  res.</span><span style="color:#B392F0">send</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'Hello World!'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">})</span></span>
<span class="line"><span style="color:#E1E4E8">app.</span><span style="color:#B392F0">listen</span><span style="color:#E1E4E8">(port, () </span><span style="color:#F97583">=></span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  console.</span><span style="color:#B392F0">log</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">`Example app listening on port ${</span><span style="color:#E1E4E8">port</span><span style="color:#9ECBFF">}`</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">});</span></span></code></pre></div>
<h2 id="ts7016--could-not-find-a-declaration-file-for-module-xfile-y-implicitly-has-an-any-type">TS7016 – Could not find a declaration file for module X.file Y implicitly has an ‘any’ type<a class="heading-anchor" href="#ts7016--could-not-find-a-declaration-file-for-module-xfile-y-implicitly-has-an-any-type" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><strong>Error</strong> 🆘</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>error TS7016:  Could not find a declaration file for module X.file Y implicitly has an 'any' type.</span></span></code></pre></div>
<p><strong>Reason</strong> 🔬</p>
<p>This error occurs because module X may not include TypeScript type definitions by default, and type definitions for module X haven’t been installed or declared in your project.</p>
<p><strong>Solution</strong> ✅</p>
<p>If there are community-maintained type definitions, e.g <code>@types/module-x</code> install them, and this will solve your issue.
Another way to overcome this error is to create a custom-type declaration if option 1 is unavailable.</p>
<h2 id="ts18003--no-inputs-were-found-in-config-file-">TS18003 – No inputs were found in config file <a class="heading-anchor" href="#ts18003--no-inputs-were-found-in-config-file-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>While initializing my project, I saw this error when running <code>npx tsc</code></p>
<p><strong>Error</strong> 🆘</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>error TS18003: No inputs were found in config file '/server-project/tsconfig.json'. Specified 'include' paths were '["**/*"]' and 'exclude' paths were '[]'.</span></span></code></pre></div>
<p><strong>Reason</strong> 🔬</p>
<p>Typescript needs at least one ts file in a project to compile. I was seeing this error cause I was too eager to run the tc compiler without any <code>.tsc</code> files include in my project.</p>
<p><strong>Solution</strong> ✅</p>
<p>Just add a <code>.ts</code> file, even an empty one, for starters, in your project.</p>
<h2 id="how-to-prevent-common-typescript-errors-in-new-projects">How to prevent common Typescript errors in new projects<a class="heading-anchor" href="#how-to-prevent-common-typescript-errors-in-new-projects" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Many Typescript errors appear not because something is broken, but because the project setup is incomplete. A few small habits can prevent most of the issues listed above.</p>
<p>First, always install type definitions alongside your dependencies. If you’re using node, Express, or other popular Javascript libraries, there’s usually a corresponding <code>@types/*</code> package available. Installing these early prevents many <code>implicit any</code> and missing type errors.</p>
<p>Second, review your <code>tsconfig.json</code> before writing too much code. Options like <code>strict</code>, <code>noImplicitAny</code>, and <code>moduleResolution</code> have a big impact on how Typescript behaves. Enabling strict mode early is usually easier than fixing hundreds of errors later. Once it is on, Typescript starts flagging every value that might be <code>undefined</code> — and the tidiest way to answer that is usually the <a href="/how-to-use-a-javascript-double-question-mark/">nullish coalescing operator <code>??</code></a>, which narrows the type and supplies a default in one go.</p>
<p>Finally, don’t silence Typescript errors just to make the project compile. Typescript is most useful when you understand why an error exists — fixing the root cause often prevents the same issue from showing up again in future projects.</p>
<h2 id="common-beginner-mistakes-when-working-with-typescript">Common beginner mistakes when working with Typescript<a class="heading-anchor" href="#common-beginner-mistakes-when-working-with-typescript" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Running the Typescript compiler too early is a frequent issue. Typescript expects at least one valid <code>.ts</code> file, so initializing a project without source files will often result in misleading errors.</p>
<p>Another common mistake is ignoring Typescript warnings just to “make it work.” While this may speed things up short-term, it usually leads to repeated issues later. Treat TypeScript errors as guidance, not obstacles.</p>
<p>Finally, relying too heavily on <code>any</code> defeats the purpose of using Typescript in the first place. If you find yourself adding <code>any</code> often, it’s usually a sign that some types or definitions are missing.</p>
<p>If you’re experiencing a recurring error that’s frustrating you, please mention it in the comments section so we can address it and help others who might be facing the same issue.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/coding-interview-series-intro-to-express-js-middleware/">Express.js Middleware Interview Questions</a></li>
<li><a href="/how-to-use-absolute-paths-in-a-node-project-2024/">Absolute Paths in a Node Project</a> — the usual cause of TS2307</li>
<li><a href="/naming-conventions-how-to-name-your-components-without-fighting-your-ui-library/">Component Naming Conventions in React</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>CSS Letter Spacing – Working on The Correct Way</title>
      <link>https://littlecodingthings.com/css-letter-spacing-working-on-the-correct-way/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/css-letter-spacing-working-on-the-correct-way/</guid>
      <pubDate>Mon, 07 Oct 2024 10:00:00 GMT</pubDate>
      <description>letter-spacing sets the gap between characters. Three headings compared side by side, plus the negative value that ruins legibility.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Greetings! 😃 In today’s post, we will explore the CSS letter spacing property, which is responsible for the <strong>horizontal distance between letters</strong>. The default letter spacing is equivalent to <code>0px</code>, known as normal (<code>letter-spacing: normal</code>). Increasing value results in bigger spacing.</p>
<p>We will continue with some examples to understand better this easy but still useful CSS property.</p>
<h2 id="html-structure-for-letter-spacing">HTML structure for letter spacing<a class="heading-anchor" href="#html-structure-for-letter-spacing" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We start with our <a href="/most-useful-html-elements-for-maximizing-better-results/">HTML</a> document by creating three <code>&#x3C;h1></code> headings with the text “Hello World”. All headings contain identical text to highlight the difference in letter spacing. The headings are styled differently, the first one uses  <code>.spacing-normal</code> class, the second one <code>.spacing-small</code> class, and the third one <code>.spacing-big</code>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">h1</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"spacing-normal"</span><span style="color:#E1E4E8">>Hello World&#x3C;/</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">h1</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"spacing-small"</span><span style="color:#E1E4E8">>Hello World&#x3C;/</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">h1</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"spacing-big"</span><span style="color:#E1E4E8">>Hello World&#x3C;/</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h2 id="css-structure-for-letter-spacing">CSS structure for letter spacing<a class="heading-anchor" href="#css-structure-for-letter-spacing" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We continue our work with the <a href="/how-to-work-with-css-syntax-the-correct-way/">CSS</a> structure. We have assigned the letter-spacing property to all three classes but with different values. Even though the text is the same in all headings, they will appear different due to class variation.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.spacing-normal</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  letter-spacing</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">normal</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.spacing-small</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  letter-spacing</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.spacing-big</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  letter-spacing</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>In the image provided, we can see the effect of varying letter spacing in css on the previously created headings. Increasing the letter spacing value results in greater distance between the letters, resulting in a more notable gap between them. The image clearly illustrates the relationship between letter spacing and letter distance.</p>
<p>🔖 Note that letter spacing affects the distance between words, too.</p>
<p><img src="/css-letter-spacing.webp" alt="An image showing our example with the CSS letter-spacing property." style="max-width:56%" class="img-narrow"></p>
<h3 id="what-to-avoid-when-using-css-letter-spacing-property">What to AVOID when using CSS letter-spacing property<a class="heading-anchor" href="#what-to-avoid-when-using-css-letter-spacing-property" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>The letter spacing can support negative values. However, reducing the default letter spacing requires caution as it can negatively impact text legibility by causing letters to appear too close together. Here’s an example:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.spacing-normal</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  letter-spacing</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">normal</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.spacing-negative</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  letter-spacing</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-letter-spacing-avoid-negative.webp" alt="Example of what to avoid when using the letter spacing in css" style="max-width:56%" class="img-narrow"></p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/css-word-spacing-how-to-do-it-right/">CSS Word Spacing – How to Do It Right</a></li>
<li><a href="/how-to-calculate-css-line-height/">How To Calculate CSS Line Height</a></li>
<li><a href="/css-text-decoration-explained-with-examples/">CSS Text Decoration Explained with Examples</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>The CSS nth-of-type Selector Explained</title>
      <link>https://littlecodingthings.com/the-css-nth-of-type-selector-how-to-target-elements-by-type/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/the-css-nth-of-type-selector-how-to-target-elements-by-type/</guid>
      <pubDate>Fri, 04 Oct 2024 10:48:00 GMT</pubDate>
      <description>:nth-of-type() counts elements by tag, not by position among siblings. Target one, target all with (n), or target several types at once.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hello there! Today, we’ll explore how the CSS <code>nth-of-type()</code> selector works. This powerful <a href="/coding-made-easy-with-css-selectors-an-ultimate-guide/" title="CSS selector">CSS selector</a> allows us to <strong>target</strong> <strong>every nth child</strong> <a href="/most-useful-html-elements-for-maximizing-better-results/" title="HTML element">HTML element</a> <strong>of a specific type</strong> within its parent container.</p>
<p>Below, I prepared some examples to analyze this amazing pseudo-class thoroughly.</p>
<h2 id="basic-html-structure">Basic HTML structure<a class="heading-anchor" href="#basic-html-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We begin with the HTML structure. We create an <code>&#x3C;article></code> HTML element. It contains two headings (<code>&#x3C;h1></code> , <code>&#x3C;h2></code>) elements. Also, we include some <code>&#x3C;p></code> and <code>&#x3C;div></code> HTML elements. The example may seem slightly complicated, but it is the right way to understand just how useful 🛠 tool this selector can be. 😃
For now, we’ll maintain the default styling with a white background and black text.</p>
<p>🔖 Please note that this HTML code snippet will be used across all examples.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">article</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">>Explore India&#x3C;/</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">h2</span><span style="color:#E1E4E8">>India's Top Ten Attractions&#x3C;/</span><span style="color:#85E89D">h2</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>Here goes the 1st paragraph about India's attractions&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>Here goes the 2nd paragraph about India's attractions&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">h2</span><span style="color:#E1E4E8">>India's Food&#x3C;/</span><span style="color:#85E89D">h2</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>Here goes text about India's cuisine&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>Here goes text about India's cuisine&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">article</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p>Below, we can see what is rendered on the screen 💻 for now. It’s just a simple article in a newspaper 🗞 or on the internet. At least as articles were once upon a time 😂 just text, no images, and no special styling. Don’t worry; it works well for us!</p>
<p><img src="/nth-of-type-css-selector-example-outlet.webp" alt="An article HTML element with <h1>, <h2>, <p>, and <div> elements, all displaying default styling, illustrating the CSS nth-of-type() selector in action." style="max-width:56%" class="img-narrow"></p>
<h2 id="targeting-a-specific-html-element">Targeting a specific HTML element<a class="heading-anchor" href="#targeting-a-specific-html-element" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Now let’s explore how this selector works. We start by using the <code>nth-of-type()</code> selector, preceded by <code>h2</code>, and placing the number <code>1</code> inside the parentheses <code>()</code>. This <strong>targets the very first</strong> <code>&#x3C;h2></code> element within our <code>&#x3C;article></code> parent.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">article</span><span style="color:#85E89D"> h2</span><span style="color:#B392F0">:nth-of-type</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>In the following image, we can see the result of the applied <code>nth-of-type</code> selector.</p>
<p><img src="/nth-of-type-css-selector-example-select-one-specific-type-html-element-1.webp" alt="An article HTML element containing <h1>, <h2>, <p>, and <div> elements. All have default styling, except the first <h2> element, which has a magenta background and white text, styled using the h2:nth-of-type(1) CSS selector." style="max-width:56%" class="img-narrow"></p>
<h2 id="targeting-all-elements-of-a-specific-type">Targeting all elements of a specific type<a class="heading-anchor" href="#targeting-all-elements-of-a-specific-type" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We continue and dive a bit deeper! We place <code>h2</code> before our <code>nth-of-type()</code> selector, but this time, we add the <code>n</code> inside the <code>parentheses</code> <code>()</code>. By doing so, <strong>we target all</strong> <code>&#x3C;h2></code> elements within our parent element.</p>
<p>The <code>n</code> in <code>nth-of-type(n)</code> enables the selector to match elements at any position among siblings. This means you can apply styles to all matching elements without specifying an exact position, ensuring that every instance is included. 😎</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">article</span><span style="color:#85E89D"> h2</span><span style="color:#B392F0">:nth-of-type</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">n</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>In the image below, we notice the styling applied to all <code>&#x3C;h2></code> HTML elements after using the <code>nth-of-type(n)</code> selector.</p>
<p><img src="/nth-of-type-css-selector-example-select-two-same-type-html-element.webp" alt="An article HTML element containing <h1>, <h2>, <p>, and <div> elements. All have default styling except the <h2> elements, which have a magenta background and white text, styled using the h2:nth-of-type(n) CSS selector." style="max-width:56%" class="img-narrow"></p>
<h2 id="targeting-elements-of-various-types">Targeting elements of various types<a class="heading-anchor" href="#targeting-elements-of-various-types" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Additionally, we have the option to use the <code>nth-of-type()</code> selector to <strong>target more than one different type</strong> of HTML elements. In our case, we set the <code>p:nth-of-type(1)</code> to target the first <code>&#x3C;p></code> element and also the <code>div:nth-of-type(2)</code> to target the second <code>&#x3C;div></code> element.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">article</span><span style="color:#85E89D"> p</span><span style="color:#B392F0">:nth-of-type</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#85E89D">article</span><span style="color:#85E89D"> div</span><span style="color:#B392F0">:nth-of-type</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">2</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">	 color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">	 background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>This is how it currently looks on the screen 💻. Cool huh? 😃 ✨</p>
<p><img src="/nth-of-type-css-selector-example-select-multiple-different-types-html-elements.webp" alt="An article HTML element containing <h1>, <h2>, <p>, and <div> elements. All have default styling except the first <p> and the second <div> elements, which have a magenta background and white text, styled using the p:nth-of-type(1) and div:nth-of-type(2) CSS selectors." style="max-width:56%" class="img-narrow"></p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/css-selectors-nth-child-vs-nth-of-type-and-how-to-use-them-correctly/">nth-child vs nth-of-type in CSS</a></li>
<li><a href="/what-you-need-to-know-about-css-nth-child-selector-a-practical-guide/">The CSS nth-child Selector Explained</a></li>
<li><a href="/css-last-child-selector-the-most-valuable-selector/">The CSS last-child Selector</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Drop-shadow VS Box-shadow: What is the difference?</title>
      <link>https://littlecodingthings.com/drop-shadow-vs-box-shadow-what-is-the-difference/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/drop-shadow-vs-box-shadow-what-is-the-difference/</guid>
      <pubDate>Mon, 30 Sep 2024 08:21:00 GMT</pubDate>
      <description>box-shadow follows an element's rectangle. filter: drop-shadow() follows its real shape. See both side by side on a CSS bee you can copy.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Greetings 😃 In today’s session, we’re about to explore 🔎 the fascinating world of the CSS shadow properties. Get ready to unlock 🗝 the secret between CSS <strong>drop-shadow</strong> and <strong>box-shadow</strong> properties!</p>
<p>I created a beautiful, playful bee 🐝 to make our example understandable and funny! You can check out my “bee code” at the end of my post and see how I created it. You are welcome to use it wherever suits you!</p>
<h2 id="css-box-shadow">CSS box-shadow<a class="heading-anchor" href="#css-box-shadow" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Now, let’s focus on our shadows! In the following example, we see the effect of the <a href="/how-box-shadow-works-made-simple/"><code>box-shadow</code> property</a>. Our shadow is applied to the two sides of our box (<code>bee-wrapper</code>). The code I provided creates a gray shadow with the following characteristics:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.bee-wrapper</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#6A737D">  /* offset-X | offset-Y | blur-radius | spread-radius | color */</span></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> #5b5959</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<ul>
<li><strong>offset-X</strong>: adds 10 pixels to the right of the element.</li>
<li><strong>offset-Y</strong>: adds 10 pixels below the element.</li>
<li><strong>blur-radius</strong>: A blurry shadow with a radius of 10 pixels. (You are free to use a higher blur radius for a softer, more diffuse shadow, or you might opt for a lower blur radius to create a sharper, crisper shadow).</li>
<li><strong>spread-radius</strong>: The shadow doesn’t expand or contract beyond the blur radius as I set it to zero. (I chose not to add spread, but it’s totally up to you if you want to add it.
🔖 Keep in mind that the <code>spread-radius</code> parameter determines whether the shadow expands or reduces in size. A positive value will enlarge the shadow, whereas a negative value will shrink it).</li>
<li><strong>color</strong>: The color of the shadow is a shade of gray (<code>#5b5959</code>).</li>
</ul>
<p><img src="/drop-shadow-vs-box-shadow2.webp" alt="Comparison between box-shadow and drop-shadow CSS properties.This is the box shadow property" style="max-width:28%" class="img-narrow"></p>
<h2 id="css-drop-shadow">CSS drop-shadow<a class="heading-anchor" href="#css-drop-shadow" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>In this case, on the other hand, we can see that by setting the <code>filter: drop-shadow()</code> property the shadow applies smoothly to all parts of our content inside the box (<code>bee-wrapper</code>). Cool 🥳 ha! So, let’s see our code in more detail and how the shadow will now be rendered on the screen through our lovely bee!</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.bee-wrapper</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#6A737D">/* offset-X | offset-Y | blur-radius | color */</span></span>
<span class="line"><span style="color:#79B8FF">filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">drop-shadow</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #5b5959</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<ul>
<li><strong>filter</strong>: The filter property in CSS applies various graphical effects, including blurs, color adjustments, and, in this instance, shadows, to an element.</li>
<li><strong>offset-X</strong>: This specifies the horizontal offset of the shadow from the element. It’s 10 pixels to the right, creating a shadow on the right side of the element.</li>
<li><strong>offset-Y</strong>: This specifies the vertical offset of the shadow from the element. It’s 10 pixels below the element, creating a shadow below it.</li>
<li><strong>blur-radius</strong>: A moderately blurry shadow with a radius of 5 pixels. (A higher value would create a more diffused and softer shadow, while a lower one would create a sharper shadow).</li>
<li><strong>color</strong>: The shadow’s color is a shade of gray (<code>#5b5959</code>).</li>
</ul>
<p>🔖 It is worth mentioning that <code>spread-radius</code> property does not appear here.</p>
<p><img src="/drop-shadow-vs-box-shadow1.webp" alt="Comparison between drop-shadow and box-shadow CSS properties. This is the drop shadow property" style="max-width:28%" class="img-narrow"></p>
<h2 id="complete-bee-code">Complete bee code<a class="heading-anchor" href="#complete-bee-code" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Below, I include my HTML and CSS bee code.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"bee-wrapper"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"face"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"antenna antenna--left"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"antenna antenna--right"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"bee-eye bee-eye-left"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"bee-eye bee-eye-right"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"bee-mouth"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"wing wing--left"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"wing wing--right"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"sting"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"bee-body"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"stripes"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">:root</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#FFAB70">  --bg-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#cdc6c7</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">*</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  margin</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  padding</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-sizing</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">border-box</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">html</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  min-width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">var</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">--bg-color</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  flex-direction</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">column</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">// BEE</span></span>
<span class="line"><span style="color:#B392F0">.bee-wrapper</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">            /* BOX-SHADOW */</span></span>
<span class="line"><span style="color:#6A737D">  /* uncomment to see the box-shadow effect</span></span>
<span class="line"><span style="color:#6A737D">  * offset-x | offset-y | blur-radius | spread-radius | color</span></span>
<span class="line"><span style="color:#6A737D">  */</span></span>
<span class="line"><span style="color:#6A737D">  // box-shadow: 10px 10px 10px 0 #5b5959;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">            /* DROP-SHADOW */</span></span>
<span class="line"><span style="color:#6A737D">  /* uncomment to see the drop-shadow effect</span></span>
<span class="line"><span style="color:#6A737D">  * x-offset | y-offset | blur | color</span></span>
<span class="line"><span style="color:#6A737D">  */</span></span>
<span class="line"><span style="color:#6A737D">  // filter: drop-shadow(10px 10px 5px #5b5959);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .face</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#ecaf2f</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #dda22c</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">80</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#B392F0">    .antenna</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#FFAB70">--left</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-48</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">12</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-20</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#B392F0">::after</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">          content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#FFAB70">--right</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-48</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">12</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">20</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#B392F0">::after</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">          content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">    .bee-eye</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">230</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">.bee-eye-left</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">14</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">4</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">.bee-eye-right</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">14</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">4</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">    .bee-mouth</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">32</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">32</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">12</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">14</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">45</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .wing</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">80</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#FFAB70">--left</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">to</span><span style="color:#79B8FF"> bottom</span><span style="color:#79B8FF"> right</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#f0f1d2</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#dda22c</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">30</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 80</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 80</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">352</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">130</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">45</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#FFAB70">--right</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">to</span><span style="color:#79B8FF"> bottom</span><span style="color:#79B8FF"> left</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#f0f1d2</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#dda22c</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">80</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 30</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 80</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">8</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">130</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">135</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .bee-body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">160</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#ecaf2f</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 8</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #dda22c</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    overflow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">hidden</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">80</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#B392F0">      .stripes</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">80</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">22</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">44</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">80</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">38</span><span style="color:#F97583">px</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">::after</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">80</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">72</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .sting</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">24</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">250</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-box-shadow-works-made-simple/">How box-shadow Works (Made Simple)</a></li>
<li><a href="/how-inset-works-in-box-shadow-made-simple/">How inset Works in box-shadow (Made Simple)</a></li>
<li><a href="/opacity-and-saturate-empower-css-filter-for-unique-images/">CSS Filters: Opacity and Saturate</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>The CSS Sepia Filter Explained</title>
      <link>https://littlecodingthings.com/the-css-sepia-filter-learn-how-to-make-vintage-images/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/the-css-sepia-filter-learn-how-to-make-vintage-images/</guid>
      <pubDate>Thu, 26 Sep 2024 08:20:00 GMT</pubDate>
      <description>Give photos an aged, brownish look with filter: sepia(). Worked example, before-and-after images, and how to stack it with grayscale.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>In the world of web design, adding a touch of nostalgia or a vintage vibe to images can significantly enhance a website’s aesthetic. One timeless technique to achieve this effect is the CSS sepia filter.</p>
<p>Originating from sepia ink, which has been used for centuries, this filter gives photos a warm, brownish tone reminiscent of old photographs, lending a sense of history and charm to the visuals.</p>
<p>An image with 0% sepia maintains its original, true colors, while at 100% sepia, the image is entirely transformed into a warm, brownish tone as an aged photograph. As you increase the percentage, you intensify the sepia effect.</p>
<p>Join me 😃 into the magic of the <code>filter: sepia(%)</code> CSS property and explore how it can be seamlessly integrated into your web design toolbox.</p>
<h2 id="history-of-the-sepia-ink">History of the sepia ink<a class="heading-anchor" href="#history-of-the-sepia-ink" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>🧐 Did you know that sepia ink is a brownish-black ink made from the ink sac of the common cuttlefish, Sepia? 🐙 They belong to the class Cephalopoda, which also includes squid, octopuses, and nautiluses.</p>
<p>Historically, it has been used for writing and drawing, and it was particularly popular in the past for writing manuscripts and creating artwork.</p>
<p>The ink took its name from the sepia cuttlefish, which was the source of the ink. The ink was widely used in antiquity and during the Renaissance*, and it has a characteristic warm, brownish hue which is why the CSS filter that replicates this effect is referred to as the “sepia” filter.</p>
<p>(* <em>The Renaissance was a period in European history that spanned roughly from the 14th century to the 17th century. It was characterized by a significant cultural, artistic, and intellectual rebirth after the Middle Ages. The term “Renaissance” is derived from the French word meaning “rebirth”</em>).</p>
<h2 id="use-the-css-sepia-filter-to-an-image">Use the CSS sepia filter to an image<a class="heading-anchor" href="#use-the-css-sepia-filter-to-an-image" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Below I craft an example as an easy way to explain this amazing CSS property to you! 😃 So, let’s proceed.</p>
<p>We will start with our HTML and CSS code snippets.</p>
<p>The HTML snippet contains two <code>&#x3C;img></code> elements. The first one has the <code>.original-image</code> class, indicating a standard image. The second one has also the <code>.original-image</code> and additionally the <code>.with-sepia</code>, implying it’s a styled image using the sepia filter, giving it a warm, brownish tone.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">img</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"original-image"</span><span style="color:#E1E4E8">/></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">img</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"original-image with-sepia"</span><span style="color:#E1E4E8">/></span></span></code></pre></div>
<p>The <code>.original-image</code> class is shared by both image elements, setting a background image, ensuring it doesn’t repeat and covering the specified <code>width</code> and <code>height</code> (400px by 500px).</p>
<p>The <code>.with-sepia</code> class applied only to the second image, introduces a sepia filter of 80%, giving a warm, brownish tone.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.original-image</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">url</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">https://images.unsplash.com/photo-1501829385782-9841539fa6bf?ixlib=rb-4.0.3&#x26;ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&#x26;auto=format&#x26;fit=crop&#x26;w=3024&#x26;q=80</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  background-repeat</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">no-repeat</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">cover</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">400</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">500</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.with-sepia</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">sepia</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">80</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>By placing the two images side by side, we can effortlessly 🧐 perceive the contrast between them. It’s absolutely fascinating, isn’t it? 😃</p>
<figure><img src="/sepia-filter-original-image.webp" alt="Red car against a backdrop of old buildings in Verona city, Italy" style="max-width:42%" class="img-narrow"><figcaption>Original photo by <a href="https://unsplash.com/@jonatanhernandez?utm_content=creditCopyText&#x26;utm_medium=referral&#x26;utm_source=unsplash">Jonatan Hernandez</a> on <a href="https://unsplash.com/photos/AWkEp5ap-vw?utm_content=creditCopyText&#x26;utm_medium=referral&#x26;utm_source=unsplash">Unsplash</a></figcaption></figure>
<figure><img src="/sepia-filter-image-adding-sepia.webp" alt="Red car with sepia-filtered old buildings in the background, captured in Verona city, Italy" style="max-width:42%" class="img-narrow"><figcaption>filter: sepia(80%)</figcaption></figure>
<h3 id="enrich-filter-css-sepia-property-with-grayscale-value">Enrich filter CSS sepia property with grayscale value<a class="heading-anchor" href="#enrich-filter-css-sepia-property-with-grayscale-value" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>In addition, we can add the <a href="/awesome-css-grayscale-filter-how-to-upgrade-images/"><code>filter: grayscale(%)</code></a> CSS property. Together, these filters can create a unique and visually captivating presentation, capturing the essence of both the past and the present in a single frame.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.with-sepia</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">sepia</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">80</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">grayscale</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Wow! 🌟 This is absolutely stunning! 😃</p>
<figure><img src="/sepia-filter-image-adding-grayscale.webp" alt="Red car against sepia and grayscale-filtered old buildings in Verona city, Italy" style="max-width:42%" class="img-narrow"><figcaption>filter: sepia(80%) grayscale(50%);</figcaption></figure>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/awesome-css-grayscale-filter-how-to-upgrade-images/">CSS Grayscale Filter – A Complete Guide</a></li>
<li><a href="/contrast-and-brightness-empower-css-filter-for-powerful-images/">CSS Filters: Adjust Contrast and Brightness</a></li>
<li><a href="/opacity-and-saturate-empower-css-filter-for-unique-images/">CSS Filters: Opacity and Saturate</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How to Make Grayscale Images with CSS</title>
      <link>https://littlecodingthings.com/css-grayscale-filter-how-to-upgrade-images/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/css-grayscale-filter-how-to-upgrade-images/</guid>
      <pubDate>Mon, 23 Sep 2024 11:00:00 GMT</pubDate>
      <description>Turn a photo black and white with the CSS filter: grayscale() property. A short worked example comparing the original, 50% and 100%.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Transforming your images into stunning black-and-white tones with depth and texture has become easier than ever with the powerful grayscale filter. Adding a touch of gray to your images creates a modern vibe and turns them into art. To achieve this effect, we use the CSS <code>filter: grayscale(%)</code> property.</p>
<p>The grayscale filter allows you to adjust the percentage of gray. When you increase the percentage, you boost the effect. An image with <code>0%</code> grayscale maintains its authentic colors, while at <code>100%</code> grayscale, the image is entirely transformed into a cold, grayish tone.</p>
<p>Join me 😃 in the magic of the grayscale filter, explore how it can be merged harmoniously, and enhance your techniques.</p>
<h2 id="monochrome--grayscale-method">Monochrome – Grayscale method<a class="heading-anchor" href="#monochrome--grayscale-method" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The grayscale method, or in other words, <a href="https://en.wikipedia.org/wiki/Monochrome_photography">monochrome photography</a> method, captures and displays different levels of light but not different colors. It includes all forms of black-and-white photography, which produces images with shades of gray ranging from black to white.</p>
<p>It originated in the 1820s when <a href="https://en.wikipedia.org/wiki/Nic%C3%A9phore_Ni%C3%A9pce">Nicephore Niepce</a>, a French inventor and photographer, created the first photograph. In today’s world, monochrome photography is mainly used for applications other than photographs.</p>
<h2 id="applying-the-grayscale-filter-to-an-image">Applying the grayscale filter to an image<a class="heading-anchor" href="#applying-the-grayscale-filter-to-an-image" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Below, I’ve prepared an example to help clarify this property for you! 😃 So, let’s move forward.</p>
<p>We begin with our HTML and CSS code snippets.</p>
<p>The HTML snippet includes three <code>img</code> elements. The first one has the <code>.original-image</code> class, indicating a standard image. The second also has <code>.original-image</code> plus <code>.with-grayscale</code>, and the third has <code>.original-image</code> plus <code>.with-grayscale-full</code>, meaning they are styled images using the grayscale filter, giving them a cold, grayish tone.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">img</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"original-image"</span><span style="color:#E1E4E8">/></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">img</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"original-image with-grayscale"</span><span style="color:#E1E4E8">/></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">img</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"original-image with-grayscale-full"</span><span style="color:#E1E4E8">/></span></span></code></pre></div>
<p>The <code>.original-image</code> class is applied to all image elements, setting a background image, ensuring no repetition, and covering the specified dimensions of <code>400px</code> width and <code>500px</code> height.</p>
<p>The <code>.with-grayscale</code> and <code>.with-grayscale-full</code> classes, applied only to the second and third images, introduce a grayscale filter. In the second case, it is set at 50%, displaying our image with some grayish tones, while in the third case, it is set at 100%, decolorizing our image and declaring a completely gray tone.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.original-image</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">url</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'...'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  background-repeat</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">no-repeat</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">cover</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">400</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">500</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.with-grayscale</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">grayscale</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.with-grayscale-full</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">grayscale</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>By positioning the three images side by side, we can clearly 🧐 observe the contrast among them. It’s absolutely captivating. Don’t you agree? 😃</p>
<figure><img src="/grayscale-filter-origin-image1.webp" alt="Image without css filter: grayscale(%). This image shows a photo of a red car with old buildings as a background.This photo was captured in Verona city Italy." style="max-width:35%" class="img-narrow"><figcaption>Original photo by <a href="https://unsplash.com/@jonatanhernandez?utm_content=creditCopyText&#x26;utm_medium=referral&#x26;utm_source=unsplash">Jonatan Hernandez</a> on <a href="https://unsplash.com/photos/AWkEp5ap-vw?utm_content=creditCopyText&#x26;utm_medium=referral&#x26;utm_source=unsplash">Unsplash</a></figcaption></figure>
<figure><img src="/grayscale-filter-image2-grayscale50.webp" alt="Utilizing the grayscale filter. This image shows a photo of a red car with old buildings as a background.This photo was captured in Verona city Italy. We set the css filter: grayscale(50%)." style="max-width:35%" class="img-narrow"><figcaption>filter: grayscale(50%)</figcaption></figure>
<figure><img src="/grayscale-filter-image3-grayscale100.webp" alt="Utilizing the grayscale filter. This image shows a photo of a red car with old buildings as a background.This photo was captured in Verona city Italy. We set the css filter: grayscale(100%)." style="max-width:35%" class="img-narrow"><figcaption>filter: grayscale(100%)</figcaption></figure>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/awesome-css-grayscale-filter-how-to-upgrade-images/">CSS Grayscale Filter – A Complete Guide</a></li>
<li><a href="/grayscale-backdrop-filter-a-useful-tool-to-make-grayish-backgrounds/">CSS backdrop-filter: grayscale()</a></li>
<li><a href="/the-css-sepia-filter-learn-how-to-make-vintage-images/">The CSS Sepia Filter Explained</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How to Make A Blinking Animation Using CSS</title>
      <link>https://littlecodingthings.com/how-to-make-a-blinking-animation-using-css/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-make-a-blinking-animation-using-css/</guid>
      <pubDate>Fri, 20 Sep 2024 11:58:00 GMT</pubDate>
      <description>Build a pair of blinking cartoon eyes in pure CSS — an eyelid pseudo-element animated by a @keyframes rule with a natural double blink.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hey there! In this post, I will show you how to create a pair of <strong>blinking eyes</strong> effect using only <a href="/how-to-work-with-css-syntax-the-correct-way/" title="CSS">CSS</a> (SCSS), complete with a smooth blinking animation to bring the eyes to life. A cow’s pair of eyes! Yes, yes, you read it right! We are dealing with a hidden 🐮 cow! Below, you can see our new 🐄 friend, with <em>flesh and bones.</em></p>
<p><img src="/blinking-eyes-1.gif" alt="A GIF demonstrating a smooth blinking animation of a pair of cartoon eyes, created using simple CSS." style="max-width:28%" class="img-narrow"></p>
<p>We are dealing with a hidden 🐮 cow!</p>
<p><img src="/blinking-eyes-effect-cow.gif" alt="A GIF demonstrating a smooth blinking animation of a pair of cartoon eyes, created using simple CSS." style="max-width:28%" class="img-narrow"></p>
<h2 id="html-structure">HTML Structure<a class="heading-anchor" href="#html-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Firstly, let’s build our blinking eyes’ initial structure using only <a href="/most-useful-html-elements-for-maximizing-better-results/">HTML</a>:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"face"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eye eye--left"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eye eye--right"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyebrow eyebrow--left"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyebrow eyebrow--right"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h2 id="css-structure">CSS Structure<a class="heading-anchor" href="#css-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Secondly, we continue by enhancing our HTML with <a href="/how-to-work-with-css-syntax-the-correct-way/">CSS</a><em>,</em> starting from the <strong>body</strong><em>.</em> We use <strong>flexbox</strong> as we want to place our face container in the center of our screen.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">vh</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">// gives us the full screen-size height</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h2 id="css-face-structure">CSS Face Structure<a class="heading-anchor" href="#css-face-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Next, we add our <strong>face</strong> container styling in order to be ready for our eyes’ positioning. We set <code>background-color: white;</code> just for contrast since our eyes will be black. Afterward, we use <code>display: grid;</code> and <code>place-items: center;</code> because we want our container’s children, our eyes, to get centered.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.face</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">grid</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  place-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h3 id="adding-the-eyes">Adding the eyes<a class="heading-anchor" href="#adding-the-eyes" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Afterward, we continue by creating our beautiful cow’s 👀 <strong>eyes</strong>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.face</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#B392F0">  .eye</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">64</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">80</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">30</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    overflow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">hidden</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> { </span><span style="color:#6A737D">// iris</span></span>
<span class="line"><span style="color:#85E89D">      content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">28</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">28</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    } </span><span style="color:#6A737D">// end of before</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#FFAB70">--left</span><span style="color:#E1E4E8"> { </span><span style="color:#6A737D">// position of left eye</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-10</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> { </span><span style="color:#6A737D">// position of left iris</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">8</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">12</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#FFAB70">--right</span><span style="color:#E1E4E8"> { </span><span style="color:#6A737D">// position of right eye</span></span>
<span class="line"><span style="color:#79B8FF">      right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">10</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> { </span><span style="color:#6A737D">// position of right iris</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">8</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">12</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">// end of eye</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">// end of face</span></span></code></pre></div>
<p><img src="/blinking-eyes-image.webp" alt="This image displays a pair of simplistic, cartoonish cow eyes in black and white, designed with thick black outlines and a minimalistic style." style="max-width:28%" class="img-narrow"></p>
<h3 id="adding-the-blinking-animation">Adding the blinking animation<a class="heading-anchor" href="#adding-the-blinking-animation" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Now is the right time, drum 🥁 roll, to add our <strong>blinking animation</strong> 😉 .</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.face</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#B392F0">  .eye</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#B392F0">::after</span><span style="color:#E1E4E8"> { </span><span style="color:#6A737D">// eyelid</span></span>
<span class="line"><span style="color:#85E89D">      content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">      /* takes the same width as the eye (width: 64px;)</span></span>
<span class="line"><span style="color:#6A737D">      in order to cover the whole eye when blinking */</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#6A737D">      /* we need 0 initial height - as our starting point before the</span></span>
<span class="line"><span style="color:#6A737D">      animation runs */</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">30</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> -2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">      /* here we add our "blink" animation since this is the</span></span>
<span class="line"><span style="color:#6A737D">      html part (:after - blinking) we want to make animate.</span></span>
<span class="line"><span style="color:#6A737D">      We want the animation to repeat every 4 seconds forever.</span></span>
<span class="line"><span style="color:#6A737D">      */</span></span>
<span class="line"><span style="color:#79B8FF">      animation</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">blink</span><span style="color:#79B8FF"> 4</span><span style="color:#F97583">s</span><span style="color:#79B8FF"> infinite</span><span style="color:#79B8FF"> ease-in</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    } </span><span style="color:#6A737D">// end of after</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">// end of eye</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">// end of face</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/* we name our animation "blink". We set different height percentages</span></span>
<span class="line"><span style="color:#6A737D">as a way to set our eye lids STAY IN DIFFERENT PART each time */</span></span>
<span class="line"><span style="color:#F97583">@keyframes</span><span style="color:#B392F0"> blink</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#B392F0">  0%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  30%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  33%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  40%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  70%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  75%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  78%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  81%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  84%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  100%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><strong>Hint</strong> 💡_Moreover, you should apply_ <strong><em>box shadow</em></strong> <em>(check code above) to make the blinking eyelid overflow the eyes’ borders. This way during the blinking animation it will cover the whole eye and make it more realistic!</em></p>
<p><img src="/blinkingeyes.gif" alt="A GIF demonstrating a smooth blinking animation of a pair of cartoon eyes, created using simple CSS." style="max-width:28%" class="img-narrow"></p>
<h3 id="adding-the-eyebrows">Adding the eyebrows<a class="heading-anchor" href="#adding-the-eyebrows" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Finally, we add the 🤨 <strong>eyebrows</strong> to complete the gaze.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.face</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#B392F0">  .eye</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">/* end of eye */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .eyebrow</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">70</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">solid</span><span style="color:#79B8FF"> 4</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> transparent</span><span style="color:#79B8FF"> transparent</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%/</span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#FFAB70">--left</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">10</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#FFAB70">--right</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-10</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">/* end of eyebrow */</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">/* end of face */</span></span></code></pre></div>
<p><img src="/blinking-eyes-1.gif" alt="A GIF demonstrating a smooth blinking animation of a pair of cartoon eyes with eyebrows added." style="max-width:28%" class="img-narrow"></p>
<h2 id="complete-code-solution">Complete code solution<a class="heading-anchor" href="#complete-code-solution" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Below is the full CSS code referenced in this blog post. Feel free to copy and use it in your projects.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">vh</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">// gives us the full screen-size height</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.face</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">grid</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  place-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#B392F0">  .eye</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">64</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">80</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">30</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    overflow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">hidden</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> { </span><span style="color:#6A737D">// iris</span></span>
<span class="line"><span style="color:#85E89D">      content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">28</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">28</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    } </span><span style="color:#6A737D">// end of before</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#B392F0">::after</span><span style="color:#E1E4E8"> { </span><span style="color:#6A737D">// eyelid</span></span>
<span class="line"><span style="color:#85E89D">      content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">      /* takes the same width as the eye (width: 64px;)</span></span>
<span class="line"><span style="color:#6A737D">      in order to cover the whole eye when blinking */</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#6A737D">      /* we need 0 initial height - as our starting point before the</span></span>
<span class="line"><span style="color:#6A737D">      animation runs */</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">30</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> -2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">      /* here we add our "blink" animation since this is the</span></span>
<span class="line"><span style="color:#6A737D">      html part (:after - blinking) we want to make animate.</span></span>
<span class="line"><span style="color:#6A737D">      We want the animation to repeat every 4 seconds forever.</span></span>
<span class="line"><span style="color:#6A737D">      */</span></span>
<span class="line"><span style="color:#79B8FF">      animation</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">blink</span><span style="color:#79B8FF"> 4</span><span style="color:#F97583">s</span><span style="color:#79B8FF"> infinite</span><span style="color:#79B8FF"> ease-in</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    } </span><span style="color:#6A737D">// end of after</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#FFAB70">--left</span><span style="color:#E1E4E8"> { </span><span style="color:#6A737D">// position of left eye</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-10</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> { </span><span style="color:#6A737D">// position of left iris</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">8</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">12</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#FFAB70">--right</span><span style="color:#E1E4E8"> { </span><span style="color:#6A737D">// position of right eye</span></span>
<span class="line"><span style="color:#79B8FF">      right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">10</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> { </span><span style="color:#6A737D">// position of right iris</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">8</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">12</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">// end of eye</span></span>
<span class="line"><span style="color:#B392F0">  .eyebrow</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">70</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">solid</span><span style="color:#79B8FF"> 4</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> transparent</span><span style="color:#79B8FF"> transparent</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%/</span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#FFAB70">--left</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">10</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#FFAB70">--right</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-10</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">/* end of eyebrow */</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">// end of face</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">@keyframes</span><span style="color:#B392F0"> blink</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#B392F0">  0%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  30%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  33%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  40%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  70%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  75%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  78%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  81%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  84%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  100%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/keyframes-in-css-explained-make-your-animations-stand-out/">CSS Keyframes Animation Explained</a></li>
<li><a href="/how-to-make-a-css-shine-effect-animation/">How To Make a CSS Shine Effect Animation</a></li>
<li><a href="/html-for-blinking-text-simple-copy-paste-code/">HTML for Blinking Text – Simple Copy &#x26; Paste Code</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Deploy a Next.js App with Render.com</title>
      <link>https://littlecodingthings.com/how-to-deploy-a-next-js-app-with-render-com-2024/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-deploy-a-next-js-app-with-render-com-2024/</guid>
      <pubDate>Sun, 15 Sep 2024 09:55:00 GMT</pubDate>
      <description>Deploy a Next.js app to Render.com step by step: connect GitHub, configure the web service, start the deploy, and add extra repositories later.</description>
      <category>Setup &amp; Tools</category>
      <content:encoded><![CDATA[<p>So you’ve developed your cool Next.js project and now you are ready to deploy it and feel proud for having it live. First of all, kudos on that!! 🤩 After doing some research, you found that <a href="https://render.com" title="Render.com">Render.com</a> is a great choice to deploy a Next.js app, but you’re not sure how to do it. Let’s learn how to do it together.</p>
<h2 id="create-your-nextjs-app">Create your Next.js app<a class="heading-anchor" href="#create-your-nextjs-app" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>In case you are here and want to start from ground zero then you’ll need to create your app by typing in your terminal</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">npx</span><span style="color:#9ECBFF"> create-next-app@latest</span><span style="color:#9ECBFF"> my-awesome-project</span></span></code></pre></div>
<p>The Next.js setup will start asking some questions regarding your project’s settings. You may choose whatever you like, I made the following choices:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">✔ Would you like to use TypeScript</span><span style="color:#F97583">?</span><span style="color:#E1E4E8"> Yes</span></span>
<span class="line"><span style="color:#E1E4E8">✔ Would you like to use ESLint</span><span style="color:#F97583">?</span><span style="color:#E1E4E8"> Yes</span></span>
<span class="line"><span style="color:#E1E4E8">✔ Would you like to use Tailwind </span><span style="color:#79B8FF">CSS</span><span style="color:#F97583">?</span><span style="color:#E1E4E8"> No</span></span>
<span class="line"><span style="color:#E1E4E8">✔ Would you like to use </span><span style="color:#9ECBFF">'src/'</span><span style="color:#E1E4E8"> directory</span><span style="color:#F97583">?</span><span style="color:#E1E4E8"> Yes</span></span>
<span class="line"><span style="color:#E1E4E8">✔ Would you like to use App Router</span><span style="color:#F97583">?</span><span style="color:#E1E4E8"> Yes</span></span>
<span class="line"><span style="color:#E1E4E8">✔ Would you like to customize the default import </span><span style="color:#B392F0">alias</span><span style="color:#E1E4E8"> (@</span><span style="color:#6A737D">/*)? No</span></span></code></pre></div>
<h2 id="connect-your-project-to-github">Connect your project to GitHub<a class="heading-anchor" href="#connect-your-project-to-github" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>To deploy on Render.com we will be using a GitHub repository so it will now be a good idea to connect our app with one of our repos.</p>
<p>When creating a repository you are given a couple of ways to connect your local project with a remote one. From the ones mentioned in GitHub, since we have our project already initialized, we will be using the “push existing repository” method:</p>
<p><img src="/connect-github-repo.webp" alt="Deploy a next.js app to Render.com:
Commands to push an existing repository from the command line"></p>
<p>When you are done with pushing your changes, you will see all your code on the GitHub repository. Great, let’s proceed with Render.com and the deployment steps.</p>
<h2 id="create-a-rendercom-service">Create a Render.com service<a class="heading-anchor" href="#create-a-rendercom-service" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>If you haven’t done so yet, make sure to sign up for a new account on Render.com. Next, you’ll need to create a new Web service</p>
<p><img src="/render-create-web-service-scaled-1.webp" alt="Deploy a next.js app to Render.com:
New Web service selection on Render.com"></p>
<p>You will be asked to connect your GitHub/GitLab account or add your repo’s URL if it’s a public one. For this post, I’ve selected to connect my GitHub account since, in this case, my GitHub repository is a private one.</p>
<p><img src="/connect-github.webp" alt="Connect your GitHub account or Gitlab in Render.com"></p>
<p>When creating your service, choose to deploy from a GitHub repository</p>
<p><img src="/render-deploy-method.webp" alt="Select to deploy from a Git repository"></p>
<p>The next step would be to decide whether you’ll give access to <strong>all</strong> your repositories or just <strong>the</strong> <strong>one</strong> used by your project.</p>
<p><img src="/render-select-repos.webp" alt="Directions from Render.com to install Render on all your repos or one of them"></p>
<p>The choice is yours, but I decided to grant access only to the one I’m deploying.</p>
<p>If you followed my choice, the next step is to choose your repository in the “<strong>Connect a repository</strong>” section. Click “<strong>Connect</strong>” where it mentions your repository name. Now that it’s connected, let’s continue to adjust our service settings. We’re getting much closer to deploying our awesome Next.js app!</p>
<h2 id="web-service-settings">Web Service settings<a class="heading-anchor" href="#web-service-settings" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Before your first deployment starts you will need to choose your deployment settings based on your project characteristics. Because of this, keep in mind that our choices may differ. Let’s see the available options in few details:</p>
<p><img src="/render-config-proj-2.webp" alt="Deploy a next.js app to Render.com:
Web service setting part 1"></p>
<p><strong>Name</strong>
Your project’s name is just a label to differentiate this service from your other Render.com services.</p>
<p><strong>Region</strong>
As clearly described, this is your server’s location.</p>
<p><strong>Branch</strong>
Your repository’s central branch. GitHub typically uses <strong>main</strong> as the default branch, but in older projects, you might encounter <strong>master</strong> being used as well.</p>
<p><strong>Root Directory</strong>
This, as mentioned, is optional. If you have built your project with <a href="#create-your-nextjs-app" title="the same setup options as I did,">the same setup options as I did,</a> Next.js will have added a <code>src</code> root folder, so you’ll need to mention that here.</p>
<p>Let’s check the rest of the options provided:</p>
<p><img src="/render-config-proj-1.webp" alt="Deploy a next.js app to Render.com:
Web service setting part 2"></p>
<p><strong>Runtime</strong>
The runtime environment your service will be using, I am guessing this will be Node for you too, but of course, change it accordingly if necessary.</p>
<p><strong>Build Command</strong>
You might see here the default option <code>yarn; yarn build</code>, if you are using <code>yarn</code> manager then leave it as is, my package manager choice was <code>npm</code> so I had to change it.</p>
<p><strong>Start Command</strong>
Same as the build command, the default prefilled option is <code>yarn start</code>, I have added <code>npm start</code>.</p>
<p>Don’t forget to select the <strong>Free</strong> instance type option so that you’re not charged for this service unless you have other plans in which case, you know better! 😎</p>
<p>Don’t worry if you are not sure about any of these settings, you can change them later.</p>
<p>At the bottom of your screen, hit “<strong>Create Web Service</strong>” to get this show on the road!</p>
<h2 id="start-deployment">Start deployment<a class="heading-anchor" href="#start-deployment" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>By default when a new Service is created, Render.com will start its deployment process based on the last commit you have pushed to your <code>main</code> branch (or the branch you’ve selected as your main one).</p>
<p>If your initial deployment went smoothly, you should see something like this:</p>
<p><img src="/render-success-deploy.webp" alt="Successfull deployment logs"></p>
<p>In that case… congratulations!! 🥳🥳 To see your deployed app, underneath your service’s name, you’ll see a link, click that and you’ll get redirected to your app’s URL.</p>
<p><img src="/render-service-link.webp" alt="Deploy a next.js app to Render.com:
Selecting your deployed service&#x27;s url"></p>
<p>However, if you weren’t as lucky as I was 😕, you might be greeted by a not-so-pleasant red message saying “<strong>Build failed</strong>“. This being my first time working with deployment on a platform like Render.com, it was quite challenging to figure out why a straightforward Next.js project, without any complex configurations, failed to deploy.</p>
<p>So, if you’ve faced a similar situation,I’ve shared my findings on <a href="/why-did-your-new-next-js-deployment-fail-on-render-com/">why my Render.com deployment failed</a>, and I sincerely hope they come in handy and ease your frustrations.</p>
<h2 id="adding-extra-repositories-to-rendercom">Adding extra repositories to Render.com<a class="heading-anchor" href="#adding-extra-repositories-to-rendercom" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>If you initially connected only one repository to Render.com and you’re looking to create an additional Web Service, you’ll notice that you have only that repository as the sole available option for connecting your new service.</p>
<p>To fix that, you don’t have to disconnect your GitHub account and reconnect it to Render. You need to visit your GitHub account, go to <strong>Settings</strong> -> <strong>Applications,</strong> and click Configure in your Render application.</p>
<p><img src="/configure-render-scaled-1.webp" alt="Deploy a next.js app to Render.com:
Add an extra repo to your Render.com through GitHub" style="max-width:83%" class="img-narrow"></p>
<p>On the middle-bottom of your page, you’ll see the “<strong>Only select repositories</strong>” option, click on “<strong>Select repositories</strong>“, select the repository you would like to add for Render.com to use, and click “<strong>Save</strong>“.</p>
<p><img src="/render-add-repos.webp" alt="Deploy a next.js app to Render.com:
Select the repo to add to Render app"></p>
<p>Go back to Render.com and you’ll be able to use this repo now.</p>
<p>Awesomeness!! 🥳</p>]]></content:encoded>
    </item>
    <item>
      <title>Why Your Next.js Deploy Fails on Render</title>
      <link>https://littlecodingthings.com/why-did-your-new-next-js-deployment-fail-on-render-com/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/why-did-your-new-next-js-deployment-fail-on-render-com/</guid>
      <pubDate>Fri, 13 Sep 2024 12:36:00 GMT</pubDate>
      <description>A brand new Next.js app fails to deploy on Render.com because of the default build settings. Here is the cause, and the change that gets it live.</description>
      <category>Setup &amp; Tools</category>
      <content:encoded><![CDATA[<p>My new Next.js app got a deployment fail on Render.com, and if you faced the same issue, you understand my frustration. I mean, why did a new Next.js project failed to deploy? I did nothing exotic, all I did was type <code>npx create-next-app@latest frontend</code> and <a href="/how-to-deploy-a-next-js-app-with-render-com-2024/" title="follow all the basic steps needed to deploy to Render.com">follow all the basic steps needed to deploy to Render.com</a>.</p>
<h2 id="why-did-the-deployment-fail">Why did the deployment fail?<a class="heading-anchor" href="#why-did-the-deployment-fail" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Long story short, you deployed an app and didn’t define the node version your deployment service (Render) will use.</p>
<p>Even though you’ve built your project successfully on your local environment, that doesn’t mean Render.com will be able to do the same, since it might be using different software versions.</p>
<p>Now hang on a minute…you are correct to assume that since you’ve specified all necessary versions through your <code>package.json</code> file you are ready, and Render.com should follow these specifications. However, if you find yourself here, it’s likely because something is still missing or not properly defined. 😇</p>
<p>Okay, what wasn’t defined then? If you are experiencing the exact same issue as I did, your <code>node</code> version wasn’t defined in your <code>package.json</code> file.</p>
<p>Check your local node version by typing</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>node -v</span></span></code></pre></div>
<p>My local node version was <code>18.18.2</code>.</p>
<p>The problem is that Render was building with a completely different one. When this post was first written, Render’s <a href="https://render.com/docs/node-version" title="Render.com docs -  default node version">default Node version</a> was far older than mine and the build fell over on syntax my local Node was perfectly happy with.</p>
<p><strong>Worth updating that detail, because it has flipped:</strong> Render’s default has moved on considerably — services created since April 2026 default to Node 24. So today the mismatch usually runs the other way, with Render on a <em>newer</em> Node than your laptop. The failure looks the same and the fix is identical. Either way, the lesson is the one that matters: <strong>don’t let the default decide.</strong> Pin the version, and your build stops depending on what your host happened to change this quarter.</p>
<p>To verify this is the issue with your deployment, you can check your last deployment logs. Somewhere in the beginning you will see Render mentioning the node version it uses:</p>
<p><img src="/render-failed-deploy-logs-e1716818178356.webp" alt="Deployment fail on Render.com: Failing logs because of default node version"></p>
<h2 id="deploying-successfully">Deploying successfully<a class="heading-anchor" href="#deploying-successfully" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>To resolve this problem, we just need to follow a few simple steps. Don’t be afraid; in just a couple of minutes, you’ll be so proud of your deployed app!</p>
<p>The first step is to add in <code>package.json</code> the npm <a href="https://docs.npmjs.com/cli/v10/configuring-npm/package-json#engines" title="npm docs - engine property">engine property</a> and state our node’s version</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>  "scripts": {</span></span>
<span class="line"><span>    "dev": "next dev",</span></span>
<span class="line"><span>    "build": "next build",</span></span>
<span class="line"><span>    "start": "next start",</span></span>
<span class="line"><span>    "lint": "next lint"</span></span>
<span class="line"><span>  },</span></span>
<span class="line"><span>  "engines": {</span></span>
<span class="line"><span>    "node": "18.18.2"</span></span>
<span class="line"><span>  },</span></span></code></pre></div>
<p>Although I haven’t read this elsewhere (so far) since we modified <code>package.json</code>, I like to run <code>npm install</code> to also generate the updated <code>package-lock.json</code>. This way I can include both package files in my commit.</p>
<p>Render’s docs say to always include an upper bound in that range, so <code>">=18.18.2 &#x3C;19"</code> is safer than an open-ended <code>">=18.18.2"</code>.</p>
<p>We’ll also add two small files. Each one contains a single line — just the version number, nothing else:</p>
<p><strong><code>.nvmrc</code></strong></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>18.18.2</span></span></code></pre></div>
<p><strong><code>.node-version</code></strong></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>18.18.2</span></span></code></pre></div>
<p>Get those filenames exactly right, because a typo here fails silently — Render doesn’t warn you about a file it never found, it just carries on with the default and you’re back where you started. It’s <code>.nvmrc</code> (no second <code>r</code>, and it stands for <em>node version manager rc</em>), and <code>.node-version</code> with a <strong>hyphen</strong>, not an underscore.</p>
<p><strong>Both files belong at the root of your repository</strong>, next to <code>package.json</code> — not inside <code>src/</code>, even if your Next.js app keeps its code there.</p>
<p>The final step is to include a new environment variable on Render.com. Simply go to the Environment section of your service, and there you can add it by using <code>NODE_VERSION</code> as the key and setting its value to <code>18.18.2</code>.</p>
<p>We are ready now! Commit and push your applied changes to the remote GitHub repo and a new deployment will be triggered automatically. Voila!</p>
<p><img src="/render-success-deploy.webp" alt="Deployment fail on Render.com:
Successfull deployment"></p>
<p>So awesome to see successful deployments!! 😎</p>
<h2 id="wait--why-four-different-files-for-one-version-number-">Wait — why four different files for one version number? 🤨<a class="heading-anchor" href="#wait--why-four-different-files-for-one-version-number-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Fair question, and the answer is that Render checks several places and uses the first one it finds. Its documented order of precedence is:</p>
<table>
<thead>
<tr>
<th scope="col">Priority</th>
<th scope="col">Where</th>
<th scope="col">Notes</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>The <code>NODE_VERSION</code> environment variable</td>
<td>Set in the Render dashboard. Beats everything else.</td>
</tr>
<tr>
<th scope="row">2</th>
<td><code>.node-version</code></td>
<td>A single line, at the repo root.</td>
</tr>
<tr>
<th scope="row">3</th>
<td><code>.nvmrc</code></td>
<td>Same format, same place.</td>
</tr>
<tr>
<th scope="row">4</th>
<td><code>engines</code> in <code>package.json</code></td>
<td>A range. Include an upper bound.</td>
</tr>
</tbody>
</table>
<p>You don’t strictly need all four. I set them anyway, because each one is read by a different tool: <code>.nvmrc</code> is what <strong>nvm</strong> picks up when a teammate types <code>nvm use</code>, <code>engines</code> is what <strong>npm</strong> warns on, and <code>NODE_VERSION</code> is what Render reads first. The same number everywhere means every tool in the chain agrees.</p>
<p>The trap comes when they <em>disagree</em>. If <code>NODE_VERSION</code> in the dashboard says 18 and your <code>.nvmrc</code> says 22, Render uses 18 and your <code>.nvmrc</code> looks like it’s being ignored — because it is. When a version change doesn’t take effect, check the dashboard environment variable first, since it silently outranks everything in your repo.</p>
<h2 id="reading-the-build-log-properly">Reading the build log properly<a class="heading-anchor" href="#reading-the-build-log-properly" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Everyone scrolls to the end of a failed log, where the error is. Scroll to the <strong>top</strong> instead: in the first few lines Render prints the Node version it decided to use, and comparing that to your local <code>node -v</code> answers the version question in about two seconds.</p>
<p>The other habit worth building is reading the <em>first</em> error rather than the last. A failed build produces a cascade, and the final twenty lines are usually consequences of something that went wrong much earlier.</p>
<p>That advice covers the build log, but the runtime log is a different problem: once your app is actually up, plain <code>console.log</code> output gives you no timestamps, no levels and nothing you can filter. Adding <a href="/how-to-set-up-pino-logging-in-next-js/">structured logging with Pino</a> makes those lines searchable, which matters a lot more at 2am than it does while everything is working.</p>
<h2 id="other-reasons-a-fresh-nextjs-deploy-dies-on-render">Other reasons a fresh Next.js deploy dies on Render<a class="heading-anchor" href="#other-reasons-a-fresh-nextjs-deploy-dies-on-render" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>If your versions match and it still fails, these are the usual suspects — in the order I’d check them.</p>
<h3 id="your-mac-ignores-capital-letters-linux-does-not-">Your Mac ignores capital letters, Linux does not 🔠<a class="heading-anchor" href="#your-mac-ignores-capital-letters-linux-does-not-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>This one catches nearly everybody once. macOS uses a case-insensitive filesystem by default; Render builds on Linux, which is case-sensitive.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">// The file on disk is components/Button.js</span></span>
<span class="line"><span style="color:#F97583">import</span><span style="color:#E1E4E8"> Button </span><span style="color:#F97583">from</span><span style="color:#9ECBFF"> './components/button'</span></span></code></pre></div>
<p>That runs perfectly on your machine and fails on Render with a module-not-found error naming a file that is <em>obviously right there</em>. Check the capitalisation of the import against the actual filename, character by character. Git may not even show the rename if you only changed the case, which is what makes it so maddening.</p>
<h3 id="a-build-tool-that-lives-in-devdependencies">A build tool that lives in <code>devDependencies</code><a class="heading-anchor" href="#a-build-tool-that-lives-in-devdependencies" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>If your build runs with <code>npm ci --omit=dev</code>, everything in <code>devDependencies</code> is absent when <code>next build</code> runs. TypeScript, Tailwind and PostCSS are the ones that most commonly end up on the wrong side of that line. Our post on <a href="/do-you-still-need-to-use-save-on-npm-install/">whether you still need <code>npm install --save</code></a> covers which packages belong where.</p>
<h3 id="a-missing-environment-variable-at-build-time">A missing environment variable at build time<a class="heading-anchor" href="#a-missing-environment-variable-at-build-time" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Next.js reads <code>NEXT_PUBLIC_</code> variables during the build, not at runtime. If one is only defined on your laptop’s <code>.env.local</code>, the build either fails or — worse — succeeds with an undefined value baked into the bundle. Add them in Render’s Environment section before deploying, not after the first failure.</p>
<h2 id="frequently-asked-questions">Frequently asked questions<a class="heading-anchor" href="#frequently-asked-questions" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<h3 id="how-do-i-know-which-node-version-render-is-using">How do I know which Node version Render is using?<a class="heading-anchor" href="#how-do-i-know-which-node-version-render-is-using" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>The top of the build log states it. You can also confirm what your service resolved to by checking the <code>NODE_VERSION</code> environment variable in the dashboard — if it isn’t set, Render fell back to a file in your repo or to its own default.</p>
<h3 id="should-i-pin-an-exact-node-version-or-a-range">Should I pin an exact Node version or a range?<a class="heading-anchor" href="#should-i-pin-an-exact-node-version-or-a-range" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Pin an exact version in <code>.nvmrc</code> and <code>.node-version</code>, and use a range with an upper bound in <code>engines</code> — Render’s docs specifically ask for that upper bound. An open-ended <code>">=18"</code> is an invitation for a future major release to break your build without you changing a line.</p>
<h3 id="my-build-succeeds-but-the-app-wont-start--is-that-the-same-problem">My build succeeds but the app won’t start — is that the same problem?<a class="heading-anchor" href="#my-build-succeeds-but-the-app-wont-start--is-that-the-same-problem" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>No, that’s a different stage and a different fix. A build failure happens while <code>next build</code> runs; a start failure happens after. The most common cause there is the start command — a Next.js app needs to be a <strong>Web Service</strong> on Render, not a Static Site, and it needs to listen on the port Render gives it rather than a hardcoded 3000.</p>
<h3 id="do-i-need-to-redeploy-after-changing-an-environment-variable">Do I need to redeploy after changing an environment variable?<a class="heading-anchor" href="#do-i-need-to-redeploy-after-changing-an-environment-variable" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Yes — they’re read when the service builds and starts. Changing <code>NODE_VERSION</code> and then wondering why the log still shows the old version is a rite of passage.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-deploy-a-next-js-app-with-render-com-2024/">How to Deploy a Next.js App with Render.com</a></li>
<li><a href="/do-you-still-need-to-use-save-on-npm-install/">Do You Still Need npm install --save?</a></li>
<li><a href="/environment-variables-101-secure-your-secrets-like-a-pro/">Environment Variables with Dotenv</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>CSS backdrop-filter: grayscale()</title>
      <link>https://littlecodingthings.com/grayscale-backdrop-filter-a-useful-tool-to-make-grayish-backgrounds/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/grayscale-backdrop-filter-a-useful-tool-to-make-grayish-backgrounds/</guid>
      <pubDate>Mon, 09 Sep 2024 09:00:00 GMT</pubDate>
      <description>backdrop-filter: grayscale() desaturates what is behind an element, leaving its own content untouched. Worked example plus a value table.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hello there! 😃 In CSS, we have a really helpful property called <code>backdrop-filter</code>. It’s like a special filter that applies grayish shades to the backgrounds. A useful tool when we want to focus on a part of the webpage without changing the actual element itself. Mm… 🤔 that is a little bit tricky! Isn’t it? Let’s grab a cup of coffee ☕ and move forward! We will clarify everything in this post about using a grayscale backdrop filter. 👩‍💻</p>
<h2 id="how-the-backdrop-filter-works">How the backdrop filter works<a class="heading-anchor" href="#how-the-backdrop-filter-works" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>So, how does this property really work? We will begin by setting the <code>backdrop-filter</code> property to <a href="/awesome-css-grayscale-filter-how-to-upgrade-images/"><code>grayscale(percentage)</code></a>, where the percentage determines the intensity of the grayscale effect, ranging from 0% to 100%. A value of 100% turns the color into a complete grayscale color, while a value of 0% will keep the element’s original color shades without any grayscale effect.</p>
<p>This CSS property is not quite noticeable on <strong>black</strong> or <strong>white</strong> backgrounds because it adds shades of gray, and black is already the darkest shade while white is the lightest one. In simpler words, black and white will not get converted to grayscale because it already belongs to the darkest side of grayscale.</p>
<p>For the filter to work properly, as a first step, we need to set the <code>background-color</code> property of the parent element. Afterward, we add the backdrop filter to the child elements we want to apply the grayscale effect. The backdrop filter will only affect the child element’s background color but not its content, text, images, etc.</p>
<p>As a result, the parent element maintains its original background color, while the child element’s background is desaturated, creating a monochromatic, grayscale effect.</p>
<h2 id="create-a-grayscale-backdrop-filter-effect">Create a grayscale backdrop filter effect<a class="heading-anchor" href="#create-a-grayscale-backdrop-filter-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>This HTML and CSS code below creates a <code>&#x3C;section></code> element (father) with a <code>&#x3C;p></code> element (child) inside. The section has a background color in a shade of pinkish peach, defined by the hex color code <code>#f99bab</code>. The paragraph has no background of its own, so the section’s color is what shows through it.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">section</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>...&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">section</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* PARENT ELEMENT */</span></span>
<span class="line"><span style="color:#85E89D">section</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#f99bab</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* a shade of pinkish peach */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/* CHILD ELEMENT */</span></span>
<span class="line"><span style="color:#85E89D">p</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  backdrop-filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">grayscale</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>We continue with the <code>&#x3C;p></code> element styled by a <code>backdrop-filter</code> with a grayscale value of 50%. This effect visually desaturates whatever is painted behind the paragraph — here, the <code>section</code>’s background. This means that the colors where the backdrop filter is applied (the area behind the element) will be desaturated to 50%. As a result, a grayscale effect will be applied where the colors are halfway between their original color and grayscale while leaving the content unaffected.</p>
<p>In simple terms, by setting this code, we create a parent element with a shade of pinkish peach-colored background, and its child element has a somewhat muted, desaturated appearance while at the same time retaining some of the original pink color.</p>
<figure><img src="/backdrop-grayscale-without-filter.webp" alt="Α p html element inside a section element.  They both have the same background color, a shade of pinkish peach (#f99bab)." style="max-width:55%" class="img-narrow"><figcaption>without grayscale</figcaption></figure>
<figure><img src="/backdrop-grayscale-with-filter.webp" alt="Α p html element inside a section element. Its background color is a shade of pinkish peach (#f99bab). The child emelent had the backdrop-filter: grayscale(50%) CSS property which means the background color is a shade of pinkish peach desaturated  by 50%." style="max-width:55%" class="img-narrow"><figcaption>with grayscale(50%)</figcaption></figure>
<h2 id="a-grayscale-themed-table">A grayscale-themed table<a class="heading-anchor" href="#a-grayscale-themed-table" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Below, I have included a table that visually presents some possible variations of the grayscale backdrop filter effect. 😃</p>
<p><img src="/backdrop-grayscale-filter-table.webp" alt="Α table with different grayscales in each row. We have a zero grayscale, a 20%, 40%, 60% and finally 100%." style="max-width:53%" class="img-narrow"></p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/introduction-to-the-powerful-css-blur-effect/">Introduction To The Powerful CSS Blur Effect</a></li>
<li><a href="/awesome-css-grayscale-filter-how-to-upgrade-images/">CSS Grayscale Filter – A Complete Guide</a></li>
<li><a href="/simple-ways-to-create-a-css-overlay-effect/">Simple Ways to Create a CSS Overlay Effect</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How To Calculate CSS Line Height</title>
      <link>https://littlecodingthings.com/how-to-calculate-css-line-height/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-calculate-css-line-height/</guid>
      <pubDate>Wed, 04 Sep 2024 10:05:00 GMT</pubDate>
      <description>How line-height sets the space above and below a line of text, what normal actually resolves to, and why negative values are ignored.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hello there! 😃 Today, we’ll explore how we can calculate the CSS line height property, which defines the height of a line on a webpage. Each line contains the main content (text) as well as <strong>the space above and below the content</strong> ↕ (<code>line-height</code>). While the default value for desktop browsers is 1.2, we should keep in mind that it can vary depending on the font family. We can also set a custom <code>line-height</code> according to our preferences.</p>
<p>⛔ Please note that the system does not accept negative values. The default value will be automatically used if a negative value is entered.</p>
<p>Below, I have drafted a plan that might help you understand things better. Check it out:</p>
<p><img src="/css-line-height-plan.webp" alt="An image depicting a box with the phrase &#x22;Hello World&#x22;, demonstrating the concept of line height in CSS" style="max-width:69%" class="img-narrow"></p>
<p>Below is an example to explain this CSS property more analytically.</p>
<h2 id="html-structure-for-css-line-height">HTML structure for CSS line height<a class="heading-anchor" href="#html-structure-for-css-line-height" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We create an <a href="/most-useful-html-elements-for-maximizing-better-results/">HTML</a> document with four headings <code>&#x3C;h1></code> . All headings have the same content (text) but different classes, each with unique characteristics concerning the line-height.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">h1</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"line-height-normal"</span><span style="color:#E1E4E8">>Hello World&#x3C;/</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">h1</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"line-height-1"</span><span style="color:#E1E4E8">>Hello World&#x3C;/</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">h1</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"line-height-2"</span><span style="color:#E1E4E8">>Hello World&#x3C;/</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">h1</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"line-height-negative-value"</span><span style="color:#E1E4E8">>Hello World&#x3C;/</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h2 id="css-structure-for-css-line-height">CSS structure for CSS line height<a class="heading-anchor" href="#css-structure-for-css-line-height" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We will move forward with our <a href="/how-to-work-with-css-syntax-the-correct-way/">CSS</a> code and add the necessary characteristics. The first heading has a class with <code>line-height: normal</code>, the second one has a class with <code>line-height: 200px</code>, the third one has a class with <code>line-height: 300px</code>, and the fourth has a class with <code>line-height: -300px</code> (⛔ negative value). </p>
<p>I am using different <code>background-color</code> for each class to easily distinguish them and notice the results clearly. 😉</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.line-height-normal</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#ffe6cc</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  line-height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">normal</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.line-height-1</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#ffcc99</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  line-height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.line-height-2</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#ffb366</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  line-height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.line-height-negative-value</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#E2964A</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  line-height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>In the image that follows, we can see the differences between the four headings regarding their <code>line-height</code> ↕.</p>
<p><img src="/line-height-example.webp" alt="Four examples of the content and the CSS line-height property." style="max-width:62%" class="img-narrow"></p>
<p>Utilizing the line-height CSS property can significantly improve text clarity and visual appeal, creating a comfortable reading experience for users. ✨ 😃</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/css-letter-spacing-working-on-the-correct-way/">CSS Letter Spacing – Working on The Correct Way</a></li>
<li><a href="/css-word-spacing-how-to-do-it-right/">CSS Word Spacing – How to Do It Right</a></li>
<li><a href="/what-is-the-css-box-model-in-simple-terms/">What Is the CSS Box Model in Simple Terms</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>The CSS nth-child Selector Explained</title>
      <link>https://littlecodingthings.com/what-you-need-to-know-about-css-nth-child-selector-a-practical-guide/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/what-you-need-to-know-about-css-nth-child-selector-a-practical-guide/</guid>
      <pubDate>Thu, 29 Aug 2024 08:00:00 GMT</pubDate>
      <description>Every :nth-child() pattern worked out on the same seven elements — odd, even, 3n, n+3, -n+3, ranges and counting backwards.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>The CSS nth child selector is an extremely useful tool for <strong>targeting and styling the nth element</strong> within a group of similar <a href="/most-useful-html-elements-for-maximizing-better-results/" title="HTML elements">HTML elements</a> on a webpage. It’s really handy for organizing your code and helps you pick elements based on their position in a sequence. It’s also part of a larger group of <a href="/coding-made-easy-with-css-selectors-an-ultimate-guide/" title="selectors">selectors</a>.</p>
<p>You can apply specific styles like color or size to just that nth item or to combinations with the nth item in a list or group, making it different from all the others.</p>
<p>The “nth” is a mathematical term that refers to any <strong>position in a list or sequence</strong>, such as the first, second, third, and so on. A sequence is a set of numbers or elements that follow a particular pattern or rule.</p>
<p>Below are examples of utilizing this selector. Let’s proceed and explore its uses in more detail. 🧐</p>
<p>We will use the same HTML code snippet for all instances. We have seven child elements inside our body element. Each one represents an ice cream cone. Yes! You read correctly! An ice cream cone! Let’s make our learning a bit fun! <em>The empty cones remain unaffected, while the cones that have ice cream strawberry</em> 🍓 <em>flavor</em> 🍦 <em>on top are styled based on the</em> <code>nth-child()</code> <em>selector</em>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>First child element&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>Second child element&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>Third child element&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>Fourth child element&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>Fifth child element&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>Sixth child element&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>Seventh child element&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p>Let’s imagine that what you see below would be rendered on the screen if each <code>div</code> child element was actually a cone.</p>
<p><img src="/nth-child-selector-sample-for-ice-creams.webp" alt="The CSS nth-child() selector. Seven ice cream cones side by side." style="max-width:56%" class="img-narrow"></p>
<h2 id="styling-the-first-element-with-nth-child1">Styling the first element with nth-child(1)<a class="heading-anchor" href="#styling-the-first-element-with-nth-child1" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The <code>nth-child(1)</code> selector targets and styles only the first element. So, in our case, we add ice cream strawberry 🍓 flavor 🍦 only to the top of the first cone. All the other cones remain unaffected.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">div</span><span style="color:#B392F0">:nth-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/nth-child-selector-first-child.webp" alt="Seven ice cream cones one next to other. The first cone has ice cream strawberry flavor.  All the others remain unaffected. We set the css nth-child(1) selector." style="max-width:56%" class="img-narrow"></p>
<p>* <em>If we want to target the third child, use</em> <code>:nth-child(3)</code><em>, and similarly for other positions</em>.</p>
<p><img src="/nth-child-selector-third-child.webp" alt="Seven ice cream cones one next to other. The third cone has ice cream strawberry flavor.  All the others remain unaffected. We set the css nth-child(3) selector." style="max-width:56%" class="img-narrow"></p>
<h2 id="styling-only-the-last-element-with-nth-last-child1">Styling only the last element with nth-last-child(1)<a class="heading-anchor" href="#styling-only-the-last-element-with-nth-last-child1" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The <code>nth-last-child(1)</code> selector targets and styles only the last element as it <em>counts backward</em>. That’s why we added the word <code>last</code> in our selector. So that it will pick the first <code>(1)</code> element <strong>from the end</strong> <strong>of the list</strong>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">div</span><span style="color:#B392F0">:nth-last-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/nth-child-selector-last-child.webp" alt="Seven ice cream cones one next to other. The last cone has ice cream strawberry flavor.  All the others remain unaffected. We set the css nth-last-child(1) selector." style="max-width:56%" class="img-narrow"></p>
<p>* <em>If we want to pick the fourth child from the end, we set the</em> <code>:nth-last-child(4)</code>, <em>etc</em>.</p>
<p><img src="/nth-child-selector-fourt-child-from-the-end.webp" alt="Seven ice cream cones one next to other. The fourh cone counting backward has ice cream strawberry flavor.  All the others remain unaffected. We set the css nth-last-child(4) selector." style="max-width:56%" class="img-narrow"></p>
<h2 id="select-all-elements-apart-from-the-last-one">Select all elements apart from the last one<a class="heading-anchor" href="#select-all-elements-apart-from-the-last-one" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Combining the <code>nth-last-child</code> selector with the <code>:not()</code> pseudo-class, we can target and style all elements apart from the last one. That’s why, in this example, we added the word <code>:not</code> and then the word <code>last</code> in our selector, indicating we wanted all but <em>not the last one</em> <code>(1)</code>. 🤔</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">div</span><span style="color:#B392F0">:not</span><span style="color:#E1E4E8">(</span><span style="color:#B392F0">:nth-last-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">)) {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/nth-child-selector-selects-all-elements-apart-from-the-last.webp" alt="Seven ice cream cones one next to other. The last one remain unaffected.  All the others have ice cream strawberry flavor. We set the css :not(:nth-last-child(1)) selector." style="max-width:56%" class="img-narrow"></p>
<p>*<em>If we want to pick all elements apart from the first one we can erase the</em> <code>last</code> <em>word and set the</em> <code>:not(:nth-child(1))</code> <em>etc</em>.</p>
<p><img src="/nth-child-selector-not-the-first-child.webp" alt="Seven ice cream cones one next to other. The first one remain unaffected.  All the others have ice cream strawberry flavor. We set the css :not(:nth-child(1)) selector." style="max-width:56%" class="img-narrow"></p>
<h2 id="target-every-odd-child-element">Target every odd child element<a class="heading-anchor" href="#target-every-odd-child-element" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Using the word “odd” in our <code>nth-child</code> selector we can target and style every other element, specifically the 1st, 3rd, 5th, 7th and so on</p>
<p>*<em>Odd numbers are those that, when divided by 2, always leave a remainder of 1</em>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">div</span><span style="color:#B392F0">:nth-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">odd</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/nth-child-selector-odd-children.webp" alt="Seven ice cream cones one next to other. The 1st, 3rd, 5th and last have ice cream strawberry flavor.  All the others remain unaffected. We set the css nth-child(odd) selector." style="max-width:56%" class="img-narrow"></p>
<h2 id="target-every-even-child-element">Target every even child element<a class="heading-anchor" href="#target-every-even-child-element" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Just as we did for odd elements, we can also target even elements by using the keyword “even” in our <code>nth-child</code> selector. This allows us to style every second element, specifically the 2nd, 4th, 6th, and so on</p>
<p>*<em>Even numbers are those that can be divided by 2 and leave no remainder</em>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">div</span><span style="color:#B392F0">:nth-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">even</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/nth-child-selector-even-children.webp" alt="Seven ice cream cones one next to other. The 2nd, 4th and 6th clouds  have ice cream strawberry flavor. All the others remain unaffected. We set the css nth-child(even) selector." style="max-width:56%" class="img-narrow"></p>
<h2 id="advanced-math-tricks-with-css-nth-child-selector">Advanced math tricks with CSS nth child selector<a class="heading-anchor" href="#advanced-math-tricks-with-css-nth-child-selector" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The <code>nth-child()</code> selector offers great flexibility, allowing us to create combinations that target multiple child elements simultaneously.</p>
<h3 id="selecting-elements-based-on-multiplying-by-the-nth-child">Selecting elements based on multiplying by the nth-child()<a class="heading-anchor" href="#selecting-elements-based-on-multiplying-by-the-nth-child" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>By using <code>nth-child(3n)</code> we target every third element. In this example, the 3rd element is the first one selected. From there, we move three steps forward to the next target, which is the 6th element.</p>
<p>The <code>n</code> in <code>3n</code> starts at <code>0</code> and increases incrementally with each integer (0, 1, 2, 3…).
By multiplying <code>n</code> by <code>3</code> we target elements at positions that are multiples of 3 (3, 6, 9…).</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">div</span><span style="color:#B392F0">:nth-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">3n</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/nth-child-selector-every-x-child.webp" alt="Seven ice cream cones one next to other. The 3rd and 6th have ice cream strawberry flavor. All the others remain unaffected. We set the css nth-child(3n) selector." style="max-width:56%" class="img-narrow"></p>
<h3 id="select-elements-based-on-multiplies-with-the-nth-child-counting-backward">Select elements based on multiplies with the nth-child(), counting backward<a class="heading-anchor" href="#select-elements-based-on-multiplies-with-the-nth-child-counting-backward" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>When using the <code>nth-last-child(3n)</code>selector we target every third element, but this time, it starts counting from the end. In our case, we have seven elements. Starting counting from the 7th one, the 5th element is the first we pick. Then we continue by taking three steps backward to the second choice, which is the 2nd element.</p>
<p>The <code>n</code> in <code>3n</code> starts at <code>0</code> and increases incrementally with each integer (0, 1, 2, 3…).
The number <code>3</code> we assign to <code>n</code> shows multiplies of it, but we also have the <code>last</code> word in our selector, which indicates we start counting from the last child towards the first one.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">div</span><span style="color:#B392F0">:nth-last-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">3n</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/nth-child-selector-every-x-last-child.webp" alt="Seven ice cream cones one next to other. The 3rd and 6th have ice cream strawberry flavor. All the others remain unaffected. We set the css nth-child(3n) selector." style="max-width:56%" class="img-narrow"></p>
<h3 id="pick-elements-that-appear-after-a-specific-point">Pick elements that appear after a specific point<a class="heading-anchor" href="#pick-elements-that-appear-after-a-specific-point" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>This one seems more complicated. 😰 Let’s analyze it a bit more! 🧐</p>
<p>When using the <code>nth-child(n + 3)</code> selector, we are targeting the third element and all subsequent elements. If we use <code>n + 5</code>, it would start counting from the fifth element onward, <strong>including the fifth element itself</strong>, and continue until the end.</p>
<p>The <code>(n)</code> starts at <code>0</code> and increases incrementally with each integer (0, 1, 2, 3…).
The <code>(+ 3)</code> means that the selector starts matching from the 3rd element onward.</p>
<p>Here’s how <code>n</code> works under the hood:</p>
<p><code>n=0</code> selects the 3rd element (<code>0 + 3 = 3</code>).
<code>n=1</code> selects the 4th element (<code>1 + 3 = 4</code>).
<code>n=2</code> selects the 5th element (<code>2 + 3 = 5</code>).
<code>n=3</code> selects the 6th element (<code>3 + 3 = 6</code>).
<code>n=4</code> selects the 7th element (<code>4 + 3 = 7</code>).</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">div</span><span style="color:#B392F0">:nth-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">n + 3</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/nth-child-selector-selects-from-a-specific-element-till-the-end.webp" alt="Seven ice cream cones one next to other. The two first remain unaffected.  From the third all the others till the end have ice cream strawberry flavor. We set the css nth-child(n + 3) selector." style="max-width:56%" class="img-narrow"></p>
<h3 id="select-elements-that-appear-up-to-a-specific-point">Select elements that appear up to a specific point<a class="heading-anchor" href="#select-elements-that-appear-up-to-a-specific-point" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Using <code>nth-child(-n+3)</code>, the selector targets elements up to a specific point, setting a limit to which element will stop. In our case, it picks and styles all the elements up to and including the third element.</p>
<p>The <code>(n)</code> represents <code>0</code>.
The <code>(-n)</code> by itself is not used in CSS selectors because it does not correspond to any valid child positions. However when combined with a positive number (e.g. <code>:nth-child(-n + 3)</code>), it allows to select the child elements up to and <strong>including the specified position</strong>, such as the 3rd child.
The <code>(+ 3)</code> part of the selector means that the selector matches elements up to and including the 3rd element.</p>
<p>Here’s how <code>n</code> works in practice:</p>
<p><code>n=0</code> selects the 3rd element (<code>-0 + 3 = 3</code>).
<code>n=1</code> selects the 2nd element (<code>-1 + 3 = 2</code>).
<code>n=2</code> selects the 1st element (<code>-2 + 3 = 1</code>).
<code>n=3</code> selects no child element (<code>-3 + 3 = 0</code>). 😮</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">div</span><span style="color:#B392F0">:nth-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-n + 3</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/nth-child-selector-selects-from-the-first-till-a-specific-element.webp" alt="Seven ice cream cones one next to other. The three first have ice cream strawberry flavor.  From the fourth and all the other cones till the end remain unaffected. We set the css nth-child(n - 3) selector." style="max-width:56%" class="img-narrow"></p>
<p><code>:nth-child(n + X)</code> targets every element from the Xth onward, ensuring the Xth element is also included.
<strong>WHILE</strong>
<code>:nth-child(-n + X)</code> targets every element up to and including the Xth element.</p>
<h3 id="pick-a-range-of-elements">Pick a range of elements<a class="heading-anchor" href="#pick-a-range-of-elements" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>If we combine the previous two types of the <code>nth-child</code> selector, we can pick and style a portion of elements. In our example, all elements between the 3rd and the 6th element. Both the start (3rd element) and the end (6th element) are included.</p>
<p>The <code>:nth-child(n + 3)</code> selector targets all children starting from the third element onward.</p>
<p>The <code>:nth-child(-n + 6)</code> selector targets all children up to the sixth element.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">div</span><span style="color:#B392F0">:nth-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">n + 3</span><span style="color:#E1E4E8">)</span><span style="color:#B392F0">:nth-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-n + 6</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/nth-child-selector-selects-a-range-of-elements.webp" alt="Seven ice cream cones one next to other. From the third cone up to sixth first have ice cream strawberry flavor. All the other cones (1st, 2nd, 7th) remain unaffected. We set the css nth-child(n + 3):nth-child(-n + 6) selector." style="max-width:56%" class="img-narrow"></p>
<h3 id="select-the-first-element-and-then-every-third-element">Select the first element and then every third element<a class="heading-anchor" href="#select-the-first-element-and-then-every-third-element" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>The <code>n</code> starts at <code>0</code> and increases by <code>1</code> with each step, representing all integer values (0, 1, 2, 3, …)</p>
<p>Using the expression (<code>n + 1</code>) we determine which elements we want to pick.</p>
<p>By applying the multiplier <code>3n</code>, we instruct CSS to target every third element in the sequence.</p>
<p>Combining all those characteristics we get:</p>
<p>When <code>n</code> is <code>0</code>, <code>3n + 1</code> => <code>3 * 0 + 1</code> = <code>1</code>, so it selects the 1st child.
When <code>n</code> is <code>1</code>, <code>3n + 1</code> => <code>3 * 1 + 1</code> = <code>4</code>, so it selects the 4th child.
When <code>n</code> is <code>2</code>, <code>3n + 1</code> => <code>3 * 2 + 1</code> = <code>7</code>, so it selects the 7th child, etc.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">div</span><span style="color:#B392F0">:nth-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">3n + 1</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/nth-child-selector-selects-the-first-and-then-every-third-element.webp" alt="Seven ice cream cones one next to other. From the third cone up to sixth first have ice cream strawberry flavor. All the other cones (1st, 2nd, 7th) remain unaffected. We set the css nth-child(n + 3):nth-child(-n + 6) selector." style="max-width:56%" class="img-narrow"></p>
<h3 id="choose-the-first-element-and-then-every-third-element-counting-backward">Choose the first element and then every third element, counting backward<a class="heading-anchor" href="#choose-the-first-element-and-then-every-third-element-counting-backward" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Same as before, but this time, we start picking elements from the end, as indicated by the word <code>last</code> in our selector.</p>
<p>The <code>n</code> starts at <code>0</code> and increases by <code>1</code> with each step, representing all integer values (0, 1, 2, 3, …)</p>
<p>Using the expression (<code>n + 1</code>) we determine which elements we want to pick.</p>
<p>By applying the multiplier <code>3n</code>, we instruct CSS to target every third element in the sequence.</p>
<p>Let’s see how that works:</p>
<p>When <code>n</code> is <code>0</code>, <code>3n + 1</code> => <code>3 * 0 + 1</code> = <code>1</code>, so it selects the 1st child <strong>from the end</strong> which is the 7th child.
When <code>n</code> is <code>1</code>, <code>3n + 1</code> => <code>3 * 1 + 1</code> = <code>4</code>, so it selects the 4th child.
When <code>n</code> is <code>2</code>, <code>3n + 1</code> => <code>3 * 2 + 1</code> = <code>7</code>, so it selects the 7th child <strong>from the end</strong> which is the 1st child.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">div</span><span style="color:#B392F0">:nth-last-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">3n + 1</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/nth-child-selector-selects-the-first-and-then-every-third-element.webp" alt="Seven ice cream cones one next to other. From the third cone up to sixth first have ice cream strawberry flavor. All the other cones (1st, 2nd, 7th) remain unaffected. We set the css nth-child(n + 3):nth-child(-n + 6) selector." style="max-width:56%" class="img-narrow"></p>
<h3 id="choose-the-second-element-and-then-every-third-element">Choose the second element and then every third element<a class="heading-anchor" href="#choose-the-second-element-and-then-every-third-element" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>The same logic applies as in the previous example, except that in this case, we are using subtraction with the selector <code>3n-1</code></p>
<p>The <code>n</code> starts at <code>0</code> and increases by <code>1</code> with each step, representing all integer values (0, 1, 2, 3, …)</p>
<p>Using the expression (<code>n - 1</code>) we determine which elements we want to pick.</p>
<p>By applying the multiplier <code>3n</code>, we instruct CSS to target every third element in the sequence.</p>
<p>Now that we know what each part does, let’s dive in and see how CSS works when using this selector:</p>
<p>When <code>n</code> is <code>0</code> then <code>3n - 1</code> => <code>3 * 0 - 1</code> = <code>-1</code>, so it selects no child. (I know 🥱)
When <code>n</code> is <code>1</code> then <code>3n - 1</code> => <code>3 * 1 - 1</code> = <code>2</code>, so it selects the 2nd child.
When <code>n</code> is <code>2</code> then <code>3n - 1</code> => <code>3 * 2 - 1</code> = <code>5</code>, so it selects the 5th child, etc.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">div</span><span style="color:#B392F0">:nth-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">3n - 1</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/nth-child-selector-selects-the-second-and-then-every-third-element.webp" alt="Seven ice cream cones one next to other. The 2nd and 5th have ice cream strawberry flavor. All the other cones (1st, 3rd, 4th, 6th and 7th) remain unaffected. We set the css nth-child(3n + 1) selector." style="max-width:56%" class="img-narrow"></p>
<p>Using <code>+</code> or <code>-</code> in the selector may sometimes result in the same outcome. In our example, doing <code>3n+2</code> or <code>3n-1</code>, ends up targeting the second element and then every third element onward. However, it’s important to understand that the underlying logic is different.</p>
<h3 id="select-the-second-element-and-then-every-third-element-counting-backward">Select the second element and then every third element, counting backward<a class="heading-anchor" href="#select-the-second-element-and-then-every-third-element-counting-backward" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Same as before, but this time, we start picking from the end since we have the word <code>last</code> in our selector.</p>
<p>The <code>n</code> starts at <code>0</code> and increases by <code>1</code> with each step, representing all integer values (0, 1, 2, 3, …)</p>
<p>Using the expression (<code>n - 1</code>) we determine which elements we want to pick.</p>
<p>By applying the multiplier <code>3n</code>, we instruct CSS to target every third element in the sequence.</p>
<p>Let’s dive in and see what’s happening:</p>
<p>When <code>n</code> is <code>0</code> then <code>3n - 1</code> => <code>3 * 0 - 1</code> = <code>-1</code>, so it selects no child.
When <code>n</code> is <code>1</code> then <code>3n - 1</code> => <code>3 * 1 - 1</code> = <code>2</code>, so it selects the 2nd child <strong>from the end</strong>.
When <code>n</code> is <code>2</code> then <code>3n - 1</code> => <code>3 * 2 - 1</code> = <code>5</code>, so it selects the 5th child <strong>from the end</strong>, etc.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">div</span><span style="color:#B392F0">:nth-last-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">3n - 1</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/nth-child-selector-every-x-child.webp" alt="Seven ice cream cones one next to other. The 3rd and 6th have ice cream strawberry flavor. All the others remain unaffected. We set the css nth-child(3n) selector." style="max-width:56%" class="img-narrow"></p>
<h2 id="select-all-elements">Select all elements<a class="heading-anchor" href="#select-all-elements" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Although the <code>nth-child()</code> selector is made in order to target specific positions or patterns among children, we can also use it to match all child elements at once by assigning the <code>n</code> inside the parenthesis <code>()</code>.</p>
<p>The <code>n</code> lets the selector match elements at any position inside the parent element. This flexibility allows us to pick elements and apply styles without specifying an exact position. As a result, we can target all possible positions. 😎
Additionally, we have all our cones full of delicious strawberry 🍓 flavor 🍦 ice cream! So, this is by far the sweetest choice!</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">div</span><span style="color:#B392F0">:nth-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">n</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/nth-child-selector-selects-all.webp" alt="Seven ice cream cones one next to other. All of them have ice cream strawberry flavor. We set the css nth-child(n) selector." style="max-width:56%" class="img-narrow"></p>
<p>I hope you enjoyed our little trip to the “ice cream CSS nth child” land!! 🎉 🎉 Keep going till next time!! 🍓 🍦 ✨</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/css-selectors-nth-child-vs-nth-of-type-and-how-to-use-them-correctly/">nth-child vs nth-of-type in CSS</a></li>
<li><a href="/learn-how-to-select-only-the-css-first-child/">Learn How to Select Only the CSS First Child</a></li>
<li><a href="/css-last-child-selector-the-most-valuable-selector/">The CSS last-child Selector</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Express.js Server with TypeScript</title>
      <link>https://littlecodingthings.com/how-to-setup-an-express-js-server-using-typescript-2024/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-setup-an-express-js-server-using-typescript-2024/</guid>
      <pubDate>Fri, 23 Aug 2024 10:50:00 GMT</pubDate>
      <description>Set up an Express.js server with TypeScript from scratch: start in plain JavaScript, add TypeScript, configure outDir, and wire up the build script.</description>
      <category>Setup &amp; Tools</category>
      <content:encoded><![CDATA[<p>This post describes all the necessary steps to <strong>set up an Express.js server using Typescript</strong>. We’ll start our project from scratch, create an <code>Express.js</code> server using Vanilla Javascript, and then convert our project to support Typescript. Let’s dive in!</p>
<h3 id="technology-stack-used">Technology stack used<a class="heading-anchor" href="#technology-stack-used" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<ul>
<li><code>npm</code> – <code>10.8.2</code></li>
<li><code>node</code> – <code>20.15.1</code></li>
<li><code>express.js</code> – <code>4.19.2</code></li>
<li><code>typescript</code> – <code>5.5.3</code></li>
</ul>
<h2 id="setting-up-the-project-with-expressjs">Setting Up the Project with Express.js<a class="heading-anchor" href="#setting-up-the-project-with-expressjs" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>In an empty folder of your choice, run the <code>npm</code> initializer with all default options selected by using the following command:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">npm</span><span style="color:#9ECBFF"> init</span><span style="color:#79B8FF"> --yes</span><span style="color:#6A737D"> # or npm init -y</span></span></code></pre></div>
<p>By using the <code>--yes</code> flag we ask <code>npm</code> to set the default answer to any question asked during setup. Remove the <code>--yes</code> flag to see the questions I am referring to.</p>
<p>We will be using a folder called <code>server-project</code> for this post. Running the previous command is the first step of our project, resulting in a <code>package.json</code> file with the following content:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">{</span></span>
<span class="line"><span style="color:#79B8FF">  "name"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"server-project"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "version"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"1.0.0"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "main"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"index.js"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "scripts"</span><span style="color:#E1E4E8">: {</span></span>
<span class="line"><span style="color:#79B8FF">    "test"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"echo </span><span style="color:#79B8FF">\"</span><span style="color:#9ECBFF">Error: no test specified</span><span style="color:#79B8FF">\"</span><span style="color:#9ECBFF"> &#x26;&#x26; exit 1"</span></span>
<span class="line"><span style="color:#E1E4E8">  },</span></span>
<span class="line"><span style="color:#79B8FF">  "keywords"</span><span style="color:#E1E4E8">: [],</span></span>
<span class="line"><span style="color:#79B8FF">  "author"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "license"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"ISC"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "description"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Now that we have initialized our project using <code>npm</code> let’s install <a href="https://expressjs.com/" title="Express.js">Express.js</a>:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">npm</span><span style="color:#9ECBFF"> install</span><span style="color:#9ECBFF"> express@4.19.2</span></span></code></pre></div>
<p>By doing so, <code>Express.js</code> will be added to the <code>package.json</code> file’s dependencies.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">{</span></span>
<span class="line"><span style="color:#79B8FF">  "name"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"server-project"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "version"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"1.0.0"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "main"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"index.js"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "scripts"</span><span style="color:#E1E4E8">: {</span></span>
<span class="line"><span style="color:#79B8FF">    "test"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"echo </span><span style="color:#79B8FF">\"</span><span style="color:#9ECBFF">Error: no test specified</span><span style="color:#79B8FF">\"</span><span style="color:#9ECBFF"> &#x26;&#x26; exit 1"</span></span>
<span class="line"><span style="color:#E1E4E8">  },</span></span>
<span class="line"><span style="color:#79B8FF">  "keywords"</span><span style="color:#E1E4E8">: [],</span></span>
<span class="line"><span style="color:#79B8FF">  "author"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "license"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"ISC"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "description"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "dependencies"</span><span style="color:#E1E4E8">: {</span></span>
<span class="line"><span style="color:#79B8FF">    "express"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"^4.19.2"</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>The next step is to set up a basic server following <a href="https://expressjs.com/en/starter/hello-world.html" title="Express&#x27;s documentation">Express’s documentation</a></p>
<p>Create a new file in your project folder, named <code>index.js</code>, and inside that file, add</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> express</span><span style="color:#F97583"> =</span><span style="color:#B392F0"> require</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'express'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> app</span><span style="color:#F97583"> =</span><span style="color:#B392F0"> express</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> port</span><span style="color:#F97583"> =</span><span style="color:#79B8FF"> 3004</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">app.</span><span style="color:#B392F0">get</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'/'</span><span style="color:#E1E4E8">, (</span><span style="color:#FFAB70">req</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">res</span><span style="color:#E1E4E8">) </span><span style="color:#F97583">=></span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  res.</span><span style="color:#B392F0">send</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'Hello World!'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">})</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">app.</span><span style="color:#B392F0">listen</span><span style="color:#E1E4E8">(port, () </span><span style="color:#F97583">=></span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  console.</span><span style="color:#B392F0">log</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">`Example app listening on port ${</span><span style="color:#E1E4E8">port</span><span style="color:#9ECBFF">}`</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">});</span></span></code></pre></div>
<p>Excellent! Using <code>node</code> we get to see this baby up and running!</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>node index.js</span></span></code></pre></div>
<p>Executing this to your terminal will show you</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>Example app listening on port 3004</span></span></code></pre></div>
<p>Opening <code>localhost:3004</code> to your browser, you will see our server’s response.</p>
<p>That <code>app.get('/', ...)</code> handler is the smallest possible Express route. Everything that runs <em>around</em> it — logging, authentication, body parsing, error handling — is <a href="/coding-interview-series-intro-to-express-js-middleware/">Express middleware</a>, which is also one of the most reliably asked Express interview questions once you start applying for Node roles.</p>
<p><img src="/hello-world-1.webp" alt="Browser showing basic express server &#x22;Hello World&#x22;reponse"></p>
<p>In any case, you get some kind of error like <code>listen EADDRINUSE: address already in use :::3004</code> it means that you are running another application in the port <code>3004</code>. To fix this, either change in the <code>index.js</code> file, this app’s port, to e.g <code>3001</code> or kill the other app you already are running on port <code>3004</code>.</p>
<h2 id="installing-typescript">Installing Typescript<a class="heading-anchor" href="#installing-typescript" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Now that we have successfully installed our <code>Express.js</code> server and we see that everything is working as expected, it’s time to add Typescript.</p>
<p>Kill the <code>node</code> script using <code>Ctrl + C</code> and install <code>Typescript</code> by running</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">npm</span><span style="color:#9ECBFF"> install</span><span style="color:#79B8FF"> --save-dev</span><span style="color:#9ECBFF"> typescript@5.5.3</span></span></code></pre></div>
<p>Typescript is stored as a development dependency because it is used only in the development phase of a project for transpiling TS code to Javascript. In production environments, browsers and servers are capable of interpreting and executing JavaScript, not Typescript code.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">{</span></span>
<span class="line"><span style="color:#79B8FF">  "name"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"server-project"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "version"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"1.0.0"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "main"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"index.js"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "scripts"</span><span style="color:#E1E4E8">: {</span></span>
<span class="line"><span style="color:#79B8FF">    "test"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"echo </span><span style="color:#79B8FF">\"</span><span style="color:#9ECBFF">Error: no test specified</span><span style="color:#79B8FF">\"</span><span style="color:#9ECBFF"> &#x26;&#x26; exit 1"</span></span>
<span class="line"><span style="color:#E1E4E8">  },</span></span>
<span class="line"><span style="color:#79B8FF">  "keywords"</span><span style="color:#E1E4E8">: [],</span></span>
<span class="line"><span style="color:#79B8FF">  "author"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "license"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"ISC"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "description"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "dependencies"</span><span style="color:#E1E4E8">: {</span></span>
<span class="line"><span style="color:#79B8FF">    "express"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"^4.19.2"</span></span>
<span class="line"><span style="color:#E1E4E8">  },</span></span>
<span class="line"><span style="color:#79B8FF">  "devDependencies"</span><span style="color:#E1E4E8">: {</span></span>
<span class="line"><span style="color:#79B8FF">    "typescript"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"^5.5.3"</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>After installing Typescript to our project we need to initialize it by typing</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">npx</span><span style="color:#9ECBFF"> tsc</span><span style="color:#79B8FF"> --init</span></span></code></pre></div>
<p><code>--init</code> flag is used to <a href="https://www.typescriptlang.org/docs/handbook/compiler-options.html" title="initialize a TS project">initialize a TS project</a> and create a <code>tsconfig.json</code> file with the default options set.</p>
<p>But what about <code>tsc</code> and <code>npx</code>? Where did these come from?</p>
<h3 id="understanding-tsc-and-npx-why-do-we-use-them">Understanding tsc and npx: Why do we use them?<a class="heading-anchor" href="#understanding-tsc-and-npx-why-do-we-use-them" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><code>tsc</code> is the command line tool used by Typescript to compile code (<code>tsc</code> 👉 <strong>t</strong>ype<strong>s</strong>cript <strong>c</strong>ompiler) into Javascript. It is a part of Typescript package, and it became available to our system when we installed Typescript.</p>
<p><code>npx</code> on the other side is a package runner tool that came with <code>npm</code>. It was released from <code>npm</code> version <code>5.2.0</code>. This tool is useful in cases where:</p>
<ul>
<li>We want to run a package without installing it</li>
<li>We will be executing a package using different versions</li>
<li>To avoid global installation of a package</li>
</ul>
<p>Ok, sure, but in our case, since we have Typescript installed in our local project folder, and because of this, we also have <code>tsc installed,</code> then why not just use <code>tsc --init</code>? Right? Why do we want to use <code>npx</code> to run <code>tsc</code>?</p>
<blockquote>
<p>Just using tsc might use a global version of Typescipt and not the local one</p>
</blockquote>
<p>That question killed some of my brain cells 🧠 before figuring it out 😅. Just using <code>tsc --init</code> may use a global version of Typescript installed on your computer. Using <code>npx tsc --init</code> instead will make sure that you are using the local version of <code>tsc</code> package. This way, you will avoid any surprises because of different package versions. 🥳</p>
<p>After successfully executing <code>npx tsc --init</code> you will see a <code>tsconfig.json</code> file created with the following content</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">{</span></span>
<span class="line"><span style="color:#79B8FF">  "compilerOptions"</span><span style="color:#E1E4E8">: {</span></span>
<span class="line"><span style="color:#6A737D">    /* Visit https://aka.ms/tsconfig to read more about this file */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">    /* Projects */</span></span>
<span class="line"><span style="color:#6A737D">    // "incremental": true,                              /* Save .tsbuildinfo files to allow for incremental compilation of projects. */</span></span>
<span class="line"><span style="color:#6A737D">    // "composite": true,                                /* Enable constraints that allow a TypeScript project to be used with project references. */</span></span>
<span class="line"><span style="color:#6A737D">    // "tsBuildInfoFile": "./.tsbuildinfo",              /* Specify the path to .tsbuildinfo incremental compilation file. */</span></span>
<span class="line"><span style="color:#6A737D">    // "disableSourceOfProjectReferenceRedirect": true,  /* Disable preferring source files instead of declaration files when referencing composite projects. */</span></span>
<span class="line"><span style="color:#6A737D">    // "disableSolutionSearching": true,                 /* Opt a project out of multi-project reference checking when editing. */</span></span>
<span class="line"><span style="color:#6A737D">    // "disableReferencedProjectLoad": true,             /* Reduce the number of projects loaded automatically by TypeScript. */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">    /* Language and Environment */</span></span>
<span class="line"><span style="color:#79B8FF">    "target"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"es2016"</span><span style="color:#E1E4E8">,                                  </span><span style="color:#6A737D">/* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */</span></span>
<span class="line"><span style="color:#6A737D">    // "lib": [],                                        /* Specify a set of bundled library declaration files that describe the target runtime environment. */</span></span>
<span class="line"><span style="color:#6A737D">    // "jsx": "preserve",                                /* Specify what JSX code is generated. */</span></span>
<span class="line"><span style="color:#6A737D">    // "experimentalDecorators": true,                   /* Enable experimental support for legacy experimental decorators. */</span></span>
<span class="line"><span style="color:#6A737D">    // "emitDecoratorMetadata": true,                    /* Emit design-type metadata for decorated declarations in source files. */</span></span>
<span class="line"><span style="color:#6A737D">    // "jsxFactory": "",                                 /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */</span></span>
<span class="line"><span style="color:#6A737D">    // "jsxFragmentFactory": "",                         /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */</span></span>
<span class="line"><span style="color:#6A737D">    // "jsxImportSource": "",                            /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */</span></span>
<span class="line"><span style="color:#6A737D">    // "reactNamespace": "",                             /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */</span></span>
<span class="line"><span style="color:#6A737D">    // "noLib": true,                                    /* Disable including any library files, including the default lib.d.ts. */</span></span>
<span class="line"><span style="color:#6A737D">    // "useDefineForClassFields": true,                  /* Emit ECMAScript-standard-compliant class fields. */</span></span>
<span class="line"><span style="color:#6A737D">    // "moduleDetection": "auto",                        /* Control what method is used to detect module-format JS files. */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">    /* Modules */</span></span>
<span class="line"><span style="color:#79B8FF">    "module"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"commonjs"</span><span style="color:#E1E4E8">,                                </span><span style="color:#6A737D">/* Specify what module code is generated. */</span></span>
<span class="line"><span style="color:#6A737D">    // "rootDir": "./",                                  /* Specify the root folder within your source files. */</span></span>
<span class="line"><span style="color:#6A737D">    // "moduleResolution": "node10",                     /* Specify how TypeScript looks up a file from a given module specifier. */</span></span>
<span class="line"><span style="color:#6A737D">    // "baseUrl": "./",                                  /* Specify the base directory to resolve non-relative module names. */</span></span>
<span class="line"><span style="color:#6A737D">    // "paths": {},                                      /* Specify a set of entries that re-map imports to additional lookup locations. */</span></span>
<span class="line"><span style="color:#6A737D">    // "rootDirs": [],                                   /* Allow multiple folders to be treated as one when resolving modules. */</span></span>
<span class="line"><span style="color:#6A737D">    // "typeRoots": [],                                  /* Specify multiple folders that act like './node_modules/@types'. */</span></span>
<span class="line"><span style="color:#6A737D">    // "types": [],                                      /* Specify type package names to be included without being referenced in a source file. */</span></span>
<span class="line"><span style="color:#6A737D">    // "allowUmdGlobalAccess": true,                     /* Allow accessing UMD globals from modules. */</span></span>
<span class="line"><span style="color:#6A737D">    // "moduleSuffixes": [],                             /* List of file name suffixes to search when resolving a module. */</span></span>
<span class="line"><span style="color:#6A737D">    // "allowImportingTsExtensions": true,               /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */</span></span>
<span class="line"><span style="color:#6A737D">    // "resolvePackageJsonExports": true,                /* Use the package.json 'exports' field when resolving package imports. */</span></span>
<span class="line"><span style="color:#6A737D">    // "resolvePackageJsonImports": true,                /* Use the package.json 'imports' field when resolving imports. */</span></span>
<span class="line"><span style="color:#6A737D">    // "customConditions": [],                           /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */</span></span>
<span class="line"><span style="color:#6A737D">    // "resolveJsonModule": true,                        /* Enable importing .json files. */</span></span>
<span class="line"><span style="color:#6A737D">    // "allowArbitraryExtensions": true,                 /* Enable importing files with any extension, provided a declaration file is present. */</span></span>
<span class="line"><span style="color:#6A737D">    // "noResolve": true,                                /* Disallow 'import's, 'require's or '&#x3C;reference>'s from expanding the number of files TypeScript should add to a project. */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">    /* JavaScript Support */</span></span>
<span class="line"><span style="color:#6A737D">    // "allowJs": true,                                  /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */</span></span>
<span class="line"><span style="color:#6A737D">    // "checkJs": true,                                  /* Enable error reporting in type-checked JavaScript files. */</span></span>
<span class="line"><span style="color:#6A737D">    // "maxNodeModuleJsDepth": 1,                        /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">    /* Emit */</span></span>
<span class="line"><span style="color:#6A737D">    // "declaration": true,                              /* Generate .d.ts files from TypeScript and JavaScript files in your project. */</span></span>
<span class="line"><span style="color:#6A737D">    // "declarationMap": true,                           /* Create sourcemaps for d.ts files. */</span></span>
<span class="line"><span style="color:#6A737D">    // "emitDeclarationOnly": true,                      /* Only output d.ts files and not JavaScript files. */</span></span>
<span class="line"><span style="color:#6A737D">    // "sourceMap": true,                                /* Create source map files for emitted JavaScript files. */</span></span>
<span class="line"><span style="color:#6A737D">    // "inlineSourceMap": true,                          /* Include sourcemap files inside the emitted JavaScript. */</span></span>
<span class="line"><span style="color:#6A737D">    // "outFile": "./",                                  /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */</span></span>
<span class="line"><span style="color:#6A737D">    // "outDir": "./",                                   /* Specify an output folder for all emitted files. */</span></span>
<span class="line"><span style="color:#6A737D">    // "removeComments": true,                           /* Disable emitting comments. */</span></span>
<span class="line"><span style="color:#6A737D">    // "noEmit": true,                                   /* Disable emitting files from a compilation. */</span></span>
<span class="line"><span style="color:#6A737D">    // "importHelpers": true,                            /* Allow importing helper functions from tslib once per project, instead of including them per-file. */</span></span>
<span class="line"><span style="color:#6A737D">    // "downlevelIteration": true,                       /* Emit more compliant, but verbose and less performant JavaScript for iteration. */</span></span>
<span class="line"><span style="color:#6A737D">    // "sourceRoot": "",                                 /* Specify the root path for debuggers to find the reference source code. */</span></span>
<span class="line"><span style="color:#6A737D">    // "mapRoot": "",                                    /* Specify the location where debugger should locate map files instead of generated locations. */</span></span>
<span class="line"><span style="color:#6A737D">    // "inlineSources": true,                            /* Include source code in the sourcemaps inside the emitted JavaScript. */</span></span>
<span class="line"><span style="color:#6A737D">    // "emitBOM": true,                                  /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */</span></span>
<span class="line"><span style="color:#6A737D">    // "newLine": "crlf",                                /* Set the newline character for emitting files. */</span></span>
<span class="line"><span style="color:#6A737D">    // "stripInternal": true,                            /* Disable emitting declarations that have '@internal' in their JSDoc comments. */</span></span>
<span class="line"><span style="color:#6A737D">    // "noEmitHelpers": true,                            /* Disable generating custom helper functions like '__extends' in compiled output. */</span></span>
<span class="line"><span style="color:#6A737D">    // "noEmitOnError": true,                            /* Disable emitting files if any type checking errors are reported. */</span></span>
<span class="line"><span style="color:#6A737D">    // "preserveConstEnums": true,                       /* Disable erasing 'const enum' declarations in generated code. */</span></span>
<span class="line"><span style="color:#6A737D">    // "declarationDir": "./",                           /* Specify the output directory for generated declaration files. */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">    /* Interop Constraints */</span></span>
<span class="line"><span style="color:#6A737D">    // "isolatedModules": true,                          /* Ensure that each file can be safely transpiled without relying on other imports. */</span></span>
<span class="line"><span style="color:#6A737D">    // "verbatimModuleSyntax": true,                     /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */</span></span>
<span class="line"><span style="color:#6A737D">    // "isolatedDeclarations": true,                     /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */</span></span>
<span class="line"><span style="color:#6A737D">    // "allowSyntheticDefaultImports": true,             /* Allow 'import x from y' when a module doesn't have a default export. */</span></span>
<span class="line"><span style="color:#79B8FF">    "esModuleInterop"</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">true</span><span style="color:#E1E4E8">,                             </span><span style="color:#6A737D">/* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */</span></span>
<span class="line"><span style="color:#6A737D">    // "preserveSymlinks": true,                         /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */</span></span>
<span class="line"><span style="color:#79B8FF">    "forceConsistentCasingInFileNames"</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">true</span><span style="color:#E1E4E8">,            </span><span style="color:#6A737D">/* Ensure that casing is correct in imports. */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">    /* Type Checking */</span></span>
<span class="line"><span style="color:#79B8FF">    "strict"</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">true</span><span style="color:#E1E4E8">,                                      </span><span style="color:#6A737D">/* Enable all strict type-checking options. */</span></span>
<span class="line"><span style="color:#6A737D">    // "noImplicitAny": true,                            /* Enable error reporting for expressions and declarations with an implied 'any' type. */</span></span>
<span class="line"><span style="color:#6A737D">    // "strictNullChecks": true,                         /* When type checking, take into account 'null' and 'undefined'. */</span></span>
<span class="line"><span style="color:#6A737D">    // "strictFunctionTypes": true,                      /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */</span></span>
<span class="line"><span style="color:#6A737D">    // "strictBindCallApply": true,                      /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */</span></span>
<span class="line"><span style="color:#6A737D">    // "strictPropertyInitialization": true,             /* Check for class properties that are declared but not set in the constructor. */</span></span>
<span class="line"><span style="color:#6A737D">    // "noImplicitThis": true,                           /* Enable error reporting when 'this' is given the type 'any'. */</span></span>
<span class="line"><span style="color:#6A737D">    // "useUnknownInCatchVariables": true,               /* Default catch clause variables as 'unknown' instead of 'any'. */</span></span>
<span class="line"><span style="color:#6A737D">    // "alwaysStrict": true,                             /* Ensure 'use strict' is always emitted. */</span></span>
<span class="line"><span style="color:#6A737D">    // "noUnusedLocals": true,                           /* Enable error reporting when local variables aren't read. */</span></span>
<span class="line"><span style="color:#6A737D">    // "noUnusedParameters": true,                       /* Raise an error when a function parameter isn't read. */</span></span>
<span class="line"><span style="color:#6A737D">    // "exactOptionalPropertyTypes": true,               /* Interpret optional property types as written, rather than adding 'undefined'. */</span></span>
<span class="line"><span style="color:#6A737D">    // "noImplicitReturns": true,                        /* Enable error reporting for codepaths that do not explicitly return in a function. */</span></span>
<span class="line"><span style="color:#6A737D">    // "noFallthroughCasesInSwitch": true,               /* Enable error reporting for fallthrough cases in switch statements. */</span></span>
<span class="line"><span style="color:#6A737D">    // "noUncheckedIndexedAccess": true,                 /* Add 'undefined' to a type when accessed using an index. */</span></span>
<span class="line"><span style="color:#6A737D">    // "noImplicitOverride": true,                       /* Ensure overriding members in derived classes are marked with an override modifier. */</span></span>
<span class="line"><span style="color:#6A737D">    // "noPropertyAccessFromIndexSignature": true,       /* Enforces using indexed accessors for keys declared using an indexed type. */</span></span>
<span class="line"><span style="color:#6A737D">    // "allowUnusedLabels": true,                        /* Disable error reporting for unused labels. */</span></span>
<span class="line"><span style="color:#6A737D">    // "allowUnreachableCode": true,                     /* Disable error reporting for unreachable code. */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">    /* Completeness */</span></span>
<span class="line"><span style="color:#6A737D">    // "skipDefaultLibCheck": true,                      /* Skip type checking .d.ts files that are included with TypeScript. */</span></span>
<span class="line"><span style="color:#79B8FF">    "skipLibCheck"</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">true</span><span style="color:#6A737D">                                 /* Skip type checking all .d.ts files. */</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h2 id="refactoring-javascript-to-typescript">Refactoring JavaScript to TypeScript<a class="heading-anchor" href="#refactoring-javascript-to-typescript" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Now that we have successfully installed and initialized Typescript we need to start writing some Typescript to have fun.</p>
<p>First of all let’s rename our <code>index.js</code> file to <code>index.ts</code>. If <strong>we don’t do</strong> that and we run our <code>tsc</code> compiler we will see an error</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>error TS18003: No inputs were found in config file 'server-project/tsconfig.json'. Specified 'include' paths were '["**/*"]' and 'exclude' paths were '[]'.</span></span></code></pre></div>
<p>because we have no <code>.ts</code> files in our project.</p>
<p>Make sense right? After all we need at least <code>.ts</code> one file to start our TS journey. Ok now that we have renamed it, lets, out of curiosity, run <code>npx tsc</code> and see what happens. By running this command, I get the following errors</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">index.ts:</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">:</span><span style="color:#79B8FF">17</span><span style="color:#F97583"> -</span><span style="color:#E1E4E8"> error </span><span style="color:#B392F0">TS2580</span><span style="color:#E1E4E8">: Cannot find name </span><span style="color:#9ECBFF">'require'</span><span style="color:#E1E4E8">. Do you need to install </span><span style="color:#F97583">type</span><span style="color:#B392F0"> definitions</span><span style="color:#E1E4E8"> for node? Try `npm i --save-dev @types/node`.</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">1 const express </span><span style="color:#F97583">=</span><span style="color:#B392F0"> require</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'express'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#F97583">                  ~~~~~~~</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">index.ts:</span><span style="color:#79B8FF">6</span><span style="color:#E1E4E8">:</span><span style="color:#79B8FF">15</span><span style="color:#F97583"> -</span><span style="color:#E1E4E8"> error </span><span style="color:#B392F0">TS7006</span><span style="color:#E1E4E8">: Parameter </span><span style="color:#9ECBFF">'req'</span><span style="color:#E1E4E8"> implicitly has an </span><span style="color:#9ECBFF">'any'</span><span style="color:#E1E4E8"> type.</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">6</span><span style="color:#E1E4E8"> app.</span><span style="color:#B392F0">get</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'/'</span><span style="color:#E1E4E8">, (</span><span style="color:#FFAB70">req</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">res</span><span style="color:#E1E4E8">) </span><span style="color:#F97583">=></span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">                ~~~</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">index.ts:</span><span style="color:#79B8FF">6</span><span style="color:#E1E4E8">:</span><span style="color:#79B8FF">20</span><span style="color:#F97583"> -</span><span style="color:#E1E4E8"> error </span><span style="color:#B392F0">TS7006</span><span style="color:#E1E4E8">: Parameter </span><span style="color:#9ECBFF">'res'</span><span style="color:#E1E4E8"> implicitly has an </span><span style="color:#9ECBFF">'any'</span><span style="color:#E1E4E8"> type.</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">6</span><span style="color:#E1E4E8"> app.</span><span style="color:#B392F0">get</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'/'</span><span style="color:#E1E4E8">, (</span><span style="color:#FFAB70">req</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">res</span><span style="color:#E1E4E8">) </span><span style="color:#F97583">=></span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">                     ~~~</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">Found </span><span style="color:#79B8FF">3</span><span style="color:#E1E4E8"> errors </span><span style="color:#F97583">in</span><span style="color:#E1E4E8"> the same file, starting </span><span style="color:#B392F0">at</span><span style="color:#E1E4E8">: index.ts:</span><span style="color:#79B8FF">1</span></span></code></pre></div>
<p>It seems the compiler is unable to successfully convert our <code>.ts</code> file to <code>.js</code> due to three issues. We need to address these issues one at a time. A guide is available that describes each error in detail, including their causes and solutions. Feel free to check it out if you want to learn more.</p>
<p>After dealing with all the necessary problems, the updated <code>.ts</code> file should look something like</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">import</span><span style="color:#E1E4E8"> express, { Express, Request, Response } </span><span style="color:#F97583">from</span><span style="color:#9ECBFF"> 'express'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> app</span><span style="color:#F97583">:</span><span style="color:#B392F0"> Express</span><span style="color:#F97583"> =</span><span style="color:#B392F0"> express</span><span style="color:#E1E4E8">();</span></span>
<span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> port</span><span style="color:#F97583"> =</span><span style="color:#79B8FF"> 3004</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">app.</span><span style="color:#B392F0">get</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'/'</span><span style="color:#E1E4E8">, (</span><span style="color:#FFAB70">req</span><span style="color:#F97583">:</span><span style="color:#B392F0"> Request</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">res</span><span style="color:#F97583">:</span><span style="color:#B392F0"> Response</span><span style="color:#E1E4E8">) </span><span style="color:#F97583">=></span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  res.</span><span style="color:#B392F0">send</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'Hello World!'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">})</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">app.</span><span style="color:#B392F0">listen</span><span style="color:#E1E4E8">(port, () </span><span style="color:#F97583">=></span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  console.</span><span style="color:#B392F0">log</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">`Example app listening on port ${</span><span style="color:#E1E4E8">port</span><span style="color:#9ECBFF">}`</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">});</span></span></code></pre></div>
<p>Now that we have everything fixed let’s run <code>npx tsc</code> to see if there is anything left. Running this command showed nothing in my terminal. Which is a good sign. To see the compilation results though, I need to make two small tweaks.</p>
<h3 id="configure-typescript-to-create-a-new-folder-for-all-compiled-files-by-using-the-outdir-compiler-option">Configure TypeScript to create a new folder for all compiled files by using the outDir compiler option.<a class="heading-anchor" href="#configure-typescript-to-create-a-new-folder-for-all-compiled-files-by-using-the-outdir-compiler-option" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">{</span></span>
<span class="line"><span style="color:#79B8FF">  "compilerOptions"</span><span style="color:#E1E4E8">: {</span></span>
<span class="line"><span style="color:#6A737D">    // ....</span></span>
<span class="line"><span style="color:#79B8FF">    "outDir"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"./dist"</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* Specify an output folder for all emitted files. */</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h3 id="rename-the-packagejson-main-file-and-add-a-compilation-script">Rename the package.json main file and add a compilation Script<a class="heading-anchor" href="#rename-the-packagejson-main-file-and-add-a-compilation-script" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">{</span></span>
<span class="line"><span style="color:#79B8FF">  "name"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"server-project"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "version"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"1.0.0"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "main"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"dist/index.js"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "scripts"</span><span style="color:#E1E4E8">: {</span></span>
<span class="line"><span style="color:#79B8FF">    "start"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"npx tsc &#x26;&#x26; node dist/index.js"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    "test"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"echo </span><span style="color:#79B8FF">\"</span><span style="color:#9ECBFF">Error: no test specified</span><span style="color:#79B8FF">\"</span><span style="color:#9ECBFF"> &#x26;&#x26; exit 1"</span></span>
<span class="line"><span style="color:#E1E4E8">  },</span></span>
<span class="line"><span style="color:#79B8FF">  "keywords"</span><span style="color:#E1E4E8">: [],</span></span>
<span class="line"><span style="color:#79B8FF">  "author"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "license"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"ISC"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "description"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "dependencies"</span><span style="color:#E1E4E8">: {</span></span>
<span class="line"><span style="color:#79B8FF">    "express"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"^4.19.2"</span></span>
<span class="line"><span style="color:#E1E4E8">  },</span></span>
<span class="line"><span style="color:#79B8FF">  "devDependencies"</span><span style="color:#E1E4E8">: {</span></span>
<span class="line"><span style="color:#79B8FF">    "@types/express"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"^4.17.21"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    "@types/node"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"^22.1.0"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    "typescript"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"^5.5.4"</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Superb! Now we have everything we need. What’s next? A victory dance! When you run <code>npm start</code>, your terminal will display “Example app listening on port 3004,” which means we did it!</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>Example app listening on port 3004</span></span></code></pre></div>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/most-common-typescript-errors-and-how-to-solve-them/">Common TypeScript Errors and Fixes</a></li>
<li><a href="/coding-interview-series-intro-to-express-js-middleware/">Express.js Middleware Interview Questions</a></li>
<li><a href="/how-to-use-absolute-paths-in-a-node-project-2024/">Absolute Paths in a Node Project</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Introduction To The Powerful CSS Blur Effect</title>
      <link>https://littlecodingthings.com/introduction-to-the-powerful-css-blur-effect/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/introduction-to-the-powerful-css-blur-effect/</guid>
      <pubDate>Mon, 19 Aug 2024 08:10:00 GMT</pubDate>
      <description>Build a frosted-glass panel with backdrop-filter: blur(), step by step — including the overflow: hidden fix for a blur that bleeds out.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hello everybody 😃 Today, we will discover the art of the powerful CSS blur effect. Get ready to meet the amazing <a href="/grayscale-backdrop-filter-a-useful-tool-to-make-grayish-backgrounds/"><code>backdrop-filter</code> CSS property</a>. We’ll dive 🤿 into the world of adding visual elegance and depth to our web design, and we will learn to create captivating and stunning web elements. Let’s get started!</p>
<h2 id="adding-basic-html-structure">Adding basic HTML structure<a class="heading-anchor" href="#adding-basic-html-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Let’s get started with the <a href="/most-useful-html-elements-for-maximizing-better-results/">HTML</a> setup. We create a parent div named <code>custom-container</code> for the background and a child div named <code>blurry-container</code> where we will apply the CSS blur effect. Follow along for the step-by-step process.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"custom-container"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"blurry-container"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h2 id="adding-the-background-image">Adding the background image<a class="heading-anchor" href="#adding-the-background-image" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We move forward with the <a href="/how-to-work-with-css-syntax-the-correct-way/">CSS</a> structure by preparing the background. I opted for a striking and colorful background image as it is more impressive and gives prominence to our effect, setting <code>background-image</code>. I also add <code>background-repeat</code> which determines how the background image is shown, and <code>background-size</code> which sets the size of the image, in our case we want to fill the entire display. Completing it with <code>height: 100vh</code> for full-screen coverage.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.custom-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">url</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">https://images.unsplash.com/photo-1540959733332-eab4deabeeaf?ixlib=rb-1.2.1&#x26;ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&#x26;auto=format&#x26;fit=crop&#x26;w=1194&#x26;q=80</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  background-repeat</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">no-repeat</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">cover</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">vh</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<figure><img src="/blur-effect1-adding-origin-image.webp" alt="Here we can see the image we chose for background." style="max-width:28%" class="img-narrow"><figcaption>Original photo by <a href="https://unsplash.com/@jezar" title="Jezael Melgoza">Jezael Melgoza</a> on <a href="https://unsplash.com/photos/people-walking-on-road-near-well-lit-buildings-layMbSJ3YOE" title="Unsplash">Unsplash</a></figcaption></figure>
<p>The next step is to create a “place” where we can accommodate our blur, I believe a box would serve this need. To begin, I create one by setting the appropriate <code>width</code> and <code>height</code> along with its <code>border</code> and <code>border-radius</code>. I utilized <a href="/how-to-be-creative-with-different-css-border-styles/">borders</a> to ensure my box remains visible. Whether to keep them or not is entirely up to you. The design can still look great in both cases. Feel free to choose whichever option suits your preference or the project’s requirements. 😃</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.blurry-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">400</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">500</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/blur-effect2-create-box.webp" alt="A box created to demonstrate the CSS blur effect." style="max-width:28%" class="img-narrow"></p>
<p>If we want our box to share the same image as its background, and not just be transparent, it is crucial to add the <code>background: inherit</code> CSS property.</p>
<p>In the following image, we can see clearly that our box now has the exact same image as its background.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.blurry-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inherit</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/blur-effect3-inherit-background.webp" alt="Applying the same background image to a box element." style="max-width:28%" class="img-narrow"></p>
<p>Now it’s time to <a href="/how-to-center-in-css-using-different-ways/">center our box</a>. We do so by applying the <code>flex</code> CSS property to the parent HTML element which is the <code>custom-container</code>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.custom-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/blur-effect4-center-box.webp" alt="A box centered using the flexbox method" style="max-width:28%" class="img-narrow"></p>
<h2 id="adding-the-blur-effect-backdrop-filter">Adding the blur effect (backdrop-filter)<a class="heading-anchor" href="#adding-the-blur-effect-backdrop-filter" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We create the blur effect using the <code>::before</code> pseudo-element. To manage this, we have to set <code>position:relative</code> to the parent element and <code>position: absolute</code> to the child. The child element needs the <a href="https://www.w3.org/TR/CSS2/generate.html#content"><code>content</code> CSS property</a> to be assigned an empty string value in order to be displayed. Despite the recent code adjustments, you won’t notice any visible changes on the screen just yet. 😭</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.custom-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#B392F0">  .blurry-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">      content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    } </span><span style="color:#6A737D">/* end of before */</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">/* end of blurry-container */</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">/* end of custom-container */</span></span></code></pre></div>
<p>Let’s proceed with our effect. 🥁 We do so by adding the <code>backdrop-filter</code> CSS property to the <code>::before</code> pseudo-element. Increasing the pixel value intensifies the blur effect by creating a stronger visual impact. I’ve applied a <code>12px</code> blur effect, but you have the flexibility to adjust it according to your preferences. If you desire a clearer look, feel free to reduce ⬇ the pixels. Alternatively, for a stronger fade effect, you can increase ⬆ the pixel value.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">&#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  backdrop-filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">blur</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">12</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h3 id="-what-to-avoid-when-applying-the-blur-effect">🔖 What to avoid when applying the blur effect<a class="heading-anchor" href="#-what-to-avoid-when-applying-the-blur-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Remember that the blur effect can sometimes get out of control on a web page because of how it’s applied to an element. When you use the blur effect, the blurred result spreads out past the edges of the element it is drawn on — the element keeps its size, but what you see does not stay inside the box. <strong>So, the more blur you add, the further the effect bleeds outward</strong>. Because of that, the blur can spill out of its container or run into nearby elements. 😟</p>
<p><img src="/blur-effect5-adding-blur.webp" alt="The desired css blur effect by setting the &#x27; backdrop-filter : blur(12px);&#x27; CSS property" style="max-width:28%" class="img-narrow"></p>
<p>Observe how the blur CSS property overflows in the current setup above. To correct that, apply the <code>overflow: hidden</code> CSS property to the <strong>PARENT</strong> element <code>custom-container</code>. With this modification, you can control the blur effect and prevent it from causing a mess on your web page.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.custom-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  overflow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">hidden</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>… and boom 🥳 here it is! Our blur effect displayed flawlessly, as intended!</p>
<p><img src="/blur-effect6-overflow-hidden.webp" alt="By setting the &#x27;overflow: hidden;&#x27; CSS property to the &#x27;custom-container&#x27; our box is finally ready! 😃" style="max-width:28%" class="img-narrow"></p>
<h2 id="complete-code-solution">Complete code solution<a class="heading-anchor" href="#complete-code-solution" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Below is the full code referenced in this blog post. Feel free to copy and use it in your own projects. If you have any questions or encounter any issues, don’t hesitate to reach out for assistance. You can easily copy the desired code snippet by clicking on the copy icon, located in the top-right corner of each snippet.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">section</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"custom-container"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"blurry-container"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"title"</span><span style="color:#E1E4E8">>Hello World&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">> </span><span style="color:#6A737D">&#x3C;!-- end of blurry-container --></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">section</span><span style="color:#E1E4E8">> </span><span style="color:#6A737D">&#x3C;!-- end of custom-container --></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">*</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  box-sizing</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">border-box</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  padding</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  margin</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.custom-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">vh</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">url</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">https://images.unsplash.com/photo-1540959733332-eab4deabeeaf?ixlib=rb-1.2.1&#x26;ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&#x26;auto=format&#x26;fit=crop&#x26;w=1194&#x26;q=80</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  background-repeat</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">no-repeat</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">cover</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .blurry-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">400</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">500</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    padding</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inherit</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    overflow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">hidden</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">      content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      bottom</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 300</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">25</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">100</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">128</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.5</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">      backdrop-filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">blur</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">12</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#B392F0">    .title</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#132216</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      font-weight</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">bold</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      padding</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> #364739</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      backdrop-filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">blur</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">8</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">/* end of blurry-container */</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">/* end of custom-container */</span></span></code></pre></div>
<h2 id="complete-code-solution-for-posts-cover">Complete code solution for post’s cover<a class="heading-anchor" href="#complete-code-solution-for-posts-cover" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Below, I include the code for my post’s cover. I also added a title to see how we add text over the blur effect. 😎</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">section</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"custom-container"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"blurry-container"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"title"</span><span style="color:#E1E4E8">>Hello World&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">> </span><span style="color:#6A737D">&#x3C;!-- end of blurry-container --></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">section</span><span style="color:#E1E4E8">> </span><span style="color:#6A737D">&#x3C;!-- end of custom-container --></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">*</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  box-sizing</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">border-box</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  padding</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  margin</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.custom-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">vh</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">url</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">https://images.unsplash.com/photo-1440342359743-84fcb8c21f21?w=800&#x26;auto=format&#x26;fit=crop&#x26;q=60&#x26;ixlib=rb-4.0.3&#x26;ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTJ8fGZvcmVzdHxlbnwwfDB8MHx8fDA%3D</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  background-repeat</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">no-repeat</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">cover</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#B392F0">  .blurry-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> #364739</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">500</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    padding</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inherit</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    overflow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">hidden</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">      content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      bottom</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">100</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">200</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">100</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.8</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">      backdrop-filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">blur</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">/* end of blurry-container */</span></span>
<span class="line"><span style="color:#B392F0">  .title</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#132216</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    font-weight</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">bold</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    padding</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> #364739</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    backdrop-filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">blur</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">8</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">/* end of custom-container */</span></span></code></pre></div>
<p><img src="/blur-effect-cover-with-title.webp" alt="Applying CSS blur effect with overlaid text." style="max-width:49%" class="img-narrow"></p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/grayscale-backdrop-filter-a-useful-tool-to-make-grayish-backgrounds/">CSS backdrop-filter: grayscale()</a></li>
<li><a href="/contrast-and-brightness-empower-css-filter-for-powerful-images/">CSS Filters: Adjust Contrast and Brightness</a></li>
<li><a href="/simple-ways-to-create-a-css-overlay-effect/">Simple Ways to Create a CSS Overlay Effect</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Do You Still Need npm install --save?</title>
      <link>https://littlecodingthings.com/do-you-still-need-to-use-save-on-npm-install/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/do-you-still-need-to-use-save-on-npm-install/</guid>
      <pubDate>Wed, 14 Aug 2024 08:15:00 GMT</pubDate>
      <description>Since npm 5, --save is the default and the flag does nothing. Here are the npm install flags that still matter: --save-dev, --save-optional, --save-peer.</description>
      <category>Setup &amp; Tools</category>
      <content:encoded><![CDATA[<p>If you are here, it probably means you are not 100% sure whether you should be using the <code>--save</code> flag when running <code>npm install --save</code>. Since this post was written in 2024, the short answer is no, you don’t need to. Let’s see why.</p>
<p>When using, <code>npm install --save</code> (shorthand <code>npm install -S</code>), what you are basically asking <code>npm</code> is to record the packages you are installing as dependencies to your project’s <code>package.json</code> file.</p>
<blockquote>
<p>Starting with npm version 5, you no longer need to use the <code>--save</code> flag</p>
</blockquote>
<p>Starting with <code>npm</code> version 5, you no longer need to use the <code>--save</code> flag when installing packages. By default, <code>npm</code> automatically saves installed packages as dependencies in your <code>package.json</code> file. This means that whether you include the <code>--save</code> flag or not, the outcome is the same: the dependencies will be recorded in the <code>package.json</code> file.</p>
<p><strong>What about developer dependencies?</strong></p>
<p>For packages that you should handle as developer dependencies – devDependencies -, you should still use <code>--save-dev</code> or <code>-D</code>.</p>
<h2 id="interesting-npm-install---save-flags">Interesting <code>npm install --save</code> flags<a class="heading-anchor" href="#interesting-npm-install---save-flags" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>By the way, while writing this post, I got curious about other <code>npm</code> flags since I have mostly been using the two mentioned earlier. As you’d expect, there are more. Here are a few that I found particularly interesting if you want to explore further:</p>
<p><code>--save-optional</code></p>
<p>The <code>--save-optional</code> flag saves packages as <code>optionalDependencies</code>. As the name suggests, these are packages that our application may not require. During the installation process, <code>npm</code> will not fail if, for any reason, an optional dependency fails to install.</p>
<p><code>--save-prod</code></p>
<p>The <code>--save-prod</code> flag is somewhat confusing at first glance, as it behaves similarly to the <code>--save</code> flag. It explicitly saves any installed package to the <code>dependencies</code> section of the <code>package.json</code> file. This ensures that your application’s production dependencies include the package.</p>
<p><code>--save-peer</code></p>
<p>The <code>--save-peer</code> made an impression! This one saves the dependencies into a <code>peerDependencies</code> section. Peer dependencies specify that your package is compatible with a particular version of another package without directly including it as a dependency.</p>
<h2 id="so-why-did---save-exist-in-the-first-place-️">So why did <code>--save</code> exist in the first place? 🕰️<a class="heading-anchor" href="#so-why-did---save-exist-in-the-first-place-️" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>This is the bit that makes the whole thing click.</p>
<p>In npm 4 and earlier, <code>npm install express</code> did exactly what it said — it downloaded Express into <code>node_modules</code> and <strong>that was all</strong>. Your <code>package.json</code> was left untouched. If you forgot the flag, everything worked perfectly on your machine and then fell over the moment a teammate cloned the repo, because nothing had ever been written down.</p>
<p>So <code>--save</code> wasn’t a nicety, it was the thing that stopped you shipping a broken project. Everybody typed it. Every tutorial included it. Then npm 5 flipped the default, and a decade of blog posts, Stack Overflow answers and half-remembered muscle memory kept it alive long after it stopped doing anything.</p>
<p>Typing it today is harmless. It’s just noise.</p>
<h2 id="every-save-flag-in-one-table">Every save flag, in one table<a class="heading-anchor" href="#every-save-flag-in-one-table" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Here’s the whole family, with the short aliases — these are the ones npm documents:</p>
<table>
<thead>
<tr>
<th scope="col">Flag</th>
<th scope="col">Alias</th>
<th scope="col">Where the package lands</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row"><code>--save-prod</code></th>
<td><code>-P</code></td>
<td><code>dependencies</code> — the default, unless <code>-D</code> or <code>-O</code> is present</td>
</tr>
<tr>
<th scope="row"><code>--save-dev</code></th>
<td><code>-D</code></td>
<td><code>devDependencies</code></td>
</tr>
<tr>
<th scope="row"><code>--save-optional</code></th>
<td><code>-O</code></td>
<td><code>optionalDependencies</code></td>
</tr>
<tr>
<th scope="row"><code>--save-peer</code></th>
<td>—</td>
<td><code>peerDependencies</code></td>
</tr>
<tr>
<th scope="row"><code>--save-bundle</code></th>
<td><code>-B</code></td>
<td>also added to <code>bundleDependencies</code></td>
</tr>
<tr>
<th scope="row"><code>--save-exact</code></th>
<td><code>-E</code></td>
<td>pins the exact version instead of a range</td>
</tr>
<tr>
<th scope="row"><code>--no-save</code></th>
<td>—</td>
<td>installs it, writes nothing to <code>package.json</code></td>
</tr>
<tr>
<th scope="row"><code>--save</code></th>
<td><code>-S</code></td>
<td><code>dependencies</code> — the default since npm 5</td>
</tr>
</tbody>
</table>
<p>You can check any of these yourself without leaving the terminal:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">npm</span><span style="color:#9ECBFF"> install</span><span style="color:#79B8FF"> -h</span></span></code></pre></div>
<h2 id="--no-save-the-one-thats-actually-still-useful"><code>--no-save</code>: the one that’s actually still useful<a class="heading-anchor" href="#--no-save-the-one-thats-actually-still-useful" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><code>--save</code> does nothing, but its opposite does something real:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">npm</span><span style="color:#9ECBFF"> install</span><span style="color:#9ECBFF"> some-package</span><span style="color:#79B8FF"> --no-save</span></span></code></pre></div>
<p>That installs the package into <code>node_modules</code> without touching <code>package.json</code>. I use it maybe twice a year, and both times for the same reason — I want to try a library for ten minutes before deciding whether it earns a place in the project. When it doesn’t, <code>rm -rf node_modules &#x26;&#x26; npm install</code> puts everything back exactly as it was.</p>
<h2 id="dependencies-vs-devdependencies-and-why-deploys-break"><code>dependencies</code> vs <code>devDependencies</code>, and why deploys break<a class="heading-anchor" href="#dependencies-vs-devdependencies-and-why-deploys-break" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>This is the distinction worth actually caring about, because it’s the one that produces a confusing failure.</p>
<ul>
<li><strong><code>dependencies</code></strong> — needed for the app to <em>run</em>. Express, React, your database driver.</li>
<li><strong><code>devDependencies</code></strong> — needed to <em>build or test</em> it. Vitest, ESLint, TypeScript, and <a href="/how-to-restart-your-node-apps-without-nodemon/">nodemon</a> if you still need it.</li>
</ul>
<p>Nothing breaks locally either way, because <code>npm install</code> installs both. It breaks on your host, where the build step commonly runs:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">npm</span><span style="color:#9ECBFF"> ci</span><span style="color:#79B8FF"> --omit=dev</span></span></code></pre></div>
<p><code>--omit=dev</code> skips <code>devDependencies</code> entirely. So if TypeScript lives in <code>devDependencies</code> and your production build needs to run <code>tsc</code>, the deploy dies with a “command not found” that made no sense on your laptop. It’s one of the usual suspects when a <a href="/why-did-your-new-next-js-deployment-fail-on-render-com/">Next.js deploy fails on Render</a> after building perfectly at home. (If you have seen <code>npm install --production</code> in an older guide, that is the deprecated spelling of the same thing.)</p>
<p>While we’re here — <code>npm ci</code> rather than <code>npm install</code> is the right command in CI. It installs strictly from <code>package-lock.json</code>, deletes <code>node_modules</code> first, and refuses to run at all if the lockfile and <code>package.json</code> disagree. That last part is a feature: it turns a silent version drift into a loud failure.</p>
<h2 id="--save-exact-and-that--in-front-of-your-versions"><code>--save-exact</code> and that <code>^</code> in front of your versions<a class="heading-anchor" href="#--save-exact-and-that--in-front-of-your-versions" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Open your <code>package.json</code> and you’ll see something like <code>"express": "^5.1.0"</code>. That caret is a <strong>range</strong>, not a version. It means “5.1.0 or any later 5.x release”, so a fresh <code>npm install</code> next month can quietly give you 5.4.0.</p>
<ul>
<li><code>^5.1.0</code> — allows minor and patch updates (5.x.x)</li>
<li><code>~5.1.0</code> — allows patch updates only (5.1.x)</li>
<li><code>5.1.0</code> — exactly that version, which is what <code>--save-exact</code> writes</li>
</ul>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">npm</span><span style="color:#9ECBFF"> install</span><span style="color:#9ECBFF"> express</span><span style="color:#79B8FF"> --save-exact</span></span></code></pre></div>
<p>You mostly don’t need this, because <code>package-lock.json</code> already pins the precise version for everyone who installs from your repo. <code>--save-exact</code> matters when you’re publishing a package of your own, where consumers get your ranges and never see your lockfile.</p>
<h2 id="peerdependencies-and-the-eresolve-error-"><code>peerDependencies</code> and the ERESOLVE error 😖<a class="heading-anchor" href="#peerdependencies-and-the-eresolve-error-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><code>--save-peer</code> is the flag you’ll never type unless you’re publishing a library — but <code>peerDependencies</code> is why you’ll one day see this:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>npm error code ERESOLVE</span></span>
<span class="line"><span>npm error ERESOLVE unable to resolve dependency tree</span></span></code></pre></div>
<p>It means a package you’re installing declared a peer dependency — “I work with React 18” — and your project has something else installed. npm is refusing to build a tree it knows is broken rather than letting you find out at runtime.</p>
<p>The right fix is to update the packages until the versions genuinely agree. The escape hatch, when you’re blocked by a library that just hasn’t updated its peer range yet, is:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">npm</span><span style="color:#9ECBFF"> install</span><span style="color:#79B8FF"> --legacy-peer-deps</span></span></code></pre></div>
<p>That tells npm to ignore peer dependency conflicts the way npm 6 did. It is a “get me through today” flag, not a solution — you have overruled a warning that was probably right.</p>
<h2 id="frequently-asked-questions">Frequently asked questions<a class="heading-anchor" href="#frequently-asked-questions" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<h3 id="is-npm-install---save-deprecated">Is <code>npm install --save</code> deprecated?<a class="heading-anchor" href="#is-npm-install---save-deprecated" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Not deprecated, just redundant. npm still accepts <code>--save</code> and <code>-S</code> and nothing warns you about them; they simply describe the behaviour you were getting anyway. Old scripts using them will keep working.</p>
<h3 id="is-npm-i-the-same-as-npm-install">Is <code>npm i</code> the same as <code>npm install</code>?<a class="heading-anchor" href="#is-npm-i-the-same-as-npm-install" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Yes, <code>i</code> is a built-in alias. <code>npm i -D vitest</code> and <code>npm install --save-dev vitest</code> do exactly the same thing.</p>
<h3 id="what-happens-if-i-forget---save-dev">What happens if I forget <code>--save-dev</code>?<a class="heading-anchor" href="#what-happens-if-i-forget---save-dev" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>The package installs and works, it just lands in <code>dependencies</code> instead. Fix it by hand — move the line into the <code>devDependencies</code> block in <code>package.json</code> — or reinstall it with <code>-D</code>, which rewrites the entry for you.</p>
<h3 id="should-i-commit-package-lockjson">Should I commit <code>package-lock.json</code>?<a class="heading-anchor" href="#should-i-commit-package-lockjson" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Yes. It records the exact version of every package in the tree, including your dependencies’ dependencies, which is the only thing that makes your install reproducible. It is also what <code>npm ci</code> reads.</p>
<h3 id="do-i-ever-need---save-with-npm-update">Do I ever need <code>--save</code> with <code>npm update</code>?<a class="heading-anchor" href="#do-i-ever-need---save-with-npm-update" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>That is the one place the default flips: npm documents <code>save</code> as defaulting to <code>true</code> <em>except</em> for <code>npm update</code>, where it defaults to <code>false</code>. So if you want <code>npm update</code> to write the new ranges back into <code>package.json</code>, <code>--save</code> there is doing real work.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-install-npm-on-macos/">How to Install npm on MacOS</a></li>
<li><a href="/environment-variables-101-secure-your-secrets-like-a-pro/">Environment Variables with Dotenv</a></li>
<li><a href="/husky-hooks-the-easy-way-to-improve-your-project-workflow/">Husky Hooks: Improve Your Git Workflow</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Developer Burnout: Signs and Recovery</title>
      <link>https://littlecodingthings.com/the-burnout-syndrome-how-to-identify-and-overcome-it/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/the-burnout-syndrome-how-to-identify-and-overcome-it/</guid>
      <pubDate>Fri, 09 Aug 2024 21:08:00 GMT</pubDate>
      <description>How burnout shows up for developers — falling productivity, lost motivation, exhaustion, isolation — and four practical ways back out.</description>
      <category>Thoughts &amp; Theory</category>
      <content:encoded><![CDATA[<p>In today’s fast world, especially in web development and programming, the pressure to continuously deliver elevated code can be really stressful. Long hours spent in front of laptops and tough deadlines. Additionally, the persistent dream of perfection and leadership can negatively affect even the most passionate and devoted developers.</p>
<p>This intense environment often leads to burnout syndrome, a state of emotional, physical, and mental exhaustion that can significantly impact your personal and professional life.</p>
<h2 id="signs-that-indicate-you-are-experiencing-burnout-syndrome">Signs that Indicate You Are Experiencing Burnout Syndrome<a class="heading-anchor" href="#signs-that-indicate-you-are-experiencing-burnout-syndrome" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Burnout can be incredibly challenging, especially in programming. It is often caused by long hours, high pressure of time, and a constantly changing technological landscape that requires continuous learning and adaptation. Below are some ways to recognize burnout syndrome. Identifying these signs early can help you take action to manage and prevent this situation, ensuring you stay healthy and productive.</p>
<h3 id="battling-or-paddling-against-the-tide-of-decreased-productivity">Battling (or Paddling) Against the Tide of Decreased Productivity<a class="heading-anchor" href="#battling-or-paddling-against-the-tide-of-decreased-productivity" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>We begin with the strongest and most obvious sign of burnout. You are <strong>not productive</strong> anymore. Your energy for work drops, and you feel unable to cope with continuous demands. You find it hard to concentrate, and eventually, you find yourself making more mistakes than usual. Occasionally, it’s hard to finish tasks on time.
Additionally, meetings can be confusing, sometimes you might feel like you are not really there. Working with others can also be tricky because you constantly feel that you are not good enough for this job and can’t cope with your work duties.</p>
<figure><img src="/burnout-syndrome-the-decrease-productivity.webp" alt="Astronaut paddling moon boat in space." style="max-width:30%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-astronaut-paddling-moon-boat-space-cartoon-vector-icon-illustration-science-sport-isolated_36101449.htm#fromView=search&#x26;page=4&#x26;position=46&#x26;uuid=a8bcbbc9-4f5c-40a8-8372-c9bfd21efcbe">Image by catalyststuff on Freepik</a></figcaption></figure>
<h3 id="lack-of-motivation-and-interest">Lack of Motivation and Interest<a class="heading-anchor" href="#lack-of-motivation-and-interest" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<figure><img src="/burnout-syndrome-the-lack-of-interest.webp" alt="Astronaut with compass." style="max-width:30%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-astronaut-backpacker-with-compass-cartoon-vector-icon-illustration-science-nature-isolated_27527310.htm#fromView=search&#x26;page=6&#x26;position=40&#x26;uuid=a8bcbbc9-4f5c-40a8-8372-c9bfd21efcbe">Image by catalyststuff on Freepik</a></figcaption></figure>
<p>Another clear indicator of burnout is that stress can result in a lack of interest and motivation in things that were previously meaningful to you. Tasks that once excited you now feel like enemies that only push you and cower 🥊 you to the corner.
There is a <strong>lack of motivation</strong>. Although you want to be creative and productive, you always feel tired and lazy, making it difficult to start new projects or complete things you’ve already taken on.
As time goes by, this becomes more and more intense, and eventually, you <strong>lose interest</strong> at all. You don’t care about work, life, activities, or, worse, about people. Everything seems stressful and meaningful.</p>
<p>If burnout is making you question your career choice, remember <a href="/am-i-too-old-to-learn-coding/" title="Am I Too Old to Learn Coding?">it’s never too late to find your path</a>!</p>
<h3 id="the-awful-never-ending-exhaustion">The Awful, Never-Ending Exhaustion<a class="heading-anchor" href="#the-awful-never-ending-exhaustion" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>A further prominent signal of burnout is the <strong>persistent feeling of exhaustion</strong>, which encloses both physical and mental tiredness. This condition appears as a constant sense of tiredness, accompanied by feelings of frustration and despair that may become part of your daily experience.
Additionally, you may experience difficulties with memory retention and problem-solving, and you may lack the ability to concentrate and think creatively or critically. Moreover, this level of exhaustion usually leads to physical symptoms such as headaches, sleep disorders, and various stress-related health issues.</p>
<figure><img src="/burnout-sundrome-the-exhaustion.webp" alt="Tired astronaut floating with planet baloon." style="max-width:30%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-astronaut-floating-with-planet-balloon-cartoon-vector-icon-illustration-science-technology_24770185.htm#fromView=search&#x26;page=2&#x26;position=26&#x26;uuid=a8bcbbc9-4f5c-40a8-8372-c9bfd21efcbe">Image by catalyststuff on Freepik</a></figcaption></figure>
<h3 id="struggling-with-negativity-and-loneliness">Struggling with Negativity and Loneliness<a class="heading-anchor" href="#struggling-with-negativity-and-loneliness" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<figure><img src="/burnout-sundrome-the-negativity.webp" alt="Sad astronaut swing on brain." style="max-width:30%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-astronaut-swing-brain-space-cartoon-vector-icon-illustration-science-technology-isolated_35978933.htm#fromView=search&#x26;page=8&#x26;position=43&#x26;uuid=a8bcbbc9-4f5c-40a8-8372-c9bfd21efcbe">Image by catalyststuff on Freepik</a></figcaption></figure>
<p>Eventually, you develop extremely <strong>negative and critical feelings</strong> about yourself, your work, and those around you. It’s hard to find pleasure and happiness in your accomplishments and in your relationships with colleagues or other people outside of your working environment.
Also, you seem to be experiencing a noticeable <strong>emotional disconnect</strong>. You appear to feel detached from your work and associates, and as a result, you find yourself seeking isolation on a frequent basis.</p>
<h2 id="how-to-overcome-burnout-syndrome">How to overcome Burnout Syndrome<a class="heading-anchor" href="#how-to-overcome-burnout-syndrome" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>When things get tough, <strong>it’s really</strong> <strong>important to take care of yourself first</strong>. Adopting the following methods can help you overcome burnout and maintain a healthier, more balanced work and life approach.</p>
<h3 id="set-boundaries-saying-no-and-prioritizing-tasks">Set Boundaries: Saying No and Prioritizing Tasks<a class="heading-anchor" href="#set-boundaries-saying-no-and-prioritizing-tasks" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>The most important factor in avoiding burnout is to educate yourself to <strong>say no</strong>. Refuse to take on additional work if you are already busy, and don’t feel obligated to do things you are not responsible for. It is crucial to respect your working environment, but it’s equally important for your working environment to respect you.
Furthermore, <strong>prioritize your tasks</strong>. Break your projects into small, manageable pieces. In addition, create a diary with clear work hours and guard your personal time by avoiding reviewing emails or working late into the night or on weekends. Also, it is really critical to understand that you have to stop using your personal mobile phone or social media for work.</p>
<p><a href="/practices-behind-clean-lines-of-code/" title="Practices Behind Clean Lines Of Code">Sustainable coding practices</a> also help prevent burnout in the long run.</p>
<figure><img src="/burnout-syndrome-the-boundaries.webp" alt="Astronaut coding and keeping notes to avoid burnout." style="max-width:30%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/astronaut-working-laptop-writing-cartoon-illustration-science-business-concept-isolated-flat-cartoon-style_16425880.htm#fromView=search&#x26;page=1&#x26;position=3&#x26;uuid=036fd1ab-2056-4a55-ac21-59b5354159d9">Image by catalyststuff on Freepik</a></figcaption></figure>
<h3 id="recharge-with-self-care-breaks-and-hobbies">Recharge with Self-Care, Breaks and Hobbies<a class="heading-anchor" href="#recharge-with-self-care-breaks-and-hobbies" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<figure><img src="/burnout-syndrome-the-recharge.webp" alt="Astronaut painting the moon holding brash and color palette."><figcaption><a href="https://www.freepik.com/free-vector/cute-astronaut-painting-moon-cartoon-vector-icon-illustration-science-technology-icon-isolated-flat_65309503.htm#fromView=search&#x26;page=1&#x26;position=22&#x26;uuid=ccd02fe5-6a4d-48c0-be7f-14067012cee2">Image by catalyststuff on Freepik</a></figcaption></figure>
<p>One effective way to maintain productivity and mental well-being during work is to ensure you get enough sleep, eat healthy food, and aim for balanced meals consumed regularly throughout the day. <strong>Taking care</strong> of your body helps your mind stay sharp.
Additionally, include <strong>regular breaks</strong> on a daily basis. Taking short breaks, such as going for a short walk, can significantly contribute to refreshing your mind and re-energizing your body.
Dedicate time to engaging in both <strong>cognitive and physical activities</strong> that fill you with joy and satisfaction beyond your work duties. For example, enjoy cognitive and creative activities such as painting and making puzzles or physical activities like volleyball and running. Hobbies can improve a relaxing and vital break, allowing you to restore energy and also enhance your mental and physical health.</p>
<h3 id="build-a-supporting-network">Build a supporting network<a class="heading-anchor" href="#build-a-supporting-network" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Remember to <strong>seek support</strong> from others when you need it. Talk to friends, family, or colleagues about your situation and express your feelings. Sometimes, just sharing can relieve some stress. Count on your loved ones for advice in order to simplify your thoughts and discover other viewpoints.
If you continue to feel crushed by burnout, <strong>seeking assistance</strong> from a therapist or counselor could be beneficial. They can suggest techniques for facing your difficulties and propose strategies to help you cope and recover.</p>
<figure><img src="/burnout-syndrome-the-support.webp" alt="Astronaut couple hunging out sitting on the earth." style="max-width:30%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-astronaut-couple-sitting-earth-world-globe-cartoon-vector-icon-illustration-science-techno_134289768.htm#fromView=search&#x26;page=2&#x26;position=29&#x26;uuid=2363cbed-a851-42d6-8426-889f55263df2">Image by catalyststuff on Freepik</a></figcaption></figure>
<h3 id="from-stress-to-serenity--one-free-afternoon-for-yourself">From Stress to Serenity – One Free Afternoon for Yourself<a class="heading-anchor" href="#from-stress-to-serenity--one-free-afternoon-for-yourself" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<figure><img src="/burnout-syndrome-the-free-time.webp" alt="Astronaut playing skateboard with coffee and donut." style="max-width:30%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-astronaut-playing-skateboard-with-cup-coffee-donut-cartoon-vector-icon-illustration-flat_33834464.htm#fromView=search&#x26;page=1&#x26;position=12&#x26;uuid=cf17d3ef-9a6d-4dce-8501-26474731abcd">Image by catalyststuff on Freepik</a></figcaption></figure>
<p>Finally, keep at least one afternoon inside the week for yourself and schedule Nothing. Yes, you read it correctly. <strong>Nothing</strong>. React spontaneously. Think. What do you really need at this moment? What are your thoughts right now? Don’t think of anyone else. <strong>Just yourself</strong>. Turn an afternoon into a mini vacation and spend it focusing only on you.
What do you miss most? Is it a walk? 👟 Maybe shopping therapy? 🛍 No? So, what is it? Something more relaxing? Reading a book 📗 close to your cat? 🐈 Still no? Oh! I found it! You just need to grab a coffee, a donut, your skateboard and play in the park! Oh, yes! That’s it for today!
Something brand new is coming your way next week! Get ready and enjoy every moment!</p>
<p>Recognizing and handling burnout syndrome is crucial for having a sustainable and also satisfying career in web development and programming. By setting boundaries and realistic goals, prioritizing self-care, fostering a healthy work-life balance, surrounding yourself with people and activities you prefer, and ensuring free time, you can protect yourself from the harmful effects of burnout. Remember, you are as important as the code you write. Take time to rest and recharge, and you’ll find yourself not only more productive but also more passionate about your work. See you around! 🎈✨</p>
<p>Sometimes a fresh start helps. If you’re considering a new role, <a href="/best-job-sites-for-web-developers/" title="Best Job Sites for Web Developers">here’s where to look</a>.</p>
<figure><img src="/cute-happy-astronaut-ezgif-ezgif-com-optiwebp.webp" alt="Cute happy astronaut." style="max-width:56%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-happy-astronaut-cartoon-vector-icon-illustration-science-technology-icon-concept-isolated-flat_43397906.htm#fromView=search&#x26;page=1&#x26;position=10&#x26;uuid=a198c817-43d3-488e-910b-6e7c87a37206">Image by catalyststuff on Freepik</a></figcaption></figure>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/unmasking-impostor-syndrome-in-tech-watch-out-for-these-signs/">Impostor Syndrome in Tech: The Signs</a></li>
<li><a href="/remote-work-freedom-or-burnout/">Remote Work! Freedom or Burnout?</a></li>
<li><a href="/practices-behind-clean-lines-of-code/">Practices Behind Clean Lines Of Code</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Transparent Button in CSS</title>
      <link>https://littlecodingthings.com/how-to-make-a-transparent-button-using-html-and-css/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-make-a-transparent-button-using-html-and-css/</guid>
      <pubDate>Mon, 05 Aug 2024 09:39:00 GMT</pubDate>
      <description>Build a transparent button in HTML and CSS: shadows instead of a background, plus hover and active states that swap the label text.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hey there! 😃 In today’s technology-driven world, it’s super important to learn how to create an awesome transparent button. A well-designed button not only adds to the product’s aesthetic appeal but also enhances the user experience. Therefore, it’s essential to create buttons that are both visually appealing and functionally efficient.</p>
<p>Let’s work together, utilizing only <a href="/is-html-a-programming-language-find-out-now/">HTML</a> and <a href="/the-truth-about-css-is-it-really-a-programming-language/">CSS</a>, to design the perfect button that stands out and enhances your app’s user-friendliness.</p>
<h2 id="html-basic-structure">HTML basic structure<a class="heading-anchor" href="#html-basic-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>First, we prepare our HTML code snippet. We need to create a parent element with the class <code>.wrapper</code> that acts as the base of the button. Next, we add a child element within the parent element that will serve as the clickable part of the button. This child element has the class <code>.custom-button</code> . Doing so will help us create an interactive button that users can click on, to perform an action. How amazing is this! 😎</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"wrapper"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">button</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"custom-button"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">button</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h2 id="css-foundation">CSS foundation<a class="heading-anchor" href="#css-foundation" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Let’s continue by using our CSS magic and making our button look cool! For this post, I am writing CSS using Sass syntax. If you would like to convert it to vanilla CSS and don’t already know how, I’d suggest you use an online Sass —CSS converter.</p>
<h3 id="create-the-base-for-the-transparent-button">Create the base for the transparent button<a class="heading-anchor" href="#create-the-base-for-the-transparent-button" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>First of all, we set the <code>background-color</code> of the body to dark grey and also add some extra positioning properties in order for our button to be centered. We will be using the same color for our button, by applying the <code>background: transparent</code> CSS property, along with some width and height of our choice in the <code>.wrapper</code> class.</p>
<p>We are also applying a <code>border-radius</code> of 80 pixels and a <a href="/how-box-shadow-works-made-simple/"><code>box-shadow</code></a> with carefully selected shades of grey. It is important to select the appropriate shades to ensure the desired outcome. 😉</p>
<p>For our example, we are placing the clickable part of the button in the center of the base. For that reason, we are using the <code>flex</code> method.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">darkgrey</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">vh</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.wrapper</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">500</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">140</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">80</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #c6c2c2</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #727070</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Take a look at the image below to see what’s currently rendered on screen.</p>
<p><img src="/transparent-button-create-base.webp" alt="Τhe base of a gray transparent button." style="max-width:56%" class="img-narrow"></p>
<h3 id="create-the-clickable-part-of-the-transparent-button">Create the clickable part of the transparent button<a class="heading-anchor" href="#create-the-clickable-part-of-the-transparent-button" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>We proceed with the clickable area of our button. After applying some basic dimensions, we need to make sure the <code>background</code> is set to transparent as we did before, with the base part of the button. After that, we adjust the <code>border-radius</code> and <code>box-shadow</code> to inherit, so that these attributes would be identical to the base. To remove any natively applied border styling we use <code>border: none</code>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.custom-button</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">460</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inherit</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inherit</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">none</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Below, you see what’s on the screen now, with the clickable (top) part of our button added.</p>
<p><img src="/transparent-button-create-clickable-part.webp" alt="Α gray transparent button" style="max-width:56%" class="img-narrow"></p>
<h3 id="add-the-button-text">Add the button text<a class="heading-anchor" href="#add-the-button-text" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>To begin, we use the <code>flex</code> method to center the button’s text appropriately. Then we add the text using the <code>::before</code> CSS pseudo-element, adding “hover me” as the <code>content</code>. I used a bold, 45-pixel blue text with a black shadow effect. For enhanced readability, I opted for the Arial <code>font-family</code> as it is really legible. 🆒 ✨</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.custom-button</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  font-family</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">'Arial'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">45</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#12528e</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* a shade of blue */</span></span>
<span class="line"><span style="color:#79B8FF">  font-weight</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">bold</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">    content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"hover me"</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    text-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> -1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>In the following image, we can see what’s displayed on the screen now.</p>
<p><img src="/transparent-button-adding-text.webp" alt="A gray clickable transparent button with the words &#x22;hover me&#x22; on the top." style="max-width:56%" class="img-narrow"></p>
<h3 id="apply-the-hovereffect-of-the-transparent-button">Apply the hover effect of the transparent button<a class="heading-anchor" href="#apply-the-hovereffect-of-the-transparent-button" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Now, is the appropriate time to implement the hover effect. We can achieve this by adding the <code>:hover</code> CSS pseudo-class with the <code>cursor</code> set to pointer. After that, we will use <code>::before</code> again to modify the text <code>content</code> to display “click me”.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.custom-button</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">    cursor</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pointer</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">      content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"click me"</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Below, we can observe 🔎 the hover effect in action. Moving the cursor over the button, immediately transforms from arrow ⬆ into pointer 👆(hand), and the text content changes. The hover effect is a widely used design technique that adds interactivity and visual interest to a webpage.</p>
<p><img src="/transparent-button-adding-hover-effect.webp" alt="A gif showing a gray clickable transparent button with the words &#x22;hover me&#x22; on the top. When we hover over the button these words turn to &#x22;click me&#x22;." style="max-width:56%" class="img-narrow"></p>
<h3 id="apply-the-active-effect-of-the-transparent-button">Apply the active effect of the transparent button<a class="heading-anchor" href="#apply-the-active-effect-of-the-transparent-button" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Now, we can add the <code>:active</code> state to the button to finish our work. Once we click on the button, the active state will be triggered. To make it look more realistic and impressive, we adjust the <code>box-shadow</code> CSS property.</p>
<p>Additionally, we will modify the text <code>content</code> using the <code>::before</code> CSS pseudo-element and change it to be inspiring and display the text “Good Job!” in indigo color with white text-shadow.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.custom-button</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:active</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> -1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #969393</span><span style="color:#E1E4E8">,  </span><span style="color:#6A737D">/* top side */</span></span>
<span class="line"><span style="color:#79B8FF">      inset</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #b7b5b5</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* inset top side */</span></span>
<span class="line"><span style="color:#79B8FF">      inset</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #969393</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* inset left side */</span></span>
<span class="line"><span style="color:#79B8FF">      inset</span><span style="color:#79B8FF"> -1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #969393</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* inset right side */</span></span>
<span class="line"><span style="color:#79B8FF">      inset</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> -4</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #969393</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* inset bottom side */</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">      content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"Good Job!"</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">indigo</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      text-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> -1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>At this moment, you can witness 🧐 the active effect in action. Take a moment to observe and analyze how the effect is taking place and what impact it has. This will help you gain a better understanding of the process and its outcomes, which can be useful for future reference and decision-making. 😇 So, good luck with your work!</p>
<p><img src="/css-button-adding-active-effect.gif" alt="A gif showing a gray clickable transparent button with the words &#x22;hover me&#x22; on the top. When we hover over the button these words turn to &#x22;click me&#x22;. If we click the message: &#x22;Good Job&#x22; appears ." style="max-width:56%" class="img-narrow"></p>
<h2 id="complete-code-solution">Complete code solution<a class="heading-anchor" href="#complete-code-solution" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Below is the full code referenced in this blog post. Feel free to copy and use it in your own projects. If you have any questions or encounter any issues, don’t hesitate to reach out for assistance. You can easily copy the desired code snippet by clicking on the copy icon, located in the top-right corner of each snippet.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"wrapper"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">button</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"custom-button"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">button</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">darkgrey</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">vh</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.wrapper</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">500</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">140</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">80</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #c6c2c2</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #727070</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.custom-button</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">460</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inherit</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inherit</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">none</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-family</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">'Arial'</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">45</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#12528e</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* a shade of blue */</span></span>
<span class="line"><span style="color:#79B8FF">  font-weight</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">bold</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">    content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"hover me"</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    text-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> -1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">    cursor</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pointer</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">      content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"click me"</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:active</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> -1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #969393</span><span style="color:#E1E4E8">,  </span><span style="color:#6A737D">/* top side */</span></span>
<span class="line"><span style="color:#79B8FF">      inset</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #b7b5b5</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* inset top side */</span></span>
<span class="line"><span style="color:#79B8FF">      inset</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #969393</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* inset left side */</span></span>
<span class="line"><span style="color:#79B8FF">      inset</span><span style="color:#79B8FF"> -1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #969393</span><span style="color:#E1E4E8">, </span><span style="color:#6A737D">/* inset right side */</span></span>
<span class="line"><span style="color:#79B8FF">      inset</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> -4</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #969393</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* inset bottom side */</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">      content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"Good Job!"</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">indigo</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      text-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> -1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-make-a-circular-clickable-button-with-shadow-effect/">Circular CSS Button with Shadow Effect</a></li>
<li><a href="/how-inset-works-in-box-shadow-made-simple/">How inset Works in box-shadow (Made Simple)</a></li>
<li><a href="/coding-made-easy-with-css-selectors-an-ultimate-guide/">CSS Selectors: A Complete Guide</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Change the Default Port in Create React App</title>
      <link>https://littlecodingthings.com/how-to-change-the-default-port-in-a-create-react-app-project/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-change-the-default-port-in-a-create-react-app-project/</guid>
      <pubDate>Thu, 01 Aug 2024 16:42:00 GMT</pubDate>
      <description>Three ways to change the default port in a Create React App project: package.json, the command line, or a .env file. Pick whichever suits your setup.</description>
      <category>Setup &amp; Tools</category>
      <content:encoded><![CDATA[<p>So you just generated a new cool side project and now you are wondering how one changes the default port in a create-react-app project. After all, we have other ports available, right? And there could be a case that <code>3000</code> port is already taken. But how can you do that? There are several ways to do that, so let’s check the basic ones.</p>
<h2 id="using-packagejson">Using package.json<a class="heading-anchor" href="#using-packagejson" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>One way is to go to your <code>package.json</code> file and change your port through your scripts options, in this case, we are adding <code>PORT=3001</code> to denote that we want our app to run in port <code>3001</code></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#9ECBFF">"scripts"</span><span style="color:#E1E4E8">: {</span></span>
<span class="line"><span style="color:#79B8FF">  "start"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"PORT=3001 react-scripts start"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "build"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"react-scripts build"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "test"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"react-scripts test"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  "eject"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"react-scripts eject"</span></span>
<span class="line"><span style="color:#E1E4E8">},</span></span></code></pre></div>
<h2 id="using-the-command-line">Using the command line<a class="heading-anchor" href="#using-the-command-line" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>In certain scenarios, you may find it necessary to specify the port directly via the command line when executing your run command. You could do that by typing in your terminal</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>PORT=3001 npm start</span></span></code></pre></div>
<p>Keep in mind that if you have a port defined on your package.json and you try adding it inline through the terminal, your package.json port setting will override any port passed through the terminal.</p>
<h2 id="using-env-file">Using .env file<a class="heading-anchor" href="#using-env-file" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>In case you are working on a more complex project or a project that you will be deploying for the world to see your awesome work, you’ll need to set the port to a dynamic value. Why is that? Because the system that will handle your deployment will also be handling the ports.</p>
<p>In this case, you just need to tell your app, where to find the port’s value that will be used, when deployed.</p>
<p>Let’s start by creating a file called <code>.env</code>. Type in your terminal</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>touch .env</span></span></code></pre></div>
<p>Now open your <code>.env</code> file and type</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>PORT=3001</span></span></code></pre></div>
<p>According to the advanced configuration <a href="https://create-react-app.dev/docs/advanced-configuration/">documentation</a>, of Create-React-App, the app’s listening port is determined by reading the value of PORT from the <code>.env</code> file by default.</p>
<p>As a result, our application will utilize the PORT value specified in the <code>.env</code> file to run, so there is no need to make any more changes to our code.</p>
<p>If you’re curious about the order of precedence in case someone adds a port to every possible option, I’ve conducted experiments that reveal the following respected order.</p>
<ul>
<li><code>package.json</code></li>
<li>command line</li>
<li><code>.env</code> file</li>
</ul>
<h2 id="before-you-go-further-create-react-app-is-deprecated-️">Before you go further: Create React App is deprecated ⚠️<a class="heading-anchor" href="#before-you-go-further-create-react-app-is-deprecated-️" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>If you’re reading this while starting something brand new, you should know this first, because it changes the answer.</p>
<p>On <strong>February 14, 2025</strong> the React team <a href="https://react.dev/blog/2025/02/14/sunsetting-create-react-app">deprecated Create React App</a>. In their words: <em>“Today, we’re deprecating Create React App for new apps, and encouraging existing apps to migrate to a framework, or to migrate to a build tool like Vite, Parcel, or RSBuild.”</em></p>
<p>Their recommendations are Next.js, React Router or Expo if you want a framework, and <strong>Vite</strong>, Parcel or Rsbuild if you just want a build tool. CRA itself keeps working — it’s in maintenance mode and a version was published that works with React 19 — so nothing you already built is going to stop running tomorrow. But <code>npx create-react-app my-app</code> is no longer the thing to type on a Monday morning.</p>
<p>Everything above still applies to your existing project — as does our guide to <a href="/how-to-add-sass-to-a-create-react-app-project/">adding Sass to a Create React App project</a>, which is in exactly the same boat. If you’re starting fresh, here’s the same job in Vite.</p>
<h2 id="changing-the-port-in-vite-">Changing the port in Vite 🚀<a class="heading-anchor" href="#changing-the-port-in-vite-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Vite’s dev server defaults to <strong>5173</strong>, not 3000, so the first thing to know is that the number in your bookmark bar is going to look different.</p>
<p>The quickest way is on the command line:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">npm</span><span style="color:#9ECBFF"> run</span><span style="color:#9ECBFF"> dev</span><span style="color:#79B8FF"> --</span><span style="color:#79B8FF"> --port</span><span style="color:#79B8FF"> 3001</span></span></code></pre></div>
<p>(The extra <code>--</code> is npm’s way of saying “everything after this belongs to the script, not to npm”.)</p>
<p>To make it stick, put it in <code>vite.config.js</code>:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">import</span><span style="color:#E1E4E8"> { defineConfig } </span><span style="color:#F97583">from</span><span style="color:#9ECBFF"> 'vite'</span></span>
<span class="line"><span style="color:#F97583">import</span><span style="color:#E1E4E8"> react </span><span style="color:#F97583">from</span><span style="color:#9ECBFF"> '@vitejs/plugin-react'</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">export</span><span style="color:#F97583"> default</span><span style="color:#B392F0"> defineConfig</span><span style="color:#E1E4E8">({</span></span>
<span class="line"><span style="color:#E1E4E8">  plugins: [</span><span style="color:#B392F0">react</span><span style="color:#E1E4E8">()],</span></span>
<span class="line"><span style="color:#E1E4E8">  server: {</span></span>
<span class="line"><span style="color:#E1E4E8">    port: </span><span style="color:#79B8FF">3001</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">    strictPort: </span><span style="color:#79B8FF">true</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">  },</span></span>
<span class="line"><span style="color:#E1E4E8">})</span></span></code></pre></div>
<p><code>strictPort</code> is the option worth knowing about. By default, if 3001 is busy Vite quietly moves to the next free port and carries on — friendly, until an OAuth callback or a CORS allowlist is pinned to a specific port and you spend twenty minutes debugging a redirect. With <code>strictPort: true</code>, Vite exits instead of moving, which is what you want the moment anything else depends on that number.</p>
<h3 id="the-trap-when-you-migrate-from-cra">The trap when you migrate from CRA<a class="heading-anchor" href="#the-trap-when-you-migrate-from-cra" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong><code>PORT=3001</code> in a <code>.env</code> file does nothing in Vite.</strong> That’s the single most common surprise coming from CRA, and it doesn’t error — the server just starts on 5173 and you assume the file isn’t being read at all.</p>
<p>Two different things are going on. CRA treats <code>PORT</code> as configuration for its dev server. Vite takes its port from <code>server.port</code> in the config file or the <code>--port</code> flag, and it only exposes environment variables to your app if they start with <code>VITE_</code>. So <code>.env</code> is still useful in Vite — for API keys and endpoints, as covered in our <a href="/environment-variables-101-secure-your-secrets-like-a-pro/">guide to environment variables with dotenv</a> — just not for this.</p>
<h2 id="something-is-already-running-on-port-3000-">“Something is already running on port 3000” 😅<a class="heading-anchor" href="#something-is-already-running-on-port-3000-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Sooner or later you get this instead of a running app. Usually it’s an earlier dev server that never actually died — you closed the terminal tab, the process didn’t get the message.</p>
<p>Find out who has it:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">lsof</span><span style="color:#79B8FF"> -nP</span><span style="color:#79B8FF"> -i</span><span style="color:#9ECBFF"> :3000</span></span></code></pre></div>
<p>You’ll get a line naming the command and a PID. If it’s a stray <code>node</code>, end it:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#79B8FF">kill</span><span style="color:#79B8FF"> 84128</span></span></code></pre></div>
<p>Use the real PID from the previous command, and try <code>kill</code> on its own before reaching for <code>kill -9</code> — the polite version lets the process clean up after itself.</p>
<p>One macOS-specific trap while you’re here: <strong>don’t move your app to port 5000</strong>. On a modern Mac, AirPlay Receiver is already listening there — and on 7000 — under the <code>ControlCenter</code> process. You can see it for yourself with <code>lsof -nP -i :5000</code>. You can turn AirPlay Receiver off in System Settings, but picking a different port is a lot less disruptive. 3001, 4000 and 8080 are all quiet.</p>
<h2 id="frequently-asked-questions">Frequently asked questions<a class="heading-anchor" href="#frequently-asked-questions" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<h3 id="what-is-the-default-port-for-a-react-app">What is the default port for a React app?<a class="heading-anchor" href="#what-is-the-default-port-for-a-react-app" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>3000 for Create React App, and <strong>5173</strong> for Vite. Neither number is special — they’re just what the tool picked, and both are easy to change.</p>
<h3 id="why-does-my-react-app-still-open-on-port-3000-after-i-changed-it">Why does my React app still open on port 3000 after I changed it?<a class="heading-anchor" href="#why-does-my-react-app-still-open-on-port-3000-after-i-changed-it" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Almost always one of three things: another config is overriding you (in CRA, the <code>PORT</code> set inside <code>package.json</code> wins over the one you typed in the terminal), you edited <code>.env</code> in a Vite project where it has no effect, or the dev server was never restarted. Port changes are read at startup — stop the server and start it again.</p>
<h3 id="how-do-i-run-two-react-apps-at-the-same-time">How do I run two React apps at the same time?<a class="heading-anchor" href="#how-do-i-run-two-react-apps-at-the-same-time" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Give each one its own port and run them in separate terminal tabs. This is the usual reason people go looking for this setting at all: an API on 3000 and a frontend on 3001, talking to each other.</p>
<h3 id="can-i-use-a-port-below-1024">Can I use a port below 1024?<a class="heading-anchor" href="#can-i-use-a-port-below-1024" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Not without <code>sudo</code>, and you don’t want to. Ports below 1024 are privileged on macOS and Linux, which is why nobody runs a dev server on port 80. Stay above 1024 and let a proxy handle port 80 in production.</p>
<p>Don’t forget to have fun with your new project!! You got this! 😎</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-add-sass-to-a-create-react-app-project/">How to Add Sass to A Create-React-App Project</a></li>
<li><a href="/environment-variables-101-secure-your-secrets-like-a-pro/">Environment Variables with Dotenv</a> — more on the .env approach used above</li>
<li><a href="/naming-conventions-how-to-name-your-components-without-fighting-your-ui-library/">Component Naming Conventions in React</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How To Make A CSS Text Reflection Effect</title>
      <link>https://littlecodingthings.com/how-to-make-a-css-text-reflection-effect/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-make-a-css-text-reflection-effect/</guid>
      <pubDate>Sat, 27 Jul 2024 12:03:00 GMT</pubDate>
      <description>Mirror a heading under itself using a ::before pseudo-element, rotate(180deg) scaleX(-1), and a gradient clipped to the text.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hi there! 😃 In this post, we’ll learn bit by bit how to create a CSS text reflection effect. When we say reflection, we’re referring to a mirror-like effect that looks like the text reflects on a surface, much like the way we see our reflection in a mirror.</p>
<p>This is a simple yet amazing way to enhance the appearance of your text. Let’s analyze our effect so that you can easily follow along.</p>
<h2 id="html-structure">HTML structure<a class="heading-anchor" href="#html-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We will begin with our <a href="/most-useful-html-elements-for-maximizing-better-results/">HTML</a> structure. As you can see below, I prepared a <code>div</code> with the class <code>.reflection-text</code> , this is where our effect will take place.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"reflection-text"</span><span style="color:#E1E4E8">>HELLO WORLD&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h2 id="css-foundation">CSS foundation<a class="heading-anchor" href="#css-foundation" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Let’s move forward with the <a href="/how-to-work-with-css-syntax-the-correct-way/">CSS</a> basic structure. We start with defining the <code>background</code>. It’s worth noting that using <code>radial-gradient</code> can make our effect more impressive. 😃</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">radial-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">lightgreen</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">darkgreen</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">vh</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Below, we can see the background we just created.</p>
<p><img src="/css-text-reflection-radial-background.webp" alt="An image showing radial-gradiant background. It has lightgreen color in the center and darkgreen as it spreads outward." style="max-width:69%" class="img-narrow"></p>
<p>In web development, we use the <code>flex</code> method in order to center our text. Then we will enhance its appearance, by making some adjustments. We will set the <code>font-size</code> to 100 pixels, select the “Roboto” <code>font-family</code>, and choose white as the text <code>color</code>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.reflection-text</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-family</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">'Roboto'</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">sans-serif</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>This is what is rendered on the screen for now. A perfectly centered, 🎯 white text.</p>
<p><img src="/css-text-reflection-1-create-origin-text.webp" alt="An image showing radial-gradiant background. It has lightgreen color in the center and darkgreen as it spreads outward. It has a perfectly centered white text writing &#x22;HELLO WORLD&#x22;." style="max-width:69%" class="img-narrow"></p>
<h2 id="adding-the-css-structure-for-the-reflection-effect">Adding the CSS structure for the reflection effect<a class="heading-anchor" href="#adding-the-css-structure-for-the-reflection-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Creating a reflection can be achieved by using pseudo-elements like <code>::before</code> and <code>::after</code>. To ensure this works properly, we need to include <code>position: relative</code> in our <code>.reflection-text</code> class.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.reflection-text</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Now, we are ready to proceed and create our reflection by adding the <code>::before</code> pseudo-element with all the necessary properties, as shown in the following code snippet.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.reflection-text::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"HELLO WORLD"</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">65</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">180</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">scaleX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-1</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#F97583">    to</span><span style="color:#79B8FF"> bottom</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.5</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span></span>
<span class="line"><span style="color:#E1E4E8">  );</span></span>
<span class="line"><span style="color:#79B8FF">  background-clip</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">text</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  opacity</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0.3</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h3 id="breaking-down-the-process">Breaking down the process<a class="heading-anchor" href="#breaking-down-the-process" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>🟢 To begin, we add the text “HELLO WORLD” to create another text element with the same <code>content</code>. This new text will serve as our reflection. Then, we set <code>position: absolute</code> so that we can move our reflected text below the original text. We use the <code>top</code> property to move the reflected text 65 pixels from the top, but you can always move the reflection in any direction you prefer. It is important to position the text and its reflection closely together for a more realistic reflection effect. 😉</p>
<p><img src="/css-text-reflection-2-adding-content.webp" alt="An image showing radial-gradiant background. It has lightgreen color in the center and darkgreen as it spreads outward. It has a perfectly centered white text writing &#x22;HELLO WORLD&#x22; and the same text reflected below." style="max-width:69%" class="img-narrow"></p>
<p>🟢 We move forward and use the <code>transform</code> CSS property to <code>rotate</code> the text by 180 degrees</p>
<p><img src="/css-text-reflection-3-adding-transform-rotation.webp" alt="An image showing radial-gradiant background. It has lightgreen color in the center and darkgreen as it spreads outward. It has a perfectly centered white text writing &#x22;HELLO WORLD&#x22; and the same text reflected below. The text has a rotate by 180deg." style="max-width:69%" class="img-narrow"></p>
<p>and then flip it horizontally using <code>scaleX(-1)</code>. Now we have the perfect reflection! Let’s continue and make it more realistic.</p>
<p><img src="/css-text-reflection-4-adding-transform-scale.webp" alt="An image showing radial-gradiant background. It has lightgreen color in the center and darkgreen as it spreads outward. It has a perfectly centered white text writing &#x22;HELLO WORLD&#x22; and the same text reflected below, rotated by 180deg and fliped horizontaly." style="max-width:69%" class="img-narrow"></p>
<p>🟢 In the next step, we will adjust the color of our reflected text. To achieve this, we will utilize the <code>linear-gradient</code> CSS property and specify the direction as downwards. This will create white gradients, with the top appearing more intense and gradually fading towards the bottom of the text.</p>
<p><img src="/css-text-reflection-5-adding-linear-gradient.webp" alt="An image showing radial-gradiant background. It has lightgreen color in the center and darkgreen as it spreads outward. It has a perfectly centered white text writing &#x22;HELLO WORLD&#x22; and the same text reflected below, rotated by 180deg and fliped horizontaly. It also has linear-gradient with downward direction." style="max-width:69%" class="img-narrow"></p>
<p>🟢 It is commonly known that gradients cannot be directly applied to texts. Don’t worry! 🤔 We already have <a href="/css-rainbow-text-how-to-make-astonishing-and-vibrant-fonts/" title="the solution to this problem">the solution to this problem</a>. For now, let’s give a quick explanation. To create a clipped linear background pattern for text, first, we add the <code>background-clip: text</code> property, and at the same time, we set the color to transparent, and our text automatically turns to transparent. In that way, our text takes the <code>background: linear-gradient</code> as its real color.</p>
<p><img src="/css-text-reflection-6-adding-webkit-text.webp" alt="An image showing a radial-gradiant background. It has lightgreen color in the center and darkgreen as it spreads outward. It has a white text writing &#x22;HELLO WORLD&#x22; and the same text reflected below. They are perfectly centered." style="max-width:69%" class="img-narrow"></p>
<p>🟢 For a more transparent text, we can adjust the <code>opacity</code>. The lower the <a href="/the-unique-css-opacity-check-out-this-amazing-property/">opacity</a>, the more transparent our text becomes. So, here we are! Our reflection is ready! 🥳</p>
<p><img src="/css-text-reflection-7-adding-opacity.webp" alt="CSS text reflection effect. An image showing a radial-gradiant background. It has lightgreen color in the center and darkgreen as it spreads outward. It has a white text writing &#x22;HELLO WORLD&#x22; and the same text reflected below. They are perfectly centered." style="max-width:69%" class="img-narrow"></p>
<h2 id="exploring-different-colors">Exploring different colors<a class="heading-anchor" href="#exploring-different-colors" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>🔖 It is always an option to use black or any other color in our work. Below, I’ve included examples of texts with black, purple, and green colors. It’s important to remember that the key factor is to set the correct gradients at the <code>linear-gradient</code> property. That way, we can create respective shades. Therefore, please give extra attention to that! 😊</p>
<h3 id="black-text">Black text<a class="heading-anchor" href="#black-text" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.reflection-text</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-family</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">'Roboto'</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">sans-serif</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* default color */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.reflection-text::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"HELLO WORLD"</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">65</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">180</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">scaleX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-1</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">to</span><span style="color:#79B8FF"> bottom</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.5</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  background-clip</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">text</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  opacity</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0.3</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-text-black-reflection.webp" alt="An image showing a radial-gradiant background. It has lightgreen color in the center and darkgreen as it spreads outward. It has a black text writing &#x22;HELLO WORLD&#x22; and the same text reflected below. They are perfectly centered." style="max-width:69%" class="img-narrow"></p>
<h3 id="purple-text">Purple Text<a class="heading-anchor" href="#purple-text" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.reflection-text</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-family</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">'Roboto'</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">sans-serif</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.reflection-text::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"HELLO WORLD"</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">65</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">180</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">scaleX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-1</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">to</span><span style="color:#79B8FF"> bottom</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">55</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">205</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">55</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">205</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.5</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">55</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">205</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  background-clip</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">text</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  opacity</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0.3</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-text-purple-reflection.webp" alt="An image showing a radial-gradiant background. It has lightgreen color in the center and darkgreen as it spreads outward. It has a purple text writing &#x22;HELLO WORLD&#x22; and the same text reflected below. They are perfectly centered." style="max-width:69%" class="img-narrow"></p>
<h3 id="green-text"><strong>Green Text</strong><a class="heading-anchor" href="#green-text" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.reflection-text</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-family</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">'Roboto'</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">sans-serif</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.reflection-text::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  content</span><span style="color:#E1E4E8">:</span><span style="color:#9ECBFF">"HELLO WORLD"</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">65</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">180</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">scaleX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-1</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">to</span><span style="color:#79B8FF"> bottom</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">20</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">150</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">20</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">20</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">150</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">20</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.5</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">20</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">150</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">20</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  background-clip</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">text</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  opacity</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0.3</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-text-green-reflection.webp" alt="An image showing a radial-gradiant background. It has lightgreen color in the center and darkgreen as it spreads outward. It has a green text writing &#x22;HELLO WORLD&#x22; and the same text reflected below. They are perfectly centered." style="max-width:69%" class="img-narrow"></p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-make-a-css-reflection-effect/">How To Make A CSS Reflection Effect</a></li>
<li><a href="/how-to-make-css-reflection-the-easy-way/">How To Make CSS Reflection – The Easy Way</a></li>
<li><a href="/how-to-build-stunning-rounded-text-handy-tips/">How To Build Stunning Rounded Text – Handy Tips</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>CSS Linear Gradient: A Practical Guide</title>
      <link>https://littlecodingthings.com/css-linear-gradient-techniques-how-to-make-colorful-line-drawings/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/css-linear-gradient-techniques-how-to-make-colorful-line-drawings/</guid>
      <pubDate>Mon, 22 Jul 2024 10:27:00 GMT</pubDate>
      <description>Control linear-gradient direction with keywords or degrees, then use percentage color stops for soft blends or hard-edged stripes.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hey there! 😃 Exploring CSS linear gradient techniques is a fantastic approach to fashion vibrant, colorful mixtures. Gradients give us the flexibility to choose any desired direction, defined by their starting and ending points. Mixing a minimum of two <a href="/what-you-need-to-know-about-css-color-methods/" title="colors">colors</a> is fundamental, yet the potential for blending expands further, enabling us to achieve seamless transitions or pronounced shifts based on our design requirements.</p>
<p>Today, let’s dive into the exciting world of CSS linear gradient techniques. 🌈✨ Picture a smooth transition of colors in a straight line, adding a sleek and dynamic touch to your web design. With linear gradients, you can smoothly transition between colors. You have the power to guide the eye seamlessly from one color to another. Whether it’s a subtle shift or a striking contrast, mastering linear gradients empowers you to enhance the visual appeal of your web projects.</p>
<p>Ready to discover 🔍 the art and versatility behind linear gradients? Let’s get started! 💻</p>
<h2 id="definition-of-a-linear-gradient">Definition of a linear gradient<a class="heading-anchor" href="#definition-of-a-linear-gradient" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>A linear gradient is a visual effect that allows us to smoothly shift between colors in a straight line inside any shape we want. It’s like blending multiple colors together in a straight line pattern, allowing us to create colorful and visually appealing backgrounds or effects for elements on our website.</p>
<blockquote>
<p>A linear gradient is a visual effect that allows us to smoothly shift between colors in a straight line inside any shape we want</p>
</blockquote>
<h2 id="the-default-css-linear-gradient">The default CSS linear gradient<a class="heading-anchor" href="#the-default-css-linear-gradient" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We will begin our exploration with the default linear gradient, characterized by its <strong>top-to-bottom direction</strong>. The following code snippet and image provide a clear representation.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.linear-default</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/* we are free to use "deg" too */</span></span>
<span class="line"><span style="color:#B392F0">.linear-default</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">180</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/linear1-by-deafault-top-to-bottom.webp" alt="Linear-gradient CSS property effect that creates a smooth transition from top to bottom (default direction) using red and green color." style="max-width:25%" class="img-narrow"></p>
<h2 id="from-side-to-side">From side to side<a class="heading-anchor" href="#from-side-to-side" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We can adjust the direction of our gradients whenever we need to. To help you understand this better, take a look at the example below, where we changed the default direction to <code>to right</code>.</p>
<p>We are also free to choose any direction we want <code>to top</code> , <code>to right</code> , <code>to bottom</code> (the default direction), <code>to left</code>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.linear-to-right</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">to</span><span style="color:#79B8FF"> right</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/linear2-from-side-to-side.webp" alt="A smooth transition from left to right using red, green and blue color using the background-image: linear-gradient (to right, red, green, blue) CSS property" style="max-width:25%" class="img-narrow"></p>
<h2 id="from-corner-to-corner">From corner to corner<a class="heading-anchor" href="#from-corner-to-corner" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>At any point, we also have the flexibility to alter the orientation of our gradients along the diagonal path. To illustrate this concept, consider the following example with the <code>to bottom right</code> direction.</p>
<p>Here colors would spread from the top-left corner to the bottom-right corner. We can combine any <strong>corner with its adjacent sides</strong>, <code>to top left</code>, <code>to top right</code>, <code>to bottom left</code>, and <code>to bottom right</code>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.linear-to-corner</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">to</span><span style="color:#79B8FF"> bottom</span><span style="color:#79B8FF"> right</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/linear3-from-corner-to-corner.webp" alt="A smooth transition from top left to bottom right using red, green and blue color using the background-image: linear-gradient (to bottom right, red, green, blue) CSS property" style="max-width:25%" class="img-narrow"></p>
<h2 id="css-linear-gradient-using-percentages-">CSS Linear gradient using percentages %<a class="heading-anchor" href="#css-linear-gradient-using-percentages-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<h3 id="with-less-blend">With less blend<a class="heading-anchor" href="#with-less-blend" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>If we want to create a linear gradient with less blending (colors have more distinct limits this way) and maintain the same space for each color, we can use equal specific stops in the gradient by adding <code>%</code> percentages.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.linear-less-blend</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#79B8FF">    red</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">red</span><span style="color:#79B8FF"> 18</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    green</span><span style="color:#79B8FF"> 22</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#79B8FF"> 38</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    blue</span><span style="color:#79B8FF"> 42</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#79B8FF"> 58</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    purple</span><span style="color:#79B8FF"> 62</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">purple</span><span style="color:#79B8FF"> 78</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    orange</span><span style="color:#79B8FF"> 82</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">%</span></span>
<span class="line"><span style="color:#E1E4E8">  );</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>🕵️‍♂️ In this example, I’ve divided the space into 5 segments, but I left a 4% blend among each space in order to create a smooth but small transition.</p>
<p>The percentages between the color stops determine how smooth the transition between colors is.</p>
<ul>
<li><strong>Red (0% – 18%)</strong>: defines a red color stop that starts at 0% and ends at 18% of the gradient.</li>
<li>Between <strong>18% and 22%</strong>, there is no specific color stop defined. This gap represents a transition zone where the gradient transitions smoothly from red to green.</li>
<li><strong>Green (22% – 38%)</strong>: defines a green color stop that starts at 22% and ends at 38% of the gradient.</li>
<li>Between <strong>38% and 42%</strong>, there is no specific color stop defined. This gap represents a transition zone where the gradient transitions smoothly from green to blue.</li>
<li><strong>Blue (42% – 58%)</strong>: defines a blue color stop that starts at 42% and ends at 58% of the gradient.</li>
<li>Between <strong>58% and 62%</strong>, there is no specific color stop defined. This gap represents a transition zone where the gradient transitions smoothly from blue to purple.</li>
<li><strong>Purple (62% – 78%)</strong>: defines a purple color stop that starts at 62% and ends at 78% of the gradient.</li>
<li>Between <strong>78% and 82%</strong>, there is no specific color stop defined. This gap represents a transition zone where the gradient transitions smoothly from purple to orange.</li>
<li><strong>Orange (82% – 100%)</strong>: defines an orange color stop that starts at 82% and ends at 100% of the gradient.</li>
</ul>
<p><img src="/linear4-less-blend.webp" alt="A colorful css linear gradient technique. Setting the background-image: linear-gradient( red 0%, red 18%, green 22%, green 38%, blue 42%, blue 58%, purple 62%, purple 78%, orange 82%, orange 100% );" style="max-width:25%" class="img-narrow"></p>
<h3 id="without-blend">Without blend<a class="heading-anchor" href="#without-blend" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Finally, it is really useful to know that we are able to create non-smooth transitions. In the following example, we will see a gradient with distinct color stops at specific percentage intervals, resulting in a distinct color transition from red to orange. Each color stop abruptly changes to the next color at the defined percentage points.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.linear-no-blend</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#79B8FF">    red</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">red</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    green</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#79B8FF"> 40</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    blue</span><span style="color:#79B8FF"> 40</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    purple</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">purple</span><span style="color:#79B8FF"> 80</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    orange</span><span style="color:#79B8FF"> 80</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">%</span></span>
<span class="line"><span style="color:#E1E4E8">  );</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>🕵️‍♂️ In this example, I’ve divided the space into 5 equal segments without blending among each other. So, we create multiple color stops without transitions.</p>
<ul>
<li><strong>Red (0% – 20%)</strong>: defines a red color stop that starts at 0% and ends at 20% of the gradient.</li>
<li><strong>Green (20% – 40%)</strong>: defines a green color stop that starts at 20% and ends at 40% of the gradient.</li>
<li><strong>Blue (40% – 60%)</strong>: defines a blue color stop that starts at 40% and ends at 60% of the gradient.</li>
<li><strong>Purple (60% – 80%)</strong>: defines a purple color stop that starts at 60% and ends at 80% of the gradient.</li>
<li><strong>Orange (80% – 100%)</strong>: defines an orange color stop that starts at 80% and ends at 100%</li>
</ul>
<p><img src="/linear5-without-blend.webp" alt="A colorful css linear gradient technique. Setting the background-image: linear-gradient( red 0%, red 20%, green 20%, green 40%, blue 40%, blue 60%, purple 60%, purple 80%, orange 80%, orange 100% ); without blending" style="max-width:25%" class="img-narrow"></p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/css-radial-gradient-techniques-how-to-make-colorful-infinite-loops/">CSS Radial Gradient: A Practical Guide</a></li>
<li><a href="/css-conic-gradient-technique-how-to-make-stunning-visual-effects/">CSS Conic Gradient Made Easy</a></li>
<li><a href="/create-playful-border-effects-combining-css-gradients-with-the-border-image-slice-css-property/">CSS Gradient Borders with border-image</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How To Make a CSS Shine Effect Animation</title>
      <link>https://littlecodingthings.com/how-to-make-a-css-shine-effect-animation/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-make-a-css-shine-effect-animation/</guid>
      <pubDate>Wed, 17 Jul 2024 10:00:00 GMT</pubDate>
      <description>Sweep a glossy highlight across an element: a skewed ::before pseudo-element, overflow: hidden, and a two-stop @keyframes animation.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Welcome to this post! Today, I will share with you how to create a fascinating CSS shine effect animation. To make it more interesting and attractive, I have already prepared an avatar (using only HTML and CSS) and added the animation to it. If you’re curious about how I made the avatar, you can find the complete avatar code at the end of this post. Please feel free to enclose it in your animation if you wish. Remember, the most important thing is to have fun and let your creativity shine. 😉 ✨</p>
<p>For the moment, let’s focus on making this astonishing animation!</p>
<p><img src="/create-shine-effect-gif-may-04-2023.gif" alt="This is a gif which shows our shine effect over the avatar-container." style="max-width:28%" class="img-narrow"></p>
<h2 id="html-structure">HTML structure<a class="heading-anchor" href="#html-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>To begin, we need to create the base for our project by adding the HTML structure. We’ll start by creating our <code>avatar-container</code> , which will serve for our manipulations. I will carefully guide you through the following steps to achieve the desired results. Once we have a good structure in place, we can build upon it our CSS shine effect.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"avatar-container"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8"> ... Here goes my avatar</span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">> </span><span style="color:#6A737D">&#x3C;!-- end of avatar-container --></span></span></code></pre></div>
<h2 id="css-basic-structure">CSS basic structure<a class="heading-anchor" href="#css-basic-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Moving forward, let’s focus on organizing our project’s visual appeal by adding the CSS structure. Our first step will be to center the <code>avatar-container</code> on the screen, therefore, we can take advantage of the <code>display: flex</code> property of the body element. This will help us align it along the horizontal and vertical axes, creating a perfectly centered layout. With this basic structure in place, we can then proceed to add styles and create everything we have in mind. 😊</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#FFAB70">$body-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#6e87ef</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">*</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  margin</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  padding</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-sizing</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">border-box</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">html</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$body-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h2 id="css-avatar-container">CSS avatar container<a class="heading-anchor" href="#css-avatar-container" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>In order to place the avatar inside the container, it is essential to set it <code>position: relative</code>. Then we can place the components we want to include for our avatar, just by adding <code>position: absolute</code> to them.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.avatar-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  min-width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">320</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">320</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">/* end of avatar-container */</span></span></code></pre></div>
<p><img src="/create-shine-effect-container.webp" alt="The curcular container with a blue background." style="max-width:28%" class="img-narrow"></p>
<h2 id="css-shine-effect">CSS Shine Effect<a class="heading-anchor" href="#css-shine-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>All the necessary preparations have been completed. Let’s now move forward and make the <strong><em>shine</em></strong> 🥳 <strong><em>effect.</em></strong></p>
<h3 id="create-the-shine">Create the shine<a class="heading-anchor" href="#create-the-shine" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<ul>
<li>Firstly, we use the <a href="/coding-made-easy-with-css-selectors-an-ultimate-guide/#before-and-after"><code>::before</code> pseudo-element</a> which allows styling specific parts of an element without adding extra content to HTML. It behaves as a child of the chosen CSS element. In our case, <code>avatar-container</code> takes extra data only by using <code>::before</code>.</li>
<li>Next, we set <code>width: 30%</code> and <code>height: 100%</code> as this is a proper space in our example.</li>
<li>We also set <code>background-color: rgba(255, 255, 255, 0.4)</code> as it is the most suitable for the CSS shine effect.</li>
<li>We continue with <code>z-index</code> which overlaps <strong>the stack order</strong> of an <em>HTML</em> element. In simple words, it manages which HTML element should appear on top of others. The higher the stack order, the higher the element will be placed at the top of the stacking order. A really useful CSS property that is responsible for layering. To achieve the desired effect over my avatar, I have specified a <code>z-index: 3</code> as my avatar has multiple layers. Without multiple layers applied to it (in simple words without the avatar), <code>z-index</code> CSS property is not necessary. It’s <strong><em>good practice</em></strong> when we use z-index to count close numbers. We can set positive and negative integer values.</li>
</ul>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.avatar-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">320</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">320</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    overflow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">hidden</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">      content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">30</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.4</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">skewX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-20</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-120</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    } </span><span style="color:#6A737D">/* end of before */</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">/* end of avatar-container */</span></span></code></pre></div>
<p>The image below displays a preview of the code mentioned above.</p>
<p><img src="/create-shine-effect1.webp" alt="This is an image which shows how we create the shine for our shine effect using the appropriate css properties." style="max-width:28%" class="img-narrow"></p>
<h3 id="transform-the-css-shine-effect">Transform the CSS shine effect<a class="heading-anchor" href="#transform-the-css-shine-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<ul>
<li>Afterward is necessary to add <code>overflow: hidden</code> to <code>avatar-container</code>, as we want to hide the content that flows over our container’s bounds.</li>
</ul>
<p><img src="/create-shine-effect2.webp" alt="This is an image which shows how we limit the shine for our shine effect using overflow: hidden css property." style="max-width:28%" class="img-narrow"></p>
<ul>
<li>We continue with <code>transform: skew</code> as a way to add inclination to our shine.</li>
</ul>
<p><img src="/create-shine-effect3.webp" alt="This is an image which shows how we transform the shine for our shine effect using transform: skew css property." style="max-width:28%" class="img-narrow"></p>
<ul>
<li>Finally <code>left: -120px</code> keeps our effect in the appropriate place, -120px left out of the <code>avatar-container</code> , in order to be invisible. As we previously used, <code>overflow: hidden</code> anything outside of the <code>avatar-container</code> is not visible, that’s why in this pick, below, we can’t see our effect. It’s still there though! 😄</li>
</ul>
<p><img src="/create-shine-effect4.webp" alt="This is an image which shows were we have to place the shine for our shine effect. We also add overflow: hidden; css property." style="max-width:28%" class="img-narrow"></p>
<p><strong>HINT</strong></p>
<p>💡 Well, maybe at this point it might be a good idea to temporarily disable the CSS property <code>overflow: hidden</code> and observe the current position of the effect. By doing so, one can see if the effect is working as intended and make any necessary adjustments. <strong>The effect is now positioned -120 pixels to the left</strong>, as this is the starting point from where the effect will begin to move.</p>
<p><img src="/create-shine-effect5.webp" alt="This is an image which shows were we have to place the shine we create previously, using left css property." style="max-width:47%" class="img-narrow"></p>
<h3 id="create-an-animation-for-the-css-shine-effect">Create an animation for the CSS shine effect<a class="heading-anchor" href="#create-an-animation-for-the-css-shine-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<ul>
<li>To finalize my work, firstly, I’m adding the animation CSS property <code>animation: &#x3C;animation-name> &#x3C;animation-duration> &#x3C;animation-iteration-count></code> which is responsible for the way our animation behaves.</li>
<li>Secondly, I add CSS <code>@keyframes</code> which is used to control the style of the animation at different points in time. In this post, we want our shine to move rightwards, starting from -120px left to 350px left and then turning back to -120px left again.</li>
<li>By combining these 2 properties we end up having the desired animation result, that is, moving our shine every 5 seconds, forever (infinite), from -120px to 350px and back.</li>
</ul>
<p>🚫 <strong><em>It is required to connect these two properties. We do so by giving a name to the @keyframes and putting the same name on the animation property.</em></strong> In our case, this name is “shine”.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.avatar-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#79B8FF">    animation</span><span style="color:#E1E4E8">: shine </span><span style="color:#79B8FF">5</span><span style="color:#F97583">s</span><span style="color:#79B8FF"> infinite</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">/* end of before */</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">/* end of avatar-container */</span></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/* My animation */</span></span>
<span class="line"><span style="color:#F97583">@keyframes</span><span style="color:#B392F0"> shine</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#B392F0">  0%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-120</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  50%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">350</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  100%</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-120</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/create-shine-effect-gif-may-04-2023.gif" alt="This is a gif which shows our shine effect moving over the avatar-container. We have this resault because we add the @keyframes." style="max-width:42%" class="img-narrow"></p>
<p>💡 If you want to see the whole move of the CSS shine effect you can once again disable the CSS property <code>overflow: hidden</code> to <code>avatar-container</code> and observe the effect. Isn’t it great? 😄</p>
<p><img src="/create-shine-effect-gif-hidden-may-09-2023.gif" alt="This is a gif which shows our CSS shine effect animation over the avatar-container with overflow: hidden in order to see the whole effect." style="max-width:47%" class="img-narrow"></p>
<p>🔖 Please be informed that you have the flexibility to modify the <code>background-color: rgba(..., ..., ..., ...)</code> CSS property at any point to adjust both the color and opacity of your shine effect. In this context, I have chosen to generate a grey shine, as this shade is widely recognized and utilized.</p>
<p><img src="/shine-effect-rgba.webp" alt="An outline about values on background-color CSS property." style="max-width:42%" class="img-narrow"></p>
<p>Below, I add some examples with different shades. You are free to try them, or you can experiment and create some from scratch! 🛠</p>
<p>Yellow shade -> <code>background-color:rgba(255, 255, 0, 0.2)</code></p>
<p><img src="/shine-effect-yellow.webp" alt="This image shows a yellow shine effect." style="max-width:42%" class="img-narrow"></p>
<p>🧨 Blue shade -> <code>background-color:rgba(100, 100, 250, 0.5)</code> always remember to make contrasts. <strong>Avoid</strong> using the same color for backgrounds and shades.</p>
<p><img src="/shine-effect-blue.webp" alt="This image shows a blue shine effect on top of a blue background." style="max-width:42%" class="img-narrow"></p>
<p>You can also try to change both the container’s and shades’ <code>background-color</code>.</p>
<p>Pink shade -> <code>background-color:rgba(238, 130, 238, 0.3)</code></p>
<p>Container’s color -> <code>background-color: #c4c0c0</code> (grey)</p>
<p><img src="/shine-effect-pink.webp" alt="This image shows a pink shine effect on top of a grey background." style="max-width:42%" class="img-narrow"></p>
<h2 id="complete-avatar-code">Complete avatar code<a class="heading-anchor" href="#complete-avatar-code" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Below, I include my HTML and CSS avatar code.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"avatar-container"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"hair-long"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"face"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"ear ear--left"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"earing earing--left"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"ear ear--right"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"hair-front"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyebrow eyebrow--left"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyebrow eyebrow--right"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eye eye--left"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--left"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--left1"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--left2"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--left3"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--left4"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">> </span><span style="color:#6A737D">&#x3C;!-- end of left eye --></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eye eye--right"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--right"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--right1"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--right2"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--right3"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--right4"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">> </span><span style="color:#6A737D">&#x3C;!-- end of right eye --></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"nose"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"lips"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">> </span><span style="color:#6A737D">&#x3C;!-- end of face --></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"body-avatar"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"neck"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"t-shirt"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"dungarees"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"pocket"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"strap strap--left"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">        &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"button button--left"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"strap strap--right"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">        &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"button button--right"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">> </span><span style="color:#6A737D">&#x3C;!-- end of dungarees --></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">> </span><span style="color:#6A737D">&#x3C;!-- end of body --></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">> </span><span style="color:#6A737D">&#x3C;!-- end of avatar-container --></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#FFAB70">$body-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#6e87ef</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$skin-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#fac8b9</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$hair-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#36272a</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$hair-ombre-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">#36272a</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">#1616ee</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#FFAB70">$eyebrow-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#36272a</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$eye-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#6d84c0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$eye-base-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#f1f1f1</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$eyeline-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#472a2a</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$eyelash-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#171616</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$iris-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#000</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$earing-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$nose-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#2b2a2a</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$lips-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#f50000</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$t-shirt-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#2c171b</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$dungarees-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#6d84c0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$strap-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#6d84c0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$button-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#2d2c2c</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">*</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  margin</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  padding</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-sizing</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">border-box</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">html</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">vh</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$body-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.avatar-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  min-width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">320</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">320</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  overflow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">hidden</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .hair-long</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">130</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">170</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">44</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 44</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">30</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">    background</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$hair-ombre-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">    filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">drop-shadow</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .face</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">110</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#F97583"> /</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 160</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 160</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$skin-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">58</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">    z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0.5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> darken</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">$skin-color</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">10</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#B392F0">    .ear</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">22</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$skin-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#FFAB70">--left</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-6</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-8</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">          content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">12</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$skin-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 40</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> -1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> darken</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">$skin-color</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">10</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#FFAB70">--right</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-6</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">8</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">          content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$skin-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 40</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> -1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> darken</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">$skin-color</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">10</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#B392F0">      .earing</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">4</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">4</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$earing-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">        filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">drop-shadow</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">4</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">          content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">16</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$earing-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#B392F0">:after</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">          content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$earing-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--left</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">15</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">4</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">          &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">            top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">            right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">          }</span></span>
<span class="line"><span style="color:#85E89D">          &#x26;</span><span style="color:#B392F0">:after</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">            top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">15</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">            left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-1</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">          }</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#E1E4E8">      } </span><span style="color:#6A737D">// end of earing</span></span>
<span class="line"><span style="color:#E1E4E8">    } </span><span style="color:#6A737D">// end of ear</span></span>
<span class="line"><span style="color:#B392F0">    .hair-front</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">104</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">30</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$hair-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">28</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$hair-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">34</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-11</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-90</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">:after</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">28</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$hair-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">34</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-11</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-90</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">    }  </span><span style="color:#6A737D">// end of hair-front</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">    .eye</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">39</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$eye-base-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#FFAB70"> $eyeline-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">85</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">45</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$eye-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #17460d</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#FFAB70">--left</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">17</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> darken</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">$eyeline-color</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#FFAB70">--right</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">17</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> -1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> darken</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">$eyeline-color</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">:after</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">4</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">4</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$iris-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#B392F0">      .eyelash</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$eyelash-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--left</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--left1</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--left2</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--left3</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--left4</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">90</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--left</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#F97583">px</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--left1</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-2</span><span style="color:#F97583">px</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--left2</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-5</span><span style="color:#F97583">px</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--left3</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">9</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-6</span><span style="color:#F97583">px</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--left4</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">13</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-6</span><span style="color:#F97583">px</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--right</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">14</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--right1</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--right2</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-7</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--right3</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-8</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--right4</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-8</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-1</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#E1E4E8">      }  </span><span style="color:#6A737D">// end of eyelash</span></span>
<span class="line"><span style="color:#E1E4E8">    }  </span><span style="color:#6A737D">// end of eye</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">    .eyebrow</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">35</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">7</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">solid</span><span style="color:#79B8FF"> 4</span><span style="color:#F97583">px</span><span style="color:#FFAB70"> $hair-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$hair-color</span><span style="color:#79B8FF"> transparent</span><span style="color:#79B8FF"> transparent</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%/</span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">32</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#FFAB70">--left</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">7</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#FFAB70">--right</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">7</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">    } </span><span style="color:#6A737D">// end of eyebrows</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">    .nose</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">18</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#FFAB70"> $nose-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-top-right-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">80</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 40</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-bottom-right-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">80</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">46</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$nose-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">19</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-30</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">:after</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$nose-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">    } </span><span style="color:#6A737D">// end of nose</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">    .lips</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">24</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$lips-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">86</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">      box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 7</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">:after</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#FFAB70"> $skin-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-1</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">    } </span><span style="color:#6A737D">// end of lips</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">// end of face</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .body-avatar</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#B392F0">    .neck</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">34</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$skin-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">      filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">drop-shadow</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">152</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">      z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">30</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$skin-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">35</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">    .t-shirt</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">160</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">140</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$t-shirt-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#F97583"> /</span><span style="color:#79B8FF"> 40</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 40</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">190</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#85E89D">      filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">drop-shadow</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    } </span><span style="color:#6A737D">// end of t-shirt</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">    .dungarees</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$dungarees-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">240</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#B392F0">      .pocket</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$dungarees-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> dashed</span><span style="color:#79B8FF"> black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">25</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#B392F0">      .strap</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">64</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$strap-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-47</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#B392F0">        .button</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$button-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">52</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">          &#x26;</span><span style="color:#FFAB70">--left</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">            left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">            transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">          }</span></span>
<span class="line"><span style="color:#85E89D">          &#x26;</span><span style="color:#FFAB70">--right</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">            left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">            transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">          }</span></span>
<span class="line"><span style="color:#E1E4E8">        } </span><span style="color:#6A737D">// end of button</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--left</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--right</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 6</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#E1E4E8">      } </span><span style="color:#6A737D">// end of strap</span></span>
<span class="line"><span style="color:#E1E4E8">    } </span><span style="color:#6A737D">// end of dungarees</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">// end of body-avatar</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">// end of avatar-container</span></span></code></pre></div>
<p><img src="/create-shine-effect4.webp" alt="This image shows our avatar." style="max-width:42%" class="img-narrow"></p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/keyframes-in-css-explained-make-your-animations-stand-out/">CSS Keyframes Animation Explained</a></li>
<li><a href="/how-to-make-a-blinking-animation-using-css/">How to Make A Blinking Animation Using CSS</a></li>
<li><a href="/how-to-create-stunning-vibrant-neon-effect-css-only/">CSS Neon Text Effect</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Learn How to Select Only the CSS First Child</title>
      <link>https://littlecodingthings.com/learn-how-to-select-only-the-css-first-child/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/learn-how-to-select-only-the-css-first-child/</guid>
      <pubDate>Fri, 12 Jul 2024 08:00:00 GMT</pubDate>
      <description>:first-child in CSS with five worked examples — lists, paragraphs, multiple parents, and :not(:first-child) — each with the Sass form.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hello everybody! In this post, we will analyze the CSS first child selector, one of the <a href="/coding-made-easy-with-css-selectors-an-ultimate-guide/" title="most useful selectors in CSS">most useful selectors in CSS</a>. We utilize the CSS <code>first-child</code> selector when we want to <strong>target and manipulate only the first element</strong> among a variety of elements of the same type. Note that when we refer to types of elements, we mean <a href="/most-useful-html-elements-for-maximizing-better-results/" title="HTML tags">HTML tags</a> like paragraphs (<code>&#x3C;p></code>), headings (<code>&#x3C;h1></code>, <code>&#x3C;h2></code> …), lists (<code>&#x3C;li></code>), and so on.</p>
<p>We often apply the CSS first child selector to list items (<code>&#x3C;li></code>), but it can be used with any type of element. Below, I have prepared some examples to help you understand how to use the CSS first child selector depending on your needs.</p>
<p>Alternatively, we can use the CSS nth child selector like this <code>:nth-child(1)</code> for the same purpose, but it’s more generic as it allows the selection of any child based on its position.</p>
<p>In addition to providing all the necessary CSS syntax for each first child case we describe, we have also included <strong>Sass syntax under each code snippet</strong> if you are using a Sass pre-processor.</p>
<h2 id="css-first-child-selector-list-element">CSS first child selector: List element<a class="heading-anchor" href="#css-first-child-selector-list-element" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>In the following example, the HTML structure consists of an ordered list (<code>&#x3C;ol></code>) with three list items (<code>&#x3C;li></code>), all colored <strong>indigo</strong>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">ol</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>First item&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Second item&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Third item&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">ol</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/first-child-selector-li-without.webp" alt="An ordered list with three items all colored indigo." style="max-width:42%" class="img-narrow"></p>
<p>Then, we add the CSS rule, which selects only the first item and applies a red color to it.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* Applies indigo color to all list items */</span></span>
<span class="line"><span style="color:#85E89D">li</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">indigo</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/* Applies red color only to the first list item */</span></span>
<span class="line"><span style="color:#85E89D">li</span><span style="color:#B392F0">:first-child</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/*       OR       */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">li</span><span style="color:#B392F0">:nth-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>🔖 When we work with <strong>Sass</strong>, our code will be structured as follows:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">li</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">indigo</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">  &#x26;:first-child {</span></span>
<span class="line"><span style="color:#79B8FF">    color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/*       OR       */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">li</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">indigo</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">  &#x26;:nth-child(</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">    color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/first-child-selector-li.webp" alt="An ordered list with three items all colored indigo apart from the first one which has color red as we used the: CSS first child selector. :first-child OR :nth-child(1)" style="max-width:42%" class="img-narrow"></p>
<p>When using the <code>:first-child</code> selector in CSS, it targets the very first element within its parent. When we add a new item to the beginning of the list, this new item becomes the first child of the list, and the previous first item now becomes the second one. This change causes the <code>:first-child</code> selector to now target the newly added item instead.</p>
<h2 id="css-first-child-selector-non-list-element">CSS first child selector: Non-list element<a class="heading-anchor" href="#css-first-child-selector-non-list-element" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>In the example below, we set the first child selector for paragraphs. The HTML structure consists of a <code>&#x3C;div></code> containing three paragraph (<code>&#x3C;p></code>) elements. By default, all HTML elements have black text color, so paragraphs will appear in black.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>First paragraph&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>Second paragraph&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>Third paragraph&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/first-child-selector-html-element-without.webp" alt="Three paragraphs all colored by default black." style="max-width:55%" class="img-narrow"></p>
<p>By applying the CSS first child selector, it selects the first <code>&#x3C;p></code> element and apply the text color red to a white background. As a result, the first paragraph appears in red with a white background, while the subsequent paragraphs maintain their default styling.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* Applies red color and background white</span></span>
<span class="line"><span style="color:#6A737D">   to the first paragraph</span></span>
<span class="line"><span style="color:#6A737D">*/</span></span>
<span class="line"><span style="color:#85E89D">p</span><span style="color:#B392F0">:first-child</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/*       OR       */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">p</span><span style="color:#B392F0">:nth-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>🔖 When working with <strong>Sass</strong>, our code will be structured as follows:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">p</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  &#x26;:first-child {</span></span>
<span class="line"><span style="color:#79B8FF">    color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/*       OR       */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">p</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  &#x26;:nth-child(</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">    color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/first-child-selector-html-element.webp" alt="Three paragraphs all colored by default black, apart from the first one which has color red and background color white as we used the first child css selector." style="max-width:55%" class="img-narrow"></p>
<h2 id="first-child-css-selector-applied-across-multiple-parent-containers">First child CSS selector applied across multiple parent containers<a class="heading-anchor" href="#first-child-css-selector-applied-across-multiple-parent-containers" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>In this example, we can see a different approach, as most times, we have multiple HTML elements to manipulate within a document. In our case, we have two <code>div</code> elements, each containing two paragraph (<code>&#x3C;p></code>) elements colored black.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>First paragraph inside the first div&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>Second paragraph inside the first div&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>First paragraph inside the second div&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>Second paragraph inside the second div&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/first-child-selector-html-multiple-elements-without.webp" alt="Four paragraphs all colored black" style="max-width:55%" class="img-narrow"></p>
<p>The CSS rule <code>div p:first-child</code> <strong>selects the first <code>&#x3C;p></code> element within any <code>&#x3C;div></code></strong> and applies the specified styles to it. As a result, the first paragraph within each <code>&#x3C;div></code> will display in red with a white background, while the remaining paragraphs will retain their default styles. This demonstrates how the <code>:first-child</code> selector can be used to style the first element within a number of parent containers. 😉</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* Applies red color and white background</span></span>
<span class="line"><span style="color:#6A737D">   to the first paragraph inside each div</span></span>
<span class="line"><span style="color:#6A737D">*/</span></span>
<span class="line"><span style="color:#85E89D">div</span><span style="color:#85E89D"> p</span><span style="color:#B392F0">:first-child</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/*       OR       */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">div</span><span style="color:#85E89D"> p</span><span style="color:#B392F0">:nth-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>🔖 When using <strong>Sass</strong>, our code will look like this:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">div</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  p</span><span style="color:#E1E4E8">:first-child {</span></span>
<span class="line"><span style="color:#79B8FF">    color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/*       OR       */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">div</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  p</span><span style="color:#E1E4E8">:nth-child(</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">    color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/first-child-selector-html-multiple-elements-all-first-children.webp" alt="Four paragraphs colored black. The first paragraphs are colored red with white background as we set the first child css selector." style="max-width:55%" class="img-narrow"></p>
<h2 id="first-child-css-selector-targeting-the-first-element-of-the-first-parent">First child CSS selector targeting the first element of the first parent<a class="heading-anchor" href="#first-child-css-selector-targeting-the-first-element-of-the-first-parent" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>In the following example, we have two <code>div</code> elements, each containing two paragraph (<code>&#x3C;p></code>) elements colored black.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>First paragraph in the first div&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>Second paragraph in the first div&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>First paragraph in the second div&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>Second paragraph in the second div&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/first-child-selector-html-multiple-elements-without.webp" alt="Four paragraphs all colored by default black." style="max-width:55%" class="img-narrow"></p>
<p>the CSS rule <code>div:first-child p:first-child</code> <strong>selects only the first paragraph (<code>&#x3C;p></code>) within the first</strong> <code>div</code> and applies the specified styles to it. Thus, the first paragraph in the first <code>div</code> will be displayed in red with a white background, while the second paragraph will remain in its default black color.</p>
<p><strong>The second <code>div</code>, remains unaffected</strong> by the styles applied to the first <code>div</code>, showcasing how to apply specific styles selectively. 😉 This approach is really helpful for applying specific styles to elements in complex layouts.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* Applies red color and white background</span></span>
<span class="line"><span style="color:#6A737D">   to the first paragraph of the first div</span></span>
<span class="line"><span style="color:#6A737D">*/</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">div</span><span style="color:#B392F0">:first-child</span><span style="color:#85E89D"> p</span><span style="color:#B392F0">:first-child</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/*       OR       */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">div</span><span style="color:#B392F0">:nth-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">) </span><span style="color:#85E89D">p</span><span style="color:#B392F0">:nth-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>🔖 When we work with <strong>Sass</strong>, we will write our code as follows:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">div</span><span style="color:#B392F0">:first-child</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  p</span><span style="color:#E1E4E8">:first-child {</span></span>
<span class="line"><span style="color:#79B8FF">    color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/*       OR       */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">div</span><span style="color:#B392F0">:nth-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  p</span><span style="color:#E1E4E8">:nth-child(</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">    color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/first-child-selector-html-multiple-elements.webp" alt="Four paragraphs colored black. Only the first paragraph of the first div is red on a white background, set with div:first-child p:first-child." style="max-width:55%" class="img-narrow"></p>
<h2 id="using-the-notfirst-child-selector">Using the <code>:not(:first-child)</code> selector<a class="heading-anchor" href="#using-the-notfirst-child-selector" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>In our last example, we have the opposite case. How <strong>not to select the CSS first child</strong>. The HTML structure consists of an ordered list <code>&#x3C;ol></code> containing three list <code>&#x3C;li></code> elements.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">ol</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>First item&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Second item&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Third item&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">ol</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/not-first-child-selector-li-without.webp" alt="An ordered list with three items all colored by default, black." style="max-width:42%" class="img-narrow"></p>
<p>The CSS rule <strong><code>ol li:not(:first-child)</code> selects all <code>&#x3C;li></code> elements within the <code>ol</code> apart from the first one</strong> and applies the specified styles to them. Because of that, <em>all list items apart from the first</em> one will be displayed in red, while the first list item will retain its default color, black.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* Applies red color to all list items</span></span>
<span class="line"><span style="color:#6A737D">   except for the first one</span></span>
<span class="line"><span style="color:#6A737D">*/</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">ol</span><span style="color:#85E89D"> li</span><span style="color:#B392F0">:not</span><span style="color:#E1E4E8">(</span><span style="color:#B392F0">:first-child</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/*       OR       */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">ol</span><span style="color:#85E89D"> li</span><span style="color:#B392F0">:not</span><span style="color:#E1E4E8">(</span><span style="color:#B392F0">:nth-child</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">)) {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>🔖 When we work with <strong>Sass</strong>, we will write our code as follows:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">ol</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  li</span><span style="color:#E1E4E8">:not(:first-child) {</span></span>
<span class="line"><span style="color:#79B8FF">    color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/*       OR       */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">ol</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  li</span><span style="color:#E1E4E8">:not(:nth-child(</span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">)) {</span></span>
<span class="line"><span style="color:#79B8FF">    color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/not-first-child-selector-li.webp" alt="An ordered list with three items. The first item has by default color black while the other two items have color red as we used the css  not first child selector." style="max-width:42%" class="img-narrow"></p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/css-last-child-selector-the-most-valuable-selector/">The CSS last-child Selector</a></li>
<li><a href="/what-you-need-to-know-about-css-nth-child-selector-a-practical-guide/">The CSS nth-child Selector Explained</a></li>
<li><a href="/css-selectors-nth-child-vs-nth-of-type-and-how-to-use-them-correctly/">nth-child vs nth-of-type in CSS</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Impostor Syndrome in Tech: The Signs</title>
      <link>https://littlecodingthings.com/unmasking-impostor-syndrome-in-tech-watch-out-for-these-signs/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/unmasking-impostor-syndrome-in-tech-watch-out-for-these-signs/</guid>
      <pubDate>Tue, 09 Jul 2024 08:10:00 GMT</pubDate>
      <description>Impostor syndrome in tech: four signs you are experiencing it, and five practical ways to quiet the voice saying you do not belong.</description>
      <category>Thoughts &amp; Theory</category>
      <content:encoded><![CDATA[<p>Impostor syndrome, also known as impostorism, is the feeling that you’re not as good as others think you are, even when you have proof of your success. In simple words, lack of confidence. It is often accompanied by the fear of being exposed as a fraud.</p>
<p>It can affect anyone, regardless of their accomplishments. It can make you doubt yourself and believe that your achievements are due to luck rather than your own skills. This feeling can impact everyone, from students and professionals to famous people.</p>
<p>In our competitive world, many people struggle with these thoughts. Realizing impostor syndrome and learning how to deal with it is essential for building confidence, maintaining a healthy and positive mind, and, by extension, enhancing one’s quality of life.</p>
<h2 id="how-to-recognize-if-you-suffer-from-impostor-syndrome">How to recognize if you suffer from impostor syndrome?<a class="heading-anchor" href="#how-to-recognize-if-you-suffer-from-impostor-syndrome" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Recognizing impostor syndrome can be the first step toward managing it. Below, I will outline some of the most important signs to watch out for.</p>
<h3 id="shadows-of-yesterday">Shadows of yesterday<a class="heading-anchor" href="#shadows-of-yesterday" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>It often originates from our <strong>childhood</strong> and the way we grew up. It is widely accepted that many parents can either overly compliment or criticize their children, sending mixed signals that can confuse them. They hesitate to let their children try new things, fearing others will criticize failure and cause ridicule. In that way, children get used to the idea that they are not worth the opportunity to try.
These behaviors leave imprints 🐾 on children’s minds and get deeper and deeper day by day. Eventually, they end up feeling like pawns, these lowest-value ♟ pieces, on a chessboard.
Instead, they should encourage their children to try new things and welcome failure as a valuable learning experience, regardless of others’ thoughts.</p>
<figure><img src="/imposter-syndrome-childhood-memories.webp" alt="Astronaut creating a sand castle in the beach" style="max-width:24%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-astronaut-playing-sand-castle-beach-cartoon-vector-icon-illustration-science-holiday-icon_38097443.htm#fromView=search&#x26;page=1&#x26;position=6&#x26;uuid=a70d9748-762c-4a26-96ab-fcd9113f66c1">Image by catalyststuff on Freepik</a></figcaption></figure>
<h3 id="keep-bearing-your-challenging-past">Keep bearing your challenging past<a class="heading-anchor" href="#keep-bearing-your-challenging-past" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<figure><img src="/imposter-syndrome-lightning.webp" alt="Astronaut hit by many lighnings" style="max-width:24%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-astronaut-electricity-lightning-element-cartoon-vector-icon-illustration-science-technology_37076532.htm#fromView=search&#x26;page=2&#x26;position=0&#x26;uuid=6aa08be6-3337-4f8e-aa3d-d120a50994c0">Image by catalyststuff</a> on Freepik</figcaption></figure>
<p>Later, as an adult, impostor syndrome affects you as you have convinced yourself that you are a “<em>broken vessel</em>” and not well prepared for real life. You may even notice that you tend to set extremely <strong>high standards</strong> for yourself. You struggle to overcome the past and prove that you deserve something like everyone around you.
You might feel disappointed when you don’t complete some goals, even if, many times, those plans are utopian.
On the other hand, when you complete your goals, you will catch yourself <strong>downplaying</strong> your victories as you continue feeling that you are not capable of handling things.</p>
<h3 id="masquerade--the-false-sense-of-deception">Masquerade – The False Sense of Deception<a class="heading-anchor" href="#masquerade--the-false-sense-of-deception" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Another clear indicator that you might struggle with this awful syndrome is that you often feel exhausted from over-preparing or overworking to cover up <strong>your falsely claimed lack of skills</strong>. You feel like you’re “<strong>faking it</strong>” at any moment, doubting and challenging yourself about your own abilities. Deep down, it seems like hiding your real self and wearing a mask that doesn’t fit right.
I have to note that it’s a really confusing situation. It’s as though you repeatedly place hurdles in your own path and sabotage yourself.</p>
<figure><img src="/imposter-syndrome-confused.webp" alt="Astronaut confused" style="max-width:24%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-astronaut-confuse-cartoon-vector-icon-illustration-science-technology-icon-concept-isolated_26124607.htm#fromView=search&#x26;page=1&#x26;position=0&#x26;uuid=98d7fec5-20e6-4516-acdf-aaeb6aab53e8">Image by catalyststuff on Freepik</a></figcaption></figure>
<h3 id="frozen-by-fear--how-it-holds-you-back">Frozen by Fear – How It Holds You Back<a class="heading-anchor" href="#frozen-by-fear--how-it-holds-you-back" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<figure><img src="/imposter-syndrome-fear-of-failure.webp" alt="Astronaut alone in galaxy" style="max-width:24%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-astronaut-galaxy-globe-space-cartoon-vector-icon-illustration-science-technology-isolated_67004128.htm#fromView=search&#x26;page=2&#x26;position=51&#x26;uuid=0307101b-54ba-4d1e-b0a0-c65d7eeef0c6">Image by catalyststuff</a> on Freepik</figcaption></figure>
<p>Finally, the <strong>fear of failure</strong>. This fear can be so strong that it literally makes you feel stuck. You become anti-social. It stops you from being creative and taking risks that could help you learn and grow. It prevents you from taking on new challenges, seeking opportunities, or making decisions.
You may constantly compare yourself to others, feeling that you’re not as talented or capable despite evidence to the contrary.
Eventually, it can make you feel really unhappy and even affect your mental health. You will soon start feeling lonely, helpless, anxious, and weak, and occasionally depression and isolation can take you down.</p>
<h2 id="how-to-deal-with-impostor-syndrome">How to deal with impostor syndrome<a class="heading-anchor" href="#how-to-deal-with-impostor-syndrome" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Handling impostor syndrome involves <strong>reconsidering,</strong> which means changing how you think and react to yourself and your plans for life, whether they are accomplishments or failures.</p>
<h3 id="embracing-self-love-accepting-your-situation-and-valuing-yourself">Embracing Self-Love: Accepting Your Situation and Valuing Yourself<a class="heading-anchor" href="#embracing-self-love-accepting-your-situation-and-valuing-yourself" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<figure><img src="/imposter-syndrome-self-compassion.webp" alt="Astronaut sleeping on heart-shaped pillow" style="max-width:24%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-astronaut-sleeping-love-heart-pillow-cartoon-vector-icon-illustration-science-technology_29084492.htm#fromView=search&#x26;page=1&#x26;position=2&#x26;uuid=0604dab3-e8e3-4678-9f51-67abd839a636">Image by catalyststuff on Freepik</a></figcaption></figure>
<p>Start by <strong>accepting your feelings</strong>. Keep in mind that many people experience these same thoughts. <strong>You are not alone</strong>. It’s just a common reaction to high pressure and expectations.
Practice <strong>self-compassion</strong> by treating yourself with the kindness and understanding you would offer a friend. Be kinder to yourself. Try to avoid negative thoughts and replace them with more balanced and positive thinking.</p>
<h3 id="setting-achievable-goals-a-pathway-to-success">Setting Achievable Goals: A Pathway to Success<a class="heading-anchor" href="#setting-achievable-goals-a-pathway-to-success" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Setting <strong>realistic goals</strong>. This can be the most crucial decision. Breaking down big tasks into smaller, manageable steps will help you handle them better, feel less stressed, and keep moving steadily toward your goals.
Also, believe it or not, it’s important to celebrate each achievement along the way. Whether small or big, each step signifies a victory on the journey toward your goals. <strong>Do not underestimate it!</strong></p>
<figure><img src="/imposter-syndrome-realistic-goals.webp" alt="Astronaut trying to paddle in a paper boat" style="max-width:24%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-astronaut-paddling-paper-boat-space-wave-cartoon-vector-icon-illustration-science-sport-flat_134521013.htm#fromView=search&#x26;page=1&#x26;position=0&#x26;uuid=0d87ab33-8fd8-46be-bddc-b1db51816183">Image by catalyststuff on Freepik</a></figcaption></figure>
<h3 id="creating-effective-programs-with-smart-planning">Creating Effective Programs with Smart Planning<a class="heading-anchor" href="#creating-effective-programs-with-smart-planning" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<figure><img src="/imposter-syndrome-keeping-notes.webp" alt="Astronaut keeping notes with a big pencil" style="max-width:30%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-astroanut-writing-book-with-pencil-cartoon-vector-icon-illustration-science-education-flat_132092181.htm#fromView=search&#x26;page=1&#x26;position=10&#x26;uuid=5baefaf1-7236-4455-847e-0aeb1c62335f">Image by catalyststuff on Freepik</a></figcaption></figure>
<p>Start <strong>keeping notes</strong>. It serves as a powerful tool for self-reflection. Write down your personal accomplishments as a strong reminder of your capabilities and successes. Maintaining a diary with plans is substantial evidence of your growth, boosting you to dive into future challenges with faith and enthusiasm.
Checking ✅ your notes is always a good idea! Celebrate your successes with pride and take time to examine your failures. By understanding what went wrong, you pave the way for future triumphs. Be confident! You will blossom in your next attempt.</p>
<h3 id="discovering-strength-through-support">Discovering Strength Through Support<a class="heading-anchor" href="#discovering-strength-through-support" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Reaching out <strong>support</strong> from others is absolutely essential, too. Let it be ingrained in your memory that you are incredibly valuable to some people. This unique sense of being heard and understood can be extremely comforting and validating for you.
Talk to friends, family, or mentors about your feelings. Trust them and lean on their shoulders. You can count on their love and help. They can offer honest opinions and critiques, multiple perspectives, and, most importantly, remind you of your worth!
After all, they are connections that can open doors to new opportunities and experiences. How calming is that?</p>
<figure><img src="/imposter-syndrome-support.webp" alt="Astronaut flying with another astronaut" style="max-width:24%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-astronaut-friend-playing-space-cartoon-vector-icon-illustration-science-technology-isolated_51406674.htm#fromView=search&#x26;page=1&#x26;position=4&#x26;uuid=514db1db-2d89-4577-b5b2-21827ff8e78a">Image by catalyststuff on Freepik</a></figcaption></figure>
<h3 id="confident-endurance--continuing-the-journey-with-determination">Confident Endurance – Continuing the Journey with Determination<a class="heading-anchor" href="#confident-endurance--continuing-the-journey-with-determination" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<figure><img src="/imposter-syndrome-support-specialist.webp" alt="Astronaut shooting at alien ghosts with water pistol" style="max-width:24%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-astronaut-shooting-alien-with-space-gun-cartoon-vector-icon-illustration-science-technology_65557700.htm#fromView=search&#x26;page=1&#x26;position=46&#x26;uuid=e3193823-8877-4269-9f0d-ec611590bcfc">Image by catalyststuff on Freepik</a></figcaption></figure>
<p>Eventually, it’s time to fight with your ghosts! Build <strong>self-confidence</strong>. If impostor syndrome persists and affects your life significantly on a daily basis, consider professional help from a therapist or consultant. They can provide invaluable guidance and propose techniques to empower you.
Furthermore, they will help you overcome these feelings and reveal your strengths and skills. Always remember you belong to yourself and you are free to live your life as you wish!</p>
<p>Overcoming impostor syndrome requires time and persistence. It involves regularly reminding your own value, celebrating your accomplishments, and sometimes getting help from others to change how you think. By recognizing it, you have to take steps and fight it. You will start to believe in yourself and appreciate your achievements. Remember that occasional doubts are normal, but they do not define who you are. Sooner or later, understanding and fighting impostor syndrome helps us reach our full potential and enjoy life to the fullest.</p>
<p>Are you ready to go? 🧨✨ Wishing you all the best! 💖💖</p>
<figure><img src="/cute-astronaut-riding-space-rocket.webp" alt="Astronaut riding space rocket" style="max-width:28%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-astronaut-riding-rocket-space-with-waving-hand-cartoon-vector-icon-illustration-science-tech_34293318.htm#fromView=search&#x26;page=4&#x26;position=19&#x26;uuid=0954eb64-853e-4083-934d-f72089263566">Image by catalyststuff on Freepik</a></figcaption></figure>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/the-burnout-syndrome-how-to-identify-and-overcome-it/">Developer Burnout: Signs and Recovery</a></li>
<li><a href="/how-to-decide-if-programming-is-right-for-you/">How To Decide If Programming Is Right For You?</a></li>
<li><a href="/am-i-too-old-to-learn-coding/">Am I Too Old to Learn Coding?</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Javascript Array Methods Explained</title>
      <link>https://littlecodingthings.com/javascript-array-methods-easy-examples-that-make-learning-a-blast/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/javascript-array-methods-easy-examples-that-make-learning-a-blast/</guid>
      <pubDate>Sat, 06 Jul 2024 08:25:00 GMT</pubDate>
      <description>The Javascript array methods you’ll actually use — map, filter, reduce, find, some, every, slice, splice and more — each with a short, clear example.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Whether you are learning Javascript for the first time or you are an experienced developer, chances are you will be working with arrays frequently. This post was created to help you understand (or remind you of) how the most common Javascript array methods work. We recommend bookmarking this post, as it will be helpful more often than you might expect.</p>
<p>In addition to briefly explaining each method and providing relevant examples, we have also included the <code>.length</code> property since it’s also commonly used.</p>
<p>All Javascript array methods described in this post have been organized in <strong>alphabetical order</strong> to make searching easier. For those who want to learn more, we’ve also included a link to the MDN documentation in the footer of each code snippet for quick access to detailed information about the related method.</p>
<p>For any beginner developers who have just started their journey, seeing <code>.prototype.</code> in the name of every method might be confusing. I have to say, in my first steps, it confused me a lot, thinking, “Why not just say <code>Array.every</code> instead of <code>Array.prototype.every</code>” ? A quick and short explanation to help you move forward without getting stuck is that when we write <code>Array.prototype.&#x3C;method_name></code> it indicates that the method described exists natively within every array instance (<em>within every array you use</em>).</p>
<h2 id="arrayprototypeevery">Array.prototype.every()<a class="heading-anchor" href="#arrayprototypeevery" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><strong>When to choose this</strong>: When you are checking if <strong>every</strong> element of an array passes a specific condition.
<strong>Returns:</strong> <code>true</code> or <code>false</code></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>[🦊, 🐻, 🐼].every(element => element === 🐼);</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// false</span></span>
<span class="line"><span></span></span>
<span class="line"><span>[🐻, 🐻, 🐻].every(element => element === 🐻);</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// true</span></span></code></pre></div>
<p><strong>Callback</strong> <strong>params</strong></p>
<ol>
<li><code>element</code> – the element checked in each step</li>
<li><code>index</code> – the element’s index (its position)</li>
<li><code>array</code> – the array itself, to which you have called <code>.every</code></li>
</ol>
<h2 id="arrayprototypefilter">Array.prototype.filter()<a class="heading-anchor" href="#arrayprototypefilter" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><strong>When to choose this</strong>: The Javascript array filter method is probably one of the most used ones. Use it when you want to create a new array with elements that pass a specific condition.
<strong>Returns:</strong> <strong>A new array,</strong> including the elements that <strong>passed</strong> the condition.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>[🦊, 🐻, 🐼].filter(element => element !== 🐼);</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// [🦊, 🐻]</span></span>
<span class="line"><span></span></span>
<span class="line"><span></span></span>
<span class="line"><span></span></span>
<span class="line"><span>[🐻, 🐻, 🐻].filter(element => element === 🐼);</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// []</span></span></code></pre></div>
<p><strong>Callback</strong> <strong>params</strong></p>
<ol>
<li><code>element</code> – the element checked in each step</li>
<li><code>index</code> – the element’s index (its position)</li>
<li><code>array</code> – the array itself, to which you have called <code>.filter</code></li>
</ol>
<p>When a method returns a new array, it is not 100% independent from its source array. It’s a <a href="https://developer.mozilla.org/en-US/docs/Glossary/Shallow_copy" title="shallow copy">shallow copy</a>! Proceed with extra caution on this because you might see some unexpected surprises!</p>
<h2 id="arrayprototypefind">Array.prototype.find()<a class="heading-anchor" href="#arrayprototypefind" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><strong>When to choose this</strong>: When trying to find the <strong>first</strong> element in an array that passes a specific condition.
<strong>Returns:</strong> The element that passes the condition or <code>undefined</code> if no element is found.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>[🦊, 🐻, 🐼].find(element => element === 🐼);</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// 🐼</span></span>
<span class="line"><span></span></span>
<span class="line"><span>[🐼, 🐻, 🐼].find(element => element === 🐼);</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// 🐼 (The first one)</span></span>
<span class="line"><span></span></span>
<span class="line"><span></span></span>
<span class="line"><span></span></span>
<span class="line"><span>[🐻, 🐻, 🐻].find(element => element === 🐼);</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// undefined</span></span></code></pre></div>
<p><strong>Callback</strong> <strong>params</strong></p>
<ol>
<li><code>element</code> – the element checked in each step</li>
<li><code>index</code> – the element’s index (its position)</li>
<li><code>array</code> – the array itself, to which you have called <code>.find</code></li>
</ol>
<h2 id="arrayprototypeflat">Array.prototype.flat()<a class="heading-anchor" href="#arrayprototypeflat" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><strong>When to choose this</strong>: When you have complex array structures (arrays in arrays), and you want to flatten everything into one level.
<strong>Returns</strong>: <strong>A new array</strong> containing all elements from different array levels.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>[🐻, 🐻, 🐻].flat();</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// [🐻, 🐻, 🐻]</span></span>
<span class="line"><span></span></span>
<span class="line"><span>[🐻, 🐻, 🐼, [🦊, [🐻, 🐻], 🦊]].flat();</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// default level is 1</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// [🐻, 🐻, 🐼, 🦊, [🐻, 🐻], 🦊]</span></span>
<span class="line"><span></span></span>
<span class="line"><span>[🐻, 🐻, 🐼, [🦊, [🐻], 🦊]].flat(Infinity);</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// Infinity will flatten all levels</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// [🐻, 🐻, 🐼, 🦊, 🐻, 🦊]</span></span></code></pre></div>
<p><em>(Remember, the new array is a <a href="https://developer.mozilla.org/en-US/docs/Glossary/Shallow_copy" title="shallow copy">shallow copy</a> of the source one).</em></p>
<h2 id="arrayprototypeforeach">Array.prototype.forEach()<a class="heading-anchor" href="#arrayprototypeforeach" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><strong>When to choose this</strong>: When you need to iterate through every element of an array and perform a specific action <strong>on each</strong> element.
<strong>Returns:</strong> <code>undefined</code></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>[🐻, 🐻, 🐼].forEach(element => {</span></span>
<span class="line"><span></span></span>
<span class="line"><span>   // check something about this element</span></span>
<span class="line"><span></span></span>
<span class="line"><span>   isAnimalCarnivore(element);</span></span>
<span class="line"><span></span></span>
<span class="line"><span>});</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// undefined</span></span></code></pre></div>
<p><strong>Callback</strong> <strong>params</strong></p>
<ol>
<li><code>element</code> – the element of each iteration</li>
<li><code>index</code> – the element’s index (its position)</li>
<li><code>array</code> – the array itself, to which you have called <code>.forEach</code></li>
</ol>
<p>Since this method always returns <code>undefined</code>, if you want your loop to return something, you might want to <a href="#arrayprototypemap" title="check .map method">check the <code>.map</code> method</a>.</p>
<p>This method doesn’t break the iteration unless you throw an Error!</p>
<h2 id="arrayprototypeincludes">Array.prototype.includes()<a class="heading-anchor" href="#arrayprototypeincludes" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><strong>When to choose this</strong>: When you want to see if a Javascript array contains a specific element.
<strong>Returns:</strong> <code>true</code> or <code>false</code></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>[🦊, 🐻, 🐼].includes(🐻);</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// true</span></span>
<span class="line"><span></span></span>
<span class="line"><span>[🦊, 🐻, 🐼].includes(🐸);</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// false</span></span></code></pre></div>
<p>When working with objects, keep in mind that something like this 👇 <strong>won’t work</strong>:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>[{ name: 'Bob' }].includes({ name: 'Bob' });</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// false</span></span></code></pre></div>
<p>What you need is probably <code>.some</code>, <code>.filter</code>, or maybe <code>.find</code>.</p>
<h2 id="arrayprototypelength">Array.prototype.length<a class="heading-anchor" href="#arrayprototypelength" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><strong>When to choose this</strong>: When you want to know/check the length of an array.
<strong>Returns:</strong> A number – The array’s length.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>[🦊, 🐻, 🐼].length;</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// 3</span></span>
<span class="line"><span></span></span>
<span class="line"><span>[].length;</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// 0</span></span></code></pre></div>
<p>This is a property, not a method. Don’t invoke it.</p>
<h2 id="arrayprototypemap">Array.prototype.map()<a class="heading-anchor" href="#arrayprototypemap" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><strong>When to choose this</strong>: When you want to create a new array where each element is transformed by applying a callback function to each element of the original array.
<strong>Returns:</strong> <strong>A new array</strong> containing the transformed elements based on the callback function.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>[🦊, 🐻, 🐼].map((element, index) => ({</span></span>
<span class="line"><span></span></span>
<span class="line"><span> id: index, animalIcon: element</span></span>
<span class="line"><span></span></span>
<span class="line"><span>}));</span></span>
<span class="line"><span></span></span>
<span class="line"><span>/*</span></span>
<span class="line"><span>   [</span></span>
<span class="line"><span>     { id: 0, animalIcon: 🦊 },</span></span>
<span class="line"><span></span></span>
<span class="line"><span>     { id: 1, animalIcon: 🐻 },</span></span>
<span class="line"><span></span></span>
<span class="line"><span>     { id: 2, animalIcon: 🐼 }</span></span>
<span class="line"><span>   ]</span></span>
<span class="line"><span></span></span>
<span class="line"><span>*/</span></span></code></pre></div>
<p><strong>Callback</strong> <strong>params</strong></p>
<ol>
<li><code>element</code> – the element checked in each step</li>
<li><code>index</code> – the element’s index (its position)</li>
<li><code>array</code> – the array itself, to which you have called <code>.map</code></li>
</ol>
<h2 id="arrayprototypepop">Array.prototype.pop()<a class="heading-anchor" href="#arrayprototypepop" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><strong>When to choose this</strong>: When you want to throw away the last item of the array.
<strong>Returns:</strong> The item you threw, or <code>undefined</code> if the array was already empty.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>[🦊, 🐻, 🐼].pop();</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// 🐼</span></span>
<span class="line"><span></span></span>
<span class="line"><span>[].pop();</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// undefined</span></span></code></pre></div>
<p>The opposite method of <code>.pop</code> is <code>[.shift](#arrayprototypeshift ".shift")</code>.</p>
<h2 id="arrayprototypepush">Array.prototype.push()<a class="heading-anchor" href="#arrayprototypepush" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><strong>When to choose this</strong>: When you want to add an element (or more than one) to the end of your array.
<strong>Returns:</strong> <strong>The new array’s length.</strong> The method <strong>modifies the original array</strong> by adding any passed element(s) to its end.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>[🦊, 🐻, 🐼].push(🦊);</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// returns 4</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// [🦊, 🐻, 🐼, 🦊];</span></span>
<span class="line"><span></span></span>
<span class="line"><span>[🦊, 🐻, 🐼].push(🦊, 🦊, 🦊);</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// returns 6</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// [🦊, 🐻, 🐼, 🦊, 🦊, 🦊];</span></span></code></pre></div>
<h2 id="arrayprototypereduce">Array.prototype.reduce()<a class="heading-anchor" href="#arrayprototypereduce" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><strong>When to choose this</strong>: When you want to condense an array into a single value based on some logic applied by the callback function. E.g., when you want to calculate a sum or an average.
<strong>Returns:</strong> A single value as a result of applying the callback function to each element of the array.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>[1, 2, 1].reduce((acc, element) => acc + element)</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// 4</span></span>
<span class="line"><span></span></span>
<span class="line"><span>[1, 2, 1].reduce((acc, element) => acc + element, 10)</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// 14 (accumulator - initial value - set to 10)</span></span></code></pre></div>
<p><strong>Callback</strong> <strong>params</strong></p>
<ol>
<li><code>accumulator</code> – What is returned by the callback function. The default value of an accumulator, if not specified otherwise, is 0</li>
<li><code>element</code> – the iteration’s element</li>
<li><code>index</code> – the element’s index position</li>
</ol>
<h2 id="arrayprototypereverse">Array.prototype.reverse()<a class="heading-anchor" href="#arrayprototypereverse" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><strong>When to choose this</strong>: When you want to reverse the order of the array’s elements.
<strong>Returns:</strong> The <strong>original</strong> array reversed.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>[🦊, 🐻, 🐼].reverse();</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// [🐼, 🐻, 🦊];</span></span></code></pre></div>
<h2 id="arrayprototypeshift">Array.prototype.shift()<a class="heading-anchor" href="#arrayprototypeshift" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><strong>When to choose this</strong>: When you want to throw away the first item of the array.
<strong>Returns:</strong> The item you threw, or <code>undefined</code> if the array was already empty.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>[🦊, 🐻, 🐼].shift();</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// 🦊</span></span>
<span class="line"><span></span></span>
<span class="line"><span>[].shift();</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// undefined</span></span></code></pre></div>
<p>The opposite method of <code>.shift</code> is <a href="#arrayprototypepop" title="the .pop method">the <code>.pop</code> method</a>.</p>
<h2 id="arrayprototypeslice">Array.prototype.slice()<a class="heading-anchor" href="#arrayprototypeslice" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><strong>When to choose this</strong>: When you want a slice 🍕 of an array.
<strong>Returns:</strong> The slice you asked for in <strong>a new array</strong>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>[🦊, 🐻, 🐼, 🐸, 🐯, 🦝].slice();</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// returns slice</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// [🦊, 🐻, 🐼, 🐸, 🐯, 🦝]</span></span>
<span class="line"><span></span></span>
<span class="line"><span>[🦊, 🐻, 🐼, 🐸, 🐯, 🦝].slice(2);</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// returns slice</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// [🐼, 🐸, 🐯, 🦝] - first 2 animals ignored</span></span>
<span class="line"><span></span></span>
<span class="line"><span>[🦊, 🐻, 🐼, 🐸, 🐯, 🦝].slice(1, 3);</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// [ ... -> 🐻] - starting position - element 1</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// (included)</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// [ ... &#x3C;- 🐸 ...] - ending position element 3</span></span>
<span class="line"><span></span></span>
<span class="line"><span>//  (not included)</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// returns slice</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// [🐻, 🐼]</span></span></code></pre></div>
<p><strong>Parameters</strong></p>
<ul>
<li><code>start</code>: The starting point from which the slicing begins. The start <strong>is included</strong> in the slice.</li>
<li><code>end</code>: The position that the slicing stops. The end position <strong>is not included</strong> in the slice.</li>
</ul>
<p><em>(Remember, the new array is a <a href="https://developer.mozilla.org/en-US/docs/Glossary/Shallow_copy" title="shallow copy">shallow copy</a> of the source one).</em></p>
<h2 id="arrayprototypesome">Array.prototype.some()<a class="heading-anchor" href="#arrayprototypesome" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><strong>When to choose this</strong>: When you are checking if <strong>at least one</strong> element of an array passes a specific condition.
<strong>Returns:</strong> <code>true</code> or <code>false</code></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>[🦊, 🐻, 🐼].some(element => element === 🐼);</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// true</span></span>
<span class="line"><span></span></span>
<span class="line"><span>[🐻, 🐻, 🐻].some(element => element === 🐼);</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// false</span></span></code></pre></div>
<p>If you want to check if all elements pass the condition, you should check <a href="#arrayprototypeevery" title=".every method"><code>.every</code> method</a>.</p>
<h2 id="arrayprototypesort">Array.prototype.sort()<a class="heading-anchor" href="#arrayprototypesort" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><strong>When to choose this</strong>: When you want to sort the elements in a specific way.
<strong>Returns:</strong> <strong>The source array</strong> sorted.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>[3, 2, 1].sort();</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// [1, 2, 3]</span></span>
<span class="line"><span></span></span>
<span class="line"><span>['A', 'C', 'B'].sort();</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// ['A', 'B', 'C']</span></span>
<span class="line"><span></span></span>
<span class="line"><span>[</span></span>
<span class="line"><span>  { id: 13 },</span></span>
<span class="line"><span></span></span>
<span class="line"><span>  { id: 42 },</span></span>
<span class="line"><span></span></span>
<span class="line"><span>  { id: 10 }</span></span>
<span class="line"><span></span></span>
<span class="line"><span>].sort((itemA, itemB) => itemA.id - itemB.id);</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// Result [{ id: 10 }, { id: 13 }, { id: 42 }]</span></span></code></pre></div>
<h2 id="arrayprototypesplice">Array.prototype.splice()<a class="heading-anchor" href="#arrayprototypesplice" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><strong>When to choose this</strong>: When you want to replace some contents of an array or remove them.
<strong>Returns:</strong> <strong>A new array</strong> is created by the removed/replaced elements.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>[🦊, 🐻, 🐼, 🐸, 🐯, 🦝].splice();</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// [🦊, 🐻, 🐼, 🐸, 🐯, 🦝] - source array</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// [] - returns empty array</span></span>
<span class="line"><span></span></span>
<span class="line"><span>[🦊, 🐻, 🐼, 🐸, 🐯, 🦝].splice(2);</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// [🦊, 🐻] - source array</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// [🐼, 🐸, 🐯, 🦝] - new array</span></span>
<span class="line"><span></span></span>
<span class="line"><span>[🦊, 🐻, 🐼, 🐸, 🐯, 🦝].splice(2, 1);</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// [🦊, 🐻, 🐸, 🐯, 🦝] - source array</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// [] - returns empty array</span></span>
<span class="line"><span></span></span>
<span class="line"><span>[🦊, 🐻, 🐼, 🐸, 🐯, 🐯].splice(2, 0, 🦝, 🦝);</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// [🦊, 🐻, 🐸, 🦝, 🦝, 🐯, 🐯] - source array</span></span>
<span class="line"><span></span></span>
<span class="line"><span>// [] - new array</span></span>
<span class="line"><span></span></span>
<span class="line"><span>/*</span></span>
<span class="line"><span>   New array was not created</span></span>
<span class="line"><span></span></span>
<span class="line"><span>   since we asked for 0 deletion.</span></span>
<span class="line"><span></span></span>
<span class="line"><span>   Instead the source array was modified.</span></span>
<span class="line"><span></span></span>
<span class="line"><span> */</span></span></code></pre></div>
<p><strong>Parameters</strong></p>
<ul>
<li><code>start</code>: The starting point from which the removing/replacing begins. The start <strong>is included</strong> in the slice.</li>
<li><code>count</code>: How many elements to delete. If omitted, it will be set from the starting position till the end of the array.</li>
<li><code>replacement</code>: New element(s) to be added from the starting position</li>
</ul>
<p><em>(Remember, the new array is a <a href="https://developer.mozilla.org/en-US/docs/Glossary/Shallow_copy" title="shallow copy">shallow copy</a> of the source one).</em></p>
<h2 id="guidance-on-using-javascript-array-methods">Guidance on using Javascript array methods<a class="heading-anchor" href="#guidance-on-using-javascript-array-methods" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>You don’t have to memorize every Javascript array method, its syntax, and its exact functionality! It’s more important to know that they exist. Over time, you’ll naturally develop muscle memory for the ones you use frequently. For the less used methods, just keep them in mind and look them up when needed. Consider bookmarking this post for future reference! 🤓</p>
<p>In this post, we tried to explain/demonstrate some of the most common Javascript array methods. Our intention was not to provide comprehensive documentation, so we intentionally omitted more advanced parameters that are applicable to some of the methods described.</p>
<p>If you’re interested in learning about these less frequently used parameters, we recommend visiting the MDN Documentation linked in the footer of each code snippet.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-use-a-javascript-double-question-mark/">Javascript Double Question Mark (??)</a></li>
<li><a href="/javascript-testing-for-beginners-a-simple-practical-introduction/">Javascript Testing for Beginners</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>CSS Flip Card with Two Sides</title>
      <link>https://littlecodingthings.com/make-amazing-css-2d-card-with-flipping-animation-on-hover/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/make-amazing-css-2d-card-with-flipping-animation-on-hover/</guid>
      <pubDate>Sun, 30 Jun 2024 21:29:00 GMT</pubDate>
      <description>Build a two-sided card that flips on hover with transform-style: preserve-3d and backface-visibility: hidden — on the X or the Y axis.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hello! In this post, I will show you how to create a visually appealing CSS 2d card with flipping animation that activates when you hover over it. To enhance the design, I have added an avatar and integrated the animation with it. If you are interested in how I created the avatar, you can check out the complete avatar code at the end of this post. You are free to use it in your animation or customize it to your liking. Enjoy! 😉</p>
<p>For now, let’s move forward and create this incredible animation!</p>
<h2 id="css-flipping-card-animation-on-hover">CSS Flipping card animation on hover<a class="heading-anchor" href="#css-flipping-card-animation-on-hover" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The following HTML and SCSS (Sass) code makes a card flip around. Using the <strong>X-axis and Y-axis</strong> which are two lines that intersect, helps us determine the position of a point in a two-dimensional area.</p>
<p>Let’s analyze our code one step at a time:</p>
<h3 id="html-structure">HTML structure<a class="heading-anchor" href="#html-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>We will begin with the <a href="/most-useful-html-elements-for-maximizing-better-results/">HTML</a> structure. We create a parent container called <code>.flip-wrapper</code>. This container acts as the parent element for our animation. Inside it, we have a child element with the <code>.flip-card</code> class, this is where our animation happens. Next, we divide the child element into two parts: the front side and the back side. On the front side, we’ll add the <code>.avatar-container</code> and place the avatar inside while on the back side, we’ll add the <code>.text-container</code> class and add some text.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"flip-wrapper"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"flip-card"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"avatar-container"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"text-container"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">>Hello&#x3C;/</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>&#x3C;</span><span style="color:#85E89D">i</span><span style="color:#E1E4E8">>How are you today?&#x3C;/</span><span style="color:#85E89D">i</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h3 id="css-basic-structure">CSS Basic structure<a class="heading-anchor" href="#css-basic-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>In our <a href="/how-to-work-with-css-syntax-the-correct-way/">CSS</a> code snippet, first of all, we set the <code>background</code> of our whole page to pink. 🐷🐷</p>
<p>Moving on to the <code>.flip-wrapper</code> container, we specify its dimensions, giving it a fixed <code>width</code> and <code>height</code> of 300 pixels. To make a circular appearance, we apply a <code>border-radius</code> of 50%. If you desire, you can maintain the square ⬜ shape. I chose this rounded ⚪ design because it makes it easier for us to observe the effect we’re aiming for. 😉</p>
<p>Next, we focus on the <code>.flip-card</code> element. We set the <code>position: relative</code> property and then its <code>width</code> and <code>height</code> to 100% to ensure it covers the entire available space. We also add a white <code>background-color</code> and a subtle gray shadow effect. To maintain the circular theme, we apply a <code>border-radius</code> of 50% to this container too.</p>
<p>Finally, we set the <code>position: absolute</code> property in both <code>.avatar-container</code> and <code>.text-container</code> classes. In that way we will be ready to place the content we want on both, the front and the back, sides of our card.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.flip-wrapper</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#B392F0">  .flip-card</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 15</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> grey</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.avatar-container</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#B392F0">.text-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>This is what’s rendered on our screen at the moment.</p>
<p><img src="/flipping-2d-card.webp" alt="A flip-card with a white cyclic shape and a pink background." style="max-width:28%" class="img-narrow"></p>
<h3 id="adding-the-hover-effect">Adding the hover effect<a class="heading-anchor" href="#adding-the-hover-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>In order for our effect to function as intended we have to work with both the parent and the child element. We begin with the parent element, where we apply the <code>:hover</code> effect and change the cursor to a pointer (you can pick any of the <a href="https://www.w3schools.com/cssref/pr_class_cursor.php">CSS cursor styles</a> you prefer).</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.flip-wrapper</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">    cursor</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pointer</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/flipping-2d-card-adding-hover.gif" alt="This gif shows a pink cyclic shape with a pointer (hand) cursor." style="max-width:28%" class="img-narrow"></p>
<h3 id="preparing-the-front-side-of-my-flipping-card">Preparing the front side of my flipping card<a class="heading-anchor" href="#preparing-the-front-side-of-my-flipping-card" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>I added an avatar on the front side of my flipping card. You can add whatever you want (some text, maybe, or an emoticon ✏️) or you can leave it empty, though it is not really useful for observing the flipping.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.avatar-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>In the following image, we can see how the front side of our flipping card would be. Nice! Isn’t it? 😃</p>
<p><img src="/flipping-2d-card-front-side.webp" alt="The front side of our 2d card. It is a blond girl with two space buns and green eyes. It wears magenta eyeglasses, magenta lipstick, a dark green  blouse and a neckless also dark green color." style="max-width:28%" class="img-narrow"></p>
<h3 id="preparing-the-back-side-of-my-flipping-card">Preparing the back side of my flipping card<a class="heading-anchor" href="#preparing-the-back-side-of-my-flipping-card" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Here we prepare our text’s style. We keep the default black <code>color</code> and we centered our text based on the <code>display: flex</code> method.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.text-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  flex-direction</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">column</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Below we can see how the back side of our flipping card would be. Cool huh! 😃</p>
<p><img src="/flipping-2d-card-back-side.webp" alt="The back side of our 2d card. It has a title with the world &#x27;Hello&#x27; and a text writting &#x27;How are you today?&#x27;." style="max-width:28%" class="img-narrow"></p>
<p>Now we are ready to connect these two parts and finally create our amazing animation.</p>
<h3 id="adding-the-flipping-animation-at-the-2d-card">Adding the flipping animation at the 2D card<a class="heading-anchor" href="#adding-the-flipping-animation-at-the-2d-card" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>We are free to create flipping animations on both axis X and Y. Below, I prepared two examples. The first one is for axis-Y while the second one is for axis-X. Let’s break it down and see them analytically. 🧐</p>
<h4 id="flipping-animation-on-axis-y">Flipping animation on axis-Y<a class="heading-anchor" href="#flipping-animation-on-axis-y" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p>In order to achieve our goal we have to combine the following CSS properties.</p>
<ol>
<li><code>transform: rotateY(180deg)</code> We begin by setting the transform property, which is responsible for the flipping, inside the hover effect. It is also necessary to add it to the class that represents the back side of our card, in our case the <code>.text-container</code> class, otherwise, our text won’t be rendered on the screen when we hover over the card.</li>
<li><code>transition: transform 6s</code> &#x26; <code>transform-style: preserve-3d</code> We continue by combining these two properties inside the <code>.flip-card</code> class. The first one shows us the exact, time in seconds (<code>s</code>), our effect will take place while the second one makes the children of an element appear as if they are positioned in a 3D space. So this property gives us the impression that the descendants (children) of our element are located within a three-dimensional space.</li>
<li><code>backface-visibility: hidden</code> We finalize our work with the backface-visibility property that defines whether or not the back side of an element should be visible when facing the user. The back face of an element is a mirror image of the front face being displayed.</li>
</ol>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.flip-wrapper</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">    cursor</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pointer</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#B392F0">    .flip-card</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateY</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">180</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  .flip-card</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#79B8FF">    transition</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transform</span><span style="color:#79B8FF"> 6</span><span style="color:#F97583">s</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    transform-style</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">preserve-3d</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.avatar-container</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#B392F0">.text-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  backface-visibility</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">hidden</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.text-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateY</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">180</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/flipping-on-hover-2d-card-2different-sides-plan-axisy.webp" alt="Five cards side by side showing the flipping animation. The first card shows the frond side of the 2d card. The second shows the card half turned. The third card shows the back side of the 2d card. The forth shows the back side half turned. The last one shows again the front side of the 2d card. Two arrows are there to show the directions of the cards." style="max-width:65%" class="img-narrow"></p>
<p>Voila!! Here is our amazing flipping 2d card animation for the Y-axis!! 🥳</p>
<p><img src="/flipping-2d-card-animation-axisy-1.webp" alt="This gif shows my 2d card flipping along the axis-Y." style="max-width:28%" class="img-narrow"></p>
<h4 id="flipping-animation-on-axis-x">Flipping animation on axis-X<a class="heading-anchor" href="#flipping-animation-on-axis-x" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p>We do as previously but in this case, we set the <code>transform: rotateX</code> as we want our animation to move along the X-axis.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.flip-wrapper</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">    cursor</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pointer</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#B392F0">    .flip-card</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">180</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  .flip-card</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#79B8FF">    transition</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transform</span><span style="color:#79B8FF"> 6</span><span style="color:#F97583">s</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    transform-style</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">preserve-3d</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.avatar-container</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#B392F0">.text-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  backface-visibility</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">hidden</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.text-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotateX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">180</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/flipping-on-hover-2d-card-2different-sides-plan-axisx.webp" alt="This image shows five cards side by side presenting the flipping animation. The first shows the frond side of the 3d card. The second shows ... The third card shows the back side of the 3d card. The forth shows the ... The fifth and last shows again the front side of the 2d card. Two arrows are there to show the directions of the cards." style="max-width:65%" class="img-narrow"></p>
<p>Boom! 🎉 This is our wonderful flipping 2d card animation for the X-axis!!</p>
<p><img src="/flipping-2d-card-animation-axisx.webp" alt="The 2d card flipping along the axis-X." style="max-width:28%" class="img-narrow"></p>
<h2 id="complete-avatar-code">Complete avatar code<a class="heading-anchor" href="#complete-avatar-code" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Below, I include my HTML and CSS avatar code.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"avatar-container"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"hair-back"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"hair hair--left"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"hair hair--right"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"hair-clip hair-clip--left"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"hair-clip hair-clip--right"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"ear ear--left"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"ear ear--right"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"face"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyebrow1 eyebrow1--left"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyebrow1 eyebrow1--right"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyebrow2 eyebrow2--left"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyebrow2 eyebrow2--right"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eye-glasses eye-glasses-left"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eye-glasses eye-glasses-right"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eye eye--left"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--left"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--left1"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--left2"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--left3"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--left4"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">> </span><span style="color:#6A737D">&#x3C;!-- end of left eye --></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eye eye--right"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--right"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--right1"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--right2"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--right3"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--right4"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">> </span><span style="color:#6A737D">&#x3C;!-- end of right eye --></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"nose"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"lips"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">> </span><span style="color:#6A737D">&#x3C;!-- end of face --></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"neck"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"t-shirt"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"neckless"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">> </span><span style="color:#6A737D">&#x3C;!-- end of avatar-container --></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#FFAB70">$body-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#ff9aab</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$container-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$skin-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#eabcb4</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$primary-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#2d2a2a</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$secondary-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#f1f1f1</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$eye-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#17884e</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$eyeline-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#5b3a3a</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$eyelash-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#6d4646</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$iris-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#000</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$hair-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#dfc2ae</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$hair-clip-color1</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$hair-clip-color2</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#b3498d</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$hair-clip-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">$hair-clip-color1</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">$hair-clip-color2</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">$hair-clip-color1</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">$hair-clip-color2</span><span style="color:#E1E4E8">, </span><span style="color:#FFAB70">$hair-clip-color1</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#FFAB70">$eye-glasses-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#a32a80</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$eyebrow-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#5b3a3a</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$nose-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#646363</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$lips-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#cd0b87</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$t-shirt-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#0b443c</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$neckless-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#0b443c</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">*</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  margin</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  padding</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-sizing</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">border-box</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">html</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">vh</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$body-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.avatar-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">320</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">320</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$container-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 15</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> grey</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  overflow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">hidden</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#B392F0">  .hair-back</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">140</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">44</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 44</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">30</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$hair-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">    filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">drop-shadow</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #bc9b83</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">    z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#B392F0">:before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">      content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0.5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">28</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#bc9b83</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">      filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">drop-shadow</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 4</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #69660f</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#B392F0">:after</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">      content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">110</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#d8baa4</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">70</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .hair</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$hair-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">      filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">drop-shadow</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #bc9b83</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">      z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#FFAB70">--left</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 70</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 70</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">22</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">80</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#FFAB70">--right</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">22</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">80</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">50</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .hair-clip</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">28</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$hair-clip-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #037203</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#FFAB70">--left</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">48</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">98</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#FFAB70">--right</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">50</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">48</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">98</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .ear</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$skin-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">    filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">drop-shadow</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #7e7a1f</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">95</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#FFAB70">--left</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">104</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-5</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">:before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">12</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$skin-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 40</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> -1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> darken</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">$skin-color</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">10</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#FFAB70">--right</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">104</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">5</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">:before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$skin-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 40</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> -1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> darken</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">$skin-color</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">10</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">// end of ear</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .face</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">110</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#F97583"> /</span><span style="color:#79B8FF"> 70</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 70</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 160</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 160</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$skin-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">54</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">    box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0.5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #b37865</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">    .eye-glasses</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">32</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#FFAB70"> $eye-glasses-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">32</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#B392F0">.eye-glasses-left</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">12</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 18</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 18</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 18</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">:before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">14</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$eye-glasses-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">35</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">:after</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$eye-glasses-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">8</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-8</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#B392F0">.eye-glasses-right</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">18</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 12</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 18</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 18</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">:before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">15</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$eye-glasses-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-15</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">:after</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$eye-glasses-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">8</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-8</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  }  </span><span style="color:#6A737D">// end of eye-glasses</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">    .eye</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">38</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$secondary-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#FFAB70"> $eyeline-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">75</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">45</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#B392F0">:before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">      content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$eye-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #17460d</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#FFAB70">--left</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">16</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> darken</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">$eyeline-color</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#FFAB70">--right</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">16</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> -1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> darken</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">$eyeline-color</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#B392F0">:after</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">      content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">4</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">4</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$iris-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#B392F0">      .eyelash</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      W</span><span style="color:#79B8FF">idth</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$eyelash-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#FFAB70">--left</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#FFAB70">--left1</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#FFAB70">--left2</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#FFAB70">--left3</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#FFAB70">--left4</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">90</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#FFAB70">--left</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#F97583">px</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#FFAB70">--left1</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-2</span><span style="color:#F97583">px</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#FFAB70">--left2</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-5</span><span style="color:#F97583">px</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#FFAB70">--left3</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">9</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-6</span><span style="color:#F97583">px</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#FFAB70">--left4</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">13</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-6</span><span style="color:#F97583">px</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#FFAB70">--right</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">14</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#FFAB70">--right1</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#FFAB70">--right2</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-7</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#FFAB70">--right3</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-8</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#FFAB70">--right4</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-8</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-1</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">    } </span><span style="color:#6A737D">// end of eye-lash</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">// end of eye</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">    .eyebrow1</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$eyebrow-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">28</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#FFAB70">--left</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">10</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">16</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#FFAB70">--right</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-10</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">        right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">16</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">    } </span><span style="color:#6A737D">// end of eyebrow1 //</span></span>
<span class="line"><span style="color:#B392F0">    .eyebrow2</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">14</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$eyebrow-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">28</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--left</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-12</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">          left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">9</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--right</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">12</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">          right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">9</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#E1E4E8">      } </span><span style="color:#6A737D">// end of eyebrow2 //</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">    .nose</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$nose-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">45</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">70</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">44</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">:before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$nose-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">90</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-6</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#E1E4E8">    } </span><span style="color:#6A737D">// end of nose</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">    .lips</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">18</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">18</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">90</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">darken</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">$lips-color</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">1</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">90</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">45</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#B392F0">:before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">      content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#FFAB70"> $skin-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-45</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">24</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">12</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  }  </span><span style="color:#6A737D">// end of lips</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">// end of face</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .neck</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">34</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$skin-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">    filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">drop-shadow</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #865748</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">149</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">    z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">9</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#B392F0">:before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">      content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$skin-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">// end of neck</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .t-shirt</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">166</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">140</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$t-shirt-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#F97583"> /</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">190</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#85E89D">    filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">drop-shadow</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">    z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">4</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">// end of t-shirt</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .neckless</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">    content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">36</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$neckless-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">183</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">// end of neckless</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">// end of avatar-container</span></span></code></pre></div>
<p><img src="/flipping-2d-card-front-side.webp" alt="The front side of our 2d card. It is a blond girl with two space buns and green eyes. It wears magenta eyeglasses, magenta lipstick, a dark green  blouse and a neckless also dark green color." style="max-width:32%" class="img-narrow"></p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-make-a-css-flipping-card-animation-on-hover/">CSS Flip Card Animation on Hover</a></li>
<li><a href="/how-to-make-a-css-infinite-flipping-card-animation/">Infinite CSS Flip Card Animation</a></li>
<li><a href="/how-to-effectively-use-css-transform-scale-on-hover/">CSS Scale on Hover with transform</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How to Improve Pull Requests: 3 Basic Rules</title>
      <link>https://littlecodingthings.com/how-to-create-better-pull-requests-3-proven-tips/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-create-better-pull-requests-3-proven-tips/</guid>
      <pubDate>Tue, 25 Jun 2024 11:25:00 GMT</pubDate>
      <description>Three habits that make a pull request easier to review: screenshots for UI changes, proactive comments, and a title that says what actually changed.</description>
      <category>Thoughts &amp; Theory</category>
      <content:encoded><![CDATA[<p>In this post, I would like to share some thoughts that have helped me structure and enhance a pull request from the perspective of both the author and the reviewer. If you’re looking to create better pull requests, this post is for you.</p>
<p>While writing this post, I am thinking mostly of GitHub, but I am sure that my thoughts apply, with a bit of modification maybe, to other platforms, too.</p>
<p>So even if you are already the best on pull requests, maybe there is still room for improvement? 😅</p>
<figure><img src="/high-five.webp" alt="High five scene from the Anchorman movie" style="max-width:64%" class="img-narrow"><figcaption><a href="https://www.imdb.com/title/tt0357413/">Anchorman: The Legend of Ron Burgundy (2004)</a></figcaption></figure>
<p>Just kidding, I am sure you are doing great and I know this post will ignite excitement among those with more basic and advanced skills.</p>
<h2 id="screenshots-for-ui-changes">Screenshots for UI changes<a class="heading-anchor" href="#screenshots-for-ui-changes" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Whenever I’ve found myself working on frontend features, I’ve seen that it can be tough to understand UI modifications by just reviewing markup. An experienced developer might be able to catch any peculiar HTML/CSS code usage, but understanding exactly what’s changed on the UI requires supernatural abilities. 🦸</p>
<p>(<em>Have to say, it’s not a myth! I’ve met a developer with such skills! They truly exist out there!</em>)</p>
<p>So what can you do to help improve the process? One way to help your reviewers do a better job is by including screenshots of the UI changes you made through your pull request, rather than letting them review only the code differences.</p>
<p>Think about it. Which one feels easier to understand? Seeing something like this:</p>
<p><img src="/better-pr-ui-changes-code-scaled.webp" alt="GitHub pull request showing side by side differences"></p>
<p>Or review it with a screenshot attached, like this:</p>
<p><img src="/better-pull-requests-ui-changes.webp" alt="Better Github pull requests"></p>
<p>By adding screenshots, you can give your colleagues a clearer understanding of what you’ve implemented and, at the same time, increase the chances of catching a <a href="/the-unique-origin-of-the-term-bug-in-software-development/">bug</a> before it gets deployed! 🐛</p>
<p><strong>Extra points</strong> 🧐</p>
<ul>
<li>Attaching an image to show how the UI looked <strong>before</strong> your tweaks, could also improve the review process. Something like before – after.</li>
<li>Including mobile/tablet screenshots may also help in identifying a potential issue by seeing the UI changes for all devices, while QA testing.</li>
</ul>
<p><strong>QA testing</strong> (Quality Assurance), is a process that amongst others, includes, checking if a code change (feature/bug) was implemented correctly. This is often done by a QA engineer/tester. Some QA testing also takes place by the actual developers, implementing a feature, before they send it for review.</p>
<p>For minor UI changes adding screenshots is probably an overkill. I am sure your reviewers will be able to understand what’s changed without seeing an image. 😎</p>
<h2 id="proactive-comments-for-better-pull-requests">Proactive comments for better pull requests<a class="heading-anchor" href="#proactive-comments-for-better-pull-requests" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Sometimes it can be difficult for me to understand if I have implemented something “correctly”. Especially when working on a large codebase, with many collaborators, it’s important to follow the agreed-upon coding guidelines.</p>
<p>If you find yourself in a situation like this, don’t hesitate to ask for help by highlighting the pieces of code for which you don’t have much confidence. How? Simply by adding an emphasis comment. Just like adding a review comment in your own pull request, state your concerns so that your reviewers will pay extra attention, like this:</p>
<p><img src="/better-pull-requests-comments.webp" alt="Better Github pull requests through comments"></p>
<p>As a result, your reviewer will conduct a more thorough review of the code modifications, and as a result, you’ll feel more confident about your pull request when it finally gets deployed.</p>
<h2 id="improving-the-pull-request-title">Improving the pull request title<a class="heading-anchor" href="#improving-the-pull-request-title" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>One of my favorite ways to improve a pull request is by adding suffixes to the titles. So, for example, let’s consider the following title:</p>
<p><img src="/better-pull-request-plain.webp" alt="Better Github pull requests - nothing on title"></p>
<p>Although this is a nice pull request title, it still doesn’t provide answers, simply by checking the pr listing, to the following questions:</p>
<ul>
<li>What’s the branch this pr is merged into?</li>
<li>What is the related issue?</li>
</ul>
<p>Let’s try and see how we can improve it, by changing its structure a bit. Our goal is to be able to extract more concise information simply by looking at the pr title.</p>
<h3 id="adding-the-target-branch">Adding the target branch<a class="heading-anchor" href="#adding-the-target-branch" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>It’s common for projects to have some basic branches, apart from the main one (old master). These branches are usually for QA testing or client demos, client playgrounds, etc.</p>
<p>If you are working on a project like that, you might find yourself creating multiple requests per branch for various reasons. One pull request for QA testing, one pull request for the final deployment to the <code>main</code> branch, and so on.</p>
<p>But if you do so, there is no way to identify the branch through the pr’s title, right? So what I prefer doing is just adding a simple suffix with the branch’s name. By doing so, if I have pull requests of the same feature to multiple branches it’s easier for me to understand what’s what.</p>
<p><img src="/better-pull-request-branch.webp" alt="Better Github pull requests - Branch on title"></p>
<h3 id="showing-the-related-issue">Showing the related issue<a class="heading-anchor" href="#showing-the-related-issue" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Another interesting suffix that works perfectly for GitHub (and I assume in a similar way for other platforms too) is adding the issue number in your pr title.</p>
<p><em>(If you are using a workflow in which you create a GitHub issue before working on a new feature, then this is for you)</em></p>
<p>Let’s assume you have created a GitHub issue with the number <code>#312</code>. After deploying your changes to the last branch, you might find yourself going through the GitHub Issues list and trying to find the respective issue so that you can close it. Right?</p>
<p>Did you know there is a way to automatically close an issue when a pull request is merged? How? Well, it’s as simple as adding the <code>Closes &#x3C;Issue number></code> in the pull request’s title. So let’s say that for our pull requests, the Issue you have been working on is <code>#312</code>. If you change the last pull request title to something like:</p>
<p><img src="/better-pull-request-issue.webp" alt="Better Github pull requests - Branch and issue on title"></p>
<p>That means that when you merge the third pull request, issue 312, will also automatically close! Cool right?</p>
<p>Likewise, other suffixes that may be used to connect an issue with a pull request are:</p>
<ul>
<li>Fixes as in <code>Fixes #312</code></li>
<li>Closes</li>
<li>Resolves</li>
</ul>
<p>Furthermore, there are several other resources available for you to explore in addition to the ones mentioned here; check the GitHub documentation for more.</p>
<p>You may also want to check out our post on <a href="/a-guide-to-better-pull-requests-prerequisite-changes-and-splitting/">simplifying pull requests through prerequisite changes</a> and helpful ways of splitting front VS back changes. This post explores how identifying and addressing necessary modifications before submitting your code for review can improve the code review process and increase your chances of success.</p>]]></content:encoded>
    </item>
    <item>
      <title>Gray vs Grey in CSS. What Is the Right Choice?</title>
      <link>https://littlecodingthings.com/gray-vs-grey-in-css-what-is-the-right-choice/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/gray-vs-grey-in-css-what-is-the-right-choice/</guid>
      <pubDate>Fri, 21 Jun 2024 12:00:00 GMT</pubDate>
      <description>gray and grey are the same CSS keyword — browsers treat them identically. The same goes for lightgray/lightgrey and darkgray/darkgrey.</description>
      <category>Thoughts &amp; Theory</category>
      <content:encoded><![CDATA[<p>Gray VS grey? Is there a right choice between these two? It is well known that both gray and grey in CSS are considered equivalent with no impact on functionality. We can use either of them without any issues. In the context of web development and CSS, they are both recognized and accepted. CSS specifications and web browsers accommodate both equally.</p>
<blockquote>
<p>Why 🤔 do web designers and programmers use both gray and grey in CSS?</p>
<p>Because they wanted to add a little color to the spelling debate!</p>
</blockquote>
<p>Below we can see an example of two elements. We set gray for the first element while the second element has grey:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* Using "gray" (American English) */</span></span>
<span class="line"><span style="color:#B392F0">.first-element</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">gray</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/* Using "grey" (British English) */</span></span>
<span class="line"><span style="color:#B392F0">.second-element</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">grey</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Both examples are correct, and your CSS should be functional, <code>.first-element</code> and <code>.second-element</code> classes will share the same color, as CSS treats gray and grey interchangeably.</p>
<p>It turns out that the choice between gray and grey in CSS is primarily a matter of personal preference and doesn’t affect how web browsers interpret your code. You are free to use either.</p>
<p>Similarly, there are other <a href="/what-you-need-to-know-about-css-color-methods/">color names</a> with variations in spelling that are recognized by most modern browsers, for example, “lightgray” and “lightgrey” or “darkgray” and “darkgrey” are all valid. 😃</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/what-you-need-to-know-about-css-color-methods/">What You Need to Know About CSS Color Methods</a></li>
<li><a href="/css-grayscale-filter-how-to-upgrade-images/">How to Make Grayscale Images with CSS</a></li>
<li><a href="/capitalizing-css-property-values-what-is-the-right-way/">Is CSS Case-Sensitive?</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How to Make Rainbow Text in CSS</title>
      <link>https://littlecodingthings.com/css-rainbow-text-how-to-make-astonishing-and-vibrant-fonts/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/css-rainbow-text-how-to-make-astonishing-and-vibrant-fonts/</guid>
      <pubDate>Mon, 17 Jun 2024 12:05:00 GMT</pubDate>
      <description>Make rainbow text in CSS with a linear-gradient, background-clip: text and color: transparent — three declarations, shown step by step.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Imagine infusing your web typography (fonts) with the vibrant hues of a dazzling 🌈✨ rainbow! Cascading Style Sheets (<a href="/the-truth-about-css-is-it-really-a-programming-language/">CSS</a>) empower designers and developers to bring this captivating vision to life. A colorful font like the CSS rainbow effect is more than just a spectrum of colors; it’s a creative and dynamic way to enhance your website’s visual appeal and make a lasting impression on your visitors.</p>
<p>Today, with this post, 😃 we’ll dive into the exciting world of creating a rainbow effect, unlocking the <a href="/what-you-need-to-know-about-css-color-methods/">magic of colors</a> and typography to elevate your web design. Enjoy! 💻</p>
<h2 id="prepare-basic-html-and-css-structure">Prepare basic HTML and CSS structure<a class="heading-anchor" href="#prepare-basic-html-and-css-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We begin with our <a href="/most-useful-html-elements-for-maximizing-better-results/">HTML</a> and <a href="/how-to-work-with-css-syntax-the-correct-way/">CSS</a> structure. We create an HTML <code>&#x3C;div></code> element that has a class called rainbow-effect. Then, we set some rules in CSS that are applied to our HTML element. So, let’s move forward and analyze our CSS code snippet.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">body</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"rainbow-effect"</span><span style="color:#E1E4E8">>rainbow effect&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">body</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#050c20</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* deep blue */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.rainbow-effect</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  text-align</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">180</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-weight</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">bold</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-family</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">'Roboto'</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">sans-serif</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>First of all, we set the background color of our body to be a deep blue. Then, we proceed with our text. We create a <code>center</code> aligned, <code>white</code> <code>180px</code> text with <code>bold</code> and highly legible fonts, as we specifically seek a font with excellent readability.</p>
<p>Once set, we can then proceed with our tweaks in order to infuse the text with the enchanting hues of a rainbow. The following image shows what is rendered on the screen for the time being. 😃</p>
<p><img src="/fonts-rainbow-effect-white.webp" alt="This image shows our text with its basic characteristics." style="max-width:53%" class="img-narrow"></p>
<h2 id="apply-the-rainbow-effect">Apply the rainbow effect<a class="heading-anchor" href="#apply-the-rainbow-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Within the style rules of the <code>.rainbow-effect</code>, we find specific directives regarding our rainbow effect:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.rainbow-effect</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#F97583">    to</span><span style="color:#79B8FF"> right</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">yellow</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">indigo</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">violet</span></span>
<span class="line"><span style="color:#E1E4E8">  );</span></span>
<span class="line"><span style="color:#79B8FF">  background-clip</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">text</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><code>background-image: linear-gradient</code>
The first thing we need to know is that by using the <code>background-image</code> CSS property we are able to create a background with <strong>more than one color</strong>.</p>
<p>We do so by setting the <code>linear-gradient</code> value, and we are free to choose any color and any direction we want for our text. In our case, we use the <code>to right</code> direction and the gradient starts with the color red on the left and smoothly transitions through orange, yellow, green, blue, indigo, and violet as it moves from left to right. So, it gives a colorful, horizontal stripe-like background.</p>
<p><img src="/fonts-rainbow-effect-applying-effect.webp" alt="The rainbow effect word with a rainbow effect as a background. This happens as we set the CSS background-image property to linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet)" style="max-width:53%" class="img-narrow"></p>
<p>You are always free to choose any direction of the <a href="/css-linear-gradient-techniques-how-to-make-colorful-line-drawings/">linear-gradient</a> you like! 👍</p>
<p><code>background-clip: text</code>
We continue our work with the <code>background-clip</code> property which is used to define how the background should be clipped or masked. In our case, it’s set to <code>text</code>, which tells the browser to apply the background gradient <strong>only to the text</strong> inside our <code>div</code>.</p>
<p><img src="/fonts-rainbow-effect-white.webp" alt="The rainbow effect word after setting the -webkit-background-clip CSS property to text. We can see that for now our text is white with the body&#x27;s background." style="max-width:53%" class="img-narrow"></p>
<p>What? Nothing happened yet? Why? Using this property, the colorful background is applied to the text, <strong>but</strong> the effect is not visible yet because it is necessary to proceed to our next step 🧐 ⬇ in order to achieve the final and desired results. So, let’s move on!</p>
<p><code>color: transparent</code>
Finally, adding the <code>color</code> property to <code>transparent</code> renders the text itself invisible, allowing the colorful background to show through the text. And there it is! 🥳</p>
<p><img src="/fonts-rainbow-effect-finalized.webp" alt="The rainbow effect word with the css rainbow effect after setting color CSS property to transparent. We are able now to see that our text inherits the colors of the rainbow. So, now we can see a completely colorful text." style="max-width:53%" class="img-narrow"></p>
<p>So, in summary, putting it all together, when you use this code, you’ll have a text with a colorful gradient background (rainbow colors) that appears within the text. The text itself is invisible, creating a striking and colorful text effect. 🎉</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/transform-your-text-black-and-white-css-stripes-made-easy/">Striped Text Effect in CSS</a></li>
<li><a href="/css-text-outline-how-to-make-amazing-outlined-texts/">CSS Text Outline Effect</a></li>
<li><a href="/transform-your-text-black-and-white-css-stripes-made-easy/">Striped Text Effect in CSS</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How To Decide If Programming Is Right For You?</title>
      <link>https://littlecodingthings.com/how-to-decide-if-programming-is-right-for-you/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-decide-if-programming-is-right-for-you/</guid>
      <pubDate>Thu, 13 Jun 2024 06:14:00 GMT</pubDate>
      <description>An honest list of what makes programming a great career and what makes it hard — opportunity and creativity against bugs, burnout and doubt.</description>
      <category>Thoughts &amp; Theory</category>
      <content:encoded><![CDATA[<p>Imagine an astronaut floating in space, laptop in hand, surrounded by twinkling ✨ stars. It’s a scene that mirrors the adventure of programming—exploring the unknown, solving 🧩 puzzles, and pushing boundaries. Just as astronauts 👨‍🚀 👩‍🚀 embark on missions into space, programmers journey into the digital 💻 frontier.</p>
<p>With the rise of remote work, programmers have the freedom to code from anywhere on 🏖 🏰 🏕 earth. Remote work opens doors to global collaboration, while continuous learning keeps them ahead in a rapidly evolving landscape. So, whether you’re reaching for the stars or diving into code, remember that programming is a journey of discovery and innovation.</p>
<p>Are you considering a career in the world of programming? It’s a wild but also exciting ride, with twists, turns, and plenty of code to go around. But why do people choose this path, you ask? Let me break it down for you, along with some pros and cons to consider. 🤔 In other words, food for thought.</p>
<h2 id="pros-why-programming-might-be-the-perfect-career-for-you">Pros: Why Programming Might Be the Perfect Career for You<a class="heading-anchor" href="#pros-why-programming-might-be-the-perfect-career-for-you" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Programming is an incredible profession that offers a wide range of opportunities. It allows you to create, innovate, and solve problems in ways that can have a significant impact on the world. Additionally, it offers attractive salaries and the flexibility of remote work. Furthermore, what a great satisfaction it is to bring ideas to life through code.</p>
<h3 id="plenty-of--opportunities">Plenty of 🎉🎉 Opportunities<a class="heading-anchor" href="#plenty-of--opportunities" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>To start, programmers have a plethora of job opportunities in a world that provides us with low budget prospects. Skilled coders are in high demand, from big tech companies to small startups. If you’re looking for a career with many options and a really good salary, programming might be your jam.</p>
<figure><img src="/programming-post-plenty-of-opportunities.webp" alt="Astronaut watering a plant" style="max-width:25%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-astronaut-watering-moon-plant-cartoon-vector-icon-illustration-science-technology-icon-isolated_30901992.htm#fromView=search&#x26;page=2&#x26;position=18&#x26;uuid=7c115fdb-f10c-4abc-862e-13a116413dd4">Image by catalyststuff on Freepik</a></figcaption></figure>
<figure><img src="/programming-post-showing-creativity.webp" alt="An astronaut thinking and testing a rocket" style="max-width:25%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-astronaut-testing-rocket-cartoon-vector-icon-illustration-science-technology-icon-isolated_31236809.htm#fromView=search&#x26;page=1&#x26;position=7&#x26;uuid=2accb607-b72b-4e70-b76f-0a9dc595f2fb">Image by catalyststuff on Freepik</a></figcaption></figure>
<h3 id="flex-your-creative--muscles">Flex Your Creative 🧠 Muscles<a class="heading-anchor" href="#flex-your-creative--muscles" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Believe it or not, coding isn’t just about numbers and logic – it’s an art form, too. Whether you’re crafting a well-designed app or solving a tricky <a href="/the-unique-origin-of-the-term-bug-in-software-development/">bug</a>, there’s a ton of room for creativity in programming. So, if you’re the type who loves to create and furthermore experiment, you’ll feel right behind your keyboard.</p>
<h3 id="problem-solving--superpowers">Problem-Solving 🧨 Superpowers<a class="heading-anchor" href="#problem-solving--superpowers" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Ever feel like you’re the master of puzzles? If you love cracking enigmas, programming is your playground. Whether you are dealing with messy code or making a slow algorithm faster, programming is all about finding solutions. And trust me, there’s nothing quite like the satisfaction of overcoming a challenge and seeing your code in action.</p>
<figure><img src="/programming-post-solving-various-problems.webp" alt="A maze with an astronaut and various elements all around" style="max-width:25%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/maze-kids-with-space-elements_11590728.htm#fromView=search&#x26;page=1&#x26;position=19&#x26;uuid=ab8fc93e-67a7-4871-b204-22c429e345dc">Image by Freepik</a></figcaption></figure>
<figure><img src="/programming-post-file-astronaut-looking-moon-with-telescope-always-discover-things.webp" alt="Astronaut looking at the moon through a telescope" style="max-width:25%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-astronaut-looking-moon-with-telescope-cartoon-vector-icon-illustration-science-technology-flat_182912648.htm#fromView=search&#x26;page=1&#x26;position=45&#x26;uuid=4c2aa2d6-39a4-45c6-9796-4be9374d5e9f">Image by catalyststuff on Freepik</a></figcaption></figure>
<h3 id="always-something-fresh-to--discover">Always Something Fresh to 🔎 Discover<a class="heading-anchor" href="#always-something-fresh-to--discover" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Forget about getting bored. The field is constantly evolving whether it’s new languages, frameworks, or technologies. It’s like embarking on a never-ending journey of learning. If you thrive on exploration and discovery, programming will definitely keep you engaged.</p>
<h3 id="remote--work"><strong>Remote 🛵 Work</strong><a class="heading-anchor" href="#remote--work" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>The beauty of remote work! With programming skills in your toolkit, you’re not tied to any particular location. Whether you’re coding from your cozy home office or enjoying a latte at your favorite café, your workspace is everywhere as long as you’ve got an internet connection.</p>
<figure><img src="/programming-post-remote-working.webp" alt="Astronaut travelling with suitcase" style="max-width:25%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-astronaut-traveling-with-suitcase-phone-cartoon-vector-icon-illustration-science-holiday_38364475.htm#fromView=search&#x26;page=1&#x26;position=43&#x26;uuid=1d1fa139-6f2a-4f7f-a4e5-d7003f2ac73e">Image by catalyststuff</a> on Freepik</figcaption></figure>
<figure><img src="/programming-post-earnings.webp" alt="Astronaut sitting on  coin" style="max-width:25%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-astronaut-sitting-gold-coin-with-pickaxe-cartoon-vector-icon-illustration-science-finance_31416612.htm#fromView=search&#x26;page=1&#x26;position=8&#x26;uuid=75a1992b-1ee4-4153-aa45-75b497f89051">Image by catalyststuff on Freepik</a></figcaption></figure>
<h3 id="spectrum-of--salaries">Spectrum of 💰 Salaries<a class="heading-anchor" href="#spectrum-of--salaries" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>If you are dreaming of hooking 🪝 high-paying opportunities such as freelance projects, contract work, or even full-time positions, improving your English skills can open doors to remote positions in countries offering generous salaries. 🤑 So, now it’s the right time to freshen them up.</p>
<h2 id="cons-challenges-you-might-face-in-a-programming-career">Cons: Challenges You Might Face in a Programming Career<a class="heading-anchor" href="#cons-challenges-you-might-face-in-a-programming-career" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Programming comes with its challenges. It demands continuous learning and dedication, which can sometimes be truly stressful. Long hours at the computer can lead to health issues, and the solitary nature of the work can be isolating. Balancing these demands is crucial if you desire to maintain your position in this sector.</p>
<h3 id="learning-curve--alert">Learning Curve 📈 Alert<a class="heading-anchor" href="#learning-curve--alert" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Programming may be challenging at first. Learning all those languages, algorithms, and frameworks can feel like trying to solve a Rubik’s cube blindfolded. Keep patience and stick with it. Before you know it, you’ll be coding 👩‍💻 like a pro. So, keep going!</p>
<figure><img src="/programming-post-keep-it-going.webp" alt="An astronaut with a baseball bat." style="max-width:25%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cool-astronaut-with-baseball-bat-jacket_15631669.htm#fromView=search&#x26;page=1&#x26;position=36&#x26;uuid=1ac0d58c-6571-48f7-971e-903cdd161078">Image by catalyststuff on Freepik</a></figcaption></figure>
<figure><img src="/programming-post-bug.webp" alt="Astronaut sitting and asking for help" style="max-width:25%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-astronaut-homeless-ask-help-cartoon-vector-icon-illustration-science-technology-isolated_133837573.htm#fromView=search&#x26;page=3&#x26;position=23&#x26;uuid=79aaaad3-7607-4633-85be-08b91be12a0e">Image by catalyststuff on Freepik</a></figcaption></figure>
<h3 id="the-dreaded--bugs">The Dreaded 🪲 Bugs<a class="heading-anchor" href="#the-dreaded--bugs" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Undoubtedly, the curse of every programmer’s existence – <a href="/the-unique-origin-of-the-term-bug-in-software-development/" title="Learn about the origin of this term">bugs</a>. Those pesky little gremlins that sneak into your code and fill you with exhaustion and devastation. Tracking them down can be a real headache! But hey, don’t give up! Every bug you squash is a victory in your hands, and at the end of the day, it feels soo goood!! 🥇🏆</p>
<h3 id="maintenance--madness">Maintenance 🤯 Madness<a class="heading-anchor" href="#maintenance--madness" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Creating software is only the start. Once it’s out there, you’ve got to keep it running according to plan. That means updating it, fixing security issues, and improving it again and again—all while handling your other tasks. It’s like juggling 🤹‍♀️ but with computer stuff. It’s not easy, but keeping your code running smoothly is one of the most crucial things to do. Believe me, you can do it, and you will!</p>
<figure><img src="/programming-post-running-coding-smoothly.webp" alt="Astronaut fixing UFO with a wrench" style="max-width:25%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-astronaut-repairing-ufo-with-wrench-cartoon-vector-icon-illustration-science-technology-flat_134020803.htm#fromView=search&#x26;page=11&#x26;position=4&#x26;uuid=1ac0d58c-6571-48f7-971e-903cdd161078">Image by catalyststuff on Freepik</a></figcaption></figure>
<figure><img src="/programming-post-keeping-balance.webp" alt="" style="max-width:25%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-couple-astronaut-playing-seesaw-planet-space-cartoon-vector-icon-illustration-science-tech_33489401.htm#fromView=search&#x26;page=1&#x26;position=33&#x26;uuid=b9bc4967-5d84-46ec-8a5d-a10580a59b7a">Image by catalyststuff on Freepik</a></figcaption></figure>
<h3 id="work-life--balance-struggle">Work-Life ⚖ Balance Struggle<a class="heading-anchor" href="#work-life--balance-struggle" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Maintaining a healthy work-life balance can be a real challenge in a world where we’re all glued to screens. It’s easy to get sucked into the endless abyss of code. Separate work life from home life it’s crucial. Don’t forget to take breaks, get fresh air, exercise, start a new hobby, travel, go back in time when reading books 📖 was a must, or spend time with loved ones. After all, life’s too short to spend it all behind a screen.</p>
<h3 id="isolation--factor">Isolation 😑 Factor<a class="heading-anchor" href="#isolation--factor" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>While programming offers the freedom to work remotely and independently, it can also lead to isolation. Spending long hours in front of a computer screen and troubleshooting code solo can sometimes lead to loneliness. Without the colleagues of a traditional office environment, programmers may miss out on all the social interactions and spontaneous collaborations that can spark creativity and association.
However, this isolation can be a welcome aspect of the job for people who blossom in solitary environments, allowing them to focus deeply on their work without distractions. Ultimately, whether isolation in programming is seen as good or bad depends on individual preferences and working styles. Some may find comfort in solitude, while others may desire more social interaction.</p>
<p>It’s completely up to you where to place it, on the pros or cons list. In the end, it’s a reflection of your character. ☔ 🌈 🌞</p>
<figure><img src="/programming-post-isolating.webp" alt="A couple of astronauts hugging at the top of the moon" style="max-width:25%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-astronaut-couple-hug-moon-cartoon-vector-icon-illustration-science-technology-isolated-flat_51406665.htm#fromView=search&#x26;page=5&#x26;position=17&#x26;uuid=1fb21f25-4e4a-41e0-a1ca-6467ea8a8d0d">Image by catalyststuff on Freepik</a></figcaption></figure>
<figure><img src="/programming-post-cons-the-imposter-syndrome.webp" alt="Astronaut overthinking while sitting in a rock" style="max-width:25%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-astronaut-thinking-rock-cartoon-vector-icon-illustration-science-technology-isolated-flat_181153464.htm#fromView=search&#x26;page=2&#x26;position=51&#x26;uuid=fe968e89-ed78-4d90-8b7b-d065c5d5fdbe">Image by catalyststuff</a> on Freepik</figcaption></figure>
<h3 id="impostor--syndrome-warning">Impostor 😰 Syndrome Warning<a class="heading-anchor" href="#impostor--syndrome-warning" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Huh, this awful self-doubt phenomenon. Impostor syndrome or impostorism is common among programmers, where skilled developers feel inadequate and fear being revealed as frauds despite their abilities. This lack of self-confidence can prevent their professional growth by discouraging them from participating in projects, speaking at conferences, or applying for advanced roles.
Always remember that you won’t know if you can do it unless you try. So, do not hesitate! Take the shot! 🥁</p>
<h3 id="burnout-">Burnout 😵‍💫<a class="heading-anchor" href="#burnout-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Last but not least – burnout. Arising from long stress and imbalance between work and personal life. Symptoms include exhaustion and reduced productivity, which can lead to physical health issues and mental health problems like depression.
We can prevent this by setting boundaries, organizing workloads, discussing it with our colleagues, asking for support, and taking breaks. Loong ☕ loong 💤 breaks! These techniques will help to maintain health and sustain enthusiasm for coding.
Are all part of the journey. So, roll up your sleeves and dive into work. But always remember that burnout is not an option. Get out of your computer when you need a break!!</p>
<figure><img src="/programming-post-web-of-work.webp" alt="Astronaut flying out of laptop&#x27;s screen" style="max-width:25%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-astronaut-out-laptop-space-cartoon-vector-icon-illustration-science-technology-isolated_35868802.htm#fromView=search&#x26;page=1&#x26;position=42&#x26;uuid=9e2c6aca-c15e-4ad0-a242-fed54072a885">Image by catalyststuff on Freepik</a></figcaption></figure>
<p>So, go ahead! Begin this programming journey and picture yourself as our courageous astronaut exploring new boundaries. Equipped with the tools of the trade—a laptop, determination, and a thirst for discovery. Whether you’re dreaming of distant 🌌 galaxies or lines of 📜 code, remember: this path is one of endless possibilities.
So, what are you waiting for? Embark on your own adventure.
Conquer the skies of coding!
Bon voyage! 🪐 ✨</p>
<figure><img src="/programming-post-bon-voyage.webp" alt="Astronaut holding a flag at the top of the moon" style="max-width:42%" class="img-narrow"><figcaption><a href="https://www.freepik.com/free-vector/cute-astronaut-holding-flag-moon-cartoon-vector-icon-illustration-science-technology-icon-concept-isolated-premium-vector-flat-cartoon-style_22383468.htm#fromView=search&#x26;page=3&#x26;position=12&#x26;uuid=79aaaad3-7607-4633-85be-08b91be12a0e">Image by catalyststuff</a> on Freepik</figcaption></figure>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/remote-work-freedom-or-burnout/">Remote Work! Freedom or Burnout?</a></li>
<li><a href="/unmasking-impostor-syndrome-in-tech-watch-out-for-these-signs/">Impostor Syndrome in Tech: The Signs</a></li>
<li><a href="/am-i-too-old-to-learn-coding/">Am I Too Old to Learn Coding?</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>What Is the CSS Box Model in Simple Terms</title>
      <link>https://littlecodingthings.com/what-is-the-css-box-model-in-simple-terms/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/what-is-the-css-box-model-in-simple-terms/</guid>
      <pubDate>Mon, 10 Jun 2024 15:00:00 GMT</pubDate>
      <description>Content, border, padding and margin explained with one worked example — including how to add up an element's real width and height.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Our life consists of large and small boxes! By saying that, I mean all those things we have to deal with daily, and we usually put them into categories as we do in programming with boxes by using the amazing CSS box model property. Are these boxes a mystery 🧐 puzzle 🧩 or could they end up being really helpful when we truly understand how they work? Let’s continue and get a clearer understanding of it! 😀</p>
<h2 id="what-is-a-css-box-model">What is a CSS box model?<a class="heading-anchor" href="#what-is-a-css-box-model" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>By saying CSS box 🎁 model we mean the <strong>space</strong> which contains an HTML element. A CSS box <strong>consists of</strong>:</p>
<p><strong>1) Content</strong>: This is the <strong>space</strong> that the HTML element occupies. By content, we mean text, images, lists, avatars, videos, icons, shapes …</p>
<p><strong>2) <a href="/how-to-be-creative-with-different-css-border-styles/">Border</a></strong>: It’s the <strong>line</strong> we surround something. We could define it as a frame that encloses HTML elements. Border doesn’t include content, it’s an independent property. Border property can take only one value (<code>border</code>) or many values (some we use more are <code>border-width</code>, <code>border-style</code>, <code>border-color</code>, <code>border-radius</code>, <code>border-image</code> but there are many others too). You can also set different values for each side of the border with <code>border-top</code>, <code>border-bottom</code>, <code>border-left</code>, <code>border-right</code> CSS properties.</p>
<p><strong>3) Paddings</strong>: It’s the <strong>distance</strong> between content and border. We can set the same value for all four sides (<code>padding</code>) or we can set different values for each side (<code>padding-top</code>, <code>padding-bottom</code>, <code>padding-left</code> &#x26; <code>padding-right</code>).</p>
<p><strong>4) Margins</strong>: It’s the <strong>external distance</strong> between HTML elements. By setting <code>margin</code> in one value it works the same for all four sides of the element, otherwise, you can set dissimilar values with <code>margin-top</code>, <code>margin-bottom</code>, <code>margin-left</code> &#x26; <code>margin-right</code> CSS properties.</p>
<p>We can <strong>COMBINE</strong> all these properties in a CSS box but we can also use them separately.
<em>Below, we have an image that shows a CSS box model diagram.</em></p>
<p><img src="/box-model-outlet.webp" alt="This is an image that shows a css box model with its content, padding, border and margin inside a screen." style="max-width:49%" class="img-narrow"></p>
<p>Paddings and margins are <strong>both transparent</strong>. Paddings use the same background as the one used by the main content, while margins inherit their background from the parent element to which they belong.</p>
<h3 id="css-box-model-example">CSS Box model example<a class="heading-anchor" href="#css-box-model-example" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>We can now take a break ☕ and continue…
Let’s analyze a little bit more our CSS box model with an example. First, we have to write down our <a href="/most-useful-html-elements-for-maximizing-better-results/" title="HTML">HTML</a> &#x26; <a href="/how-to-work-with-css-syntax-the-correct-way/" title="CSS">CSS</a> code <strong>without</strong> <code>padding</code>, <code>border</code> &#x26; <code>margin</code>. The image, that follows our code snippet, shows what was rendered through our code.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">body</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"title"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    Hello there! How are you today?</span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">body</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">html</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#6A737D">  /* we use display property to center our HTML element to the body */</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">grey</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.title</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  text-align</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* to center our text */</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">blue</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>For the time being, we are able to observe the content displayed on the screen.</p>
<p><img src="/box-model-outlet-without-padding-border-margin.webp" alt="This is an image that shows a centered box with content but without paddings, borders, and margins inside a screen." style="max-width:49%" class="img-narrow"></p>
<p>Below, we can see the same example after <strong>adding</strong> <code>padding</code>, <code>border</code> &#x26; <code>margin</code>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.title</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#6A737D">  /* if you have different values, instead of padding-left padding-top,</span></span>
<span class="line"><span style="color:#6A737D">  padding-right, padding-bottom you can write all padding values together</span></span>
<span class="line"><span style="color:#6A737D">  like above. */</span></span>
<span class="line"><span style="color:#79B8FF">  padding</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 150</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 150</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* top, right, bottom, left */</span></span>
<span class="line"><span style="color:#6A737D">  /* instead of border-width, border-style &#x26; border-color you can write just</span></span>
<span class="line"><span style="color:#6A737D">  border and set all these values together like above */</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#6A737D">  /* if margin-top &#x26; margin-bottom have the same value, margin-left &#x26;</span></span>
<span class="line"><span style="color:#6A737D">  margin-right the same too you can write all margin values together</span></span>
<span class="line"><span style="color:#6A737D">  like above */</span></span>
<span class="line"><span style="color:#79B8FF">  margin</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* (top &#x26; bottom 50px) then (left &#x26; right 100px) */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/box-model-outlet-with-defferent-padding-border-margin-around.webp" alt="What is a css box model? This is an image that shows a css box model diagram, that is  a centered box with content and all relative paddings, borders, and margins inside a screen." style="max-width:63%" class="img-narrow"></p>
<h3 id="explaining-css-box-model-calculations">💡<strong>Explaining CSS Box Model Calculations</strong><a class="heading-anchor" href="#explaining-css-box-model-calculations" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>It would be helpful to understand the calculation process for determining <strong>“<em>Total Width</em>”</strong> &#x26; <strong>“<em>Total Height</em></strong>” and make the concepts clearer. At this point, it would be really helpful to know that the CSS box model has, by default, <code>box-sizing: content-box</code> which means that <em><strong>borders and paddings take extra place around the object</strong></em> we want to add them.</p>
<p>Margins are <strong>NOT</strong> included, as they are outside the CSS box model.</p>
<p><code>width:</code> ➡ <strong>300px</strong> (content’s width) + <strong>40px</strong> (20px border-left + 20px border-right) + <strong>300px</strong> (150px padding-left &#x26; 150px padding-right) = <strong>640px</strong>;</p>
<p><code>height:</code> ➡ <strong>100px</strong> (content’s height) + <strong>40px</strong> (20px border-top + 20px border-bottom) + <strong>150px</strong> (50px padding-top + 100px padding-bottom) = <strong>290px</strong>;</p>
<p>🕵️‍♀️ There is a method to include borders and paddings within the box’s dimensions. If you’re interested in learning more about the <code>box-sizing</code> CSS property to achieve this, I recommend <a href="/css-box-sizing-better-implementations-less-headaches/" title="Find Out About The Unique CSS Box-Sizing Property">checking out our guide</a> for detailed insights on this topic. You will find detailed instructions and explanations.</p>
<h3 id="-avoid-these-mistakes">⛔ <strong>Avoid These Mistakes</strong><a class="heading-anchor" href="#-avoid-these-mistakes" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>When we want to <strong>SEPARATE</strong> HTML ELEMENTS we must use <code>margin</code> instead of <code>padding</code>. Most times, we work without borders, so we can’t see the elements’ boundaries. Because of that, we think that we can use both paddings or margins to create space between elements, <strong>BUT</strong> we should <strong>NOT</strong>.
I’ve included an example with two images below, to show you the wrong usage of separating elements using padding instead of margin. As you see, when we use padding, even though we create space, we do it the wrong way.</p>
<p><strong>We should not separate HTML elements using their INNER SPACE (padding).</strong></p>
<p><img src="/box-model-difference-between-padding-and-margin.webp" alt="Box model CSS: Here we have two images. The first image shows two boxes, (one box next to the other box) with content, padding, border and margin. We separate these two boxes with margin between them. The second image shows exactly the same boxes but we separate them with big paddings. In the second case, we see that paddings alter boxes&#x27; content. Also content stops being centered as padding give more space only to one side." style="max-width:69%" class="img-narrow"></p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/css-box-sizing-better-implementations-less-headaches/">CSS box-sizing: border-box Explained</a></li>
<li><a href="/how-to-be-creative-with-different-css-border-styles/">CSS Border Styles Explained</a></li>
<li><a href="/how-to-center-in-css-using-different-ways/">How to Center in CSS Using Different Ways</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Absolute Paths in a Node Project</title>
      <link>https://littlecodingthings.com/how-to-use-absolute-paths-in-a-node-project-2024/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-use-absolute-paths-in-a-node-project-2024/</guid>
      <pubDate>Thu, 06 Jun 2024 14:23:00 GMT</pubDate>
      <description>Two ways to use absolute paths in a Node project — NODE_PATH and package.json imports — with the tradeoffs of each and how your IDE handles them.</description>
      <category>Server Side</category>
      <content:encoded><![CDATA[<p>In this post, I will share my findings and what I learned while trying to understand how to use absolute paths in a node project. I found two different methods for doing so, using <code>NODE_PATH</code> and <code>package.json</code> imports, so let’s quickly dive in and hopefully help you out with your own project, too.</p>
<p><em><strong>Disclaimer</strong></em>!
I hate path resolving, I truly hate it! 😋 It feels so complicated for some reason, especially when you have to decide if you want Typescript, if you want <a href="https://nodejs.org/api/modules.html#modules-commonjs-modules" title="CommonJS">CommonJS</a>, or <a href="https://nodejs.org/api/esm.html#modules-ecmascript-modules" title="ESM">ESM</a>… it feels that hell breaks loose for something that should be much simpler….! 😡 Now that I got it out of my system, let’s continue.🤭</p>
<p>By the way, if you are here because you are creating a cool side project and want to stop using relative paths hell, this is your post! If, on the other hand, you are a node guru 🧙‍♂️, and you have already climbed the ladders of node wisdom then this is also a post for you. In your case, though, maybe you could add some comments in the end and share your knowledge with us. Don’t be shy! We need Gandalfs like you to guide us! 🌟</p>
<figure><img src="/gandalf-no-memory.webp" alt="Gandalf gif saying &#x22;I have no memory of this place&#x22;." style="max-width:69%" class="img-narrow"><figcaption>Source: <a href="https://giphy.com/gifs/lost-gandalf-memory-FPjbHO0jJxGsE">Giphy</a></figcaption></figure>
<h2 id="initializing-our-project-structure">Initializing our project structure<a class="heading-anchor" href="#initializing-our-project-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The stack I am using in this post:</p>
<ul>
<li>Ubuntu 22.04.4 LTS</li>
<li>npm 10.5.0</li>
<li>node 20.12.0</li>
</ul>
<p>Before explaining how you can change your importing using absolute paths, let’s build a basic project structure so that we are both on the same page when referring to folders/files in our post’s code snippets.</p>
<p>So, nothing fancy here, just an empty folder initialized by npm. I just ran <code>npm init --yes</code> so that my project is initialized automatically with all default values preselected. After doing that, we’ll need some basic folder files and folders:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>📦node-paths</span></span>
<span class="line"><span> ┣ 📁 server</span></span>
<span class="line"><span> ┃   ┗ 📁 src</span></span>
<span class="line"><span> ┃       ┣ 📁 controllers</span></span>
<span class="line"><span> ┃       ┃  ┗ 📜 UserController.js</span></span>
<span class="line"><span> ┃       ┣ 📁 utils</span></span>
<span class="line"><span> ┃       ┃  ┗ 📜 helper.js</span></span>
<span class="line"><span> ┃       ┗ 📜 app.js</span></span>
<span class="line"><span> ┗ 📜 package.json</span></span></code></pre></div>
<p>Typing <code>mkdir -p server/src/controllers</code> will create all structures at once. The <a href="https://man7.org/linux/man-pages/man1/mkdir.1.html" title="-p flag">-p flag</a> throws no error if the parent folder doesn’t exist, on the contrary, it creates the parent.</p>
<h2 id="define-our-importing-challenge">Define our importing challenge<a class="heading-anchor" href="#define-our-importing-challenge" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Now that we have completed our project’s structure let’s decide on our challenge. Suppose we want to import one helper – in this case <code>validateEmail</code> – from <code>server/src/utils/helper.js</code></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">function</span><span style="color:#B392F0"> validateEmail</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">email</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#6A737D">  // ... validating email logic here</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">module</span><span style="color:#E1E4E8">.</span><span style="color:#79B8FF">exports</span><span style="color:#F97583">  =</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  validateEmail,</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>to our <code>`server/src/controllers/UserController.js`</code> file.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">class</span><span style="color:#B392F0"> UserController</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#F97583">  static</span><span style="color:#B392F0"> createUser</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">userParams</span><span style="color:#E1E4E8">) {</span></span>
<span class="line"><span style="color:#F97583">    const</span><span style="color:#E1E4E8"> { </span><span style="color:#79B8FF">email</span><span style="color:#E1E4E8"> } </span><span style="color:#F97583">=</span><span style="color:#E1E4E8"> userParams;</span></span>
<span class="line"><span style="color:#F97583">    if</span><span style="color:#E1E4E8"> (</span><span style="color:#F97583">!</span><span style="color:#B392F0">validateEmail</span><span style="color:#E1E4E8">(email)) {</span></span>
<span class="line"><span style="color:#F97583">      throw</span><span style="color:#F97583"> new</span><span style="color:#B392F0"> Error</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'Email is not valid'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>With our current settings, we could do it by adding a relative import</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">const</span><span style="color:#E1E4E8"> { </span><span style="color:#79B8FF">validateEmail</span><span style="color:#E1E4E8"> } </span><span style="color:#F97583">=</span><span style="color:#B392F0"> require</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">"../utils/helper"</span><span style="color:#E1E4E8">);</span></span></code></pre></div>
<p>Well, that’s nice, but we could do much better. Let’s challenge ourselves and change our project’s setting so that we can import by writing:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">const</span><span style="color:#E1E4E8"> { </span><span style="color:#79B8FF">validateEmail</span><span style="color:#E1E4E8"> } </span><span style="color:#F97583">=</span><span style="color:#B392F0"> require</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">"src/utils/helper"</span><span style="color:#E1E4E8">);</span></span></code></pre></div>
<p>Now be honest! Wouldn’t that be so much better? Great then! Challenge accepted!</p>
<p>I’ve created a basic <code>app.js</code> file which basically imports and calls the <code>createUser</code> method.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> userController</span><span style="color:#F97583"> =</span><span style="color:#B392F0"> require</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">"./controllers/UserController.js"</span><span style="color:#E1E4E8">);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">userController.</span><span style="color:#B392F0">createUser</span><span style="color:#E1E4E8">({})</span></span></code></pre></div>
<p>Now that we are ready, I’ll start my node server by running <code>nodemon app.js</code>. (I am using <code>nodemon</code> to watch for file changes and make my life easier, instead of using <code>node</code>).</p>
<h2 id="using-node_path-for-absolute-paths">Using NODE_PATH for absolute paths<a class="heading-anchor" href="#using-node_path-for-absolute-paths" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>One common approach for asking node to search for our imported paths from the root folder is by exploiting <code>NODE_PATH</code>. Based on <a href="https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders" title="node&#x27;s documentation">node’s documentation</a>, we just need to add our root folder path in the <code>NODE_PATH</code> variable.</p>
<p>Let’s do that by adding the following lines in our <strong>app’s earliest possible point</strong>, in our case, the app.js file’s first lines.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">process.env.</span><span style="color:#79B8FF">NODE_PATH</span><span style="color:#F97583"> =</span><span style="color:#E1E4E8"> process.</span><span style="color:#B392F0">cwd</span><span style="color:#E1E4E8">();</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">require</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">"module"</span><span style="color:#E1E4E8">).Module.</span><span style="color:#B392F0">_initPaths</span><span style="color:#E1E4E8">();</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> userController</span><span style="color:#F97583"> =</span><span style="color:#B392F0"> require</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">"./controllers/UserController.js"</span><span style="color:#E1E4E8">);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">userController.</span><span style="color:#B392F0">createUser</span><span style="color:#E1E4E8">({})</span></span></code></pre></div>
<p>There it is! Nodemon restarted our server and the new import path worked like a charm! 🥳🥳</p>
<p>For those of you who would like to know a bit more, let’s see what we did.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>process.env.NODE_PATH = process.cwd();</span></span></code></pre></div>
<p>In this line of code we are configuring the environment variable <code>NODE_PATH</code> to match our Node process’s current working directory.</p>
<p><code>NODE_PATH</code> is used when the <code>require</code> method is called to import modules, so we are expanding Node’s search scope by adding one more place to search for, when we ask it to load a new module.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>require("module").Module._initPaths();</span></span></code></pre></div>
<p>This line of code serves to initialize the module paths within our Node.js application. The <code>initPaths</code> method is pivotal in this process, as it handles the initialization.</p>
<h2 id="using-packagejson-imports-for-absolute-paths">Using package.json imports for absolute paths<a class="heading-anchor" href="#using-packagejson-imports-for-absolute-paths" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>If the first method didn’t suit you or didn’t work, there’s another way to import your files using absolute paths by exploiting <strong>imports</strong> in your <code>package.json</code> file.</p>
<p>Open your <code>package.json</code> file and add the following highlighted lines</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>"main": "app.js",</span></span>
<span class="line"><span>"scripts": {</span></span>
<span class="line"><span>  "test": "echo \"Error: no test specified\" &#x26;&#x26; exit 1"</span></span>
<span class="line"><span>},</span></span>
<span class="line"><span>"imports": {</span></span>
<span class="line"><span>  "#helper": "./server/src/utils/helper.js"</span></span>
<span class="line"><span>}</span></span></code></pre></div>
<p>then in our app.js add the following import path</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#F97583">const</span><span style="color:#E1E4E8"> { </span><span style="color:#79B8FF">validateEmail</span><span style="color:#E1E4E8"> } </span><span style="color:#F97583">=</span><span style="color:#B392F0"> require</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">"#helper"</span><span style="color:#E1E4E8">);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#F97583">const</span><span style="color:#79B8FF"> userController</span><span style="color:#F97583"> =</span><span style="color:#B392F0"> require</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">"./controllers/UserController.js"</span><span style="color:#E1E4E8">);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">userController.</span><span style="color:#B392F0">createUser</span><span style="color:#E1E4E8">({})</span></span></code></pre></div>
<p>Voila! This is another way to import your paths! 😎</p>
<p>Keep in mind that the “Imports” feature <a href="https://nodejs.org/api/packages.html#imports" title="was introduced in version 14.6.0">was introduced in version 14.6.0</a> and must start with a <code>#</code>.</p>
<h3 id="packagejson-imports-and-ides">Package.json imports and IDEs<a class="heading-anchor" href="#packagejson-imports-and-ides" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>If you decide to go with “imports” you could see some errors thrown by your IDE. I had the same issue while working with Webstorm 2023.3.6.</p>
<p>This happens because your IDE does not support the imports field, and you need to help your IDE understand your new setting. (You could also be facing the same issue with other IDEs like VScode.)</p>
<p>I managed to help my Webstorm understand what was going on by adding the following <code>jconfig.json</code> file in the root folder</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">{</span></span>
<span class="line"><span style="color:#79B8FF">  "compilerOptions"</span><span style="color:#E1E4E8">: {</span></span>
<span class="line"><span style="color:#79B8FF">    "baseUrl"</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"./"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    "paths"</span><span style="color:#E1E4E8">: {</span></span>
<span class="line"><span style="color:#79B8FF">      "src/*"</span><span style="color:#E1E4E8">: [</span></span>
<span class="line"><span style="color:#9ECBFF">        "server/src/*"</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#E1E4E8">      ]</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-setup-an-express-js-server-using-typescript-2024/">How To Setup An Express.js Server Using Typescript</a></li>
<li><a href="/most-common-typescript-errors-and-how-to-solve-them/">Most Common Typescript Errors and How to Solve Them</a></li>
<li><a href="/how-to-restart-your-node-apps-without-nodemon/">How to Restart Your Node App Without Nodemon</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How to Use !important in CSS</title>
      <link>https://littlecodingthings.com/how-to-use-important-in-css/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-use-important-in-css/</guid>
      <pubDate>Fri, 31 May 2024 11:00:00 GMT</pubDate>
      <description>!important overrides every other declaration for a property. Where the flag goes, a worked id/class/type example, and why to avoid it.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Attention everyone! 😃 In this post, we will learn about the <code>!important</code> flag, which overrides other rules to give a declaration the highest priority. (It is a flag on a declaration, not a property of its own.) We use it selectively when we want to override stylings. We utilize it as a LAST RESORT only when we find ourselves in a situation where no alternative method can achieve the desired results.</p>
<p>Below, I’ve presented an outline designed to assist you in precisely placing 📌 our CSS property. It is typically applied to individual CSS properties within a style rule, not to the entire rule itself. Notice that the <code>!important</code> always follows the property <strong>value</strong> and always comes before the <strong>semicolon</strong>.</p>
<p><img src="/important-outline.webp" alt="This image shows an explanation about the unique CSS !important property (color: green !important;)." style="max-width:42%" class="img-narrow"></p>
<p>I tried to make things clearer for you by preparing the example that follows:</p>
<p>We will begin with this simple <a href="/most-useful-html-elements-for-maximizing-better-results/" title="HTML">HTML</a> code snippet.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> id</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"hello"</span><span style="color:#E1E4E8">>Hello everybody! This is an " !important property " example!&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"hi"</span><span style="color:#E1E4E8">>Hello everybody! This is an " !important property " example!&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>Hello everybody! This is an " !important property " example!&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p>Now, we can continue with our <a href="/how-to-work-with-css-syntax-the-correct-way/" title="CSS">CSS</a> code snippet. The code specifies different styles for the HTML elements based on their identifiers, their classes, and their names.</p>
<ul>
<li>Elements with the <code>id</code> hello will have a smaller font size and be colored orange 🟧</li>
<li>Elements with the <code>class</code> hi will have a slightly larger font size and be colored purple 🟪</li>
<li>All <code>div</code> elements will have the largest font size and be colored green 🟩</li>
</ul>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">#hello</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.hi</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">30</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">div</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>The image below captures the current screen rendering, reflecting the output generated by the previous code.</p>
<p><img src="/important-property1.webp" alt="This image shows three sentences with the same text inside. The first has 20px font size and color orange, the second has 30px font size and color purple while the third has 40px font size and color green."></p>
<p>Now, let’s proceed and witness our property in action 🥁. As I previously explained, HTML elements are styled uniquely, guided by their attributes and the corresponding CSS rules. The <a href="/coding-made-easy-with-css-selectors-an-ultimate-guide/"><code>id</code> and <code>class</code> attributes</a> play a crucial role in defining which styles are assigned to individual elements. Additionally, the careful use of the <code>!important</code> ensures that certain styles take priority.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">div</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">green</span><span style="color:#F97583"> !important</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>In the provided image, it’s obvious that the <code>font-size</code> of our HTML elements remain consistent, while the text <code>color</code> switches to green 🟩. We can see clearly that this color change takes precedence over other specified colors, thanks to the application of the <code>!important</code> flag. 😃</p>
<p><img src="/important-property2.webp" alt="This image shows three sentences with the same text inside. The first has 20px font size , the second has 30px font size while the third has 40px font size. All three sentences follows the !important CSS property and have color green."></p>
<h2 id="best-practices-avoid-using-important"><strong>Best Practices: Avoid Using <code>!important</code></strong><a class="heading-anchor" href="#best-practices-avoid-using-important" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Understanding the ✨ usage of the <code>!important</code> flag is crucial but it should only be employed when absolutely necessary. Here are several reasons to steer clear of it:</p>
<ol>
<li><strong>Specificity Conflicts:</strong> The <code>!important</code> declaration makes a CSS rule very strong 💪, so it’s hard to change it with other styles. This might cause surprising 💣 problems when we try to edit our styles later.</li>
<li><strong>Maintainability overheads:</strong> If we use it too often, our styles can become a confusing 🍝 mix of conflicting instructions. Over time, as your project grows, the number of <code>!important</code> can increase significantly, making it extremely challenging to maintain and extend our CSS.</li>
<li><strong>Debugging Complexity:</strong> When we’re trying to fix problems in our CSS, it gets trickier 🤹‍♀️ 🤹‍♂️ if we’re using <code>!important</code>. We might end up spending more time trying to figure out issues and less time making our styles better. Over time, it becomes difficult to determine why a style was applied, and making changes or debugging becomes more complex.</li>
<li><strong>Override Difficulty:</strong> If we want to change a rule that uses <code>!important</code> later on, we’ll have to make another rule 💥 with even more strength using <code>!important</code>. This can create a loop 🌪 that becomes hard to control.</li>
<li><strong>Code readability and understandability:</strong> Overuse <code>!important</code> can make your CSS code harder to read 👀 and can create a challenge for other developers trying to understand 🤯 it.</li>
<li><strong>Future Compatibility:</strong> Relying on <code>!important</code> to fix styling issues might not work well in the long 🏃‍♀️ 🏃‍♂️ run. It’s better to understand and use CSS specificity and inheritance properly to build styles that are adaptable and easy to maintain.</li>
</ol>
<p>While there are situations where <code>!important</code> can be really useful, such as dealing with third-party CSS or when working with dynamically generated styles, it’s generally best to use it rarely and as a last resort. It’s usually better to write well-structured 🏗, specific 🎯, and organized 🧩 CSS rules to avoid the problems associated with <code>!important</code>.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/coding-made-easy-with-css-selectors-an-ultimate-guide/">CSS Selectors: A Complete Guide</a></li>
<li><a href="/make-your-work-easier-by-using-variables-in-css/">Make Your Work Easier by Using Variables in CSS</a></li>
<li><a href="/practices-behind-clean-lines-of-code/">Practices Behind Clean Lines Of Code</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Striped Text Effect in CSS</title>
      <link>https://littlecodingthings.com/transform-your-text-black-and-white-css-stripes-made-easy/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/transform-your-text-black-and-white-css-stripes-made-easy/</guid>
      <pubDate>Mon, 27 May 2024 14:00:00 GMT</pubDate>
      <description>Fill text with black and white stripes using a linear-gradient, background-clip: text and color: transparent. Three stripe directions.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Welcome to a world where ⚫ black and ⚪ white aren’t just colors. In this post, 😃 we’ll explore the exciting world of creating black and white CSS stripes. It is a really cool effect to level up your text by adding stripes, making it even more fascinating and appealing.</p>
<p>We will be learning about this effect by using an example to make it crystal clear. Let’s check it out! 👩‍💻</p>
<h2 id="create-basic-html-and-css-structure">Create basic HTML and CSS structure<a class="heading-anchor" href="#create-basic-html-and-css-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We will begin with our <a href="/most-useful-html-elements-for-maximizing-better-results/" title="HTML">HTML</a> and <a href="/how-to-work-with-css-syntax-the-correct-way/" title="CSS">CSS</a> structure. Our HTML code includes a <code>&#x3C;div></code> element that has a class named <code>.stripes-effect</code> for identification and styling purposes. Following that, we add some CSS rules to apply specific styles to our HTML element with this class.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">body</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"stripes-effect"</span><span style="color:#E1E4E8">>black &#x26; white text with shadow&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">body</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.stripes-effect</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  font-family</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">'Bungee'</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">sans-serif</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  text-align</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">:  </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>By doing so, our heading is ready for applying our CSS stripes effect and should now look like this</p>
<p><img src="/black-white-stripes-init.webp" alt="This image shows a white text with a black background" style="max-width:56%" class="img-narrow"></p>
<h2 id="adding-black-and-white-vertical-stripes">Adding black and white vertical stripes<a class="heading-anchor" href="#adding-black-and-white-vertical-stripes" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Now that we have added our basic structure, we’ll create our stripe effect gradually, step by step, until it’s perfected. Let’s add the following styling</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.stripes-effect</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">to</span><span style="color:#79B8FF"> right</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, ...);</span></span>
<span class="line"><span style="color:#6A737D">  /* clips the background pattern */</span></span>
<span class="line"><span style="color:#79B8FF">  background-clip</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">text</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#6A737D">  /* makes text invisible */</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>In our already existing <code>.stripes-effect</code> class, we have the following rules:</p>
<p><code>background-image: linear-gradient(to right, white, black, ...)</code> ➡ We begin by setting this CSS property that creates a background pattern using a gradient of alternating black and white stripes from left to right. The default direction is from top to bottom.</p>
<p><img src="/black-white-stripes-effect.webp" alt="This image shows a white text with black and white background that comes from the CSS property background-image: linear-gradient(to right, white, black, ...) CSS property." style="max-width:56%" class="img-narrow"></p>
<p>Don’t worry if our black-and-white text is hard to read; 🕯 😂 it is a temporary phase just to serve our purpose for now. We will move forward and see! So let’s proceed immediately! ⏳</p>
<p><code>background-clip: text</code> ➡ By adding this property, it clips the background pattern to the shape of the text, making the text appear as if it’s filled with black and white stripes. If we just add this property and leave our CSS settings without any other change, our effect will not show properly.</p>
<p><img src="/black-white-stripes-init-1.webp" alt="This image shows that the browser clips the background when we set the -webkit-background-clip: text CSS property." style="max-width:56%" class="img-narrow"></p>
<p>If we want this to see our effect it is necessary to proceed with the following step (<code>color: transparent</code> ⬇).</p>
<p><code>color: transparent</code> ➡ It’s time to make the text transparent, enabling the background pattern we created in the previous step to be visible!</p>
<p><img src="/black-white-stripes-final.webp" alt="This image shows the color: transparent CSS property. We now see our text having a black and white - css zebra effect." style="max-width:56%" class="img-narrow"></p>
<h2 id="black-and-white-css-stripes-variations">Black and white CSS stripes variations<a class="heading-anchor" href="#black-and-white-css-stripes-variations" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The Zebra effect is not limited to vertical stripes (<a href="/css-linear-gradient-techniques-how-to-make-colorful-line-drawings/">linear-gradient</a>) for your texts; you can explore more options and create any effect you want. Below, you will find some variations to give you the inspiration you need.</p>
<h3 id="horizontal-striped-text">Horizontal striped text<a class="heading-anchor" href="#horizontal-striped-text" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.stripes-effect</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, ...);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/black-white-stripes-effect-horizontal.webp" alt="This image shows the CSS stripes effect but with horizontal lines direction." style="max-width:56%" class="img-narrow"></p>
<h3 id="diagonal-striped-text">Diagonal striped text<a class="heading-anchor" href="#diagonal-striped-text" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.stripes-effect</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">to</span><span style="color:#79B8FF"> bottom</span><span style="color:#79B8FF"> right</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">, ...);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/black-white-stripes-effect-diagonal.webp" alt="This image shows the black and white CSS stripes effect but with diagonal lines direction." style="max-width:56%" class="img-narrow"></p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/css-rainbow-text-how-to-make-astonishing-and-vibrant-fonts/">How to Make Rainbow Text in CSS</a></li>
<li><a href="/css-colorful-text-crafting-vibrant-effects/">CSS Colorful Text – Crafting Vibrant Effects</a></li>
<li><a href="/css-linear-gradient-techniques-how-to-make-colorful-line-drawings/">CSS Linear Gradient: A Practical Guide</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How To Make A CSS Reflection Effect</title>
      <link>https://littlecodingthings.com/how-to-make-a-css-reflection-effect/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-make-a-css-reflection-effect/</guid>
      <pubDate>Wed, 22 May 2024 15:04:00 GMT</pubDate>
      <description>Build a mirror-like reflection under any block with a ::before pseudo-element, a fading linear-gradient and a touch of opacity.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hello everyone! 😃 Today, we will learn how to create a cool CSS reflection effect. Through step-by-step instructions, we will understand how to manipulate <code>linear-gradient</code> and <code>opacity</code> CSS properties to create a stunning mirror-like effect. Below, I’ll give you all the information you need. Let’s get started.</p>
<h2 id="html-structure">HTML structure<a class="heading-anchor" href="#html-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Our <a href="/most-useful-html-elements-for-maximizing-better-results/" title="HTML">HTML</a> structure starts with an empty <code>div</code> element, with the class <code>.reflection</code> where our effect will take place.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"reflection"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h2 id="css-foundation">CSS foundation<a class="heading-anchor" href="#css-foundation" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Let’s continue with the <a href="/how-to-work-with-css-syntax-the-correct-way/" title="CSS">CSS</a> basic structure. We will start by setting the <code>background-color</code> to orange.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">orange</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/reflection-with-css-create-background.webp" alt="An image showing an orange background." style="max-width:42%" class="img-narrow"></p>
<h2 id="creating-the-element">Creating the element<a class="heading-anchor" href="#creating-the-element" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>In the following step, we will define the element. I opt for a <code>color</code> black rectangle with 300 pixels <code>width</code> and 200 pixels <code>height</code>.We will also be adding the <code>flex</code> method to the body <a href="/how-to-center-in-css-using-different-ways/">to center our element</a>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.reflection</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>This is what is rendered on the screen for now. A perfectly centered black rectangle! </p>
<p><img src="/reflection-with-css-create-element-1.webp" alt="An image showing an orange background with a centered black rectangle." style="max-width:42%" class="img-narrow"></p>
<h2 id="adding-the-css-structure-for-the-reflection-effect">Adding the CSS structure for the reflection effect<a class="heading-anchor" href="#adding-the-css-structure-for-the-reflection-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>A CSS reflection effect can be accomplished using pseudo-elements like <code>::before</code> and <code>::after</code>. First, we need to add <code>position: relative</code> in our <code>.reflection</code> class to get prepared for our pseudo-element’s positioning.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.reflection</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Then we are ready to create our reflection utilizing the <code>::before</code> pseudo-element.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.reflection::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#F97583">    to</span><span style="color:#79B8FF"> bottom</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#79B8FF">    rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">80</span><span style="color:#F97583">%</span></span>
<span class="line"><span style="color:#E1E4E8">  );</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>We initiate by setting the position as absolute. Setting the <code>content</code> to an empty string (“”) and then its <code>width</code> and <code>height</code> to 100%, will make our pseudo-element appear and inherit its parent’s dimensions (width 300px and height 200px).  </p>
<p>Next, we add a <a href="/css-linear-gradient-techniques-how-to-make-colorful-line-drawings/"><code>background: linear-gradient</code></a> that goes downwards, by specifying its direction, from top <code>to bottom</code>. This way, we create black gradients that are more intense at the top and gradually fade toward the bottom to achieve our desired effect.</p>
<p>So far, we have created the CSS reflection effect below our original rectangle. However, we need to take one more step for our effect to be visible. We add the <code>top</code> CSS property and set it to 205 pixels. This will move our reflection 5 pixels down from the origin rectangle.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.reflection::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">205</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  opacity</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0.5</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-reflection-create-reflection-2.webp" alt="An image showing an orange background with a centered black rectangle. Below there is the css reflection effect of the rectangle. We use the pseudoelements the css background: linear-gradient and the opacity." style="max-width:42%" class="img-narrow"></p>
<p>Additionally, we set the <code>opacity</code> to achieve a smoother and more natural-looking effect. You might be thinking that the same result could be accomplished by adjusting the linear-gradient property and you are right. It’s just that using the opacity this way requires much less effort and produces similar results.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.reflection::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  opacity</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0.5</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Voila! Here is our amazing reflection! 🥳</p>
<p><img src="/css-reflection-adding-opacity-3.webp" alt="An image showing an orange background with a centered black rectangle. Below there is the css reflection effect of the rectangle. With the css opacity property." style="max-width:42%" class="img-narrow"></p>
<h2 id="exploring-different-reflection-colors">Exploring different reflection colors<a class="heading-anchor" href="#exploring-different-reflection-colors" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>🔖 Feel free to use any color you prefer, but it’s important to create a <code>linear-gradient</code> that gives the perspective shades. Here are examples of white and yellow reflections. I am keeping the orange background to facilitate easier comparison.</p>
<h3 id="white-reflection">White reflection<a class="heading-anchor" href="#white-reflection" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.reflection</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.reflection::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">205</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">to</span><span style="color:#79B8FF"> bottom</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#79B8FF">  rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">80</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  opacity</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0.5</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-reflection-white-element.webp" alt="An image showing an orange background with a centered white rectangle. Below there is the css reflection effect of the rectangle." style="max-width:42%" class="img-narrow"></p>
<h3 id="yellow-reflection">Yellow reflection<a class="heading-anchor" href="#yellow-reflection" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.reflection</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">yellow</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.reflection::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">205</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#F97583">to</span><span style="color:#79B8FF"> bottom</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">  rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">),</span></span>
<span class="line"><span style="color:#79B8FF">  rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">255</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">80</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">  opacity</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0.5</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/css-reflection-yellow-element.webp" alt="An image showing an orange background with a centered yellow square. Below there is the css reflection effect of the square." style="max-width:42%" class="img-narrow"></p>
<p>Choosing the perfect colors with their appropriate shades can truly transform your work. Be bold in your choices and let your creativity shine. Remember, there are endless possibilities and your creativity knows no bounds. 🎉 ✨</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-make-css-reflection-the-easy-way/">How To Make CSS Reflection – The Easy Way</a></li>
<li><a href="/how-to-make-a-css-text-reflection-effect/">How To Make A CSS Text Reflection Effect</a></li>
<li><a href="/the-unique-css-opacity-check-out-this-amazing-property/">Using CSS Opacity for Transparency</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>CSS Radial Gradient: A Practical Guide</title>
      <link>https://littlecodingthings.com/css-radial-gradient-techniques-how-to-make-colorful-infinite-loops/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/css-radial-gradient-techniques-how-to-make-colorful-infinite-loops/</guid>
      <pubDate>Thu, 16 May 2024 12:46:00 GMT</pubDate>
      <description>Blend colors outward from a point with radial-gradient. Circle vs ellipse, moving the center to a side or corner, and target-like rings.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Greetings! 😃 Utilizing CSS radial gradient techniques is a remarkable approach for vibrant, colorful combinations. Gradients give us the liberty to choose any desired direction, defined by a clear starting and ending point. Using a minimum of two <a href="/what-you-need-to-know-about-css-color-methods/" title="colors">colors</a> is essential, but we are free to blend even more based on our needs. This lets us achieve progressions or variations based on our specific requirements.</p>
<p>In today’s post, we will analyze the captivating world of CSS radial gradient techniques. 🌈✨ Imagine colors coming out from a central point, spreading outwards in a circular fashion—an effect 🌀 that can truly elevate your design.</p>
<p>Radial gradients offer a versatile approach to blending colors, creating central points or smooth transitions. By mastering radial gradients, you unlock the potential to infuse depth and excitement into your web design.</p>
<p>Excited to learn more about this captivating technique? Let’s dive 🤿 right in! 💻</p>
<h2 id="definition-of-a-radial-gradient">Definition of a radial gradient<a class="heading-anchor" href="#definition-of-a-radial-gradient" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>A radial gradient is a visual effect in which colors blend outward from a central point, creating a smooth transition from one color to another in a circular or elliptical pattern. Circular ones spread colors outward from the center, evenly, making a symmetrical look. Elliptical ones also start from the center but stretch the colors toward the edges, creating an oval appearance.</p>
<blockquote>
<p>A radial gradient is a visual effect in which colors blend outward from a central point, creating a smooth transition from one color to another in a circular or elliptical pattern</p>
</blockquote>
<h3 id="the-default-css-radial-gradient">The default CSS radial gradient<a class="heading-anchor" href="#the-default-css-radial-gradient" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>We’ll start by exploring the default orientation for the radial gradient which <strong>starts in the center of our elements and spreads outward</strong>. To better understand, look at the following piece of code and the pictures that go with it.</p>
<p>The first picture shows a circle, while the second one depicts an ellipse.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.radial-default</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">radial-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/* circle default */</span></span>
<span class="line"><span style="color:#B392F0">.box-square</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">240</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">240</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/* elliptical default */</span></span>
<span class="line"><span style="color:#B392F0">.box-rectangle</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">340</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">240</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/radial1-by-default-inner-to-outer.webp" alt="CSS Radial Gradient Techniques for cyclic shapes. This image shows a colorful radial gradient technique. Setting the background-image: radial-gradient (red, green, blue) CSS property we create a smooth transition from the center and directs to out (default direction) using red, green, and blue color." style="max-width:34%" class="img-narrow"></p>
<p><img src="/radial1-by-default-inner-to-outer-ellipse.webp" alt="CSS Radial Gradient Techniques for oval shapes. This image shows a colorful radial gradient technique. Setting the background-image: radial-gradient (red, green, blue) CSS property we create a smooth transition from the center and directs to out (default direction) using red, green, and blue color." style="max-width:33%" class="img-narrow"></p>
<h3 id="center-at-sides">Center at sides<a class="heading-anchor" href="#center-at-sides" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>We can change the center of our element by setting <code>circle at left</code> , <code>circle at top</code> , <code>circle at bottom</code> and <code>circle at right</code>. To understand this better we’ve prepared an example. As before, the left picture relates to the circle, whereas the second one refers to the ellipse.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.radial-at-side</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">radial-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">circle</span><span style="color:#F97583"> at</span><span style="color:#79B8FF"> top</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/* circle default */</span></span>
<span class="line"><span style="color:#B392F0">.box-square</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">240</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">240</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/* elliptical default */</span></span>
<span class="line"><span style="color:#B392F0">.box-rectangle</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">340</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">240</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/radial2-center-at-top-side.webp" alt="CSS Radial Gradient Techniques for cyclic shapes. This image shows a colorful radial gradient technique. Setting the background-image: radial-gradient (circle at top, red, green, blue) CSS property we create a smooth transition with the center point to be at the top side of our element and directs to the bottom using red, green, and blue color." style="max-width:34%" class="img-narrow"></p>
<p><img src="/radial2-center-at-top-side-ellipse.webp" alt="CSS Radial Gradient Techniques for oval shapes. This image shows a colorful radial gradient technique. Setting the background-image: radial-gradient (circle at top, red, green, blue) CSS property we create a smooth transition with the center point to be at the top side of our element and directs to the bottom using red, green, and blue color." style="max-width:33%" class="img-narrow"></p>
<h3 id="center-at-corners">Center at corners<a class="heading-anchor" href="#center-at-corners" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Also, the diagonal direction of our circle can change if we combine any <strong>corner with its adjacent sides</strong>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.radial-at-corner</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">radial-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">circle</span><span style="color:#F97583"> at</span><span style="color:#79B8FF"> top</span><span style="color:#79B8FF"> right</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/* circle default */</span></span>
<span class="line"><span style="color:#B392F0">.box-square</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">240</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">240</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/* elliptical default */</span></span>
<span class="line"><span style="color:#B392F0">.box-rectangle</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">340</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">240</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/radial3-center-at-top-right-corner.webp" alt="CSS Radial Gradient Techniques for cyclic shapes. This image shows a colorful radial gradient technique. Setting the background-image: radial-gradient (circle at top right, red, green, blue) CSS property we create a smooth transition with the center point to be at the top right corner of our element and directs to the bottom left corner using red, green, and blue color." style="max-width:34%" class="img-narrow"></p>
<p><img src="/radial2-center-at-top-right-corner-ellipse.webp" alt="CSS Radial Gradient Techniques for oval shapes. This image shows a colorful radial gradient technique. Setting the background-image: radial-gradient (circle at top right, red, green, blue) CSS property we create a smooth transition with the center point to be at the top right corner of our element and directs to the bottom left corner using red, green, and blue color." style="max-width:33%" class="img-narrow"></p>
<h3 id="css-radial-gradient-using-">CSS Radial gradient using %<a class="heading-anchor" href="#css-radial-gradient-using-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<h4 id="with-less-blend">With less blend<a class="heading-anchor" href="#with-less-blend" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p>We are also up to play with the blend we want to create. In the following example, the gradient blends between various colors in a circular pattern, it begins with red at the center, transitioning to green, and finally blue at the outer edge.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.radial-less-blend</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">radial-gradient</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#79B8FF">    red</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">red</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    green</span><span style="color:#79B8FF"> 30</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    blue</span><span style="color:#79B8FF"> 60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">%</span></span>
<span class="line"><span style="color:#E1E4E8">  );</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/* circle default */</span></span>
<span class="line"><span style="color:#B392F0">.box-square</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">240</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">240</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/* elliptical default */</span></span>
<span class="line"><span style="color:#B392F0">.box-rectangle</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">340</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">240</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>🕵️‍♂️ In this example, I’ve divided the space into 3 sections. I left a 10% blend in each space in order to create a smooth small transition. The percentages between the color stops, determine how smoothly the transition between colors happens.</p>
<ul>
<li><strong>Red (0%-20%):</strong> The gradient starts at the center (0%) with the red color.</li>
<li><strong>Red to Green (20%-30%):</strong> Within this radial range, there is a subtle transition from red to green, creating a visually appealing blend.</li>
<li><strong>Green (30%-50%):</strong> the gradient takes a solid green color.</li>
<li><strong>Green to Blue (50%-60%):</strong> Between this radial distance, there’s a gentle transition from green to blue.</li>
<li><strong>Blue (60%-100%):</strong> Finally, the gradient concludes with a blue hue, providing a vibrant and visually striking finish.</li>
</ul>
<p><img src="/radial4-less-blend.webp" alt="A circular radial gradient with soft blends, set with background-image: radial-gradient(red 0%, red 20%, green 30%, green 50%, blue 60%, blue 100%)" style="max-width:34%" class="img-narrow"></p>
<p><img src="/radial4-less-blend-ellipse.webp" alt="The same soft-blend radial gradient on a wider box, so it renders as an ellipse" style="max-width:33%" class="img-narrow"></p>
<h4 id="without-blend">Without blend<a class="heading-anchor" href="#without-blend" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p>We also have the option to make non-blend gradients. As you can see below, the gradient consists of multiple color stops, transitioning from red to blue in a radial pattern, like colorful rings. Each color is assigned to specific percentage intervals, creating a visually appealing gradient effect.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.radial-no-blend</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">radial-gradient</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#79B8FF">    red</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">red</span><span style="color:#79B8FF"> 33</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    green</span><span style="color:#79B8FF"> 33</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#79B8FF"> 66</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    blue</span><span style="color:#79B8FF"> 66</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">%</span></span>
<span class="line"><span style="color:#E1E4E8">  );</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/* circle default */</span></span>
<span class="line"><span style="color:#B392F0">.box-square</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">240</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">240</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/* elliptical default */</span></span>
<span class="line"><span style="color:#B392F0">.box-rectangle</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">340</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">240</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>🕵️‍♂️ In this example, I’ve divided the space into 3 sections. There is no blending among them. We can see a shape like a target, 🎯 that creates clear bands of sharp colors.</p>
<ul>
<li><strong>Red</strong>: Starts at 0% and ends at 33%.</li>
<li><strong>Green</strong>: Starts at 33% and ends at 66%.</li>
<li><strong>Blue</strong>: Starts at 66% and ends at 100%.</li>
</ul>
<p><img src="/radial5-no-blend.webp" alt="A circular radial gradient with hard edges like a target, set with background-image: radial-gradient(red 0%, red 33%, green 33%, green 66%, blue 66%, blue 100%)" style="max-width:34%" class="img-narrow"></p>
<p><img src="/radial5-no-blend-ellipse.webp" alt="The same hard-edged radial gradient on a wider box, so the rings render as ellipses" style="max-width:33%" class="img-narrow"></p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/css-linear-gradient-techniques-how-to-make-colorful-line-drawings/">CSS Linear Gradient: A Practical Guide</a></li>
<li><a href="/css-conic-gradient-technique-how-to-make-stunning-visual-effects/">CSS Conic Gradient Made Easy</a></li>
<li><a href="/simple-ways-to-create-a-css-overlay-effect/">Simple Ways to Create a CSS Overlay Effect</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>CSS Scale on Hover with transform</title>
      <link>https://littlecodingthings.com/how-to-effectively-use-css-transform-scale-on-hover/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-effectively-use-css-transform-scale-on-hover/</guid>
      <pubDate>Fri, 10 May 2024 15:16:00 GMT</pubDate>
      <description>Grow or shrink an element on hover with transform: scale(). Eight examples covering both axes, scaleX and scaleY, plus a transition.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hey there! Today, I’m gonna teach you how to use CSS transform scale on hover by using the <code>transform: scale</code> property. I’ve already created an avatar in order to make our animation more understandable and fun! 😄 If you’re curious about how I made the avatar, you will find the complete avatar code at the end of my post. You are encouraged to incorporate it into your animation as well 😉 The choice is yours!</p>
<p>Meanwhile, let’s just dive 🤿 into creating these amazing scale animations!</p>
<p><img src="/scale-transformation-on-hover-increases-xy-axis-1.webp" alt="This image shows one of the css scale transformations effect on hover. This transformation decrease with the same value, the size of the avatar-container in both axes." style="max-width:35%" class="img-narrow"></p>
<h2 id="html-structure">HTML structure<a class="heading-anchor" href="#html-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>In order to create the scale transformations, first of all, it is necessary to make a container, which I named scale-content. This is the ‘place’ where we will do our CSS manipulations. After that, we move forward with a second container, the <code>avatar-container</code>. I named it that way as I intend to position the avatar inside it. As a matter of choice, 😊 you are able to add the avatar, too. Otherwise, you can continue only with the box. Once we prepare those two containers we are ready to move on.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"scale-content"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"avatar-container"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    ... Here goes my avatar</span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">> </span><span style="color:#6A737D">&#x3C;!-- end of avatar-container --></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">> </span><span style="color:#6A737D">&#x3C;!-- end of scale-content --></span></span></code></pre></div>
<h2 id="css-basic-styling">CSS basic styling<a class="heading-anchor" href="#css-basic-styling" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Next, we do the appropriate settings in order to center our container to the body, using the <code>display: flex</code> CSS property. We have also added the colors, setting <code>body-color</code> and <code>container-color</code>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#FFAB70">$body-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#8e7d9e</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$container-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#0f0b0f</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">*</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  margin</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  padding</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-sizing</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">border-box</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">html</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  min-width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">500</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$body-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h2 id="css-containers-structure">CSS containers structure<a class="heading-anchor" href="#css-containers-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We begin with <code>position: relative</code> CSS property to the parent container and <code>position: absolute</code> to the child container in order to achieve the desired positioning of elements. Next, we specify the <code>width</code> and <code>height</code> of both containers according to our desired dimensions. We also use the CSS properties we want in order to create our <code>avatar-container</code> with the willing characteristics.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.scale-content</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">320</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">320</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  .</span><span style="color:#79B8FF">avatar-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: $container-color;</span></span>
<span class="line"><span style="color:#79B8FF">    border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    overflow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">hidden</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">/* end of avatar-container */</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">/* end of scale-content */</span></span></code></pre></div>
<p>Great! Now, take a break and look at the container we made using our earlier code. Feel free to go with it, or you may come up with your own! 😊</p>
<p><img src="/scale-transformation-container.webp" alt="CSS scale transform: This image shows an empty black circle. It is the basic structure for our project." style="max-width:28%" class="img-narrow"></p>
<h2 id="css-scale-transformation-structure">CSS scale transformation structure<a class="heading-anchor" href="#css-scale-transformation-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Our containers are ready!! We can continue by doing our manipulations and creating scale transformations.</p>
<p>We apply the <code>transition: transform</code> CSS property to the parent element, which enables us to achieve smooth changes in property values within a specified duration. As you can see below, I set 4s, and as a result, our transition lasts 4 seconds.</p>
<p>Next, we set the CSS <code>transform: scale(X, Y)</code> property on that same parent element, in its <code>:hover</code> state, <strong>in order to resize</strong>, increase, or decrease the size of an element in the axes. We have the capability to simultaneously resize both axes with the same or different values or selectively resize either the X-axis or the Y-axis.</p>
<p>💡 Below there are some examples of scale transformations as a way to understand it better 😃</p>
<h3 id="transform-scalex-y-with-the-same-value-on-both-axes">transform: scale(X, Y) with the same value on both axes<a class="heading-anchor" href="#transform-scalex-y-with-the-same-value-on-both-axes" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<ul>
<li>Resizes (increases) with the <strong>same value</strong>, the size of an element in both axes.</li>
</ul>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.scale-content</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  transition</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transform</span><span style="color:#79B8FF"> 4</span><span style="color:#F97583">s</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">    cursor</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pointer</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">scale</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">1.2</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  .avatar-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">/* end of avatar-container */</span></span>
<span class="line"><span style="color:#E1E4E8">}  </span><span style="color:#6A737D">/* end of scale-content */</span></span></code></pre></div>
<p><img src="/scale-transformation-on-hover-increases-axisxy.gif" alt="CSS scale transform:This image shows a scale transformation effect on hover which increase, with the same value, the size of the avatar-container in both axes." style="max-width:28%" class="img-narrow"></p>
<ul>
<li>Resizes (decreases) with the <strong>same value</strong>, the size of an element in both axes.</li>
</ul>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.scale-content</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  transition</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transform</span><span style="color:#79B8FF"> 4</span><span style="color:#F97583">s</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">    cursor</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pointer</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">scale</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0.5</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  .avatar-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">/* end of avatar-container */</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">/* end of scale-content */</span></span></code></pre></div>
<p><img src="/scale-transformation-on-hover-decreases-xy-axis.webp" alt="CSS scale transform: This image shows a scale transformation effect on hover which decrease, with the same value, the size of the avatar-container in both axes." style="max-width:28%" class="img-narrow"></p>
<h3 id="transform-scalex-y-with-different-values-on-both-axes">transform: scale(X, Y) with different values on both axes<a class="heading-anchor" href="#transform-scalex-y-with-different-values-on-both-axes" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<ul>
<li>Resizes (increase the width and decrease the height), <strong>with different values</strong>, the size of an element in both axes.</li>
</ul>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.scale-content</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  transition</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transform</span><span style="color:#79B8FF"> 4</span><span style="color:#F97583">s</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">    cursor</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pointer</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">scale</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">1.4</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.4</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  .avatar-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">/* end of avatar-container */</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">/* end of scale-content */</span></span></code></pre></div>
<p><img src="/scale-transformation-on-hover-increases-with-different-values-xy-axis.webp" alt="CSS Transform scale: This image shows a scale transformation effect on hover which increase the width and decrease the height of the avatar-container in both axes." style="max-width:35%" class="img-narrow"></p>
<ul>
<li>Resizes (decrease the width and increase the height), <strong>with different values</strong>, the size of an element in both axes.</li>
</ul>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.scale-content</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  transition</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transform</span><span style="color:#79B8FF"> 4</span><span style="color:#F97583">s</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">    cursor</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pointer</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">scale</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0.4</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">1.4</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  .avatar-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">/* end of avatar-container */</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">/* end of scale-content */</span></span></code></pre></div>
<p><img src="/scale-transformation-on-hover-decreases-with-different-values-xy-axis.webp" alt="CSS Transform scale: This image shows a scale transformation effect on hover which decrease the width and increase the height of the avatar-container in both axes." style="max-width:28%" class="img-narrow"></p>
<h3 id="transform-scalex-increase-or-decrease-width">transform: scaleX() increase or decrease width<a class="heading-anchor" href="#transform-scalex-increase-or-decrease-width" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<ul>
<li>Resizes (increases) the <strong>width</strong> of an element (X-axis).</li>
</ul>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.scale-content</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  transition</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transform</span><span style="color:#79B8FF"> 4</span><span style="color:#F97583">s</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">    cursor</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pointer</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">scaleX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">2</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  .avatar-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">/* end of avatar-container */</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">/* end of scale-content */</span></span></code></pre></div>
<p><img src="/scale-transformation-on-hover-increases-x-axis.webp" alt="CSS Transform scale: This image shows a scale transformation effect on hover which increases the width of the avatar-container (X-axis)." style="max-width:49%" class="img-narrow"></p>
<ul>
<li>Resizes (decreases) the <strong>width</strong> of an element (X-axis).</li>
</ul>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.scale-content</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  transition</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transform</span><span style="color:#79B8FF"> 4</span><span style="color:#F97583">s</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">    cursor</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pointer</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">scaleX</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0.2</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  .avatar-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">/* end of avatar-container */</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">/* end of scale-content */</span></span></code></pre></div>
<p><img src="/scale-transformation-on-hover-decreases-x-axis.webp" alt="CSS Transform scale: This image shows a scale transformation effect on hover which decreases the width of the avatar-container (X-axis)." style="max-width:28%" class="img-narrow"></p>
<h3 id="transform-scaley-increase-or-decrease-height">transform: scaleY() increase or decrease height<a class="heading-anchor" href="#transform-scaley-increase-or-decrease-height" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<ul>
<li>Resizes (increases) the <strong>height</strong> of an element (Y-axis).</li>
</ul>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.scale-content</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  transition</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transform</span><span style="color:#79B8FF"> 4</span><span style="color:#F97583">s</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">    cursor</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pointer</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">scaleY</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">2</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  .avatar-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">/* end of avatar-container */</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">/* end of scale-content */</span></span></code></pre></div>
<p><img src="/scale-transformation-on-hover-increases-y-axis.webp" alt="CSS Transform scale: This image shows a scale transformation effect on hover which increases the height of the avatar-container (Y-axis)." style="max-width:28%" class="img-narrow"></p>
<ul>
<li>Resizes (decreases) the <strong>height</strong> of an element (Y-axis).</li>
</ul>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.scale-content</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  transition</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transform</span><span style="color:#79B8FF"> 4</span><span style="color:#F97583">s</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">    cursor</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pointer</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">scaleY</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">0.5</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#B392F0">  .avatar-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">    ...</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">/* end of avatar-container */</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">/* end of scale-content */</span></span></code></pre></div>
<p><img src="/scale-transformation-on-hover-decreases-y-axis.webp" alt="This image shows a scale transformation effect on hover which decreases the height of the avatar-container (Y-axis)." style="max-width:28%" class="img-narrow"></p>
<h2 id="complete-avatar-code">Complete avatar code<a class="heading-anchor" href="#complete-avatar-code" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Below, I include my HTML and CSS avatar code.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">section</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"avatar-container"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"hair-back"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"face"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"ear ear-left"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"earing earing-left"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"ear ear-right"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"earing earing-right"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyebrow eyebrown-left"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyebrow eyebrown-right"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"hair-front"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"hair-long"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"hairband"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"bow-big"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"bow-small"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eye eye-left"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--left"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--left1"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--left2"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--left3"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--left4"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eye eye-right"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--right"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--right1"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--right2"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--right3"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eyelash eyelash--right4"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eye-glasses eye-glasses-left"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"eye-glasses eye-glasses-right"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"nose"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"lips"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"avatar-body"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"neck"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"t-shirt"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"pocket"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"neckless"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"perl perl--perl1"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"perl perl--perl2"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"perl perl--perl3"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"perl perl--perl4"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"perl perl--perl5"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"perl perl--perl6"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"perl perl--perl7"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"perl perl--perl8"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"perl perl--perl9"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">      &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"perl perl--perl10"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">section</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#FFAB70">$body-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#8e7d9e</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$container-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#0f0b0f</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$skin-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#fbd0c3</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$hair-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#ec3535</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$eyebrow-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#5b3a3a</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$hairband-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#091845</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$bow-big-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#2d2b78</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$bow-small-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#9914d2</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$eye-base-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#f1f1f1</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$eyeline-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#5b3a3a</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$eyelash-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#6d4646</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$iris-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#000</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$eye-glasses-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#0d2b85</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$nose-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#383737</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$lips-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#e41202</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$t-shirt-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#e6e9ee</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$button-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#2d2a2a</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#FFAB70">$perl-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#8314d2</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">*</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  margin</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  padding</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-sizing</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">border-box</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">html</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$body-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.avatar-container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">320</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">320</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$container-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  overflow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">hidden</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#B392F0">  .hair-back</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">106</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">110</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">30</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$hair-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">      content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">34</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$hair-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">74</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-8</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">// end of hair-back</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .face</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">110</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#F97583"> /</span><span style="color:#79B8FF"> 70</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 70</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 140</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 140</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$skin-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">54</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">    box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0.5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#B392F0">    .ear</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">12</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">22</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$skin-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#B392F0">.ear-left</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-9</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-6</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#85E89D">       &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">7</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$skin-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> darken</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">$skin-color</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">15</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#B392F0">.ear-right</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-9</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">6</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">7</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$skin-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> -1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> darken</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">$skin-color</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">15</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#B392F0">    .earing</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$perl-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">7</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">15</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">.earing-left</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">.earing-right</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">    } </span><span style="color:#6A737D">// end of earings</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">// end of ears</span></span>
<span class="line"><span style="color:#B392F0">    .eyebrow</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">34</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">solid</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#FFAB70"> $eyebrow-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$eyebrow-color</span><span style="color:#79B8FF"> transparent</span><span style="color:#79B8FF"> transparent</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">28</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">.eyebrown-left</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">7</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%/</span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">.eyebrown-right</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">7</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%/</span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">// end of eyebrows</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">    .hair-front</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">80</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">36</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    border-radius</span><span style="color:#E1E4E8">:</span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-7</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-14</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$hair-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">    z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">4</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">    &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">      content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">70</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">30</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">:</span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">44</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-23</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$hair-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-85</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">    }</span></span>
<span class="line"><span style="color:#E1E4E8">}  </span><span style="color:#6A737D">// end of hair-front</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">    .hair-long</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 12</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#FFAB70"> $hair-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-1</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">116</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">122</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 12</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#FFAB70"> $hair-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">58</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">37</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">230</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">}  </span><span style="color:#6A737D">// end of hair-long</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">    .hairband</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">4</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 4</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#FFAB70"> $hairband-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">225</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#B392F0">      .bow-big</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">14</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$bow-big-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">90</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">96</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">          content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border-top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border-left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#FFAB70"> $bow-big-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border-bottom</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">30</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-4</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#B392F0">::after</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">          content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border-top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border-right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#FFAB70"> $bow-big-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border-bottom</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">30</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-4</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#B392F0">      .bow-small</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$bow-small-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">90</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">42</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">98</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">          content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border-top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border-left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">16</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#FFAB70"> $bow-small-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border-bottom</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">30</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#B392F0">::after</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">          content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border-top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border-right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">16</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#FFAB70"> $bow-small-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border-bottom</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">30</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">// end of hairband</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">    .eye</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">38</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$eye-base-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#FFAB70"> $eyeline-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">75</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 0</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">45</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-30</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">-70</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">        background</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">radial-gradient</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">circle</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">blue</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">        box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inset</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 3</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">.eye-left</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">15</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> darken</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">$eyeline-color</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">10</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">.eye-right</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">15</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> -1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> darken</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">$eyeline-color</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">10</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">::after</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">4</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">4</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">-120</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$iris-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#B392F0">      .eyelash</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$eyelash-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--left</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--left1</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--left2</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--left3</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--left4</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">90</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--left</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">         top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">         left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--left1</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">         top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">         left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--left2</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">         top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">6</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">         left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-4</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--left3</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">         top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">         left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--left4</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">         top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">14</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">         left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--right</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-1</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">15</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--right1</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-4</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">11</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--right2</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-7</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">7</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--right3</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-8</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--right4</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-8</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-1</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">// end of eye</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">    .eye-glasses</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">34</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">4</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#FFAB70"> $eye-glasses-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">31</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">.eye-glasses-left</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">          content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">14</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">4</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$eye-glasses-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">8</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">35</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#B392F0">::after</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">          content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">9</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$eye-glasses-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">8</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-9</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">.eye-glasses-right</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#B392F0">::after</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">          content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">9</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$eye-glasses-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">8</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">    } </span><span style="color:#6A737D">// end of eyeglasses</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">    .nose</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">8</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">8</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#FFAB70"> $nose-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">62</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">46</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">45</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#FFAB70"> $nose-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">75</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">::after</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 1</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 0</span><span style="color:#FFAB70"> $nose-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-3</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-3</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-65</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">// end of nose</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">    .lips</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">18</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">18</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">90</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">darken</span><span style="color:#E1E4E8">(</span><span style="color:#FFAB70">$lips-color</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">1</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">90</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">45</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">3</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#FFAB70"> $skin-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">60</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-45</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">24</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">12</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">// end of lips</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">// end of face</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">  .avatar-body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#B392F0">    .neck</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">36</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$skin-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">150</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">      z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">      &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">        content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">34</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$t-shirt-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">26</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">      }</span></span>
<span class="line"><span style="color:#E1E4E8">    } </span><span style="color:#6A737D">// end of neck</span></span>
<span class="line"><span style="color:#B392F0">    .t-shirt</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">160</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">140</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$t-shirt-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">%</span><span style="color:#F97583"> /</span><span style="color:#79B8FF"> 40</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 40</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">%</span><span style="color:#79B8FF"> 20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">190</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#B392F0">      .pocket</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">32</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$t-shirt-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">          content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">30</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">12</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$t-shirt-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-4</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">-3</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#B392F0">::after</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">          content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">""</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$button-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">9</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#E1E4E8">      } </span><span style="color:#6A737D">// end of pocket</span></span>
<span class="line"><span style="color:#E1E4E8">    } </span><span style="color:#6A737D">// end of t-shirt</span></span>
<span class="line"><span style="color:#B392F0">    .neckless</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">      position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      box-shadow</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 0</span><span style="color:#79B8FF"> transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">167</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">      transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">) </span><span style="color:#79B8FF">rotate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">45</span><span style="color:#F97583">deg</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#79B8FF">      z-index</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#B392F0">      .perl</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">        position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border-radius</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">        background-color</span><span style="color:#E1E4E8">: </span><span style="color:#FFAB70">$perl-color</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--perl1</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">4</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">42</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--perl2</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">42</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">4</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--perl3</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">12</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">44</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--perl4</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">44</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">12</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--perl5</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">45</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--perl6</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">45</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--perl7</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">28</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">45</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--perl8</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">45</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">28</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--perl9</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">36</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">42</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#85E89D">        &#x26;</span><span style="color:#FFAB70">--perl10</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">          top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">42</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">          left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">35</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">        }</span></span>
<span class="line"><span style="color:#E1E4E8">      } </span><span style="color:#6A737D">// end of perl</span></span>
<span class="line"><span style="color:#E1E4E8">    } </span><span style="color:#6A737D">// end of neckless</span></span>
<span class="line"><span style="color:#E1E4E8">  } </span><span style="color:#6A737D">// end of body</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">// end of avatar-container</span></span></code></pre></div>
<p><img src="/scale-transformations-on-hover-avatar.webp" alt="This image shows our avatar." style="max-width:41%" class="img-narrow"></p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-make-a-circular-clickable-button-with-shadow-effect/">Circular CSS Button with Shadow Effect</a></li>
<li><a href="/how-to-make-a-css-flipping-card-animation-on-hover/">CSS Flip Card Animation on Hover</a></li>
<li><a href="/keyframes-in-css-explained-make-your-animations-stand-out/">CSS Keyframes Animation Explained</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>CSS Colorful Text – Crafting Vibrant Effects</title>
      <link>https://littlecodingthings.com/css-colorful-text-crafting-vibrant-effects/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/css-colorful-text-crafting-vibrant-effects/</guid>
      <pubDate>Sun, 05 May 2024 10:53:00 GMT</pubDate>
      <description>Layer a gradient fill, a colored outline and a drop shadow onto the same heading, one declaration at a time, with a screenshot per step.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hello, everybody 😃 Get ready to add a vibrant twist to your web designs with my latest post on fonts. In this post, we’ll explore the fascinating world of typography, sharing clever ways to add a burst of colors, outlines, shadows, and CSS colorful text. Whether we are looking to level up designs or experiment with <a href="/the-truth-about-css-is-it-really-a-programming-language/">CSS</a>, this post provides the inspiration and know-how to make texts truly stand out on your screen. Stay tuned for an amazing journey into the art of CSS typography! 🌈✨</p>
<p>We already know the <a href="/what-you-need-to-know-about-css-color-methods/">color CSS property</a>. When setting the text color, we’re setting the color of the text itself. In contrast, setting the background-color sets the background color behind the text. But what if we want a more challenging font? Can we do that? Absolutely!</p>
<p>Below, I prepared an example as a way to make it more understandable. Enjoy! 💻</p>
<h2 id="preparing-our-html-and-css-structure">Preparing our HTML and CSS structure<a class="heading-anchor" href="#preparing-our-html-and-css-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The following code creates a colorful text with gradient, outline, and shadow. We will start with our <a href="/most-useful-html-elements-for-maximizing-better-results/" title="HTML">HTML</a> structure. Our body has background-color: black. Inside, we make an HTML <code>div</code> element that serves as a container for our text and has a class attribute named <code>font-effects</code>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">body</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"font-effects"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    colorful text with gradient, outline &#x26; shadow is so impressive</span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">body</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p>Next, let’s proceed with our <a href="/how-to-work-with-css-syntax-the-correct-way/" title="CSS">CSS</a> structure. The <code>font-effects</code> class contains the rules applied to the HTML element mentioned earlier. We’ll provide a thorough examination of these rules as we progress through this post. For now, it’s important to note that our text has <code>color</code> white, our body has <code>background-color</code> black, and we’ve also integrated (<code>@import url(...)</code>) a <code>font-family</code> of Google Fonts.</p>
<p>Ensure this statement is placed at the beginning of your CSS code snippet, just like I did (check line 2).</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* insert google fonts */</span></span>
<span class="line"><span style="color:#F97583">@import</span><span style="color:#79B8FF"> url</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#9ECBFF">  'https://fonts.googleapis.com/css2?family=Stick+No+Bills'</span></span>
<span class="line"><span style="color:#E1E4E8">);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">black</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.font-effects</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">1100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">150</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-family</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">'Stick No Bills'</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">sans-serif</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  text-align</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>The following image shows what is rendered on the screen now.</p>
<p><img src="/fonts-colorful-outline-shadow-1.webp" alt="CSS colorful text: This image shows a 150px text with color white and background-color black. It has font-family: &#x27;Stick No Bills&#x27;." style="max-width:56%" class="img-narrow"></p>
<h2 id="explaining-the-css-colorful-text-effect">Explaining the CSS colorful text effect<a class="heading-anchor" href="#explaining-the-css-colorful-text-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Inside the <code>.font-effects</code> style rules, we include the following instructions to create these amazing fonts:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.font-effects</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#6A737D">  /* adding colors */</span></span>
<span class="line"><span style="color:#79B8FF">  background-image</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">linear-gradient</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#F97583">    to</span><span style="color:#79B8FF"> right</span><span style="color:#79B8FF"> bottom</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">red</span><span style="color:#79B8FF"> 0</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#79B8FF"> 15</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#79B8FF"> 25</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">pink</span><span style="color:#79B8FF"> 25</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    transparent</span><span style="color:#79B8FF"> 27</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">indigo</span><span style="color:#79B8FF"> 27</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">black</span><span style="color:#79B8FF"> 50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    transparent</span><span style="color:#79B8FF"> 52</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#79B8FF"> 52</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">indigo</span><span style="color:#79B8FF"> 73</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    transparent</span><span style="color:#79B8FF"> 73</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">pink</span><span style="color:#79B8FF"> 75</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">orange</span><span style="color:#79B8FF"> 75</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">green</span><span style="color:#79B8FF"> 90</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#79B8FF">    red</span><span style="color:#79B8FF"> 100</span><span style="color:#F97583">%</span></span>
<span class="line"><span style="color:#E1E4E8">  );</span></span>
<span class="line"><span style="color:#6A737D">  /* Makes the text shape match the background */</span></span>
<span class="line"><span style="color:#79B8FF">  -webkit-background-clip</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">text</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#6A737D">    /* adding outline to text */</span></span>
<span class="line"><span style="color:#79B8FF">  -webkit-text-stroke-width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  -webkit-text-stroke-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#6A737D">  /* adding shadow to text */</span></span>
<span class="line"><span style="color:#79B8FF">  filter</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">drop-shadow</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> 2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> rgba</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">250</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">190</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">210</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">0.8</span><span style="color:#E1E4E8">));</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h3 id="adding-the-linear-gradient-effect">Adding the linear gradient effect<a class="heading-anchor" href="#adding-the-linear-gradient-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><code>background-image: linear-gradient(...)</code> ➡ This CSS rule creates a background gradient using the <code>linear-gradient</code> function. The gradient begins with red, transitions to green, and then shifts to orange. It then transitions to pink, becomes transparent, then indigo, returns orange becomes transparent once more, shifts to green, then indigo, then transparent again, returns to pink, then orange for the third time, then green, and finally returns red again.</p>
<p>Remember that this gradient will be used as the background for our text. Isn’t this awesome? 😎</p>
<p><img src="/fonts-colorful-outline-shadow-2.webp" alt="CSS colorful text: This image shows our text with the background-image: linear-gradient(to right bottom, orange 0, orange 25%, black 25%, transparent 27%, indigo 27%, orange 50%, black 50%, transparent 52%, green 52%, indigo 73%, transparent 73%, black 75%, orange 75%, orange 100%); CSS property. It is a colorful background." style="max-width:56%" class="img-narrow"></p>
<p><code>-webkit-background-clip: text</code> ➡ We continue with this CSS rule that tells the browser to clip the background gradient to the shape of the text. We are not ready yet to see the colorful background as text. 😕 We just prepared the space (fonts). Don’t worry we will proceed with our work and see the amazing result! 😉</p>
<p><img src="/fonts-colorful-outline-shadow-1.webp" alt="CSS colorful text: This image shows that the browser clips the background when we set the -webkit-background-clip: text CSS property. For now we can see only our black colored (default) text with body&#x27;s background." style="max-width:56%" class="img-narrow"></p>
<p><code>color: transparent</code> ➡ This CSS rule makes the actual text content transparent. This allows the colorful gradient to show through the text 🥳, and there it 🥁 is!</p>
<p><img src="/fonts-colorful-outline-shadow-3.webp" alt="CSS colorful text: This image shows that now our text has the colors of the its background as we set the color: transparent CSS property." style="max-width:56%" class="img-narrow"></p>
<h3 id="adding-the-outline-effect">Adding the outline effect<a class="heading-anchor" href="#adding-the-outline-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><code>-webkit-text-stroke: 2px pink</code> ➡ Then we add a pink outline or stroke with a width of 2 pixels. This makes the text more visible against the background gradient.</p>
<p>🔖 We are free to write it more analytically setting the following two CSS properties <code>-webkit-text-stroke-width</code> and <code>-webkit-text-stroke-color</code>. It’s up to you!</p>
<p><img src="/fonts-colorful-outline-shadow-4.webp" alt="CSS colorful text: This image shows that we add to our text a 2px pink outline setting the -webkit-text-stroke: 2px pink CSS property. We are free to write it more analytically setting the following two CSS properties -webkit-text-stroke-width and -webkit-text-stroke-color." style="max-width:56%" class="img-narrow"></p>
<h3 id="applying-the-shadow-effect">Applying the shadow effect<a class="heading-anchor" href="#applying-the-shadow-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><code>filter: drop-shadow(-2px 2px 2px rgb(250, 190, 210, 0.8))</code> ➡ To finalize our work we add a <a href="/drop-shadow-vs-box-shadow-what-is-the-difference/">shadow</a> to the entire section, with an offset of <code>-2</code> pixels to the left, <code>2</code> pixels down, a blur radius of <code>2</code> pixels, and a subtle pink shadow <code>rgba(250, 190, 210, 0.8)</code>. This shadow adds a soft but noticeable lift to our text.</p>
<p><img src="/fonts-colorful-outline-shadow-5.webp" alt="CSS colorful text: This image shows that our text  (fonts) has now the colors of the background with outline and shadow. So we finallize our effects by adding the shadow to our text setting the filter: drop-shadow(-2px 2px 2px rgba(250, 190, 210, 0.8)) CSS property." style="max-width:56%" class="img-narrow"></p>
<p>To infuse our text with a touch of fantasy and vibrance 🎉 ✨, we can use a brighter color for the outline and change the shadow to match. For example, we could create a vivid or dark background as a way to create contrast and then swap out the pink outline and shadow for a more vibrant magenta. In the picture below, you can see how these small changes make a big difference, giving a more colorful and bright result.</p>
<p><img src="/fonts-colorful-outline-shadow-green-background.webp" alt="CSS colorful text: This image includes colorful text effects variations" style="max-width:56%" class="img-narrow"></p>
<p><img src="/fonts-colorful-outline-shadow-black-background.webp" alt="CSS colorful text: This image includes colorful text effects variations" style="max-width:56%" class="img-narrow"></p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/css-rainbow-text-how-to-make-astonishing-and-vibrant-fonts/">How to Make Rainbow Text in CSS</a></li>
<li><a href="/css-text-outline-how-to-make-amazing-outlined-texts/">CSS Text Outline Effect</a></li>
<li><a href="/how-to-build-stunning-rounded-text-handy-tips/">How To Build Stunning Rounded Text – Handy Tips</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>CSS Text Outline Effect</title>
      <link>https://littlecodingthings.com/css-text-outline-how-to-make-amazing-outlined-texts/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/css-text-outline-how-to-make-amazing-outlined-texts/</guid>
      <pubDate>Wed, 01 May 2024 16:22:00 GMT</pubDate>
      <description>Outline text and hollow out the middle with -webkit-text-stroke plus color: transparent. Step-by-step, with the split width/color form.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hello, there 😃 Let’s step into a digital world where <a href="/the-truth-about-css-is-it-really-a-programming-language/">CSS</a> brings forth the captivating CSS text outline effect. It’s a simple yet powerful technique that adds structure and clarity to texts and elements.</p>
<p>Let’s dive into how CSS outlines 🖋 can make a significant difference in the visual appeal of your website. 💻 🫧</p>
<h2 id="create-basic-html-and-css-structure">Create basic HTML and CSS structure<a class="heading-anchor" href="#create-basic-html-and-css-structure" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>As a first step, we need some basic <a href="/most-useful-html-elements-for-maximizing-better-results/" title="HTML">HTML</a> structure to apply our <a href="/how-to-work-with-css-syntax-the-correct-way/" title="CSS">CSS</a> stylings.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">body</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"outline-effect"</span><span style="color:#E1E4E8">>outline effect&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">body</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* insert google fonts */</span></span>
<span class="line"><span style="color:#F97583">@import</span><span style="color:#79B8FF"> url</span><span style="color:#E1E4E8">(</span></span>
<span class="line"><span style="color:#9ECBFF">  'https://fonts.googleapis.com/css2?family=Emilys+Candy&#x26;display=swap'</span></span>
<span class="line"><span style="color:#E1E4E8">);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.outline-effect</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">650</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">180</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  text-align</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-family</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">'Emilys Candy'</span><span style="color:#E1E4E8">, cursive;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Let’s see what we have done so far. I have chosen a vibrant purple color for our background while keeping the text in the default black color. Our text is set to 180px, perfectly aligned to the center.</p>
<p>To give a playful and lively vibe to our design, I’ve chosen the “Emilys Candy” <code>font-family</code> which adds a delightful touch. If you also intend to use this font family, <em>importing it into your CSS file is essential.</em> Ensure the <code>@import</code> statement is placed at the beginning of your CSS code snippet, just like I did (check above lines 2-4).</p>
<p>In the image below, you can see the current rendering on the screen up to this point.</p>
<p><img src="/outline-effect1.webp" alt="CSS text outline: This image shows our text with its specific fonts." style="max-width:42%" class="img-narrow"></p>
<h2 id="apply-the-css-text-outline-effect">Apply the CSS text outline effect<a class="heading-anchor" href="#apply-the-css-text-outline-effect" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.outline-effect</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  -webkit-text-stroke</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">2</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> #8695e9</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* medium blue shade */</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">transparent</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>The first thing we have to do is set the <code>-webkit-text-stroke</code> property which represents a specific style line. (There is no unprefixed <code>text-stroke</code> — the <code>-webkit-</code> form is the one every browser actually supports.) Here, in our example, the text should have a light to medium blue color (<code>#8695e9</code>) outline with 2 pixels wide. Remember that as we increase the pixels, the outline becomes wider.</p>
<p><img src="/outline-effect2.webp" alt="CSS text outline: In this image we have set the -webkit-text-stroke CSS property which adds a medium blue 2px wide outline to our text." style="max-width:42%" class="img-narrow"></p>
<p>🔖 It’s useful to know that we can split the <code>-webkit-text-stroke</code> property in two: <code>-webkit-text-stroke-width</code> and <code>-webkit-text-stroke-color</code>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* 1st choice */</span></span>
<span class="line"><span style="color:#E1E4E8">  -webkit-text-stroke: 2px </span><span style="color:#FDAEB7;font-style:italic">#8695e9</span><span style="color:#E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/* 2nd choice */</span></span>
<span class="line"><span style="color:#E1E4E8">  -webkit-text-stroke-width: 2px;</span></span>
<span class="line"><span style="color:#E1E4E8">  -webkit-text-stroke-color: </span><span style="color:#FDAEB7;font-style:italic">#8695e9</span><span style="color:#E1E4E8">;</span></span></code></pre></div>
<p>(Personally, I opt for the shortened form, saving time and extra lines of code, but the choice is yours. 🙂)</p>
<p>Finally, by adding <code>color: transparent</code> we complete our effect by allowing the background to show through.</p>
<p><img src="/outline-effect3.webp" alt="CSS text outline: This image shows our text with only the outline effect.Our text is now transparent as we add the color: transparent CSS property." style="max-width:42%" class="img-narrow"></p>
<p>To sum up, this code styles a piece of text with a see-through center and a visible 2px blue outline. It’s simple yet impressive 🎈 ✨</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/css-colorful-text-crafting-vibrant-effects/">CSS Colorful Text – Crafting Vibrant Effects</a></li>
<li><a href="/enhance-your-content-utilizing-the-css-text-shadow-property/">The CSS text-shadow Property</a></li>
<li><a href="/css-rainbow-text-how-to-make-astonishing-and-vibrant-fonts/">How to Make Rainbow Text in CSS</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>CSS Border Styles Explained</title>
      <link>https://littlecodingthings.com/how-to-be-creative-with-different-css-border-styles/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-be-creative-with-different-css-border-styles/</guid>
      <pubDate>Sun, 28 Apr 2024 09:29:00 GMT</pubDate>
      <description>Border style, width, color, the shorthand and border-radius, with worked examples for single sides, mixed sides and curved corners.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hello everybody! 😀 In this post, we’ll work with the amazing CSS border property, which is basically the line that surrounds our objects. Borders are an independent property and do not affect the content within. You can think of borders as beautiful frames that enclose <a href="/most-useful-html-elements-for-maximizing-better-results/" title="HTML elements">HTML elements</a>. ✨ 🖼 Let’s dive into the details of CSS border styles.</p>
<p>When working with borders in <a href="/how-to-work-with-css-syntax-the-correct-way/" title="CSS">CSS</a>, we have four key properties to consider:</p>
<ul>
<li><code>border-width</code></li>
<li><code>border-style</code></li>
<li><code>border-color</code></li>
<li><code>border-radius</code></li>
</ul>
<p>Furthermore, we have the option to handle each side individually by using properties like <code>border-top</code>, <code>border-right</code>, <code>border-bottom</code> and <code>border-left</code>. You can also use an image or a gradient as the border with <a href="/border-image-slice-css-property-for-one-of-a-kind-border-effects/"><code>border-image-slice</code></a>. We can either modify all four sides at once or selectively apply changes to different sides.</p>
<p>Below, there are some basic examples of borders so that you can have a quick glimpse of the possibilities offered by this CSS property. Afterward, we will go deeper and explore every case more analytically.</p>
<p><img src="/border-example1-1.webp" alt="CSS border styles: This is an image that shows a box with border box none." style="max-width:65%" class="img-narrow"></p>
<p><img src="/border-example2.webp" alt="CSS border styles: This is an image that shows a box with 4 sides border, 10px width, dotted style and color black." style="max-width:65%" class="img-narrow"></p>
<p><img src="/border-example3.webp" alt="CSS border styles: This is an image that shows a box with 1 side border, 10px width, dashed style and color purple." style="max-width:65%" class="img-narrow"></p>
<p><img src="/border-example4.webp" alt="CSS border styles: This is an image that shows a box with 2 sides border, 8px width, double style top but solid style bottom and color white." style="max-width:65%" class="img-narrow"></p>
<p><img src="/border-example5.webp" alt="CSS border styles: This is an image that shows a box with a 3 sides mixed styled and mixed color border with 5px width and border-radius 50px." style="max-width:65%" class="img-narrow"></p>
<p><img src="/border-example6.webp" alt="CSS border styles: This is an image that shows a 4 sides border with 10px width, solid style, color blue and border-radius 25%." style="max-width:65%" class="img-narrow"></p>
<h2 id="css-border-style--the-playful-property">CSS border style – The playful property<a class="heading-anchor" href="#css-border-style--the-playful-property" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We can now move forward and focus on the first thing we need to know about borders is the <code>border-style</code> CSS property. There are <strong>many styles available</strong>, but for today, we will concentrate on the most common ones.</p>
<p>The first and most usual is the <code>solid</code> type which is just a simple line. Then we have the <code>double</code> which is as you’d expect a double line border. Another style is the <code>dashed</code> one in which, the line is made up of dashes. It’s nice to have clear and descriptive names right? Finally, the <code>dotted</code> style is the one in which the border line consists of dots.</p>
<p>Below, you will find examples showcasing the styles we’ve just mentioned alongside their respective CSS code:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">border-style</span><span style="color:#E1E4E8">: solid;</span></span></code></pre></div>
<p><img src="/border-solid.webp" alt="CSS border style: This is an image that shows a box with border style solid." style="max-width:28%" class="img-narrow"></p>
<p><img src="/border-double.webp" alt="CSS border style: This is an image that shows a box with border style double." style="max-width:28%" class="img-narrow"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">border-style</span><span style="color:#E1E4E8">: double;</span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">border-style</span><span style="color:#E1E4E8">: dashed;</span></span></code></pre></div>
<p><img src="/border-dashed.webp" alt="CSS border style: This is an image that shows a box with border style dashed." style="max-width:28%" class="img-narrow"></p>
<p><img src="/border-dotted.webp" alt="CSS border style: This is an image that shows a box with border style dotted." style="max-width:28%" class="img-narrow"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">border-style</span><span style="color:#E1E4E8">: dotted;</span></span></code></pre></div>
<h2 id="css-border-width--focusing-on-precision">CSS border width – Focusing on precision<a class="heading-anchor" href="#css-border-width--focusing-on-precision" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Now that you’ve seen the basic border stylings, it’s time to check out the border’s <strong>width</strong> property. By default, <code>border-width</code> is <code>medium</code> — around 3px in most browsers — and nothing is drawn at all until <code>border-style</code> is set. To change the width, we modify the <code>border-width</code> property according to our needs.</p>
<p>Before we continue, it’s important to give you some insights on an important property that directly affects border behaviors and is called <code>box-sizing</code>. Box sizing’s value is set, by default, to <code>content-box</code> . Because of that <em><strong>borders occupy additional space around the object</strong></em><strong>s</strong> <strong>they surround</strong>.</p>
<p>In simple words, if I have a box with 300px width and 200px height and I want to add a 20px border to all sides, then I will end up having a bordered box with 340px width and 240px height. Let’s see how I came up with this result:</p>
<p><code>width:</code> ➡ <strong>300px</strong> (box’s width) + <strong>40px</strong> (20px border-left + 20px border-right) = <strong>340px</strong>;</p>
<p><code>height:</code> ➡ <strong>200px</strong> (box’s height) + <strong>40px</strong> (20px border-top + 20px border-bottom) = <strong>240px</strong>;</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">border-width</span><span style="color:#E1E4E8">: 20px;</span></span></code></pre></div>
<p><img src="/border-width.webp" alt="Border-style css: This is an image that shows two boxes. The first one has width: 300px and height 100px; The second one shows a box with" style="max-width:56%" class="img-narrow"></p>
<p>🕵️‍♀️ <em>By exploring the</em> <code>box-sizing</code> <em>CSS property, we can include borders within the box’s dimensions. If you’re interested in learning more about it</em> <a href="/css-box-sizing-better-implementations-less-headaches/" title="check out my post">check out my post</a><em>. You will find detailed instructions and explanations on each box sizing method.</em></p>
<h2 id="css-border-color--for-vivid-results">CSS border color – For vivid results<a class="heading-anchor" href="#css-border-color--for-vivid-results" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The next step is to understand how border color works. By default, <code>border-color</code> is <code>currentColor</code>, which means the border picks up the element’s own text <code>color</code>. Since text is black by default in most browsers, an unstyled border usually looks black too — but change the element’s <code>color</code> and the border changes with it.</p>
<blockquote>
<p>By default, a border takes the element’s text color (<code>currentColor</code>)</p>
</blockquote>
<p>However, if we want a different color we have the freedom to choose any color we desire and simply assign it to the <code>border-color</code> property. Let’s see that in action:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">border-color</span><span style="color:#E1E4E8">: blue;</span></span></code></pre></div>
<p><img src="/border-color.webp" alt="Border-style css: This is an image that shows a box with blue border color." style="max-width:28%" class="img-narrow"></p>
<p>Border colors can be described using various different value types. For instance, you can specify the color blue by using :</p>
<ul>
<li>The word <code>blue</code></li>
<li>The corresponding hex code <code>#00F</code></li>
<li>The RGB value <code>rgb(0, 0, 255)</code></li>
<li>The HSL value <code>hsl(240, 100%, 50%)</code></li>
</ul>
<p><a href="/what-you-need-to-know-about-css-color-methods/" title="A color 🌈 guide is also available">A color 🌈 guide is also available</a> to help expand your knowledge of colors.</p>
<h2 id="border-shorthand-for-simplified-stylings">Border shorthand for simplified stylings<a class="heading-anchor" href="#border-shorthand-for-simplified-stylings" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><code>border: border-width border-style border-color</code></p>
<p>There is a cool method for writing all the above border properties that prove to be highly useful. By choosing this approach, you can set multiple values simultaneously. This technique is a super efficient way to define all border properties in a quick and easy manner. It’s a total time and space saver! 😃</p>
<p>Instead of listing each property separately, you just add each property side by side in a single line:</p>
<p><img src="/border-shorthand.webp" alt="Border-style css: This image shows that border-width, border-style and border-color can be declared only with the word border." style="max-width:56%" class="img-narrow"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">border: 10px dashed blue;</span></span></code></pre></div>
<p><img src="/border-shorthand-example.webp" alt="Border-style css: This image shows a box with a 10px dashed blue 4 sides border." style="max-width:28%" class="img-narrow"></p>
<p>Cool right? 😎 ✨ Keep in mind that the order of the property doesn’t matter! We usually start with pixels and then add style and color, but it’s up to you the final decision!</p>
<h2 id="css-border-styles-for-unique-results">CSS Border Styles for unique results<a class="heading-anchor" href="#css-border-styles-for-unique-results" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Additionally, we have the flexibility to <strong>selectively choose specific sides</strong> when defining our border styles. This allows us to create borders combined with different styling. In the following example, you can check out some of these combinations. But still, you are free to make your own! 😀</p>
<h3 id="one-side-border">One side border<a class="heading-anchor" href="#one-side-border" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">border-top</span><span style="color:#E1E4E8">: 10px double white;</span></span></code></pre></div>
<p><img src="/border-top.webp" alt="Border styles css: This image shows a box with a 10px double white border-top." style="max-width:28%" class="img-narrow"></p>
<p><img src="/border-right.webp" alt="Border styles css: This image shows a box with a 10px dashed purple border-right." style="max-width:28%" class="img-narrow"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">border-right</span><span style="color:#E1E4E8">: 10px dashed purple;</span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">border-bottom</span><span style="color:#E1E4E8">: 10px solid white;</span></span></code></pre></div>
<p><img src="/border-bottom.webp" alt="Border styles css: This image shows a box with a 10px solid white border-bottom." style="max-width:28%" class="img-narrow"></p>
<p><img src="/border-left.webp" alt="Border styles css: This image shows a box with a 10px dotted purple border-left." style="max-width:28%" class="img-narrow"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">border-left</span><span style="color:#E1E4E8">: 10px dotted purple;</span></span></code></pre></div>
<h3 id="multiple-sides-border">Multiple sides border<a class="heading-anchor" href="#multiple-sides-border" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">  border-top</span><span style="color:#E1E4E8">: 10px double white;</span></span>
<span class="line"><span style="color:#85E89D">  border-right</span><span style="color:#E1E4E8">: none;</span></span>
<span class="line"><span style="color:#85E89D">  border-bottom</span><span style="color:#E1E4E8">: 10px solid purple;</span></span>
<span class="line"><span style="color:#85E89D">  border-left</span><span style="color:#E1E4E8">: none;</span></span></code></pre></div>
<p><img src="/border-combinations-two-sides-border.webp" alt="Border styles css: This image shows a box with a 10px double white border-top and a 10px solid purple border-bottom. Border-left and border-right have value none." style="max-width:28%" class="img-narrow"></p>
<p><img src="/border-combinations-three-sides-border.webp" alt="Border styles css: This image shows a box with a 10px double white border-top, a 10px solid purple border-bottom and a 10px dashed black border-right. Border-left has value none." style="max-width:28%" class="img-narrow"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">  border-top</span><span style="color:#E1E4E8">: 10px double white;</span></span>
<span class="line"><span style="color:#85E89D">  border-right</span><span style="color:#E1E4E8">: 10px dashed black;</span></span>
<span class="line"><span style="color:#85E89D">  border-bottom</span><span style="color:#E1E4E8">: 10px solid purple;</span></span>
<span class="line"><span style="color:#85E89D">  border-left</span><span style="color:#E1E4E8">: none;</span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">  border-top</span><span style="color:#E1E4E8">: 10px double white;</span></span>
<span class="line"><span style="color:#85E89D">  border-right</span><span style="color:#E1E4E8">: 10px dashed black;</span></span>
<span class="line"><span style="color:#85E89D">  border-bottom</span><span style="color:#E1E4E8">: 10px solid purple;</span></span>
<span class="line"><span style="color:#85E89D">  border-left</span><span style="color:#E1E4E8">: 10px dotted blue;</span></span></code></pre></div>
<p><img src="/border-combination-four-sides-different-border.webp" alt="Border styles css: This image shows a box with a 10px double white border-top, a 10px solid purple border-bottom, a 10px dashed black border-right and a 10px dotted blue border-left." style="max-width:28%" class="img-narrow"></p>
<p><img src="/border-combination-four-sides-same-border.webp" alt="Border styles css: This image shows a box with a 10px solid purple border applied to all 4 sides." style="max-width:28%" class="img-narrow"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">  border-top</span><span style="color:#E1E4E8">: 10px solid purple;</span></span>
<span class="line"><span style="color:#85E89D">  border-right</span><span style="color:#E1E4E8">: 10px solid purple;</span></span>
<span class="line"><span style="color:#85E89D">  border-bottom</span><span style="color:#E1E4E8">: 10px solid purple;</span></span>
<span class="line"><span style="color:#85E89D">  border-left</span><span style="color:#E1E4E8">: 10px solid purple;</span></span>
<span class="line"><span style="color:#6A737D">  /* OR */</span></span>
<span class="line"><span style="color:#E1E4E8">  border: 10px solid purple;</span></span></code></pre></div>
<p>🔖 Keep in mind when working with the CSS border property that it is considered a good practice to set equal border widths for all sides. Being consistent helps by bringing a sense of balance and distraction-free results.
Furthermore, try to avoid mismatched styles and colors. Matching styles and colors lead to a smooth and cohesive look that’s easy on the eyes. Not to mention, it keeps your code cleaner 🎉 and easier to manage. 😀</p>
<h4 id="dos"><strong>DO’S</strong><a class="heading-anchor" href="#dos" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">  border-top</span><span style="color:#E1E4E8">: 10px solid white;</span></span>
<span class="line"><span style="color:#85E89D">  border-right</span><span style="color:#E1E4E8">: 10px dashed purple;</span></span>
<span class="line"><span style="color:#85E89D">  border-bottom</span><span style="color:#E1E4E8">: 10px solid white;</span></span>
<span class="line"><span style="color:#85E89D">  border-left</span><span style="color:#E1E4E8">: 10px dashed purple;</span></span></code></pre></div>
<p><img src="/border-do-s.webp" alt="This image shows a box with a 10px solid white border top and bottom, while border right and left have 10px dashed purple. Also this image has a message inside it that says: &#x27;DO&#x27;S&#x22;" style="max-width:28%" class="img-narrow"></p>
<h4 id="donts"><strong>DON’TS</strong><a class="heading-anchor" href="#donts" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><img src="/border-don-s.webp" alt="This image shows a box with a 30px double red border-top, a 5px dashed green border-right, a 20px solid orande border-bottom,  and a 15px dotted blue border-left. Also this image has a message inside it that says: &#x27;DON&#x27;TS&#x22;" style="max-width:28%" class="img-narrow"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">border-top</span><span style="color:#E1E4E8">: 30px double red;</span></span>
<span class="line"><span style="color:#85E89D">border-right</span><span style="color:#E1E4E8">: 5px dashed green;</span></span>
<span class="line"><span style="color:#85E89D">border-bottom</span><span style="color:#E1E4E8">: 20px solid orange;</span></span>
<span class="line"><span style="color:#85E89D">border-left</span><span style="color:#E1E4E8">: 15px dotted blue;</span></span></code></pre></div>
<h2 id="create-curved-corners-using-border-radius">Create curved corners using border-radius<a class="heading-anchor" href="#create-curved-corners-using-border-radius" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Last but not least we have the <code>border-radius</code> CSS property, which enables us to give our elements rounded corners. We can opt for uniform rounding or we can apply different degrees of rounding to each corner. In addition to that, it’s useful to know that when we are working with different radius per corner, we can also combine <code>px</code> with <code>%</code>.</p>
<blockquote>
<p>When we are setting different border-radius per corner, we are free to combine px with %.</p>
</blockquote>
<h3 id="same-corners">Same corners<a class="heading-anchor" href="#same-corners" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">border-radius</span><span style="color:#E1E4E8">: 50%;</span></span></code></pre></div>
<p><img src="/border-radius-50.webp" alt="This image shows a box with border-radius: 50%, rounding all four corners equally." style="max-width:28%" class="img-narrow"></p>
<p><img src="/border-radius-50px.webp" alt="This image shows a box with border-radius: 50px, rounding all four corners equally." style="max-width:28%" class="img-narrow"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">border-radius</span><span style="color:#E1E4E8">: 50px;</span></span></code></pre></div>
<h3 id="different-corners">Different corners<a class="heading-anchor" href="#different-corners" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* top-left &#x26; bottom-right | top-right &#x26; bottom-left */</span></span>
<span class="line"><span style="color:#85E89D">border-radius</span><span style="color:#E1E4E8">: 50% 25%;</span></span></code></pre></div>
<p><img src="/border-top-left-bottom-right-top-right-bottom-left.webp" alt="This image shows a box with border-radius: 50% 25%; Top-left and bottom-right corners have radius 50% while top-right and bottom-left corners have radius 25%." style="max-width:28%" class="img-narrow"></p>
<p><img src="/border-top-left-top-right-bottom-left-bottom-right.webp" alt="This image shows a box with border-radius: 40% 20px 30%; Top-left corner have radius 40%, top-right and bottom-left corners have radius 20px while bottom-right corners have radius 30%." style="max-width:28%" class="img-narrow"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* top-left | top-right &#x26; bottom-left | bottom-right */</span></span>
<span class="line"><span style="color:#85E89D">border-radius</span><span style="color:#E1E4E8">: 40% 20px 30%;</span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* top-left | top-right | bottom-right | bottom-left */</span></span>
<span class="line"><span style="color:#85E89D">border-radius</span><span style="color:#E1E4E8">: 40% 10% 50px 20px;</span></span></code></pre></div>
<p><img src="/border-top-left-top-right-bottom-right-bottom-left.webp" alt="This image shows a box with border-radius: 40% 10% 50px 20px. Top-left corner has radius 40%, top-right corner has radius 10%, bottom-right corner has radius 50px and bottom-left corner has radius 20px." style="max-width:28%" class="img-narrow"></p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/create-playful-border-effects-combining-css-gradients-with-the-border-image-slice-css-property/">CSS Gradient Borders with border-image</a></li>
<li><a href="/css-box-sizing-better-implementations-less-headaches/">CSS box-sizing: border-box Explained</a></li>
<li><a href="/how-to-make-a-transparent-button-using-html-and-css/">Transparent Button in CSS</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>CSS Text Decoration Explained with Examples</title>
      <link>https://littlecodingthings.com/css-text-decoration-explained-with-examples/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/css-text-decoration-explained-with-examples/</guid>
      <pubDate>Thu, 25 Apr 2024 22:49:00 GMT</pubDate>
      <description>Underline, overline and line-through in CSS: the line, style, color and thickness properties, how to mix them, and the shorthand.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hi to everyone 😃 Today, we will analyze the CSS text decoration property, which is a valuable tool for improving the presentation of text on your website. It allows us to add visual enhancements such as underlines for hyperlinks, strikethroughs for completed tasks, or the removal of decoration for a clean and professional appearance.</p>
<p>With minor code adjustments to our <a href="/how-to-work-with-css-syntax-the-correct-way/" title="CSS">CSS</a> code, we can enhance the visual appeal of our text content. Consider integrating it to elevate the aesthetics of our website. Below, I’ve prepared a detailed guide.</p>
<p>Wishing you <a href="/the-unique-origin-of-the-term-bug-in-software-development/">bug</a>-free reading 👩‍💻, I mean coding! 💻 ✨</p>
<h2 id="text-decoration-line">Text-decoration line<a class="heading-anchor" href="#text-decoration-line" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>First of all, we define the position of the line we desire by setting <code>text-decoration-line</code>. Those are: <code>underline</code>, <code>overline</code>, and <code>line-through</code>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">text-decoration-line</span><span style="color:#E1E4E8">: overline;</span></span></code></pre></div>
<p><img src="/text-decoration-line-eg1-overline.webp" alt="CSS text decoration: An image showing the text-decoration-line: overline; CSS property." style="max-width:45%" class="img-narrow"></p>
<p><img src="/text-decoration-line-eg2-underline.webp" alt="CSS text decoration: An image showing the text-decoration-line: underline; CSS property." style="max-width:45%" class="img-narrow"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">text-decoration-line</span><span style="color:#E1E4E8">: underline;</span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* the keyword is line-through — plain "through" is not valid */</span></span>
<span class="line"><span style="color:#85E89D">text-decoration-line</span><span style="color:#E1E4E8">: </span><span style="color:#85E89D">line-through</span><span style="color:#E1E4E8">;</span></span></code></pre></div>
<p><img src="/text-decoration-line-eg3-line-through.webp" alt="CSS text decoration: An image showing the text-decoration-line: line-through; CSS property." style="max-width:45%" class="img-narrow"></p>
<p><img src="/text-decoration-line-eg4-combinations.webp" alt="CSS text decoration: An image showing the text-decoration-line: overline line-through underline; CSS property. That means we can make line combinations." style="max-width:45%" class="img-narrow"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* we are also able to make line combinations */</span></span>
<span class="line"><span style="color:#85E89D">text-decoration-line</span><span style="color:#E1E4E8">: overline </span><span style="color:#85E89D">line-through</span><span style="color:#E1E4E8"> underline;</span></span></code></pre></div>
<h2 id="text-decoration-style">Text-decoration style<a class="heading-anchor" href="#text-decoration-style" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Next, we proceed by configuring <code>text-decoration-style</code> to specify the desired line style, such as <code>solid</code>, <code>dashed</code>, <code>dotted</code>, <code>double</code>, or <code>wavy</code>.</p>
<p>🔖 Each example set a different position (<code>text-decoration-line</code>) for the lines as an opportunity to see more combinations. 😎</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">text-decoration-line</span><span style="color:#E1E4E8">: </span><span style="color:#85E89D">line-through</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#6A737D">/* default style */</span></span>
<span class="line"><span style="color:#85E89D">text-decoration-style</span><span style="color:#E1E4E8">: solid;</span></span></code></pre></div>
<p><img src="/text-decoration-style-eg1-solid.webp" alt="An image showing the text-decoration-style: solid; CSS property." style="max-width:45%" class="img-narrow"></p>
<p><img src="/text-decoration-style-eg2-dashed.webp" alt="An image showing the text-decoration-style: dashed; CSS property." style="max-width:45%" class="img-narrow"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">text-decoration-line</span><span style="color:#E1E4E8">: underline;</span></span>
<span class="line"><span style="color:#85E89D">text-decoration-style</span><span style="color:#E1E4E8">: dashed;</span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">text-decoration-line</span><span style="color:#E1E4E8">: overline;</span></span>
<span class="line"><span style="color:#85E89D">text-decoration-style</span><span style="color:#E1E4E8">: dotted;</span></span></code></pre></div>
<p><img src="/text-decoration-style-eg3-dotted.webp" alt="An image showing the text-decoration-style: dotted; CSS property." style="max-width:45%" class="img-narrow"></p>
<p><img src="/text-decoration-style-eg4-double.webp" alt="An image showing the text-decoration-style: double; CSS property." style="max-width:45%" class="img-narrow"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">text-decoration-line</span><span style="color:#E1E4E8">: underline;</span></span>
<span class="line"><span style="color:#85E89D">text-decoration-style</span><span style="color:#E1E4E8">: double;</span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">text-decoration-line</span><span style="color:#E1E4E8">: overline;</span></span>
<span class="line"><span style="color:#85E89D">text-decoration-style</span><span style="color:#E1E4E8">: wavy;</span></span></code></pre></div>
<p><img src="/text-decoration-style-eg5-wavy.webp" alt="An image showing the text-decoration-style: wavy; CSS property." style="max-width:45%" class="img-narrow"></p>
<h2 id="the-amazing-color-property">The amazing color property<a class="heading-anchor" href="#the-amazing-color-property" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Using colors is a timeless strategy for enhancing aesthetics. Embracing the use of colors is equally effective in our case, accomplished through the addition of <code>text-decoration-color</code>.</p>
<p><img src="/text-decoration-color-eg1-default-color-black.webp" alt="An image showing the text-decoration-color: black; CSS property, which is the default color." style="max-width:45%" class="img-narrow"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* the initial value is currentColor — black here only because the text is black */</span></span>
<span class="line"><span style="color:#85E89D">text-decoration-color</span><span style="color:#E1E4E8">: currentColor;</span></span>
<span class="line"><span style="color:#6A737D">/* or */</span></span>
<span class="line"><span style="color:#85E89D">text-decoration-color</span><span style="color:#E1E4E8">: initial;</span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">text-decoration-color</span><span style="color:#E1E4E8">: orange;</span></span></code></pre></div>
<p><img src="/text-decoration-color-eg2-orange.webp" alt="An image showing the text-decoration-color: orange; CSS property." style="max-width:45%" class="img-narrow"></p>
<p><img src="/text-decoration-color-eg3-current-color.webp" alt="An image showing the text-decoration-color: currentColor; CSS property. This property follows the text&#x27;s color." style="max-width:45%" class="img-narrow"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.text-color</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"><span style="color:#6A737D">/* follows the text's color */</span></span>
<span class="line"><span style="color:#85E89D">text-decoration-color</span><span style="color:#E1E4E8">: currentColor;</span></span>
<span class="line"><span style="color:#6A737D">/* or */</span></span>
<span class="line"><span style="color:#85E89D">text-decoration-color</span><span style="color:#E1E4E8">: inherit;</span></span></code></pre></div>
<p><a href="/what-you-need-to-know-about-css-color-methods/" title="An analytical post about colors 🌈 is now available">An analytical post about colors 🌈 is now available</a> if you are interested in expanding your knowledge of colors.</p>
<h2 id="text-decoration-thickness">Text-decoration thickness<a class="heading-anchor" href="#text-decoration-thickness" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Lastly, adjusting the <code>text-decoration-thickness</code> allows us to precisely manage the thickness and also offers us the flexibility to choose between pixels (px) or percentages (%) based on our preferences.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* the browser pick the thickness of the text decoration line */</span></span>
<span class="line"><span style="color:#85E89D">text-decoration-thickness</span><span style="color:#E1E4E8">: auto;</span></span></code></pre></div>
<p><img src="/text-decoration-thickness-eg1-default-thickness.webp" alt="CSS for text decoration: An image showing the text-decoration-thickness: auto; CSS property, which is the default thickness." style="max-width:45%" class="img-narrow"></p>
<p><img src="/text-decoration-thickness-eg4-initial-thickness.webp" alt="CSS for text decoration: An image showing the text-decoration-thickness: initial; CSS property, which is the default thickness as determined by the browser." style="max-width:45%" class="img-narrow"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/*  means "use the default thickness for underlines as determined</span></span>
<span class="line"><span style="color:#6A737D"> *  by the browser".</span></span>
<span class="line"><span style="color:#6A737D"> */</span></span>
<span class="line"><span style="color:#85E89D">text-decoration-thickness</span><span style="color:#E1E4E8">: initial;</span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span> /* The percentage value is relative to the font size of the text</span></span>
<span class="line"><span>  *  to which the decoration is applied.</span></span>
<span class="line"><span>  *  Example:</span></span>
<span class="line"><span>  *  In our case the font size is set to 40 pixels,</span></span>
<span class="line"><span>  *  so the underline will be 6 pixels thick,</span></span>
<span class="line"><span>  *  which is 15% of its font size (15% of 40 pixels)</span></span>
<span class="line"><span>  */</span></span>
<span class="line"><span>text-decoration-thickness: 15%;</span></span></code></pre></div>
<p><img src="/text-decoration-thickness-eg3-relative-to-text-size.webp" alt="CSS for text decoration: An image showing the text-decoration-thickness: 15%; CSS property. That mean the thickness of our line will be 15% of the text&#x27;s font-size." style="max-width:45%" class="img-narrow"></p>
<p><img src="/text-decoration-thickness-eg2.webp" alt="CSS for text decoration: An image showing the text-decoration-thickness: 10px; CSS property." style="max-width:45%" class="img-narrow"></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* override the applied default thickness */</span></span>
<span class="line"><span style="color:#85E89D">text-decoration-thickness</span><span style="color:#E1E4E8">: 10px;</span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"parent"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  hello, I'm the parent</span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"child"</span><span style="color:#E1E4E8">>hi, I'm the child&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">/* Thickness for the parent element */</span></span>
<span class="line"><span style="color:#B392F0">.parent</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  text-decoration</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">underline</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  text-decoration-style</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">solid</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  text-decoration-thickness</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">/* Inherits thickness from the parent */</span></span>
<span class="line"><span style="color:#B392F0">.child</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  text-decoration-thickness</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">inherit</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/text-decoration-thickness-eg5-inherit-thickness.webp" alt="CSS for text decoration: An image showing that the child element inherits the parents thickness setting the text-decoration-thickness: inherit CSS property." style="max-width:42%" class="img-narrow"></p>
<h2 id="be-distinctive-by-mixing-text-decoration">Be distinctive by mixing text-decoration<a class="heading-anchor" href="#be-distinctive-by-mixing-text-decoration" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We can always create mixings and make our texts more strong and more stylish. Below I prepared two examples for you in order to make it clearer. 😃</p>
<h3 id="underline-mixings">Underline mixings<a class="heading-anchor" href="#underline-mixings" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>We combined the following HTML and CSS code snippets to create a styled text element. The HTML part consists of a <code>&#x3C;div></code> element with the class <code>underline-mixings</code> containing the text <code>hello</code> and a nested <code>&#x3C;span></code> element with the class <code>extra-underline</code>, also containing the text <code>hello</code>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"underline-mixings"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  hello</span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"extra-underline"</span><span style="color:#E1E4E8">>hello&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  hello</span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.underline-mixings</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  text-decoration-line</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">underline</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  text-decoration-style</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">double</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  text-decoration-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"><span style="color:#B392F0">.extra-underline</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  text-decoration-line</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">underline</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  text-decoration-style</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">dashed</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  text-decoration-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  text-decoration-thickness</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">12</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>The CSS styles are applied to these elements using their respective class selectors. The <code>underline-mixings</code> class applies an underline with a double style and green color to the text within the <code>&#x3C;div></code>.</p>
<p>On the other hand, the <code>extra-underline</code> class applies a red dashed underline to the text within the <code>&#x3C;span></code>, along with a 12-pixel thickness for the underline.</p>
<p>When combined, this code creates a styled text element where the text inside the <code>&#x3C;div></code> is underlined with a green double line, while the text inside the <code>&#x3C;span></code> has a red dashed underline with increased thickness. We can use it if we want to emphasize a specific part of a text.</p>
<p><img src="/text-decoration-eg1-combinations.webp" alt="CSS for text decoration: An image showing that we are able to make mixing decorations." style="max-width:56%" class="img-narrow"></p>
<h3 id="strike-through-mixings">Strike through mixings<a class="heading-anchor" href="#strike-through-mixings" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Within the HTML code, there is a <code>&#x3C;div></code> element with the class <code>strike-through-mixings</code>, encompassing the text <code>hello</code> and containing a nested <code>&#x3C;span></code> element with the class <code>extra-underline</code>, which also contains the text <code>hello</code>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"strike-through-mixings"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  hello</span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"extra-underline"</span><span style="color:#E1E4E8">>hello&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  hello</span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.strike-through-mixings</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  text-decoration-line</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">underline</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  text-decoration-style</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">solid</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  text-decoration-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"><span style="color:#B392F0">.extra-underline</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  text-decoration-line</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">line-through</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  text-decoration-style</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">double</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  text-decoration-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">red</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  text-decoration-thickness</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">8</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>The CSS styles are assigned to these elements through their corresponding class selectors. The <code>strike-through-mixings</code> class gives the text within the <code>&#x3C;div></code> an underline with a solid style and a green color. Meanwhile, the <code>extra-underline</code> class applies a red double line-through decoration to the text inside the <code>&#x3C;span></code>, with an 8-pixel thickness.</p>
<p>When we put together this code, generates a styled text element where the text within the <code>&#x3C;div></code> has a green solid underline, and the text within the <code>&#x3C;span></code> is displayed with a red double line-through decoration of increased thickness. It is really useful if we want to erase a part of a text.</p>
<p><img src="/text-decoration-eg2-combinations.webp" alt="Text decoration CSS: An image showing that we are able to make mixing decorations." style="max-width:56%" class="img-narrow"></p>
<h2 id="text-decoration-shorthand">Text-decoration shorthand<a class="heading-anchor" href="#text-decoration-shorthand" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The CSS <code>text-decoration</code> shorthand property lets you apply decorations like underline, overline, and line-through in a single statement. It simplifies things by merging multiple properties into one. Settling the shorthand makes your code shorter and easier to understand. You can set all of these properties at once, making it more efficient or you can pick some of them based on your requirements.</p>
<blockquote>
<p>The CSS text-decoration shorthand property lets you apply decorations like underline, overline, and line-through in a single statement</p>
</blockquote>
<p>🔖 Note that the order of these values doesn’t matter; you can change the order and still achieve the same results. However, it is essential to specify the type of the line, as setting the <code>text-decoration-line</code> is a necessary step for your code to work properly.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">text-decoration</span><span style="color:#E1E4E8">: 10px dashed orange underline;</span></span></code></pre></div>
<p><img src="/text-decoration-shorthand.webp" alt="Text decoration CSS: An image showing showing the word &#x27;Goodbye!&#x27; with the text-decoration: 10px dashed orange underline; CSS property." style="max-width:42%" class="img-narrow"></p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/css-letter-spacing-working-on-the-correct-way/">CSS Letter Spacing – Working on The Correct Way</a></li>
<li><a href="/how-to-calculate-css-line-height/">How To Calculate CSS Line Height</a></li>
<li><a href="/what-you-need-to-know-about-css-color-methods/">What You Need to Know About CSS Color Methods</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>CSS box-sizing: border-box Explained</title>
      <link>https://littlecodingthings.com/css-box-sizing-better-implementations-less-headaches/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/css-box-sizing-better-implementations-less-headaches/</guid>
      <pubDate>Sat, 20 Apr 2024 14:00:00 GMT</pubDate>
      <description>Why a 300px box ends up 350px wide, and how box-sizing: border-box fixes it. Both models compared with the maths written out.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hello there! 😃 In this post, we’ll explore the unique CSS box sizing property, which is a part of the <a href="/what-is-the-css-box-model-in-simple-terms/" title="box model">box model</a>. We’ll explore how this property affects the size of an element on a webpage and take a closer look at the details of the <code>content-box</code> and <code>border-box</code> CSS properties.</p>
<p>So, let’s move forward and delve into 🕵️‍♀️ the powerful <code>box-sizing</code> CSS property!</p>
<p>First of all, we have to create a simple box with specific dimensions for its <code>width</code> and <code>height</code>. Also, assigning a color for our box would be essential, hence, we also need to set a <code>background-color</code>. I like the idea of giving our box a vibrant and cheerful yellow 🟨 as it is super appealing! 😃</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">300</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">yellow</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/box-sizing-yellow-box.webp" alt="This image shows a yellow box with 300px width and 100px height. We will use it in order to understand the unique box-sizing CSS propety." style="max-width:69%" class="img-narrow"></p>
<p>Since our box is now prepared, 🥁 we can proceed further by adding <code>padding</code>, <code>border</code> and <code>margin</code> and observe the changes in the dimensions surrounding our box.</p>
<p>Paddings &#x26; margins are <strong>both transparent</strong>. Paddings use the same background as the one used by the main content, while margins inherit their background from the parent element to which they belong.</p>
<p>🔖 For today, and only in order to make our example more explicit and easily understandable, we have chosen to apply a purple 🟪 color to the padding. In the image below we can see what is rendered to our screen based on the code snippet.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  padding</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* to all 4 sides */</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">5</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> black</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* to all 4 sides */</span></span>
<span class="line"><span style="color:#79B8FF">  margin</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* to all 4 sides */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/box-sizing-yellow-box-with-surroundings-scaled.webp" alt="This image shows the yellow box surrounded by a 20px padding, a 5px border and a 50px margin." style="max-width:69%" class="img-narrow"></p>
<h2 id="understanding-css-content-box">Understanding CSS content-box<a class="heading-anchor" href="#understanding-css-content-box" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>First and foremost, we need to know that all elements have, by default, <code>box-sizing: content-box</code>. That means when we add <code>border</code> and <code>padding</code> to an element, it automatically <strong>grows bigger and occupies more place</strong>.</p>
<p>(The provided code snippet serves as an illustration of the configuration. It should be emphasized that this snippet is specifically designed for the purpose of this example, and represents the default setting, as we previously mentioned).</p>
<p>The box-sizing property does not have any effect on <code>margins</code> as they are already positioned outside of the element’s space and are not considered part of it.</p>
<h3 id="calculate-dimensions-️️">Calculate dimensions 🕵️‍♀️<a class="heading-anchor" href="#calculate-dimensions-️️" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><code>width:</code> ➡ <strong>300px</strong> (box’s width) + <strong>40px</strong> (20px <code>padding-left</code> + 20px <code>padding-right</code>)+ <strong>10px</strong> (5px <code>border-left</code> + 5px <code>border-right</code>) = <strong>350px</strong>;</p>
<p><code>height:</code> ➡ <strong>100px</strong> (box’s height) + <strong>40px</strong> (20px <code>padding-top</code> + 20px <code>padding-bottom</code>)+ <strong>10px</strong> (5px <code>border-top</code> + 5px <code>border-bottom</code>) = <strong>150px</strong>;</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  box-sizing</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">content-box</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/box-sizing-content-box-scaled.webp" alt="This image shows the yellow box surrounded by a 20px padding, a 5px border and a 50px margin. It also shows that when we calculate all these CSS properties we have an HTML element (the yellow box) that holds 350px width and 150px height as a resault of the box-sizing: content-box CSS proprty." style="max-width:69%" class="img-narrow"></p>
<h2 id="mastering-css-border-box">Mastering CSS border-box<a class="heading-anchor" href="#mastering-css-border-box" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>To modify the default configuration and include the borders and paddings of an element within its initial size, it is necessary to apply the CSS property <code>box-sizing: border-box</code>. This property ensures that the specified width and height of the element is now adjustable and the content box can reduce its dimensions in order to include/accommodate paddings and borders.</p>
<h3 id="calculate-dimensions-️️-1">Calculate dimensions 🕵️‍♀️<a class="heading-anchor" href="#calculate-dimensions-️️-1" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><code>width:</code> ➡ <strong>250px</strong> (the content shrinks to fit) + <strong>40px</strong> (20px padding-left + 20px padding-right)+ <strong>10px</strong> (5px border-left + 5px border-right) = <strong>300px</strong>;</p>
<p><code>height:</code> ➡ <strong>50px</strong> (the content shrinks to fit) + <strong>40px</strong> (20px padding-top + 20px padding-bottom)+ <strong>10px</strong> (5px border-top + 5px border-bottom) = <strong>100px</strong>;</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.box</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  box-sizing</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">border-box</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/box-sizing-border-box.webp" alt="This image shows the yellow box surrounded by a 20px padding, a 5px border and a 50px margin. It also shows that when we calculate all these CSS properties we have an HTML element (the yellow box) that holds 300px width and 100px height as a resault of the box-sizing: border-box CSS proprty." style="max-width:69%" class="img-narrow"></p>
<h2 id="comparing-content-box-vs-border-box">Comparing: content-box VS border-box<a class="heading-anchor" href="#comparing-content-box-vs-border-box" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>To summarize in a nutshell, 😌 <code>content-box</code> calculates the width and height based only on the content while <code>border-box</code> includes the paddings and borders in the calculation.</p>
<p>Let’s examine both images side by side to simplify the contrast of their different sizes.</p>
<p><img src="/box-sizing-content-box-vs-border-box-scaled.webp" alt="This image shows the image with the &#x27;content-box&#x27; side by side with the image with the &#x27;border-box&#x27; in order to be easier to check out the size difference between them."></p>
<h2 id="tech-tips"><strong>Tech tips</strong><a class="heading-anchor" href="#tech-tips" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">*</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  box-sizing</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">border-box</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>🔖 We usually choose the <code>border-box</code> method due to its simplicity in achieving consistent layouts. We include the corresponding code in our CSS files by setting the asterisk (*) from the <a href="/coding-made-easy-with-css-selectors-an-ultimate-guide/" title="CSS selectors">CSS selectors</a>. By doing so, we apply it to all <a href="/most-useful-html-elements-for-maximizing-better-results/">HTML elements</a>, hence, we no longer need to include it repeatedly in each HTML 👌 element.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/what-is-the-css-box-model-in-simple-terms/">What Is the CSS Box Model in Simple Terms</a></li>
<li><a href="/how-to-be-creative-with-different-css-border-styles/">CSS Border Styles Explained</a></li>
<li><a href="/coding-made-easy-with-css-selectors-an-ultimate-guide/">CSS Selectors: A Complete Guide</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>What is Scrum? 101 Guide For New Developers</title>
      <link>https://littlecodingthings.com/what-is-scrum-101-guide-for-new-developers/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/what-is-scrum-101-guide-for-new-developers/</guid>
      <pubDate>Fri, 12 Apr 2024 19:30:00 GMT</pubDate>
      <description>Scrum explained for new developers: sprints, backlog, standups, sprint planning, planning poker and retros — the jargon your first job assumes you know.</description>
      <category>Thoughts &amp; Theory</category>
      <content:encoded><![CDATA[<p>When I got my first job as a web developer, I was over the moon! Part of my everyday work was to join various meetings. In many of them, I heard unfamiliar terms about scrum repeatedly without recognizing them. Inevitably, this sparked my curiosity, leading me to research what is scrum and its associated jargon.</p>
<p>Don’t get me wrong, I could, of course, ask, I could, and I did, when I didn’t feel shy to do so (yeah, I am that kind of person… 🤷‍♂‍).</p>
<p>After learning these terms, though, I wanted to share them with you. They might help you by preparing you for interviews, for your first meetings, or if you are feeling a bit shy (though you really shouldn’t be). After all, as one of my professors used to say:</p>
<blockquote>
<p>There’s no such thing as a stupid question! Only stupid answers!</p>
</blockquote>
<p>Heads up! This post is meant to be a simplistic approach to Scrum, think about it as a friendly and practical introduction to some of Scrum’s concepts. My basic goal here is to help you become more prepared by having all the information you need when working with these concepts.</p>
<p>Ok, you’ve been warned, let’s start our exploration…</p>
<h2 id="scrum-terminology">Scrum terminology<a class="heading-anchor" href="#scrum-terminology" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><strong>Scrum</strong> is a framework, a set of “rules” and tools, used for managing projects. It has nothing to do with the way you write code and implement features. Companies use it for managing software development phases but it may also apply to other types of projects.</p>
<p>Scrum has a set of meetings, principles, and tools that were created to help teams achieve their goals faster and more efficiently.</p>
<p>Let’s check some terminology about Scrum’s tools:
(<em>I dislike terminologies too! It’s just that we need to define a few words so that we can both be on the same page</em>…)</p>
<h3 id="sprint">Sprint<a class="heading-anchor" href="#sprint" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>A sprint is a pre-determined period of 2–4 weeks (duration is agreed upon by the team), during which the team decides to achieve specific objectives. In a team of developers, these objectives would consist of implementing some features.</p>
<h3 id="backlog">Backlog<a class="heading-anchor" href="#backlog" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>A list of tasks and features that the team needs to evaluate, prioritize, and add in a sprint. You could think about it as a to-do list.</p>
<h3 id="roadmap">Roadmap<a class="heading-anchor" href="#roadmap" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>A roadmap is a plan that includes all high-level goals and milestones for a product. Picture it as a combination of the desired features the team intends to implement along with a carefully crafted timeline. By looking at a roadmap, one should have a clear overview of the path that was defined by the product team regarding the product’s vision.</p>
<h3 id="daily-scrum-aka-standup">Daily Scrum (a.k.a Standup)<a class="heading-anchor" href="#daily-scrum-aka-standup" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>A meeting that is held on a daily basis, in which each developer answers the following questions:</p>
<ul>
<li>What did you do yesterday?</li>
<li>What will you be working on today?</li>
<li>Is there anything blocking your work?</li>
</ul>
<p>Why is it called a standup? Usually, when this meeting takes place, the team creates a circle in which every member is standing. The reason behind standing up is to finish quickly your daily report and not spend more time than needed.</p>
<p>Now that we know a bit more about Scrum let’s see what is a <strong>Sprint planning</strong> meeting and how we play <strong>Scrum poker</strong>.</p>
<h2 id="sprint-planning">Sprint planning<a class="heading-anchor" href="#sprint-planning" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Before the start of a sprint, the development team and members of the product team will hold a meeting called the <strong>Sprint Planning</strong> meeting or simply <strong>Planning</strong>.</p>
<p>The goal of this meeting is to decide, usually based on priorities, which features will be implemented by the team in the upcoming sprint.</p>
<figure><img src="/sprint-planning.webp" alt="Group of people discussing in front of a kanban board" style="max-width:42%" class="img-narrow"><figcaption>Photo by Austin Distel on Unsplash</figcaption></figure>
<p>Although guidelines on what you would discuss during such meetings vary from team to team, some common discussion topics are:</p>
<ul>
<li>Which tasks from the backlog should you, as a team, implement in the new sprint?</li>
<li>Define the team’s capacity. By capacity, we mean how much work each team member can achieve during the next sprint</li>
<li>Review any new feature specifications and acceptance criteria</li>
<li>Define potential bottlenecks</li>
<li>Assign tasks/features to a developer based on their capacity</li>
</ul>
<p>Each planning is unique and may vary from team to team. So take what I describe here with a grain of salt.</p>
<p><strong>Acceptance criteria</strong> is a list of characteristics a feature should have to be considered successfully implemented.</p>
<p><strong>Bottleneck</strong> is a term used when we refer to an issue that is blocking other processes.</p>
<h2 id="scrum-poker">Scrum poker<a class="heading-anchor" href="#scrum-poker" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>During your sprint planning, and before the product manager decides to finalize it by starting the new sprint, you could hear your team members asking for <strong>poker time</strong>!</p>
<figure><img src="/poker.webp" alt="Poker scene of Casino Royal movie"><figcaption>Casino Royale</figcaption></figure>
<p>Yeah not that kind of poker, although a good poker face is always an asset! To play Scrum poker, first of all, you will need a special deck of cards, one example is seen in the image below:</p>
<figure><img src="/scrum-poker-deck.webp" alt="A scrum poker deck of cards" style="max-width:42%" class="img-narrow"><figcaption>Source: Wikipedia — Planning poker</figcaption></figure>
<p>Each card has a score, which represents the difficulty of the implementation of a feature. The larger the number, the greater the difficulty.</p>
<p>Playing poker isn’t hard at all… Scrum poker I mean. How is it played you ask? Let’s have a quick glimpse:</p>
<h3 id="preparation">Preparation<a class="heading-anchor" href="#preparation" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Every team member gets their own cards or uses scrum poker mobile apps, instead of cards, if they fancy electronic cards. They all sit together or open cameras if the team is remote.</p>
<h3 id="playing-poker">Playing poker<a class="heading-anchor" href="#playing-poker" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>One member of your team selects a feature from the ones you have decided to add in the new sprint.</p>
<p>Every member evaluates the feature by deciding on its implementation difficulty and selecting the respective card. This process is done without members sharing their thoughts or showing the card to each other. Not yet at least.</p>
<p>One member (usually from inside the team) starts a countdown, of a few seconds.</p>
<p>When the countdown ends all members show each other the scoring card they‘ve selected, for the sprint item, under evaluation.</p>
<p>If all scores are the same (yeap it can happen) this score gets assigned to the sprint item. If there are significant differences between cards, then, whoever has a card that deviates from the team’s average shares their thoughts on the reason for their selection.</p>
<p>E.g if the average amount of cards shown is 13 and one member has selected a card with the number 40, it would be nice to explain the reason. This way the team might find out if something got ignored by mistake about the item’s implementation, from the other members of the team. If the team still feels they need to stay at 13 then the score is assigned to the card, otherwise, they change it to a new one.</p>
<p>Since the evaluation of the feature has finished, The next sprint item is selected and the loop starts again. This process is repeated until all sprint items have poker scores.</p>
<h3 id="why-do-we-play-poker">Why do we play poker?<a class="heading-anchor" href="#why-do-we-play-poker" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Ok, we played poker, but why? What does this score represent for each card? This score is just a difficulty level, it means something is more difficult compared to something else. It has nothing to do with how many hours, or days it will take for a feature to be deployed.</p>
<p>But why do we care to score, based on how difficult something is?</p>
<p>Let’s say you have a team that has worked for 10 sprints, and in each sprint, the team has developed, features of, on average, 65 points. By knowing this, a product manager will be able to identify how much their team can deliver and how fast that could happen.</p>
<p>Now, wait a minute there… I used the “how much” word, right? And we said that score has nothing to do with time…
Well yeah, but in the end, it’s a metric, which will inevitably get used by the product team when a roadmap is created. It will be used to answer how soon some features may be deployed and when some goals from the product team could be reached.</p>
<p>I believe now you are ready to play some poker when requested by your team! Just don’t forget your hat and sunglasses! 🤭</p>
<p><strong><em>Hint</em></strong>_
If you have just been onboarded on your team, it may be not easy to evaluate a feature, since you may know nothing about the codebase… It makes sense, and your team knows that, so don’t feel bad about it, give it your best guess and you’ll be just fine!_</p>
<h2 id="retros">Retros<a class="heading-anchor" href="#retros" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>So your sprint has finished, you gave it your best and now it’s time for confession, the retro meeting!</p>
<p>The first time I got in a retro meeting, my manager, told me “<em>Would you like to start?</em>” and I was like… “<em>Sure… what should I say?</em>” 😇</p>
<p><strong>Retros</strong>, or <strong>Sprint retrospectives</strong>, are the best meetings of the Scrum framework! At least from my point of view. A retro meeting is set at the end of a sprint and is a powerful tool that teams use to get information about the issues they faced during the sprint.</p>
<p>During the retro, each team member reflects on what was good or bad during their sprint. As a guideline, usually, some of the questions you would see getting answered would be:</p>
<ul>
<li>What went well during the sprint?</li>
<li>Was something problematic?</li>
<li>What could be improved in the next sprint?</li>
<li>What can the team do to better support each other?</li>
<li>How can the team improve its performance?</li>
</ul>
<p>I like it because it’s a great opportunity to share your thoughts/feelings and by doing so, <strong>bond</strong> with your team. It might feel difficult to do so at your first gatherings, but after a while, you’ll love it! I’m sure!</p>
<p>It’s group therapy if you think about it 😇 and a great way to finish your sprint/week! Believe me, if you learn how to master this meeting, you will be able to help your team and also improve your workflow! Don’t be shy, you got this!</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-create-better-pull-requests-3-proven-tips/">How to Improve Pull Requests: 3 Basic Rules</a></li>
<li><a href="/a-guide-to-better-pull-requests-prerequisite-changes-and-splitting/">Better Pull Requests: Prep and Split</a></li>
<li><a href="/am-i-too-old-to-learn-coding/">Am I Too Old to Learn Coding?</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Environment Variables with Dotenv</title>
      <link>https://littlecodingthings.com/environment-variables-101-secure-your-secrets-like-a-pro/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/environment-variables-101-secure-your-secrets-like-a-pro/</guid>
      <pubDate>Mon, 08 Apr 2024 08:56:00 GMT</pubDate>
      <description>Keep API keys out of Git with dotenv. Setup for JavaScript and Rails, per-environment .env files, .gitignore, and how to print variables safely.</description>
      <category>Server Side</category>
      <content:encoded><![CDATA[<p>So you are ready to use your secret credentials for your awesome project but have no idea how to hide them from the world? You’re in the perfect place! Let’s dive into the steps you should follow to add environment variables to your project using dotenv.</p>
<p>In this post, you will find solutions for Ruby on Rails and Javascript projects. Simply select the approach that best fits your tech stack.</p>
<h2 id="why-use-environment-variables">Why use environment variables?<a class="heading-anchor" href="#why-use-environment-variables" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>I am pretty sure you already know why environment variables are essential, but just to get it out of our way, let’s take a moment and dig a bit deeper. Why do we need to use environment variables? Is it because everyone else is using them? I am sure your gut feeling tells you that’s not the case. So, what’s the main reason?</p>
<blockquote>
<p>Security is the key to all your environment variable questions</p>
</blockquote>
<p>The first and most important answer to this question is <strong>Security</strong>. Imagine you have credentials for a database with sensitive user information, like financial data. Or perhaps you have an API key that you get charged for using, e.g an API for sending emails.</p>
<p>Worth keeping the two apart in your head, by the way: environment variables protect the secrets <em>your application</em> uses. Your users’ passwords are a separate problem with a separate answer, and that one is <a href="/why-websites-dont-store-your-password/">never to store them at all</a>.</p>
<p>To use these sensitive credentials in your codebase, you’ll eventually need to hardcode them. The problem with hardcoding is that whoever accesses your code, even accidentally, could gain access to these credentials. This could lead to a major security breach, especially if they start using them for personal gain, leaving you with the charges!</p>
<p>How do we solve this? <strong>Dotenv to the rescue</strong>! 🦸‍♂️</p>
<h2 id="what-is-dotenv">What is dotenv?<a class="heading-anchor" href="#what-is-dotenv" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p><strong>Dotenv</strong> is a popular library that helps with managing variables in applications. It loads environment variables from an <code>.env</code> file to your development environment, making them accessible via the <code>process.env</code> for Javascript developers or through <code>ENV</code> for Rails developers.</p>
<p><em>In Javascript, the library’s name is <a href="https://www.npmjs.com/package/dotenv" title="dotenv">dotenv</a> and, in Rails, its name is <a href="https://rubygems.org/gems/dotenv-rails/versions/2.1.1" title="dotenv-rails">dotenv-rails</a>.</em></p>
<p>But what is an <code>.env</code> file? An <code>.env</code> file is a simple text file used to store environment variables for an application. It typically contains <code>key:value</code> pairs, like <code>API_KEY=123456</code>, and is used to keep sensitive information separate from the application code.</p>
<p>Using dotenv allows our code to pull specific values from a secure, designated location instead of hardcoding them into the codebase. These values are loaded by <code>dotenv</code> from the <code>.env</code> file.</p>
<p>dotenv is mainly for development, in production, platforms like Vercel, Netlify, Heroku, or AWS usually provide their own way of setting environment variables.</p>
<h2 id="environment-variables-for-javascript">Environment variables for Javascript<a class="heading-anchor" href="#environment-variables-for-javascript" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>As mentioned above, we will be using the <a href="http://npmjs.com/package/dotenv">dotenv</a> library for our Javascript project.</p>
<h3 id="how-to-install-dotenv">How to install dotenv?<a class="heading-anchor" href="#how-to-install-dotenv" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>The first thing we need to do is install the <code>dotenv</code> package by typing:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">npm</span><span style="color:#9ECBFF"> install</span><span style="color:#9ECBFF"> dotenv</span></span></code></pre></div>
<p><em>(In case you are wondering, <a href="/do-you-still-need-to-use-save-on-npm-install/" title="we don&#x27;t need the--save flag">we don’t need the<code>--save</code> flag</a> to record dotenv in our package.json dependencies).</em></p>
<p>The next thing we need to do is create our <code>.env</code> file by doing:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>touch .env</span></span></code></pre></div>
<p>Make sure your <code>.env</code> file is included in your <code>.gitignore</code> so you don’t accidentally commit sensitive values to your repo.</p>
<h3 id="how-to-use-dotenv">How to use dotenv?<a class="heading-anchor" href="#how-to-use-dotenv" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Great, so we have our empty <code>.env</code> file and <code>dotenv</code> installed. Let’s combine all the necessary pieces and make this work.</p>
<p>In the <code>.env</code> file, add an <code>API_KEY</code> variable like this:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>API_KEY="my super secret key here"</span></span></code></pre></div>
<p>At this point, if you try to print the <code>API_KEY</code> you won’t see anything. Although we’ve defined the variable, we haven’t properly loaded <code>dotenv</code> yet.</p>
<p>To load the <code>dotenv</code> library and make it populate all variables from our <code>.env</code> file, simply add the following line to your code:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">require</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'dotenv'</span><span style="color:#E1E4E8">).</span><span style="color:#B392F0">config</span><span style="color:#E1E4E8">();</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">// or ES6 if you have "type": "module" enabled in your package.json</span></span>
<span class="line"><span style="color:#F97583">import</span><span style="color:#9ECBFF"> "dotenv/config"</span><span style="color:#E1E4E8">;</span></span></code></pre></div>
<p>Make sure to add this line at the very beginning of your code to load environment variables as early as possible.</p>
<p>By loading dotenv, all variables from our <code>.env</code> file are added to <code>process.env</code> (in JavaScript) or <code>ENV</code> (in Rails).</p>
<h2 id="environment-variables-for-rails">Environment variables for Rails<a class="heading-anchor" href="#environment-variables-for-rails" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>For our Rails project, we’ll be using <code>dotenv-rails</code> to manage environment variables. Here’s how to set it up and use it effectively:</p>
<h3 id="how-to-install-dotenv-rails">How to install dotenv rails?<a class="heading-anchor" href="#how-to-install-dotenv-rails" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>In your <code>Gemfile</code> add the following line</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>  gem 'dotenv-rails'</span></span></code></pre></div>
<p>Remember, you need to activate this for your <code>development</code> and <code>test</code> environment, so if you have used the Rails generator, you will see the development/test group near the bottom of your <code>Gemfile</code>. That’s where you need to add your new <code>dotenv-rails</code> gem.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>group :development, :test do</span></span>
<span class="line"><span>  gem 'dotenv-rails' # add this line</span></span>
<span class="line"><span>end</span></span></code></pre></div>
<p>Otherwise, you could also add the following code:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>gem 'dotenv-rails', groups: [:development, :test]</span></span></code></pre></div>
<p>You need to create an <code>.env</code> file now in which you’ll be adding all your environment variables. In your terminal, type:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>touch .env</span></span></code></pre></div>
<p>Let’s now proceed with installing the new gem that we added to our Gemfile:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>bundle install</span></span></code></pre></div>
<h3 id="how-to-use-dotenv-rails">How to use dotenv rails?<a class="heading-anchor" href="#how-to-use-dotenv-rails" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Suppose we have the following env variable in our <code>.env</code> file</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>MY_VARIABLE="cool-password-here"</span></span></code></pre></div>
<p>Depending on where you are, you might see the following ways to access your environment variable</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>value = ENV["MY_VARIABLE"]</span></span></code></pre></div>
<p>or in a YAML file, e.g <code>database.yml</code></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>&#x3C;%= ENV.fetch("MY_VARIABLE") %></span></span></code></pre></div>
<h3 id="different-env-files-per-environment">Different .env files per environment<a class="heading-anchor" href="#different-env-files-per-environment" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>In some cases, you will need to use different <code>.env</code> files per environment.</p>
<p>Common setups are:</p>
<ul>
<li>A single<code>.env</code> file for all environments</li>
<li>Separate <code>.env</code> files for each environment, such as <code>.env.development</code>, <code>.env.test</code> and <code>.env.production</code>.</li>
</ul>
<p>This approach may make it easier for you to manage environment-specific settings and needs.</p>
<p>Not everything you keep here has to be a secret, by the way. A variable like <code>LOG_LEVEL</code> is a good example — it holds no credentials, but having it differ per environment is exactly the point, so you can run <a href="/how-to-set-up-pino-logging-in-next-js/">Pino logging in Next.js</a> at <code>debug</code> on your machine and <code>info</code> in production without touching the code.</p>
<h3 id="how-to-create-an-env-template-file">How to create an .env template file?<a class="heading-anchor" href="#how-to-create-an-env-template-file" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Regardless of the names you’ve included in your .env files, sharing them with your team can pose challenges since you won’t be including the .env file in your repository, for security reasons.</p>
<p>So, if you’re not sharing the <code>.env</code> file, how will your team – or anyone else working on the codebase – know which variable names to use?</p>
<p>The solution is to create an <code>.env</code> template file that lists all your variable keys but <strong>NOT</strong> their values. Once you’ve set up your <code>.env</code> file and are ready to create a template, run the following command in your terminal:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span># where .env is an example of a file name, yours maybe different.</span></span>
<span class="line"><span></span></span>
<span class="line"><span>dotenv -t .env</span></span></code></pre></div>
<p>By doing so you will see a newly generated env file which will have the same keys as in the <code>.env</code>, but only placeholders as their respective values.</p>
<p>So, suppose we have the following <code>.env</code></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>MY_DB_PASSWORD="my db password"</span></span>
<span class="line"><span>MY_AUTH_PASSWORD="my auth password"</span></span></code></pre></div>
<p>by executing the env template command, we’ll get the following <code>.env.template</code> file</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>MY_DB_PASSWORD=MY_DB_PASSWORD</span></span>
<span class="line"><span>MY_AUTH_PASSWORD=MY_AUTH_PASSWORD</span></span></code></pre></div>
<p>The <code>.env.template</code> file can be shared with your team members with no fear. Afterward, you’ll just need to find a secure way to share the actual env values so they can replace the placeholders and use them instead.</p>
<p>Unfortunately, templating doesn’t work for Node, so you will have to do it manually.</p>
<h2 id="add-env-files-to-gitignore">Add .env files to .gitignore<a class="heading-anchor" href="#add-env-files-to-gitignore" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>So far, we’ve discussed creating and using an <code>.env</code> file, but how can we prevent it from being accidentally committed to version control?</p>
<p>To ignore our <code>.env</code> files, we need to add to our <code>.gitignore</code> file:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>.env</span></span></code></pre></div>
<p>This way, we are ignoring our <code>.env</code> file and not our <code>.env-template</code> (if we have generated one).</p>
<p>In case we have more than one .env files, e.g <code>.env.production</code> and <code>.env.test</code> and we want to ignore these but not the template file we will have to change our previous entry to:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>.env*</span></span>
<span class="line"><span>!.env.template</span></span></code></pre></div>
<p>Try testing this by running <code>git status</code> to ensure the <code>.env</code> file is indeed being ignored before committing your code. It’s always a good idea to double-check and validate your setup to avoid accidental commits.</p>
<p>Make sure to add your sensitive files to <code>.gitignore</code> to prevent them from being committed! This simple step protects your sensitive data from accidental exposure.</p>
<p>For more configuration settings, check the <a href="https://github.com/bkeepers/dotenv#installation" title="dotenv GitHub">dotenv GitHub</a> page.</p>
<h2 id="frequently-asked-questions-">Frequently Asked Questions 🤔<a class="heading-anchor" href="#frequently-asked-questions-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<h3 id="should-i-use-vites-dotenv-or-dotenv-package">Should I use Vite’s dotenv or dotenv package?<a class="heading-anchor" href="#should-i-use-vites-dotenv-or-dotenv-package" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><a href="https://v2.vitejs.dev/guide/env-and-mode.html#env-files" title="Vite is using dotenv to load environment variables from specific files">Vite is using dotenv to load environment variables from specific files</a> like e.g <code>.env</code>, <code>.env.local</code>. Because of this you don’t need to install <code>dotenv</code> separately, you just need to create these files in your project and use them.</p>
<p>I would suggest staying with Vite’s approach for simple projects. If you need more control and flexibility. then consider installing the <code>dotenv</code> package</p>
<h3 id="which-command-prints-partial-or-full-environment-variables">Which command prints partial or full environment variables?<a class="heading-anchor" href="#which-command-prints-partial-or-full-environment-variables" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Let’s assume our variable’s key is <code>API_KEY</code>. To print its value, we have the following commands available:</p>
<h3 id="for-javascript">For Javascript<a class="heading-anchor" href="#for-javascript" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong>In your codebase:</strong></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">// To print all environment variables, use:</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">console.</span><span style="color:#B392F0">log</span><span style="color:#E1E4E8">(process.env);</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D">// Or to print a specific variable:</span></span>
<span class="line"></span>
<span class="line"><span style="color:#E1E4E8">console.</span><span style="color:#B392F0">log</span><span style="color:#E1E4E8">(process.env.</span><span style="color:#79B8FF">API_KEY</span><span style="color:#E1E4E8">);</span></span></code></pre></div>
<p><strong>In your terminal:</strong></p>
<p>Environment variables from your project’s <code>.env</code> file are not loaded as a part of your shell’s environment. Your shell’s session keeps track of its own set of variables. So, if you try to do something like <code>printenv API_KEY</code> it won’t work unless you have explicitly exported your app’s <code>.env</code> file’s variables in your shell’s session.</p>
<p>To be able to print your project’s variables while inside a shell, you need to load them first by doing:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>source .env</span></span></code></pre></div>
<p>The <code>source</code> command will load your <code>.env</code> file variables directly in your shell’s session. By doing that, you now can type</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>echo $API_KEY</span></span></code></pre></div>
<p>and see the value of your variable. Remember, though, that this will be temporary and only for your current shell session. If you close your terminal and start another session, your variables will not be available unless you reload them.</p>
<h3 id="for-rails">For Rails<a class="heading-anchor" href="#for-rails" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong>In your codebase:</strong></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D"># To print all environment variables, use:</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">puts</span><span style="color:#79B8FF"> ENV</span><span style="color:#E1E4E8">.</span><span style="color:#B392F0">inspect</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A737D"># Or to print a specific variable:</span></span>
<span class="line"></span>
<span class="line"><span style="color:#79B8FF">puts</span><span style="color:#79B8FF"> ENV</span><span style="color:#E1E4E8">[</span><span style="color:#9ECBFF">'API_KEY'</span><span style="color:#E1E4E8">]</span></span></code></pre></div>
<p>For terminal use, it’s the same as Javascript.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/do-you-still-need-to-use-save-on-npm-install/">Do You Still Need npm install --save?</a></li>
<li><a href="/docker-docker-compose-commands-i-keep-forgetting-cheat-sheet/">Docker &#x26; Docker Compose Cheat Sheet</a></li>
<li><a href="/how-to-install-postgres-on-macos/">How to Install Postgres on MacOS</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How to Embed CodePen in a WordPress Blog</title>
      <link>https://littlecodingthings.com/how-to-embed-codepen-in-a-wordpress-blog/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-embed-codepen-in-a-wordpress-blog/</guid>
      <pubDate>Thu, 04 Apr 2024 18:55:00 GMT</pubDate>
      <description>How to embed a CodePen project in a WordPress blog properly, and how to fix the “referer required” error that pasting the project URL gives you.</description>
      <category>Setup &amp; Tools</category>
      <content:encoded><![CDATA[<p>In this post, we’ll learn how to embed Codepen projects in WordPress the right way. If you are here, chances are, you have tried to embed a project and got an error about a referer required by Codepen.</p>
<p><img src="/codepen-referrer-error.webp" alt="Codepen information message: Do not enter passwords or personal information on this page"></p>
<p>I might also be right to assume that you did so by copy-pasting the project’s URL on your website while trying to do so.</p>
<p>Let’s explore a different way to embed Codepen projects without getting this error. The first thing you need to do is visit the project you would like to embed. While on the project’s page check to the bottom right and find a button labelled <strong>“Embed”</strong>.</p>
<figure><img src="/codepen-embed-button.webp" alt="Codepen screesnshot - Embed button located on bottom left on Codepen project"><figcaption><a href="https://codepen.io/marilenakarp/pen/oNdJqmy" title="Codepen project by Marilena">Codepen project by Marilena</a></figcaption></figure>
<p>Click on it and you will see a modal popping up with the following options:</p>
<p><em>(We have added colored light blue numbers in the following image to help you out with each setting)</em></p>
<p><img src="/codepen-embed-settings.webp" alt="Codepen screesnshot - Embed process available settings"></p>
<p><strong>1️⃣</strong> <strong>Default tabs</strong> – Here, you have the option to choose which tab will be initially displayed as selected.</p>
<p><strong>2️⃣</strong> <strong>Theme</strong> – Select if you would like to show your embedding in a light, dark, or custom theme.</p>
<p><strong>3️⃣</strong> <strong>Click to load</strong> – By enabling this setting your embedding will not load by default, it will rather show a “<em>Run Pen</em> ⚙️” cta at the bottom of your embedding preview.</p>
<p><strong>4️⃣ Code Editable</strong> – Enable this setting if you would like to provide your viewers with the ability to edit the embedded pen in real time.</p>
<p><strong>5️⃣</strong> <strong>Code snippet type</strong> – Each tab (HTML, WordPress, etc.) shows a different type of code snippet you need for your embedding. The type you need depends on your WordPress Editor so you’d better check the <a href="https://blog.codepen.io/documentation/wordpress-plugin/" title="Embeds Codepen&#x27;s guide">Embeds Codepen’s guide</a> to be sure what to select.</p>
<p><strong>6️⃣</strong> <strong>Copy code</strong> – Rather than manually selecting the code snippet, simply click this button to copy it. 😋</p>
<p><strong>Adjusting height</strong></p>
<p>There is a way to adjust the height of your embedding which is often easily overlooked. While on the embedding settings modal, hover over the bottom border on your preview screen, click on it, and adjust your height according to your needs.</p>
<p><img src="/codepen-height.webp" alt="Codepen recorded gif showing how to adjust height of embeded preview while setting it up"></p>
<p>An alternative approach could involve directly modifying the value of the <code>data-height</code> attribute within your code snippet to your desired value.</p>
<p>Finally, to embed your pen, go to your WordPress editor, type /shortcode, and press Enter.</p>
<p><img src="/codepen-shortcode.webp" alt="How to embed codepen in WordPress: Using WordPress shortcode to embed your codepen"></p>
<p>Paste the code snippet you copied from Codepen where it says: “<em>Write shortcode here</em>“.</p>
<p>Saving your post and previewing your changes should look something like:</p>
<p>See the Pen<a href="https://codepen.io/marilenakarp/pen/oNdJqmy">
Avatar with Shine Effect</a> by MarilenaKarp (<a href="https://codepen.io/marilenakarp">@marilenakarp</a>)
on <a href="https://codepen.io">CodePen</a>.</p>
<h2 id="the-four-ways-to-embed-a-pen-and-when-each-one-is-right">The four ways to embed a pen, and when each one is right<a class="heading-anchor" href="#the-four-ways-to-embed-a-pen-and-when-each-one-is-right" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>“Embed a CodePen” means four different things depending on where you paste it, and only some of them survive WordPress. Roughly worst to best:</p>
<p><strong>1. Pasting the pen URL on its own line.</strong> What most of us try first, and the route that produced the error that brought you here. CodePen’s own documentation is blunt about it too — the block editor’s default embed gives you <em>“very little in the way of customization”</em>. No height control, no theme, no default tab.</p>
<p><strong>2. The HTML embed.</strong> The snippet from the Embed modal that starts with a <code>&#x3C;p class="codepen"></code> and ends with a <code>&#x3C;script></code> tag pointing at <code>https://cpwebassets.codepen.io/assets/embed/ei.js</code>. This is the one with all the settings baked in, and it’s what you want in a <strong>Custom HTML</strong> block.</p>
<p><strong>3. The <code>[codepen_embed]</code> shortcode.</strong> CodePen publishes a WordPress plugin that provides this shortcode, which is what the <code>/shortcode</code> step above is for. Handy if you embed pens often and don’t fancy pasting a <code>&#x3C;script></code> tag every time.</p>
<p><strong>4. A plain <code>&#x3C;iframe></code>.</strong> The one nobody mentions. Take your pen URL and change <code>/pen/</code> to <code>/embed/</code>:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>https://codepen.io/marilenakarp/embed/oNdJqmy</span></span></code></pre></div>
<p>That URL is a complete, self-contained embed. Drop it into an iframe and you’re done — no script tag, nothing for a security plugin to strip. It’s my fallback whenever a site refuses to run CodePen’s embed script.</p>
<h2 id="tweaking-the-embed-after-youve-pasted-it-️">Tweaking the embed after you’ve pasted it 🎛️<a class="heading-anchor" href="#tweaking-the-embed-after-youve-pasted-it-️" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Every setting in that modal is just a <code>data-</code> attribute in the snippet, which means you can change your mind later by editing one word instead of going back to CodePen. These are the ones documented by CodePen and the ones you’ll actually reach for:</p>
<table>
<thead>
<tr>
<th scope="col">Attribute</th>
<th scope="col">What it does</th>
<th scope="col">Default</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row"><code>data-slug-hash</code></th>
<td>Which pen to show — the ID from the URL</td>
<td>required</td>
</tr>
<tr>
<th scope="row"><code>data-user</code></th>
<td>The pen’s author</td>
<td>—</td>
</tr>
<tr>
<th scope="row"><code>data-height</code></th>
<td>Embed height in pixels; accepts <code>"100%"</code></td>
<td><code>300</code></td>
</tr>
<tr>
<th scope="row"><code>data-default-tab</code></th>
<td>Which tab opens first: <code>html</code>, <code>css</code>, <code>js</code> or <code>result</code></td>
<td><code>result</code></td>
</tr>
<tr>
<th scope="row"><code>data-theme-id</code></th>
<td>The embed theme</td>
<td><code>0</code></td>
</tr>
<tr>
<th scope="row"><code>data-preview</code></th>
<td>Click-to-load instead of running immediately</td>
<td>off</td>
</tr>
<tr>
<th scope="row"><code>data-animations</code></th>
<td><code>run</code> or <code>stop-after-5</code></td>
<td><code>run</code></td>
</tr>
<tr>
<th scope="row"><code>data-border</code></th>
<td><code>none</code>, <code>thin</code> or <code>thick</code></td>
<td><code>none</code></td>
</tr>
<tr>
<th scope="row"><code>data-zoom</code></th>
<td>Scales the preview: <code>1</code>, <code>0.5</code> or <code>0.25</code></td>
<td><code>1</code></td>
</tr>
</tbody>
</table>
<p><code>data-default-tab</code> is the one that earns its keep on a blog. If the point of the post is <em>the code</em>, sending readers to a rendered result they have to click away from is backwards — set it to <code>css</code> or <code>js</code> and they land on what you were writing about.</p>
<h2 id="use-data-preview-if-you-embed-more-than-one-pen-per-post-">Use <code>data-preview</code> if you embed more than one pen per post ⚡<a class="heading-anchor" href="#use-data-preview-if-you-embed-more-than-one-pen-per-post-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>This is the setting labelled <strong>Click to load</strong> back in the modal, and it matters more than it sounds.</p>
<p>Every live embed is an iframe that loads CodePen, runs your HTML, CSS and Javascript, and pulls in whatever external libraries the pen depends on. Four of those on one page is four small websites booting up before your reader has scrolled far enough to see any of them.</p>
<p>With click-to-load, the reader gets a still preview and a “Run Pen” button, and nothing executes until they ask for it. The pens nobody clicks cost nothing at all.</p>
<h2 id="when-the-embed-just-doesnt-show-up">When the embed just doesn’t show up<a class="heading-anchor" href="#when-the-embed-just-doesnt-show-up" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>A few failure modes that look mysterious and aren’t:</p>
<ul>
<li><strong>You see the raw code instead of the pen.</strong> The snippet went into a paragraph block rather than a Custom HTML block, so WordPress escaped it and printed it. Move it into a Custom HTML block.</li>
<li><strong>The block is empty on the live site but fine in the editor.</strong> Something is stripping the <code>&#x3C;script></code> tag — usually a security plugin, a caching layer, or user permissions that don’t allow unfiltered HTML. Switch to the <code>/embed/</code> iframe method above and the problem disappears, because there’s no script to strip.</li>
<li><strong>The embed is the wrong height and clips the result.</strong> Edit <code>data-height</code> directly. The drag handle in the modal writes this same number, so there’s no reason to go back and re-copy the snippet.</li>
<li><strong>The embed shows an older version of your pen.</strong> Embeds serve the <em>saved</em> pen. Unsaved changes sitting open in your CodePen tab aren’t part of it — save the pen and reload the post.</li>
</ul>
<h2 id="frequently-asked-questions">Frequently asked questions<a class="heading-anchor" href="#frequently-asked-questions" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<h3 id="can-readers-edit-the-code-inside-an-embedded-pen">Can readers edit the code inside an embedded pen?<a class="heading-anchor" href="#can-readers-edit-the-code-inside-an-embedded-pen" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>They can be allowed to, using the <strong>Code Editable</strong> option in the embed settings. Their changes are theirs alone — nothing they type touches your original pen. It’s a lovely thing to enable on a tutorial, because “try changing this number” stops being a suggestion and becomes something they can just do.</p>
<h3 id="will-an-embedded-pen-slow-down-my-blog">Will an embedded pen slow down my blog?<a class="heading-anchor" href="#will-an-embedded-pen-slow-down-my-blog" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Yes, a little, and noticeably if you embed several. Each one is a live iframe. Turn on click-to-load (<code>data-preview</code>) when you have more than one on a page, and consider whether a plain code block would serve the reader better for a snippet that doesn’t need to <em>run</em>.</p>
<h3 id="what-happens-to-my-post-if-i-delete-the-pen">What happens to my post if I delete the pen?<a class="heading-anchor" href="#what-happens-to-my-post-if-i-delete-the-pen" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>The embed breaks. Anything embedded from a third-party service is a link you don’t control — if the pen is deleted, or the account goes, the box on your post goes with it. For code you genuinely care about keeping, paste it into the post as well.</p>
<h3 id="can-i-embed-a-pen-in-a-specific-state-like-showing-only-the-css">Can I embed a pen in a specific state, like showing only the CSS?<a class="heading-anchor" href="#can-i-embed-a-pen-in-a-specific-state-like-showing-only-the-css" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Yes — that’s <code>data-default-tab</code>. Set it to <code>css</code> and the embed opens on the CSS panel rather than the rendered result.</p>]]></content:encoded>
    </item>
    <item>
      <title>How to Center in CSS Using Different Ways</title>
      <link>https://littlecodingthings.com/how-to-center-in-css-using-different-ways/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-center-in-css-using-different-ways/</guid>
      <pubDate>Mon, 01 Apr 2024 12:32:00 GMT</pubDate>
      <description>Four ways to centre an element in CSS — flexbox, grid, place-items and absolute positioning — compared on the same box, plus what to avoid.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>In this post, we will explore how to center elements in CSS using various methods and make our lives, as developers, much easier. Are you ready to dive deeper? Take your snorkel 🤿 and follow me!</p>
<p>As in life, so in programming, placing items in a way that will be helpful or more beautiful, is one of the most important things you can achieve. There are plenty of ways to place or **position (**in programming terms) items, although it still remains quite a challenge. </p>
<p>We will start by adding our basic HTML &#x26; CSS structure:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">body</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"parent"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"child"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">body</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.parent</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">200</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.child</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  width</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  height</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">100</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Now, we can move forward. 😕 Don’t worry — everything is going to be okay! We‘ll go step by step together and continue working only on CSS.</p>
<p>Below are two images. The left one shows what was rendered through our code above, and the right one shows what we want to achieve. 
<strong><em>Let’s get started!</em></strong> 💪</p>
<p><img src="/center-div-outlet.webp" alt="Center in CSS: We see two images. The left one shows what was rendered through our code above, a small box in the left-up corner inside a big box. The right one shows what we want to achieve, to center the small box inside the big box." style="max-width:42%" class="img-narrow"></p>
<h2 id="center-in-css-usingflexbox">Center in CSS using flexbox<a class="heading-anchor" href="#center-in-css-usingflexbox" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>First, a few words about flexbox. 😇 <strong>Flexbox</strong> is a modern layout model, in simpler words, a way to easily position our HTML elements in rows or columns. It provides multiple ways, through CSS, to organize our layout and at the same time be flexible and responsive on different devices.</p>
<h3 id="basic-steps-for-centering-html-elements-using-flexbox">Basic steps for centering HTML elements using flexbox<a class="heading-anchor" href="#basic-steps-for-centering-html-elements-using-flexbox" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>The basic property for flexbox is the <code>display</code> property. Using <code>display: flex</code> is not gonna give us something but it is necessary if we want to work with the other flexbox properties.</p>
<p>To center HTML elements we have to use <code>align-items</code> &#x26; <code>justify-content</code> properties. <code>align-items: center</code> centers child elements <strong>vertically</strong> &#x26; <code>justify-content: center</code> centers child-elements <strong>horizontally</strong>.</p>
<p>All these three properties combined give us the desired outcome, as seen in the code snippet below:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.parent</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">flex</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  align-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span><span style="color:#6A737D">/* centers vertically */</span></span>
<span class="line"><span style="color:#79B8FF">  justify-content</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span><span style="color:#6A737D">/* centers horizontally */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/center-div-axis-display-flex.webp" alt="Center in CSS: Here we have three images. The first one shows a small box in the left-up corner inside a big box. We use align-items: center property and we centered the small box vertically inside the big box. The second one shows a small box in the left-up corner inside a big box. We use justify-content: center and we center the small box horizontally inside the big box. The third box shows what we want to achieve, to center the small box inside the big box, by combining these two properties." style="max-width:56%" class="img-narrow"></p>
<h2 id="center-in-css-usinggrid">Center in CSS using Grid<a class="heading-anchor" href="#center-in-css-usinggrid" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>There is a small prologue for the grid here. 😇 The grid is a layout system. There is a basic difference between flexbox and grid. Flexbox is one-dimensional (best suited for small-scale layouts) while grid is two-dimensional (best suited for large-scale layouts).</p>
<p>In simple words, with flexbox we work in rows or columns while with grid, we work on both at the same time. Grid layout makes it easier to create complex, responsive designs that adapt to different screen sizes and orientations.</p>
<blockquote>
<p>Flexbox &#x26; grid
can work together
and complement
each other</p>
</blockquote>
<h3 id="using-align-self-and-justify-self">Using align-self and justify-self<a class="heading-anchor" href="#using-align-self-and-justify-self" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>As in flexbox, the basic property for the grid is the <code>display</code> property. Using <code>display: grid</code> is not gonna give us something but it is necessary if we want to work with the other properties. By setting the display property of an element to a grid, the element becomes a container for grid elements, which can be positioned using the grid layout.</p>
<p>To center HTML elements we have to use <code>align-self</code> &#x26; <code>justify-self</code> properties. <code>align-self: center</code> centers child-elements <strong>vertically</strong> and <code>justify-self: center</code> centers child-elements <strong>horizontally</strong>.
All these three properties combined give us the desired outcome, as seen in the code snippet below:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.parent</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">grid</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.child</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  align-self</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* centers vertically */</span></span>
<span class="line"><span style="color:#79B8FF">  justify-self</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* centers horizontally */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/center-div-axis-display-grid.webp" alt="Center in CSS:  Here we have three images. The first one shows a small box in the left-up corner inside a big box. We use align-self: center property and we centered the small box vertically inside the big box. The second one shows a small box in the left-up corner inside a big box. We use justify-self: center and we center the small box horizontally inside the big box. The third box shows what we want to achieve, to center the small box inside the big box, by combining these two properties." style="max-width:56%" class="img-narrow"></p>
<h3 id="using-place-items">Using place-items<a class="heading-anchor" href="#using-place-items" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Another way to center HTML elements through a grid is with place-items property. <code>place-items: center</code> centers child elements <strong>vertically</strong> &#x26; <strong>horizontally</strong> at the same time.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.parent</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  display</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">grid</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  place-items</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* centers vertically &#x26; horizontally at the same time */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/center-div-grid-auto-flow-margin-auto-methods-1.webp" alt="Center in CSS:  We see two images. The left one shows what was rendered through our code above, a small box in the left-up corner inside a big box. The right one shows what we want to achieve, to center the small box inside the big box." style="max-width:35%" class="img-narrow"></p>
<h2 id="center-in-css-using-positioning">Center in CSS using Positioning<a class="heading-anchor" href="#center-in-css-using-positioning" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>At this point, a few words about positioning property would be helpful, I suppose. 😇 CSS position property defines the position of an HTML element in a document. There are five types of <a href="/coding-made-easy-with-css-selectors-an-ultimate-guide/">positioning</a>:</p>
<ul>
<li>static</li>
<li>relative</li>
<li>absolute</li>
<li>fixed</li>
<li>and sticky</li>
</ul>
<p>In this post, we will use <code>position: relative</code> &#x26; <code>position: absolute</code> . By default the position property of HTML elements is <code>static</code>. That means that our flow (direction of HTML elements) follows HTML order and goes from top to bottom. If we want to change this flow we have to change the position property. </p>
<p><code>Position: relative</code> works exactly as position static but <strong>allows you to change the position of an HTML element</strong>. In simple words, you can now move your HTML element, for example, 20px left. </p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.examRel</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">20</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><code>Position: absolute</code> takes the element out of the normal flow and <strong>places it relative to its closest positioned ancestor</strong> — that is, the nearest parent whose <code>position</code> is anything other than <code>static</code>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.examAbs</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">40</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>🤔 So if we have two HTML elements and we want to put one (which we used to call child-element) inside the other (which we used to call parent-element) all we have to do is put <strong>position relative to the parent and position absolute to the child</strong>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.examParent</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* parent element */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.examChild</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* child element */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h3 id="using-transform-and-translate">Using transform and translate<a class="heading-anchor" href="#using-transform-and-translate" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>First of all, we set <code>position: relative</code> to our parent element. Secondly, we set <code>position: absolute</code> to our child element. Then we set <code>left: 50%</code> and <code>top: 50%</code> to move the child-element from the parent, using as a reference the child’s top-left edge (see <strong>black</strong> dot).</p>
<p>To finalize our centering, we use <code>transform: translate(-50%, -50%)</code> to align the <strong><em>middle</em></strong> of the child element (green dot) to the middle of the parent element.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.parent</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.child</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  transform</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">translate</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">, </span><span style="color:#79B8FF">-50</span><span style="color:#F97583">%</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/center-div-transform-translate-method.webp" alt="Center html elements: We see four images. The first image shows what was rendered through our code above, a small box in the left-up corner inside a big box. The second image shows. The third image shows. The last image shows what we want to achieve, to center the small box inside the big box." style="max-width:63%" class="img-narrow"></p>
<h3 id="using-margin-auto">Using margin: auto<a class="heading-anchor" href="#using-margin-auto" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>First of all, we set <code>position: relative</code> to our parent element. Secondly, we set <code>position: absolute</code> to our child element. Then we set <code>left: 0</code> <code>top: 0</code> <code>right: 0</code> <code>bottom: 0</code> . By doing so**,** the child element will fill all available space of the parent container.</p>
<p>Finally, we use <code>margin: auto</code>. Using the margin property lets the browser calculate the appropriate margin for the child element and divide the space evenly. It centers our element <strong>horizontally</strong> &#x26; <strong>vertically</strong> at the same time.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.parent</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">relative</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.child</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#79B8FF">  position</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">absolute</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  top</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  bottom</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">0</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  margin</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">auto</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* centers vertically &#x26; horizontally at the same time */</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/center-div-grid-auto-flow-margin-auto-methods.webp" alt="Center html elements: We see two images. The left one shows what was rendered through our code above, a small box in the left-up corner inside a big box. The right one shows what we want to achieve, to center the small box inside the big box." style="max-width:35%" class="img-narrow"></p>
<p>📢 <strong><em>Warning:</em></strong> you need to set a <strong>fixed</strong> width to the HTML element you are trying to center (in our case the child element). Otherwise, it won’t work!</p>
<h2 id="dos-for-css-centering">Dos for CSS centering<a class="heading-anchor" href="#dos-for-css-centering" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>If instead of a box, you have to center a div or even a whole paragraph you can use all these methods described above! To do so, remember <strong>NOT</strong> to add <code>width</code> and <code>height</code> to the child and just let the child get its dimensions based on the included text. This way when centering the child it will be the same as centering the text, check the image below:</p>
<p><img src="/center-div-dos.webp" alt="Center in CSS - Donts - Image showing a Hello string centered using width" style="max-width:35%" class="img-narrow"></p>
<p>If you decide, though, to add bigger dimensions, bigger than your text, I mean, you need to be careful. By doing so you might end up centering the child element but not its content, the text.</p>
<p><img src="/center-div-donts.webp" alt="Center in CSS - Donts - Image showing a Hello string centered using width" style="max-width:35%" class="img-narrow"></p>
<h2 id="donts-for-css-centering">Don’ts for CSS centering<a class="heading-anchor" href="#donts-for-css-centering" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>🥵 <strong>DO NOT</strong> center elements using huge paddings. It may seem easy at first but it is considered to be extremely risky and error-prone. Especially now that we have to deal with all these different screen sizes. You will be forced to change paddings again and again with media queries. (<code>@media only screen and (max-width: 600px) { }</code>).</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/what-is-the-css-box-model-in-simple-terms/">What Is the CSS Box Model in Simple Terms</a></li>
<li><a href="/css-box-sizing-better-implementations-less-headaches/">CSS box-sizing: border-box Explained</a></li>
<li><a href="/how-to-effectively-use-css-transform-scale-on-hover/">CSS Scale on Hover with transform</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Better Pull Requests: Prep and Split</title>
      <link>https://littlecodingthings.com/a-guide-to-better-pull-requests-prerequisite-changes-and-splitting/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/a-guide-to-better-pull-requests-prerequisite-changes-and-splitting/</guid>
      <pubDate>Sun, 31 Mar 2024 22:47:00 GMT</pubDate>
      <description>Split a large feature into reviewable pull requests using prerequisite changes and well-scoped commits, worked through on a real full-stack example.</description>
      <category>Thoughts &amp; Theory</category>
      <content:encoded><![CDATA[<p>There will be times when you will be working on huge features (if you haven’t already 😎), some of which could take weeks and some even months. During your implementation, you will have to find a way to create better pull requests and try to write kickass code, all while figuring out how to make the review process better. After all, better reviews mean fewer <a href="/the-unique-origin-of-the-term-bug-in-software-development/">bugs</a>, right?</p>
<p>In our previous post, we discussed some ideas for <a href="/how-to-create-better-pull-requests-3-proven-tips/" title="improving pull requests">improving pull requests</a> <strong>after</strong> a pull request has been created. However, sometimes, improving a pull request may require actions to be taken <strong>before</strong> our initial commit.</p>
<p>So how can one create a better pull request before even committing their changes? The answer lies in carefully planning the steps of implementation before starting the actual implementation process. Whaaat? 🫨</p>
<figure><img src="/mind-blown.webp" alt="FX Networks series - Mind blown gif" style="max-width:67%" class="img-narrow"><figcaption>Source: <a href="https://giphy.com/gifs/cakefx-cake-fxx-fx-networks-kH66pmpo7NjIgtI696" title="Giphy">Giphy</a></figcaption></figure>
<p>Let’s decide on an example or a use case so that we can discuss our theory on common ground.</p>
<h2 id="a-full-stack-feature-use-case">A full-stack feature use case<a class="heading-anchor" href="#a-full-stack-feature-use-case" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>(<em>This is a use case with <em>simplified</em> specs, used only as an example for this post, to ensure that we are both on the same page when discussing the topic at hand</em>)</p>
<p>To illustrate, let’s suppose we were asked to implement a new full-stack feature. In our example, we’ll assume that we want to add a new comments section to our blog.</p>
<p>After having a design session with our team, the following specs were requested:</p>
<h3 id="use-case--feature-specs">Use case – Feature specs<a class="heading-anchor" href="#use-case--feature-specs" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><strong>specs_,_</strong> short for specifications, outline the requirements a new feature implementation must meet to pass QA testing and be deployed.</p>
<ul>
<li>In the existing post section, a new comments section will be added where readers can view and add comments related to the post.</li>
<li>Both the writer and the admin will be able to add, edit, and delete any type of comment.</li>
<li>A reader will also have the ability to add/edit/delete their own comments.</li>
<li>Show statistics for each post’s comments.</li>
</ul>
<h2 id="prerequisite-changes">Prerequisite changes<a class="heading-anchor" href="#prerequisite-changes" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>It’s considered good practice to always take a step back and carefully consider the steps you should follow to implement a feature before diving headfirst. As the saying goes:</p>
<blockquote>
<p>Measure twice
Cut once!</p>
</blockquote>
<p>But how does this relate to creating better pull requests?</p>
<p>Well, in my opinion, when thinking about a feature’s implementation, the potential outcomes typically fall into the following categories:</p>
<ul>
<li>Ways to achieve the desired outcome</li>
<li>Challenging code areas that may need refactoring beforehand</li>
<li>Necessary changes that are not directly related to the feature</li>
</ul>
<p>(<em>This list is not that comprehensive</em>! 😋)</p>
<p>Both the last two items on the list are related to prerequisite changes that need to be made before the feature is successfully implemented. Some examples of these changes could be:</p>
<ul>
<li>Introducing a new package dependency that needs to be used by your feature</li>
<li>Introducing some reusable components (this is also the moment to settle on a <a href="/naming-conventions-how-to-name-your-components-without-fighting-your-ui-library/">naming convention for your components</a>, especially if your UI library already has a <code>&#x3C;Modal /></code> of its own — renaming them later is its own painful pull request)</li>
<li>Perform some code cleanup before introducing new code</li>
</ul>
<p>By identifying similar changes early on, you can significantly streamline your feature’s review process. Rather than creating one massive pull request that could make your colleagues’ lives challenging, you could create initial pull requests with independent changes, merge them, and continue with your feature implementation. In the follow</p>
<h3 id="identifying-our-use-case-prerequisite-changes">Identifying our use case prerequisite changes<a class="heading-anchor" href="#identifying-our-use-case-prerequisite-changes" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>While thinking about the feature’s implementation, I realized that it would be beneficial to introduce some distinct roles for our users, such as readers, writers, and admins. Additionally, since we have decided that we need statistics, I did some research and came across a fantastic statistics package to use for displaying how many comments a writer has over time.</p>
<p>Although both changes are connected to our feature implementation, it’s worth considering the extent of their interdependence. Could we introduce these two changes and deploy them without completing our feature? The answer is yes! But how?</p>
<p>These two changes, along with any necessary tests, could be included in different branches from which we would create pull requests and get them deployed.</p>
<p>One branch will introduce user roles, and the other will contain the installation and configuration of the statistics package.</p>
<p>These two branches can be referred to as <strong>prerequisite</strong> branches.</p>
<p>Both pull requests will likely (<em>depending on the codebase and implementation</em>) not affect our existing codebase and can be reviewed and merged independently. As a result, we can continue working on our feature, without having our work blocked, at least not initially.</p>
<p>Don’t get me wrong. Eventually, we will need our prerequisite changes. However, until that point, we will have found a way to continue our work and also start deploying pieces of code that do not impact our users or hinder our work.</p>
<h2 id="splitting-commits">Splitting commits<a class="heading-anchor" href="#splitting-commits" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Now that we have reviewed and deployed our prerequisites, we need to focus on the actual feature. If you also like to work on full-stack features, you might find yourself following three paths while implementing a new change:</p>
<ul>
<li>Starting from the backend.</li>
<li>Starting from the frontend.</li>
<li>Diving in both.</li>
</ul>
<p>Defining the best approach depends on your developer profile and the work needed. Each approach has many advantages but I’ve seen that shifting between approaches from time to time can transform and improve your mindset as a developer. So choose wisely and have fun!</p>
<p>Meanwhile, if you decide to adopt the one-side-at-a-time approach then why not improve your pull request using the same method? How? By splitting your commits as you progress with your implementation.</p>
<p>Splitting commits, for example, by backend and frontend ones, may also help if you are working with a team that doesn’t have full-stack engineers but separate teams of front and back-oriented developers.</p>
<p>Splitting your work into smaller commits may also enhance your review process and lead to better pull requests. This is because individual commits also help reviewers concentrate on specific commit changes rather than the entire scope of your pull request.</p>
<h3 id="applying-split-commits-to-our-example">Applying split commits to our example<a class="heading-anchor" href="#applying-split-commits-to-our-example" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>To see that in action, let’s assume in our example that we will be following the implementation steps below:</p>
<p><strong>Backend implementation</strong></p>
<ul>
<li>Implement the comments CRUD logic.</li>
<li>Introduce role handlers needed for checking who can see what.</li>
<li>Add any unit/integration tests.</li>
</ul>
<p><strong>Frontend implementation</strong></p>
<ul>
<li>Create our new UI views and any additional components.</li>
<li>Add the necessary routes.</li>
<li>Add any unit/integration tests.</li>
</ul>
<p>By creating two separate pull requests or one pull request with different commits, each containing the respective changes (backend &#x26; frontend), we can greatly improve the efficiency and effectiveness of the review process.</p>
<p>I get it. Sometimes, this may seem like overkill, but trust me, breaking work into smaller pieces, will unlock new paths in your thinking process which will boost your problem-solving skills in multiple ways.</p>
<p>In general, developers often neglect managing pull requests as we tend to believe that our work ends when pushing that final commit. I can assure you, though, that giving more emphasis on the other aspects of your workflow, as we’ve talked about in this post, can have a significant impact on your work.</p>]]></content:encoded>
    </item>
    <item>
      <title>What Is a Cron Job? Simple Guide for Beginners</title>
      <link>https://littlecodingthings.com/what-is-a-cron-job-simple-guide-for-beginners/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/what-is-a-cron-job-simple-guide-for-beginners/</guid>
      <pubDate>Tue, 26 Mar 2024 17:53:00 GMT</pubDate>
      <description>What a cron job is, how cron works, and how to write cron time syntax — every minute, daily, weekly — plus the crontab file and how to read cron logs.</description>
      <category>Server Side</category>
      <content:encoded><![CDATA[<p>I have been using crons for a while now, but I always wanted to spend some time reading about them or creating one from scratch so that I could fully understand what is a cron job. This post is exactly that: notes on creating my first cron job, learning what a cron is, and what I’ve discovered during the process. </p>
<h2 id="what-is-cron-and-how-does-it-work">What is cron, and how does it work?<a class="heading-anchor" href="#what-is-cron-and-how-does-it-work" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The name <strong>cron</strong> originates from the Greek word hronos (Greek χρόνος), which means time. Υou may also know the word as Chronos or Kronos, who was the god of time and king of the Titans in Greek mythology.</p>
<p>A cron is a daemon, meaning it is a process — <em>an instance of a program</em> — that runs continuously in the background of a Unix-like operating system. It usually starts along with the system and stops when the system shuts down.</p>
<p>We suffix daemon process names with the letter <em>d</em> to show that they refer to a daemon. That’s why you might see a cron also mentioned as <strong>crond</strong>, instead of just <strong>cron</strong>.</p>
<h2 id="a-typical-cron-day">A typical cron day<a class="heading-anchor" href="#a-typical-cron-day" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>If a cron runs continuously, what does it do while running?</p>
<p>📆 A cron’s typical day would probably look something like this:</p>
<p><strong>For each minute of every day</strong></p>
<ol>
<li>Check if you have anything to do now, this minute.</li>
<li>If you have something to do, do it.</li>
<li>Get back to sleep for one minute.</li>
<li>Wake up and go back to step 1.</li>
</ol>
<p>Now we are getting somewhere, so it is a process that checks every minute if it has something to do, at that specific minute. But where does it live? Can we see it?</p>
<p>Let’s open our terminal and type</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">sudo</span><span style="color:#9ECBFF"> systemctl</span><span style="color:#9ECBFF"> status</span><span style="color:#9ECBFF"> cron.service</span></span></code></pre></div>
<p>ℹ️ <code>systemctl</code> command is a utility – <em>a helper command</em> – which helps us control the <code>systemd</code>, the system daemon. (<code>ctl</code> suffix stands for control)</p>
<p>ℹ️ <code>systemd</code> – is a system daemon that is used to manage other daemons.</p>
<p>So basically, what we are trying to do through this command is ask a manager daemon to show us the status of our cron service. Executing it shows the following information:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>● cron.service - Regular background program processing daemon</span></span>
<span class="line"><span>     Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: ></span></span>
<span class="line"><span>     Active: active (running) since Sat 2024-03-01 09:55:40 EEST; 3 days ago</span></span>
<span class="line"><span>       Docs: man:cron(8)</span></span>
<span class="line"><span>   Main PID: 981 (cron)</span></span>
<span class="line"><span>      Tasks: 1 (limit: 38136)</span></span>
<span class="line"><span>     Memory: 1.1M</span></span>
<span class="line"><span>        CPU: 1.491s</span></span>
<span class="line"><span>     CGroup: /system.slice/cron.service</span></span>
<span class="line"><span>             └─981 /usr/sbin/cron -f -P</span></span></code></pre></div>
<p>Say hello to this little process inside your system! This is a cron!
(<em>That reminds me of a famous Al Pacino quote</em>… 😎)</p>
<p>There is a lot of info in this message, and I am not quite familiar with the terminology. What is important for now is that this is about our <code>cron.service</code> which is a <code>Regular background program processing daemon currently</code> in <code>active</code> state and running since <code>Sat 2023-06-10 09:55:40 EEST</code>.</p>
<p>Excellent! We now know what a cron looks like and how it spends its days.</p>
<h2 id="using-a-cron-to-do-our-work">Using a cron to do our work<a class="heading-anchor" href="#using-a-cron-to-do-our-work" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>You can set a cron to do whatever you imagine! <em>Ooh, strong word, right</em>? 😯 <em>Examples, please</em>? <em>Fair enough</em>… 🤓</p>
<p>You could use a cron to:</p>
<ul>
<li>Send emails to your clients.</li>
<li>Have a backup for specific files in your system.</li>
<li>Remind yourself of a specific task you have to do.</li>
<li>Assign a cron to do heavy-duty work when your machine’s resources are used the least.</li>
</ul>
<p>But wait… that doesn’t make sense. Why would I need to send an email to my clients, every minute?</p>
<p>Well, I said a cron checks every minute, after all, didn’t I?</p>
<p>True, that is correct, it would (probably!) not make sense, but I also didn’t say that we <strong>have</strong> to do something <strong>every</strong> minute. I just said that the cron will check every minute if it <strong>has</strong> something to do.</p>
<p>We can schedule it to do something whenever we want, every minute, every hour, every end of the month, once a year, etc, by creating a <strong>cron job</strong>.</p>
<p>Once you define what is a cron job for your needs it becomes a reliable tool for task automation.</p>
<h2 id="what-is-a-cron-job">What is a cron job?<a class="heading-anchor" href="#what-is-a-cron-job" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>So what is a cron job exactly? In simple terms, a cron job is a task, that is automated and set to repeat. This task is saved in a file called crontab and it will execute automatically based on your set schedule.</p>
<p>By understanding what is a cron job, you unlock a powerful way to automate repetitive tasks effortlessly. Whether it’s running scripts, performing backups, or scheduling system maintenance, cron jobs ensure that tasks are executed reliably and on time without manual intervention.</p>
<h2 id="how-to-schedule-cron-jobs-with-time-syntax">How to schedule cron jobs with time syntax<a class="heading-anchor" href="#how-to-schedule-cron-jobs-with-time-syntax" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Now that you know what is a cron job and how it automates tasks, the next step is understanding how to schedule it. The timing of a cron job is defined using specific fields that allow you to set it to run at precise intervals. Whether you need a task to run every minute, daily, or on specific days of the week, learning how to configure these settings is essential for mastering cron jobs. Let’s dive into the details!</p>
<p>We use the following formatting when we add a cron job to specify when we want our task to run:</p>
<p><code>&#x3C;when> &#x3C;what></code></p>
<p><strong>when</strong>: when we want something to happen.</p>
<p><strong>what</strong>: what we want our cron to do at that point in time.</p>
<p>Let’s see the cron job formatting in more detail before we discover where to write a cron job. For our cron to understand when something should happen we need to add the following information:</p>
<table>
<thead>
<tr>
<th scope="col">minute</th>
<th scope="col">hour</th>
<th scope="col">day of month</th>
<th scope="col">month</th>
<th scope="col">day of week</th>
</tr>
</thead>
</table>
<p>What is this? 😩 All good, we’ll figure it out.</p>
<p>We need to find a way to describe in great detail and without any doubts when a job (a cron’s task) should be executed. By combining these columns, we can define any point in time we want our job to run. Let’s figure out more, through the following examples. 🧐</p>
<p>If we wanted to ask a cron to do something every minute, we should write it like this:</p>
<h3 id="cron-job-every-minute">Cron job every minute<a class="heading-anchor" href="#cron-job-every-minute" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<table>
<thead>
<tr>
<th scope="col">minute</th>
<th scope="col">hour</th>
<th scope="col">day of month</th>
<th scope="col">month</th>
<th scope="col">day of week</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">*</th>
<td>*</td>
<td>*</td>
<td>*</td>
<td>*</td>
</tr>
</tbody>
</table>
<p>Using <code>*</code> is the same as saying, every minute of every hour of every day of the month…</p>
<h3 id="cron-job-every-5-minutes">Cron job every 5 minutes<a class="heading-anchor" href="#cron-job-every-5-minutes" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<table>
<thead>
<tr>
<th scope="col">minute</th>
<th scope="col">hour</th>
<th scope="col">day of month</th>
<th scope="col">month</th>
<th scope="col">day of week</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">5</th>
<td>*</td>
<td>*</td>
<td>*</td>
<td>*</td>
</tr>
</tbody>
</table>
<p>Populating only the <strong>minute</strong> field will run the cron job every 5 minutes</p>
<h3 id="cron-job-daily-at-1000-am">Cron job daily at 10:00 am<a class="heading-anchor" href="#cron-job-daily-at-1000-am" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<table>
<thead>
<tr>
<th scope="col">minute</th>
<th scope="col">hour</th>
<th scope="col">day of month</th>
<th scope="col">month</th>
<th scope="col">day of week</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">0</th>
<td>10</td>
<td>*</td>
<td>*</td>
<td>*</td>
</tr>
</tbody>
</table>
<p>See that we set the hour column to <code>10</code> and minute to <code>0</code>? This means that our task will run only in the first minute of the 10th hour. If we wanted our task to run every minute of the 10th hour we should set the minute column to <code>*</code>.</p>
<h3 id="cron-job-every-saturday-at-1000-am">Cron job every Saturday at 10:00 am<a class="heading-anchor" href="#cron-job-every-saturday-at-1000-am" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<table>
<thead>
<tr>
<th scope="col">minute</th>
<th scope="col">hour</th>
<th scope="col">day of month</th>
<th scope="col">month</th>
<th scope="col">day of week</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">0</th>
<td>10</td>
<td>*</td>
<td>*</td>
<td>6</td>
</tr>
</tbody>
</table>
<p>Saturday is the sixth day of the week so we define it by adding the number <code>6</code> on the “<strong>day of week</strong>“ column.</p>
<h3 id="cron-job-on-the-1st-of-every-month-at-1530">Cron job on the 1st of every month at 15:30<a class="heading-anchor" href="#cron-job-on-the-1st-of-every-month-at-1530" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<table>
<thead>
<tr>
<th scope="col">minute</th>
<th scope="col">hour</th>
<th scope="col">day of month</th>
<th scope="col">month</th>
<th scope="col">day of week</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">30</th>
<td>15</td>
<td>1</td>
<td>*</td>
<td>*</td>
</tr>
</tbody>
</table>
<h3 id="cron-job-daily-for-the-first-week-of-the-month"><strong>Cron job daily for the first week of the month</strong><a class="heading-anchor" href="#cron-job-daily-for-the-first-week-of-the-month" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<table>
<thead>
<tr>
<th scope="col">minute</th>
<th scope="col">hour</th>
<th scope="col">day of month</th>
<th scope="col">month</th>
<th scope="col">day of week</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">0</th>
<td>0</td>
<td>1-7</td>
<td>*</td>
<td>6</td>
</tr>
</tbody>
</table>
<p>We can also use duration, in this case, <code>1-7</code> is used for all days, starting from the 1st till the 7th.</p>
<h3 id="cron-job-every-30-minutes-during-working-hours"><strong>Cron job every 30 minutes during working hours</strong><a class="heading-anchor" href="#cron-job-every-30-minutes-during-working-hours" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<table>
<thead>
<tr>
<th scope="col">minute</th>
<th scope="col">hour</th>
<th scope="col">day of month</th>
<th scope="col">month</th>
<th scope="col">day of week</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">*/30</th>
<td>10-18</td>
<td>*</td>
<td>*</td>
<td>*</td>
</tr>
</tbody>
</table>
<p>There is an awesome site called <a href="https://crontab.guru/">crontab guru</a> if you’d like to play around and see more complex cases of cron time settings. I suggest you check it out and bookmark it, it will come in handy, trust me!</p>
<h2 id="understanding-the-crontab-file">Understanding the crontab file<a class="heading-anchor" href="#understanding-the-crontab-file" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Now that we are a bit more familiar with the way we set the time for our cron job, let’s see the <strong>where</strong> part.</p>
<p>There’s a file in our system called <strong>crontab</strong>. The word crontab comes from the combination of the words <strong>cron</strong> + <strong>table</strong>. This is the file in which we will be adding our instructions on what we want our cron to do and when we would like that to happen.</p>
<p>You can find the crontab file living inside the <code>/var/spool/cron/crontabs</code> folder. In the<code>crontabs</code> folder, you will find one crontab file per system user, so the file is named after whoever you are logged in as. In my case that was <code>webdev</code>. <strong>Do not edit this file directly</strong> <strong>though</strong>, if you want to edit your assigned file, type in your terminal:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>crontab -e</span></span></code></pre></div>
<p>ℹ️ <strong>-e</strong> stands for edit.</p>
<p>If it is the first time you open crontab you might be asked to select your preferred editor, I prefer vim, you can select whatever you like.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>Select an editor.  To change later, run 'select-editor'.</span></span>
<span class="line"><span>  1. /bin/nano        &#x3C;---- easiest</span></span>
<span class="line"><span>  2. /usr/bin/vim.basic</span></span>
<span class="line"><span>  3. /usr/bin/vim.tiny</span></span>
<span class="line"><span>  4. /bin/ed</span></span></code></pre></div>
<p>In my case, pressing <code>2</code> and hitting <code>Enter</code> my crontab opened.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8"># Edit </span><span style="color:#79B8FF">this</span><span style="color:#E1E4E8"> file to introduce tasks to be run by cron.</span></span>
<span class="line"><span style="color:#E1E4E8">#</span></span>
<span class="line"><span style="color:#E1E4E8"># Each task to run has to be defined through a single line</span></span>
<span class="line"><span style="color:#E1E4E8"># indicating </span><span style="color:#F97583">with</span><span style="color:#E1E4E8"> different fields when the task will be run</span></span>
<span class="line"><span style="color:#E1E4E8"># and what command to run for the task</span></span>
<span class="line"><span style="color:#E1E4E8">#</span></span>
<span class="line"><span style="color:#E1E4E8"># To define the time you can provide concrete values for</span></span>
<span class="line"><span style="color:#E1E4E8"># </span><span style="color:#B392F0">minute</span><span style="color:#E1E4E8"> (m), </span><span style="color:#B392F0">hour</span><span style="color:#E1E4E8"> (h), day </span><span style="color:#F97583">of</span><span style="color:#B392F0"> month</span><span style="color:#E1E4E8"> (dom), </span><span style="color:#B392F0">month</span><span style="color:#E1E4E8"> (mon),</span></span>
<span class="line"><span style="color:#E1E4E8"># and day </span><span style="color:#F97583">of</span><span style="color:#B392F0"> week</span><span style="color:#E1E4E8"> (dow) or use </span><span style="color:#9ECBFF">'*'</span><span style="color:#F97583"> in</span><span style="color:#E1E4E8"> these </span><span style="color:#B392F0">fields</span><span style="color:#E1E4E8"> (for </span><span style="color:#9ECBFF">'any'</span><span style="color:#E1E4E8">).</span></span>
<span class="line"><span style="color:#E1E4E8">#</span></span>
<span class="line"><span style="color:#E1E4E8"># Notice that tasks will be started based on the cron</span><span style="color:#9ECBFF">'s syste</span><span style="color:#FDAEB7;font-style:italic">m</span></span>
<span class="line"><span style="color:#E1E4E8"># daemon</span><span style="color:#9ECBFF">'s notion of time and timezones</span><span style="color:#FDAEB7;font-style:italic">.</span></span>
<span class="line"><span style="color:#E1E4E8">#</span></span>
<span class="line"><span style="color:#E1E4E8"># Output </span><span style="color:#F97583">of</span><span style="color:#E1E4E8"> the crontab </span><span style="color:#B392F0">jobs</span><span style="color:#E1E4E8"> (including errors) is sent through</span></span>
<span class="line"><span style="color:#E1E4E8"># email to the user the crontab file belongs </span><span style="color:#B392F0">to</span><span style="color:#E1E4E8"> (unless redirected).</span></span>
<span class="line"><span style="color:#E1E4E8">#</span></span>
<span class="line"><span style="color:#E1E4E8"># For example, you can run a backup </span><span style="color:#F97583">of</span><span style="color:#E1E4E8"> all your user accounts</span></span>
<span class="line"><span style="color:#E1E4E8"># at </span><span style="color:#79B8FF">5</span><span style="color:#E1E4E8"> a.m every week </span><span style="color:#F97583">with</span><span style="color:#E1E4E8">:</span></span>
<span class="line"><span style="color:#E1E4E8"># </span><span style="color:#79B8FF">0</span><span style="color:#79B8FF"> 5</span><span style="color:#F97583"> *</span><span style="color:#F97583"> *</span><span style="color:#79B8FF"> 1</span><span style="color:#E1E4E8"> tar </span><span style="color:#F97583">-</span><span style="color:#E1E4E8">zcf </span><span style="color:#F97583">/var</span><span style="color:#E1E4E8">/backups/home.tgz /home/</span></span>
<span class="line"><span style="color:#E1E4E8">#</span></span>
<span class="line"><span style="color:#E1E4E8"># For more information see the manual pages </span><span style="color:#F97583">of</span><span style="color:#B392F0"> crontab</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">5</span><span style="color:#E1E4E8">) and </span><span style="color:#B392F0">cron</span><span style="color:#E1E4E8">(</span><span style="color:#79B8FF">8</span><span style="color:#E1E4E8">)</span></span>
<span class="line"><span style="color:#E1E4E8">#</span></span>
<span class="line"><span style="color:#E1E4E8"># m h  dom mon dow   command</span></span>
<span class="line"><span style="color:#F97583">~</span></span>
<span class="line"><span style="color:#F97583">~</span></span></code></pre></div>
<p>Under the last line of this file, (# m h dom mon dow command) let’s write our first actual cron job! 🥳🥳🥳</p>
<h2 id="write-your-first-cron-job-command"><strong>Write your first cron</strong> j<strong>ob command</strong><a class="heading-anchor" href="#write-your-first-cron-job-command" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Our first cron job will be running every minute so that we can start our victory dance as soon as possible 🤭</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span># m h  dom mon dow   command</span></span>
<span class="line"><span># my first cron job instructions</span></span>
<span class="line"><span></span></span>
<span class="line"><span>* * * * * echo "This is my FIRST CRON!!! :)" > /dev/pts/1</span></span></code></pre></div>
<p>Let’s break down a bit this command</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span># m h  dom mon dow   command</span></span>
<span class="line"><span># my first cron job instructions</span></span>
<span class="line"><span></span></span>
<span class="line"><span>* * * * * echo "This is my FIRST CRON!!! :)" > /dev/pts/1</span></span></code></pre></div>
<p>Starting a line with a <code>#</code> indicates that this is a comment. Adding comments could help if you have, for example, more than one crons and it gets difficult to understand what each of them does.
Watch out not to add comments in line with your cron job command since they will be considered as a part of the command.</p>
<p>White spaces and blank lines are ignored in this file so feel free to format it however you’d like.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span># m h  dom mon dow   command</span></span>
<span class="line"><span># my first cron instructions</span></span>
<span class="line"><span></span></span>
<span class="line"><span>* * * * * echo "This is my FIRST CRON!!! :)" > /dev/pts/1</span></span></code></pre></div>
<p><code>* * * * *</code> These are the 5 values of the columns we described in our previous section. Don’t forget to add spaces between each <code>*</code>.</p>
<p><code>echo "This is my FIRST CRON!!! :)"</code> displays the message <em>“This is my FIRST CRON!!! :)”.</em></p>
<p>ℹ️ <code>echo</code> is a Linux command used to print strings/texts on the terminal.</p>
<p><code>></code> is a symbol used to take a command’s output and redirect it somewhere else. So in this case the result of the <code>echo</code> command – what the echo <code>command</code> would print in the cron’s terminal – will be redirected to the next argument 👇</p>
<p><code>/dev/pts/1</code> #%$#@? 😟 Oh sorry I think I accidentally wrote my actual thought when I searched about it 🤓. I was trying to create a cron that just prints/displays a message in the terminal.</p>
<p>The problem is that crons have their own console so I needed to explicitly ask our cron to display a message in the terminal I am using. 
To find which terminal I was using, I typed in my terminal, <code>tty</code> and got the following response</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>~ tty</span></span>
<span class="line"><span>/dev/pts/1</span></span></code></pre></div>
<p>So I added this terminal’s description in my cron command.</p>
<p>To wrap this up we’d say that we asked our first cron job to display the message <code>This is my FIRST CRON!!! :)</code> to our currently open terminal.</p>
<p>By saving and closing the <code>crontab</code> file you should see a message <code>crontab: installing new crontab</code> which informs you that all changes added to your crontab file were saved.</p>
<p>At the beginning of the next minute, you should see in your terminal your first cron running.</p>
<p>Wait for it…. wait waaaaaaaaait waiiiit (<em>brings back memories from Braveheart!</em>) now! Did you see it????? 🥳🥳🥳🥳</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>This is my FIRST CRON!!! :)</span></span></code></pre></div>
<p>This message will show up every minute forever so you probably need to edit your crontab and remove this cron, after all, it was just for learning purposes! 🤭</p>
<p>(<em>Just type <code>crontab -e</code> and remove the cron job you have added to do so.</em>)</p>
<h2 id="how-to-view-cron-logs">How to view cron logs<a class="heading-anchor" href="#how-to-view-cron-logs" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>If you haven’t modified your system settings, then by default, all system logs are kept in the <code>/var/logs/systemlog</code> file. Typing the following command in your terminal will get you all CRON-related logs written in your system</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">grep </span><span style="color:#79B8FF">CRON</span><span style="color:#F97583"> /var</span><span style="color:#E1E4E8">/log/syslog</span></span></code></pre></div>
<p>ℹ️ <code>grep</code> command searches for patterns inside a file</p>
<p>In my case, the result looked like</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>Mar 24 20:18:01 webdev CRON[224509]: (webdev) CMD (echo "This is my FIRST CRON!!! :)" > /dev/pts/5)</span></span>
<span class="line"><span>Mar 24 20:19:01 webdev CRON[224892]: (webdev) CMD (echo "This is my FIRST CRON!!! :)" > /dev/pts/5)</span></span>
<span class="line"><span>Mar 24 20:20:01 webdev CRON[225143]: (webdev) CMD (echo "This is my FIRST CRON!!! :)" > /dev/pts/5)</span></span>
<span class="line"><span>Mar 24 20:21:01 webdev CRON[225356]: (webdev) CMD (echo "This is my FIRST CRON!!! :)" > /dev/pts/5)</span></span></code></pre></div>
<p>This is, I guess, one way you can use to check what’s going on with your crons and when they ran.</p>
<p>And there you have it! You created your first cron and saw all the little details about your new cron job! Well done! It’s time for more victory dance!</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/environment-variables-101-secure-your-secrets-like-a-pro/">Environment Variables with Dotenv</a></li>
<li><a href="/docker-docker-compose-commands-i-keep-forgetting-cheat-sheet/">Docker &#x26; Docker Compose Cheat Sheet</a></li>
<li><a href="/why-every-developer-should-still-know-curl-in-2026/">Why You Should Still Know curl in 2026</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>What You Need to Know About CSS Color Methods</title>
      <link>https://littlecodingthings.com/what-you-need-to-know-about-css-color-methods/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/what-you-need-to-know-about-css-color-methods/</guid>
      <pubDate>Thu, 21 Mar 2024 14:00:00 GMT</pubDate>
      <description>CSS color names, HEX, RGB and HSL side by side — what each value means and how to add an alpha channel to every one of them.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Welcome to the vibrant 🎡 world of colors! The CSS <code>color</code> property is one of the most creative building blocks of web design. Whether you want to create a visually stunning user interface or simply add a touch of flair to your project, understanding the variation of colors will empower you to paint your digital canvas with endless possibilities. In this post, we’ll dive into CSS color methods and explore their syntax and formats. Let’s embark on this chromatic journey together! 🌈✨</p>
<h2 id="exploring-css-color-methods">Exploring CSS color methods<a class="heading-anchor" href="#exploring-css-color-methods" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Most colors have a predefined name, allowing us to easily declare them by referencing their designated names. For instance, if we desire a blue color, we can do so by setting <code>background-color: blue</code>.</p>
<p><img src="/color-name.webp" alt="CSS color methods: This image shows a box with color blue. In the center it has the title &#x27;blue&#x27;." style="max-width:39%" class="img-narrow"></p>
<p>Apart from names, we can declare colors by setting the values <code>HEX</code> , <code>RGB</code> , and <code>HSL</code>.</p>
<h3 id="hex-color-method">HEX color method<a class="heading-anchor" href="#hex-color-method" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>A hexadecimal (<code>HEX</code>) color is stated with <code>#RRGGBB</code> where RR represents the red color, GG stands for the green color, and BB acts for the blue color. In the example below, we can see that the HEX value for pure blue is <code>#0000FF</code> , where the first two ’00’ represent no red and the second two ’00’ represent no green, while ‘FF’ indicates the maximum intensity of blue color. So, at this point, is the right time to say that ’00’ stands for zero and represents the absence or off state, while ‘FF’ stands for the highest value and represents full intensity or the presence of all components.</p>
<p>Hexadecimal syntax supports 3, 4, 6 or 8 digits in order to denote RGB color combinations. As you may have already guessed, using less letter syntax reduces our color combinations, that’s why it’s mostly common to see 6-digit hexadecimal system when working on projects. In our example, we could write <code>#00F</code> instead of <code>#0000FF</code>.</p>
<p>🔖 It is essential to note that hexadecimal color works only if we add the <code>#</code> in front of it.</p>
<p><img src="/color-hex.webp" alt="CSS color methods: This image shows a box with color blue. In the center it has the title: hex #0000ff." style="max-width:49%" class="img-narrow"></p>
<p>🔖 This 6-digit format for RGB colors (<code>#rrggbb</code>), can be <strong>extended to 8 digits</strong> to include an alpha channel, where the last two digits (<code>00</code> to <code>ff</code>) represent the alpha value, with 00 being fully transparent and ff being fully opaque.
Hexadecimal numbers use digits 0-9 and letters a-f. They represent numbers in a base-16 system.
🔹 Higher <code>aa</code> values (closer to <code>ff</code> or <code>ee</code>, etc.) mean less see-through colors.
🔹 Lower <code>aa</code> values (closer to <code>00</code> or <code>11</code>, etc.) mean more see-through colors.</p>
<p><img src="/color-hex-0-1-opacity.webp" alt="CSS color methods: This image shows a box with a shade of color blue. In the center it has the title: #0000ff1a. That means we have a blue color with very low (0.1) opacity, so it is almost fully transparent." style="max-width:45%" class="img-narrow"></p>
<p><img src="/color-hex-0-5-opacity.webp" alt="CSS color methods: This image shows a box with a shade of color blue. In the center it has the title: #0000ff80. That means we have a blue color with half (0.5) opacity." style="max-width:45%" class="img-narrow"></p>
<p><img src="/color-hex-0-9-opacity.webp" alt="CSS color methods: This image shows a box with a shade of color blue. In the center it has the title: #0000ffe6. That means we have a blue color with high (0.9) opacity, so it is almost fully opaque." style="max-width:45%" class="img-narrow"></p>
<h3 id="rgb-color-method">RGB color method<a class="heading-anchor" href="#rgb-color-method" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>The <code>RGB</code> color model is a way of defining colors using red (R), green (G), and blue (B) values. These values go from 0 to 255, or you can use percentages from 0% to 100%. This gives us loads of different shades to play with!</p>
<p>Each value determines how strong that color should be. When the values are at ‘0’ or ‘0%’, it means the color is completely off, like it’s not there at all. But when they’re set to ‘255’ or ‘100%’, the color is at its maximum power or indicates the highest achievable intensity level. Cool, right? 😎</p>
<p>By skillfully combining them, we open up a plethora of possibilities, allowing us to create captivating color combinations.</p>
<p>Below, we see an example of the <code>RGB</code> color model for the color blue. The intensity of red and green is set to 0, and the intensity of blue is set to its maximum value of 255, resulting in pure blue color. In terms of percentages, it would be <code>rgb(0%, 0%, 100%)</code>.</p>
<p><img src="/color-rgb.webp" alt="CSS color methods: This image shows a box with color blue. In the center it has the title: rgb(0, 0, 255)." style="max-width:45%" class="img-narrow"></p>
<p>🔖 This function also allows us to add the <strong>alpha</strong> value (<code>a</code>) responsible for our color’s <a href="/the-unique-css-opacity-check-out-this-amazing-property/">opacity</a> (transparency), but this time written in a different way. It ranges from 0.0, which is fully transparent, to 1.0, which represents full color.</p>
<p><img src="/color-rgba-0-1-opacity.webp" alt="CSS color methods: This image shows a box with a shade of color blue. In the center it has the title: rgba(0, 0, 255, 0.1). That means we have a blue color with 0.1 opacity." style="max-width:45%" class="img-narrow"></p>
<p><img src="/color-rgba-0-5-opacity.webp" alt="CSS color methods: This image shows a box with a shade of color blue. In the center it has the title: rgba(0, 0, 255, 0.5). That means we have a blue color with 0.5 opacity." style="max-width:45%" class="img-narrow"></p>
<p><img src="/color-rgba-0-9-opacity.webp" alt="CSS color methods: This image shows a box with a shade of color blue. In the center it has the title: rgba(0, 0, 255, 0.9). That means we have a blue color with 0.9 opacity." style="max-width:45%" class="img-narrow"></p>
<h3 id="hsl-color-method">HSL color method<a class="heading-anchor" href="#hsl-color-method" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>The <code>HSL</code> is another cool way to define colors. It consists of three parts that work together. So, let’s break it down!</p>
<p>The first part is hue (H), which is a number on a color 🎨 wheel. It goes from 0 to 360, where red is 0 (360 wraps back round to it), green is 120, and blue is 240. So, you can pick any hue you want, and it’ll give you a different color.</p>
<p>The second part is saturation (S). This one controls how vibrant the color is. When it’s at 0%, the color becomes grayish, but when it’s turned on at 100%, you get the boldest, brightest color!</p>
<p>And finally, we’ve got lightness (L). This guy decides how light or dark the color should be. At 0%, it’s dark as black; 50% is the regular normal color, and at 100%, it’s bright as white.</p>
<p>Combining all the parts we can effortlessly create a myriad of captivating color 🍭 combinations.</p>
<p>Below is an example of the <code>HSL</code> color model for the color blue. We begin with the hue value of 240 degrees, which corresponds to the blue color on the HSL color wheel. The saturation is set to 100%, meaning it is fully saturated and vivid. The lightness is set to 50%, which represents a mid-level brightness for the blue color.</p>
<p><img src="/color-hsl.webp" alt="CSS color methods: This image shows a box with color blue. In the center it has the title: hsl(240, 100%, 50%)." style="max-width:45%" class="img-narrow"></p>
<p>🔖 This function also includes the alpha (<code>a</code>) component which controls opacity (transparency) and is written in the same way as <code>rgb()</code>, a number between 0.0, fully transparent, and 1.0, which gives a clear color.</p>
<p><img src="/color-hsla-0-1-opacity.webp" alt="CSS color methods: This image shows a box with a shade of color blue. In the center it has the title: hsla(240, 100%, 50%, 0.1). That means we have a blue color with 0.1 opacity." style="max-width:45%" class="img-narrow"></p>
<p><img src="/color-hsla-0-5-opacity.webp" alt="CSS color methods: This image shows a box with a shade of color blue. In the center it has the title: hsla(240, 100%, 50%, 0.5). That means we have a blue color with 0.5 opacity." style="max-width:45%" class="img-narrow"></p>
<p><img src="/color-hsla-0-9-opacity.webp" alt="CSS color methods: This image shows a box with a shade of color blue. In the center it has the title: hsla(240, 100%, 50%, 0.9). That means we have a blue color with 0.9 opacity." style="max-width:45%" class="img-narrow"></p>
<h2 id="defining-colors-in-css">Defining colors in CSS<a class="heading-anchor" href="#defining-colors-in-css" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>In CSS, colors can be defined in <strong>three primary ways</strong>, each serving a specific purpose.</p>
<ul>
<li>The first way is used to change the color of the text. This is achieved through the <code>color</code> property.</li>
<li>We continue with the second one, which focuses on adding color to the background by utilizing the <code>background-color</code> property.</li>
<li>Finally, the third way revolves around defining colors for element borders, providing them with a distinct and visually appealing appearance. This is accomplished by setting the <code>border-color</code> property. If you’d like to learn more, check out my post <a href="/how-to-be-creative-with-different-css-border-styles/" title="How To Be Creative With Different CSS Border Styles">on creative ways to style CSS borders</a>.</li>
</ul>
<p>Explore different color combinations and properties to create a user experience that matches your design vision. For now, check out a simple example that follows:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"container"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">>Goodbye&#x3C;/</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>Hope to see you around again! 😀&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">body</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  text-align</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">center</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">#0000ff</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#B392F0">.container</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#6A737D">  /* border-width border-style border-color */</span></span>
<span class="line"><span style="color:#79B8FF">  border</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">30</span><span style="color:#F97583">px</span><span style="color:#79B8FF"> solid</span><span style="color:#79B8FF"> #00ff00</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">,</span></span>
<span class="line"><span style="color:#85E89D">p</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">white</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>Not too cool 💫 for the eyes 😵‍💫 but still, it works for our example 😄</p>
<p><img src="/color-definitions-example-web.webp" alt="CSS color methods: This image shows a box with three colors. Background blue, border green and white text. The text is centered and says &#x27;Goodbye Hope to see you around again! 😀(smiling face)&#x27;." style="max-width:45%" class="img-narrow"></p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/how-to-be-creative-with-different-css-border-styles/">CSS Border Styles Explained</a></li>
<li><a href="/gray-vs-grey-in-css-what-is-the-right-choice/">Gray vs Grey in CSS. What Is the Right Choice?</a></li>
<li><a href="/css-colorful-text-crafting-vibrant-effects/">CSS Colorful Text – Crafting Vibrant Effects</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>CSS Selectors: A Complete Guide</title>
      <link>https://littlecodingthings.com/coding-made-easy-with-css-selectors-an-ultimate-guide/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/coding-made-easy-with-css-selectors-an-ultimate-guide/</guid>
      <pubDate>Sun, 17 Mar 2024 21:28:00 GMT</pubDate>
      <description>Every CSS selector a beginner needs: universal, class, id, type, the four combinators, and the ::before, ::after and :hover pseudo-classes.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Greetings everyone! 😃 Today, our focus will be on addressing CSS selectors. These unique tools 🛠 are essential for targeting 🎯 specific <a href="/most-useful-html-elements-for-maximizing-better-results/" title="HTML elements">HTML elements</a> and controlling their appearance using <a href="/how-to-work-with-css-syntax-the-correct-way/" title="CSS">CSS</a>. Utilizing CSS selectors enables us to apply styles to those chosen elements which simplify and organize our code as well as improve the presentation and display of our websites.</p>
<p>CSS selectors offer a wide range of options, from a basic element selection <code>class</code>, <code>id</code>, <code>type</code>, <code>*</code> to more advanced techniques when combining them. In addition, we have the <code>::before</code> and <code>::after</code> pseudo-elements which also apply styles but only to specific parts of an element, and then there is the <code>:hover</code> pseudo-class which adds the hover effect. So, let’s continue and analyze them one by one!</p>
<h2 id="universal-css-selector">Universal CSS Selector<a class="heading-anchor" href="#universal-css-selector" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We are able to select <strong>ALL</strong> elements by setting the asterisk <code>*</code> selector. We utilize the asterisk to seamlessly/harmoniously apply uniform styles across all elements on our page. Below we can see an example where the CSS selector <code>*</code> applies a padding of 10 pixels to all HTML elements on the page. This means that every element, such as headings, paragraphs, images, buttons, and more, will have a padding of 10 pixels on all sides, creating consistent spacing around each element.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">*</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  padding</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h2 id="basic-css-selectors">Basic CSS Selectors<a class="heading-anchor" href="#basic-css-selectors" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>Now, it’s time to continue with the basic CSS selectors.</p>
<h3 id="class-selector">class selector<a class="heading-anchor" href="#class-selector" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>The first one is when we select elements based on their <code>class</code>. In the following example, we set all elements with <code>class="custom-class"</code> to have <code>background-color: yellow</code>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">.custom-class</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">yellow</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h3 id="id-selector">id selector<a class="heading-anchor" href="#id-selector" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>We continue with the second selector where we pick out elements based on their <code>id</code>. In the example below, we set all elements with <code>id="custom-id"</code> to have <code>background-color: yellow</code>.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#B392F0">#custom-id</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">yellow</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h3 id="type-selector">type selector<a class="heading-anchor" href="#type-selector" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Finally, the third selector is when we target elements based on their <code>type</code> (e.g.: <code>p</code>, <code>h3</code>, <code>div</code>, etc…). The code to the coming example selects all <code>p</code> elements from our document. The rules <code>background-color: yellow</code> and <code>font-size: 14px</code> means that all paragraphs on our document will be displayed with this specified background color and font size.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">p</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">yellow</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">14</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h2 id="combine-css-selectors">Combine CSS Selectors<a class="heading-anchor" href="#combine-css-selectors" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We can further enhance CSS selectors by creating powerful combinations. Mixing and matching elements, make our selectors stronger and maintain our code super clean. 😄✨ The examples provided above show how adeptly combining CSS selectors can lead to remarkable outcomes.</p>
<h3 id="multiple-selectors">Multiple selectors<a class="heading-anchor" href="#multiple-selectors" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>We can begin with the power of CSS selectors in tailoring styles to a variety of HTML elements. Using the above code snippet we set the text color for <code>h1</code> and <code>h3</code> to magenta, while the text color for <code>h2</code>, <code>h4</code> and <code>p</code> will be pink. All other elements (e.g.: <code>h5</code>, <code>h6</code>, <code>div</code>, <code>a</code>, etc…) will not be affected by these rules and will retain their default styling.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">, </span><span style="color:#85E89D">h3</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">h2</span><span style="color:#E1E4E8">, </span><span style="color:#85E89D">h4</span><span style="color:#E1E4E8">, </span><span style="color:#85E89D">p</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<h3 id="adjacent-sibling-selector-">Adjacent Sibling Selector (+)<a class="heading-anchor" href="#adjacent-sibling-selector-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>We move forward with a slightly different example. Here, our code selects only the first <code>p</code> element that stands after every <code>section</code> element. So, here we will give a purple <code>background-color</code> to paragraphs that <strong>come immediately after</strong> sections. If there are paragraphs that follow other sections but are not direct siblings, they will not be affected by this specific rule.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">section</span><span style="color:#F97583"> +</span><span style="color:#85E89D"> p</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">section</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>This paragraph will NOT have a purple background.&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">section</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>This paragraph will have a purple background because it is immediately preceded by a section element.&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">section</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>This paragraph will NOT have a purple background.&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">section</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>This paragraph will have a purple background because it is immediately preceded by a section element.&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>This is an additional paragraph after the last 'p' element, and it will NOT have a purple background.&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h3 id="direct-children-selector-">Direct children selector (>)<a class="heading-anchor" href="#direct-children-selector-" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>We continue by setting the following code which selects all the <code>p</code> elements but only when they are nested inside a <code>section</code> and only the <strong>direct children</strong>. So, here will give a purple <code>background-color</code> to all paragraphs <code>p</code> that are direct children of all <code>section</code> elements. Any other paragraphs inside nested elements or outside the section elements will not be affected by this specific rule.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">section</span><span style="color:#F97583"> ></span><span style="color:#85E89D"> p</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">section</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>This paragraph will be selected.&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>This paragraph will be selected.&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>This paragraph will NOT be selected.&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">section</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>This paragraph will NOT be selected&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h3 id="all-descendants-selector">All descendants selector<a class="heading-anchor" href="#all-descendants-selector" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>Our last example selects all <code>p</code> elements <strong>inside</strong> <code>section</code> elements. So, here will give a purple <code>background-color</code> to all paragraphs <code>p</code> that are nested to <code>section</code> elements. Any other paragraphs outside the <code>section</code> elements will not be affected by this specific rule.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">section</span><span style="color:#85E89D"> p</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">purple</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">section</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>This paragraph will be selected.&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>This paragraph will ALSO be selected.&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">section</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>This paragraph will NOT be selected&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>This paragraph will NOT be selected&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p>🔎 🕵️‍♀️ 🔍 The main <strong>difference between 3 and 4</strong> is that <code>section > p</code> selects all <code>p</code> elements that are direct children, of the <code>section</code>, while <code>section p</code> selects all <code>p</code> elements that are descendants of the <code>section</code>, <em>no matter how deeply nested</em>.</p>
<h2 id="pseudo-classes-and-pseudo-elements">Pseudo-classes and pseudo-elements<a class="heading-anchor" href="#pseudo-classes-and-pseudo-elements" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<h3 id="before-and-after">Before and After<a class="heading-anchor" href="#before-and-after" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>The <code>::before</code> and <code>::after</code> are <strong>not standalone selectors</strong> in CSS. They are pseudo-elements that can be used with regular CSS selectors to apply styles to specific parts of an element’s <code>content</code>. They are used in conjunction with regular selectors to add content before or/and after the selected elements and apply specific styles to that generated content.</p>
<p>Here we have an example using an <code>h1</code> selector with the <code>::before</code> and <code>::after</code> pseudo-elements. Styles defined within <code>h1::before</code> will be applied to the content that appears <strong>before(left)</strong> the <code>h1</code> element while styles defined within <code>h1::after</code> will be applied to the content that appears <strong>after(right)</strong> the <code>h1</code> element.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">h1</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"🥰 😀"</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* the two faces will be placed before my heading(h1) */</span></span>
<span class="line"><span style="color:#79B8FF">  padding-right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">h1</span><span style="color:#B392F0">::after</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"😀 🥰"</span><span style="color:#E1E4E8">; </span><span style="color:#6A737D">/* the two faces will be placed after my heading(h1) */</span></span>
<span class="line"><span style="color:#79B8FF">  padding-left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><strong>OR</strong> (using Sass)</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">h1</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">::before</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">    content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"🥰 😀"</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    padding-right</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">::after</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#85E89D">    content</span><span style="color:#E1E4E8">: </span><span style="color:#9ECBFF">"😀 🥰"</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">    padding-left</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">10</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">} </span><span style="color:#6A737D">/* end of h1 */</span></span></code></pre></div>
<p>🔖 We need to add <code>padding-right</code> and <code>padding-left</code> in order to give our pseudo-elements a small space, in our case 10px, from our heading.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">>Pseudo-selectors are awesome!&#x3C;/</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p>Ta-da 🥁 ! Below, we are able to view the current visual output displayed on the screen. Awesome! Isn’t it? ✨ 🎉</p>
<p><img src="/selectors-css-pseudo-selectors.webp" alt="CSS selectors: This is an image that shows an <h1> html element tag with <before> and <after> pseudo selectors." style="max-width:83%" class="img-narrow"></p>
<h3 id="hover">Hover<a class="heading-anchor" href="#hover" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p>We use the <code>:hover</code> pseudo-class to change the style of an element when we hover over it. While it is commonly used with links it can also be applied to all elements. To implement this effect, first, select the element you want to target, in our case the <code>&#x3C;button></code>, and then apply the <code>:hover</code> pseudo-class to it. After that, when we hover over the button, its color will change from pink to green.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">button</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#85E89D">button</span><span style="color:#B392F0">:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><strong>OR</strong> (using Sass)</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">button</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">pink</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#85E89D">  &#x26;</span><span style="color:#B392F0">:hover</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p>The CSS selectors play a fundamental role in web development, enabling us to target and style specific elements efficiently. They provide great flexibility and precision in styling web pages. Use them in the right way 🧐 and you will be able to do amazing things! Sending good vibes for your CSS explorations! Happy coding!!</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/learn-how-to-select-only-the-css-first-child/">Learn How to Select Only the CSS First Child</a></li>
<li><a href="/css-last-child-selector-the-most-valuable-selector/">The CSS last-child Selector</a></li>
<li><a href="/css-selectors-nth-child-vs-nth-of-type-and-how-to-use-them-correctly/">nth-child vs nth-of-type in CSS</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>How To Work With CSS Syntax: The Correct Way!</title>
      <link>https://littlecodingthings.com/how-to-work-with-css-syntax-the-correct-way/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/how-to-work-with-css-syntax-the-correct-way/</guid>
      <pubDate>Tue, 12 Mar 2024 13:00:00 GMT</pubDate>
      <description>Every CSS rule has four parts: selector, declaration block, property and value. Here is what each one is called and where it goes.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>Hey there! 😄 Welcome to my post about CSS syntax. The Cascading Style Sheet (CSS) is a language we use to style and design ✨ 🎨 our HTML documents. It is NOT a programming 💻 language, and it is not stand-alone; hence, you should only use CSS to accompany and enrich <a href="/most-useful-html-elements-for-maximizing-better-results/" title="HTML">HTML</a>.</p>
<p>Below we can see an outline as a way to analyze and understand the CSS syntax better. You have to configure all the essential parts that compose CSS to make it work effectively.</p>
<p>The first thing we have to do is target the part of the HTML document we want to style, and we do so by setting the <code>selector</code> .</p>
<p>We continue with the <code>declaration</code> we want to make. The declaration block is the area that contains the styles we want to apply. Each block can contain one or more declarations depending on our needs, and it is necessary to be nested; that’s why we put it inside <code>{}</code> curly braces.</p>
<p>Each declaration includes a CSS <code>property</code> name and a <code>value</code>. The property represents the characteristics we want to apply to an element and is always followed by a <code>:</code> colon, while the value is the assigned setting for the property and is always followed by a <code>;</code> semicolon.</p>
<p><img src="/syntax-css-outlet.webp" alt="This image shows the CSS syntax. It contains only the declaration: &#x27;background-color: aqua;&#x27;." style="max-width:56%" class="img-narrow"></p>
<p>🔖 In CSS, when we have more than one declarations we traditionally write them vertically to enhance readability. You can see that in the following example:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  Wishing you smooth sailing through your CSS adventures!</span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#85E89D">p</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">  font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">14</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">magenta</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#79B8FF">  background-color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">navy</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">}</span></span></code></pre></div>
<p><img src="/syntax-css-example.webp" alt="This image shows the CSS syntax. It contains three declarations: &#x27;font-size: 14px; color: magenta; background-color: navy;&#x27;." style="max-width:83%" class="img-narrow"></p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/capitalizing-css-property-values-what-is-the-right-way/">Is CSS Case-Sensitive?</a></li>
<li><a href="/coding-made-easy-with-css-selectors-an-ultimate-guide/">CSS Selectors: A Complete Guide</a></li>
<li><a href="/make-your-work-easier-by-using-variables-in-css/">Make Your Work Easier by Using Variables in CSS</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>HTML Text Formatting Elements</title>
      <link>https://littlecodingthings.com/html-formatting-elements-made-simple-with-easy-and-practical-examples/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/html-formatting-elements-made-simple-with-easy-and-practical-examples/</guid>
      <pubDate>Fri, 08 Mar 2024 17:00:00 GMT</pubDate>
      <description>Format text with HTML alone — b, strong, i, em, u, del, mark, sub and sup — plus when to reach for strong over b, with br and hr.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>We often format <a href="/most-useful-html-elements-for-maximizing-better-results/" title="HTML elements">HTML elements</a> using CSS but can achieve basic text formatting using only HTML. Below are some of the most common HTML formatting elements for text and layout. I also prepared some examples for better understanding.</p>
<h2 id="html-elements--text-formatting">HTML Elements – Text Formatting<a class="heading-anchor" href="#html-elements--text-formatting" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<h3 id="bold">bold<a class="heading-anchor" href="#bold" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><code>&#x3C;b>...&#x3C;/b></code></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>I am a &#x3C;</span><span style="color:#85E89D">b</span><span style="color:#E1E4E8">>bold&#x3C;/</span><span style="color:#85E89D">b</span><span style="color:#E1E4E8">> text&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/html-formating-elements-bold.webp" alt="HTML formatting elements: An image showing a purple box with the sentence &#x27;I am a bold text&#x27;. The word bold is formatted in bold." style="max-width:28%" class="img-narrow"></p>
<h3 id="strong">strong<a class="heading-anchor" href="#strong" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><code>&#x3C;strong>...&#x3C;/strong></code></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>I am a &#x3C;</span><span style="color:#85E89D">strong</span><span style="color:#E1E4E8">>strong&#x3C;/</span><span style="color:#85E89D">strong</span><span style="color:#E1E4E8">> text&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/html-formatting-elements-strong.webp" alt="An image showing a purple box with the sentence &#x27;I am a strong text&#x27;. The word strong is formatted in strong." style="max-width:28%" class="img-narrow"></p>
<h4 id="-bold-vsstrong">📢 Bold <em>VS</em> Strong<a class="heading-anchor" href="#-bold-vsstrong" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p>As we can see below <code>&#x3C;b></code> and <code>&#x3C;strong></code> look exactly the same. The difference is that we use strong when we have to show an important text and bold when we want just to pay attention to the text, something like highlighting.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>I am a &#x3C;</span><span style="color:#85E89D">b</span><span style="color:#E1E4E8">>simple&#x3C;/</span><span style="color:#85E89D">b</span><span style="color:#E1E4E8">> text BUT i am an &#x3C;</span><span style="color:#85E89D">strong</span><span style="color:#E1E4E8">>important&#x3C;/</span><span style="color:#85E89D">strong</span><span style="color:#E1E4E8">> text!!&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/html-formating-elements-boldvsstrong.webp" alt="An image showing a pink box with the sentence &#x27;I am a simple text BUT I am an important text&#x27;. The word simple is formatted in bold and the word important is formatted in strong." style="max-width:69%" class="img-narrow"></p>
<h3 id="italic">italic<a class="heading-anchor" href="#italic" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><code>&#x3C;i>...&#x3C;/i></code></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>I am an &#x3C;</span><span style="color:#85E89D">i</span><span style="color:#E1E4E8">>italic&#x3C;/</span><span style="color:#85E89D">i</span><span style="color:#E1E4E8">> text&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/html-formatting-elements-italic.webp" alt="An image showing a purple box with the sentence &#x27;I am an italic text&#x27;. The word italic is formatted in italic." style="max-width:28%" class="img-narrow"></p>
<h3 id="emphasized">emphasized<a class="heading-anchor" href="#emphasized" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><code>&#x3C;em>...&#x3C;/em></code></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>I am an &#x3C;</span><span style="color:#85E89D">em</span><span style="color:#E1E4E8">>emphasized&#x3C;/</span><span style="color:#85E89D">em</span><span style="color:#E1E4E8">> text&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/html-formatting-elements-emphasized.webp" alt="An image showing a purple box with the sentence &#x27;I am an emphasized text&#x27;. The word emphasized is formatted in emphasized." style="max-width:36%" class="img-narrow"></p>
<h4 id="-italic-vs-emphasized">📢 Italic VS Emphasized<a class="heading-anchor" href="#-italic-vs-emphasized" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p>Formatting italic <code>&#x3C;i></code> and emphasized <code>&#x3C;em></code> appear in the exact same way. We use emphasized when we want to give emphasis to the text and italic when we want to present different our text.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>I am an &#x3C;</span><span style="color:#85E89D">i</span><span style="color:#E1E4E8">>italic&#x3C;/</span><span style="color:#85E89D">i</span><span style="color:#E1E4E8">> text BUT i am an &#x3C;</span><span style="color:#85E89D">em</span><span style="color:#E1E4E8">>emphasized&#x3C;/</span><span style="color:#85E89D">em</span><span style="color:#E1E4E8">> text!!&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/html-formatting-elements-italicvsemphasized.webp" alt="An image showing a pink box with the sentence &#x27;I am an italic text BUT I am an emphasized text&#x27;. The word italic is formatted in italic and the word emphasized is formatted in emphasized." style="max-width:69%" class="img-narrow"></p>
<h3 id="underline">underline<a class="heading-anchor" href="#underline" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><code>&#x3C;u>...&#x3C;/u></code></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>I am an &#x3C;</span><span style="color:#85E89D">u</span><span style="color:#E1E4E8">>underline&#x3C;/</span><span style="color:#85E89D">u</span><span style="color:#E1E4E8">> text&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/html-formatting-elements-underline.webp" alt="An image showing a purple box with the sentence &#x27;I am an underline text&#x27;. The word underline is formatted in inderline." style="max-width:35%" class="img-narrow"></p>
<h3 id="deleted">deleted<a class="heading-anchor" href="#deleted" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><code>&#x3C;del>...&#x3C;/del></code></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>I am a &#x3C;</span><span style="color:#85E89D">del</span><span style="color:#E1E4E8">>deleted&#x3C;/</span><span style="color:#85E89D">del</span><span style="color:#E1E4E8">> text&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/html-formatting-elements-deleted.webp" alt="An image showing a purple box with the sentence &#x27;I am a deleted text&#x27;. The word deleted is formatted in deleted." style="max-width:28%" class="img-narrow"></p>
<h3 id="marked">marked<a class="heading-anchor" href="#marked" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><code>&#x3C;mark>...&#x3C;/mark></code></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>I am a &#x3C;</span><span style="color:#85E89D">mark</span><span style="color:#E1E4E8">>marked&#x3C;/</span><span style="color:#85E89D">mark</span><span style="color:#E1E4E8">> text&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/html-formatting-elements-marked.webp" alt="An image showing a purple box with the sentence &#x27;I am a marked text&#x27;. The word marked is formatted in marked as hypertext." style="max-width:28%" class="img-narrow"></p>
<h3 id="big-obsolete--do-not-use">big (obsolete — do not use)<a class="heading-anchor" href="#big-obsolete--do-not-use" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><code>&#x3C;big>...&#x3C;/big></code></p>
<p>⛔ <code>&#x3C;big></code> was <strong>removed from the HTML standard</strong>. Browsers still render it out of backwards compatibility, but it carries no meaning, no accessibility value, and may stop working. Use CSS <code>font-size</code> instead. It is included here only so you recognise it in old code.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#6A737D">&#x3C;!-- obsolete: use CSS font-size instead --></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>I am a &#x3C;</span><span style="color:#FDAEB7;font-style:italic">big</span><span style="color:#E1E4E8">>big&#x3C;/</span><span style="color:#FDAEB7;font-style:italic">big</span><span style="color:#E1E4E8">> text&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/html-formatting-elements-big.webp" alt="An image showing a purple box with the sentence &#x27;I am a bid text&#x27;. The word big is formatted in big which means it has bigger font-size than the rest of the words." style="max-width:28%" class="img-narrow"></p>
<h3 id="small">small<a class="heading-anchor" href="#small" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><code>&#x3C;small>...&#x3C;/small></code></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>I am a &#x3C;</span><span style="color:#85E89D">small</span><span style="color:#E1E4E8">>small&#x3C;/</span><span style="color:#85E89D">small</span><span style="color:#E1E4E8">> text&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/html-formatting-elements-small.webp" alt="An image showing a purple box with the sentence &#x27;I am a small text&#x27;. The word small is formatted in small which means it has smaller font-size than the rest of the words." style="max-width:28%" class="img-narrow"></p>
<h3 id="superscript">superscript<a class="heading-anchor" href="#superscript" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><code>&#x3C;sup>...&#x3C;/sup></code></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>I am a superscripted text: a&#x3C;</span><span style="color:#85E89D">sup</span><span style="color:#E1E4E8">>2&#x3C;/</span><span style="color:#85E89D">sup</span><span style="color:#E1E4E8">> X a&#x3C;</span><span style="color:#85E89D">sup</span><span style="color:#E1E4E8">>2&#x3C;/</span><span style="color:#85E89D">sup</span><span style="color:#E1E4E8">> = a&#x3C;</span><span style="color:#85E89D">sup</span><span style="color:#E1E4E8">>2 + 2&#x3C;/</span><span style="color:#85E89D">sup</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/html-formatting-elements-superscripted.webp" alt="An image showing a purple box with the sentence &#x27;I am a supscripted text: a2 X a2 = a2 + 2&#x27;. Number 2 are all formatted in superscripted." style="max-width:56%" class="img-narrow"></p>
<h3 id="subscript">subscript<a class="heading-anchor" href="#subscript" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><code>&#x3C;sub>...&#x3C;/sub></code></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>I am a subscripted text: H&#x3C;</span><span style="color:#85E89D">sub</span><span style="color:#E1E4E8">>2&#x3C;/</span><span style="color:#85E89D">sub</span><span style="color:#E1E4E8">>O&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/html-formatting-elements-subscripted.webp" alt="An image showing a purple box with the sentence &#x27;I am a subscripted text: H2O&#x27;. The number 2 is formatted in subscripted." style="max-width:42%" class="img-narrow"></p>
<h2 id="html-elements--layout-formatting">HTML Elements – Layout Formatting<a class="heading-anchor" href="#html-elements--layout-formatting" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>We can use two tags in HTML to manipulate our document’s layout. <strong><em>Break Line tag</em></strong> <code>&#x3C;br/></code> which inserts a new line by adding the tag wherever we want to force the text to break and the <strong><em>Horizontal rule tag</em></strong> <code>&#x3C;hr></code> which marks a thematic break between sections of content.
They are both <strong>void elements</strong> — they have no closing tag and no content. You may see them written <code>&#x3C;br/></code> and <code>&#x3C;hr/></code>; in HTML that trailing slash is allowed but does nothing, it is a leftover from XHTML.</p>
<h3 id="break-line">break line<a class="heading-anchor" href="#break-line" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><code>&#x3C;br></code></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>This is a sentence which &#x3C;</span><span style="color:#85E89D">br</span><span style="color:#E1E4E8">>forced to break in two lines!!&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/html-formatting-elements-break-line.webp" alt="An image showing a purple box with the sentence &#x27;This is a sentence which forced to break in two lines&#x27;. The sentence is separated into two lines." style="max-width:42%" class="img-narrow"></p>
<p>💡 A common practice for adding a new line is using the break line tag, which is helpful if we want to write an address.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>Jane Doe&#x3C;</span><span style="color:#85E89D">br</span><span style="color:#E1E4E8">/>Champs-Élysées Avenue&#x3C;</span><span style="color:#85E89D">br</span><span style="color:#E1E4E8">/>Paris - France&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/html-formatting-elements-break-line-address-example.webp" alt="An image showing a purple box with an adress. The adress is separated into three lines. Jane Doe in the first line Champs-Elysees Avenue in the second line and Paris-France in the third line." style="max-width:39%" class="img-narrow"></p>
<h3 id="horizontal-rule">horizontal rule<a class="heading-anchor" href="#horizontal-rule" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><code>&#x3C;hr></code></p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">h2</span><span style="color:#E1E4E8">>Chapter 1&#x3C;/</span><span style="color:#85E89D">h2</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>Here goes text for chapter 1&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">hr</span><span style="color:#E1E4E8">/></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">h2</span><span style="color:#E1E4E8">>Chapter 2&#x3C;/</span><span style="color:#85E89D">h2</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>Here goes text for chapter 2&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p><img src="/html-formatting-elements-horizontal-row.webp" alt="This image shows how we separate two chapters with a horizontal row among them." style="max-width:35%" class="img-narrow"></p>
<p>💡 Remember, if you want to apply extra styling, you have to use 🔓 CSS instead! <a href="/is-html-a-programming-language-find-out-now/">HTML</a> is used as a markup language, whereas <a href="/the-truth-about-css-is-it-really-a-programming-language/">CSS</a> is the one responsible for making something more beautiful. 😄</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/most-useful-html-elements-for-maximizing-better-results/">The Most Useful HTML Elements</a></li>
<li><a href="/html-lists-made-easy-ordered-unordered-and-special-lists/">HTML Lists: ol, ul and dl Explained</a></li>
<li><a href="/what-does-span-do-in-html-unlocking-its-full-potential/">What Does span Do in HTML?</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>The Most Useful HTML Elements</title>
      <link>https://littlecodingthings.com/most-useful-html-elements-for-maximizing-better-results/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/most-useful-html-elements-for-maximizing-better-results/</guid>
      <pubDate>Mon, 04 Mar 2024 17:00:00 GMT</pubDate>
      <description>A working reference for the HTML elements you actually use — head tags, body tags, lists, tables and images — with a snippet for each.</description>
      <category>In the Browser</category>
      <content:encoded><![CDATA[<p>In order to create a web page, it is necessary to use HTML elements. These tags, also known as components represent the fundamental building blocks of a webpage. Each tag consists of:</p>
<p><img src="/html-element-tags-1.webp" alt="This image shows the basic structure of an html tag which is < > ... </ >." style="max-width:56%" class="img-narrow"></p>
<ul>
<li>the opening tag <code>&#x3C; ></code> declare the beginning of an element and contains its characteristics, which are called attributes.</li>
<li>the closing tag <code>&#x3C;/ ></code> declare the end of an element.</li>
<li>its content <code>...</code> — the element’s content is accommodated within this space.</li>
</ul>
<p>Here are some examples of how to construct HTML elements.</p>
<p><img src="/element-tag-example.webp" alt="HTML elements. This is an image showing an example of en element tag." style="max-width:56%" class="img-narrow"></p>
<p>There are also <strong>void elements</strong> <code>&#x3C;.../></code>, which means they have only one tag and no content. (You will often hear them called "self-closing tags", but that is XHTML terminology — in HTML they simply cannot have a closing tag.) Some void elements, e.g. <code>&#x3C;img></code>, have attributes and some don’t, like <code>&#x3C;hr></code> and <code>&#x3C;br></code>.</p>
<p><img src="/element-tag-self-closing-with-attributes-example.webp" alt="HTML elements. This is an image showing an example of a self closing tag with attributes." style="max-width:69%" class="img-narrow"></p>
<p><img src="/element-tag-self-closing-empty-example.webp" alt="HTML elements. This is an image showing an example of an empty self closing tag." style="max-width:56%" class="img-narrow"></p>
<p>📝 Regarding closing tags, you may see them closing in the following ways:</p>
<ul>
<li><code>&#x3C;br></code></li>
<li><code>&#x3C;br/></code></li>
<li><code>&#x3C;br /></code></li>
</ul>
<p>All three types are valid and you are free to use whichever you prefer. In our case, I’ll be using the closure slash without a space.</p>
<h2 id="html-elements">HTML elements<a class="heading-anchor" href="#html-elements" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<p>The <code>&#x3C;html></code> tag <strong>is required</strong> and is the container of all tags. It defines how the browser will present the document. In order to be functional we have to add the <code>&#x3C;head></code> tag and the <code>&#x3C;body></code> tag with their content.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;!</span><span style="color:#85E89D">DOCTYPE</span><span style="color:#B392F0"> html</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">html</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">head</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#6A737D">    &#x3C;!-- head elements here --></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">head</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">body</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#6A737D">    &#x3C;!-- body elements here --></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">body</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">html</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h3 id="head-elements">Head elements<a class="heading-anchor" href="#head-elements" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><code>&#x3C;head>...&#x3C;/head></code></p>
<p>The head tag has a crucial role in our HTML document. It is the container for adding all required information, in order to upload the document on the browser. Anything included in the head element, though, is not displayed on the browser. Each document can have only a single head element. A list, of head tags and their usage, is shown below:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">head</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">base</span><span style="color:#E1E4E8">/></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">link</span><span style="color:#E1E4E8">/></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">meta</span><span style="color:#E1E4E8">/></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">style</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">style</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">title</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">title</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">head</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h4 id="base">base<a class="heading-anchor" href="#base" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><code>&#x3C;base/></code></p>
<p>The base tag is the one we use when specifying the base URL for our document/site. It is the one used when creating relative URLs. For example, if we would like to add as a base URL for our site we would do something like:</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">base</span><span style="color:#B392F0"> href</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"https://littlecodingthings.com/"</span><span style="color:#E1E4E8">/></span></span></code></pre></div>
<h4 id="link">link<a class="heading-anchor" href="#link" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><code>&#x3C;link/></code></p>
<p>It’s the tag that specifies a connection between our document and another source. Some of the most commonly used attributes are, the <code>rel</code> , the <code>type</code> and the <code>href</code> attribute.</p>
<p><code>rel</code> shows the relationship between the two parts, <code>type</code> shows the type of resource linked to the document, and last (but not least) <code>href</code> gives the path to the resource, in simple words it is the resource’s address. <code>type</code> is an optional attribute and therefore can be omitted. The resource we are connecting our document to could be internal (inside our project’s folder) or external e.g another website.</p>
<p>In the example below you can see that I connect my HTML page with a CSS stylesheet (internal file) and a font awesome icons resource (external file).</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">link</span><span style="color:#B392F0"> rel</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">'stylesheet'</span><span style="color:#B392F0"> type</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"text/css"</span><span style="color:#B392F0"> href</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">'styles.css'</span><span style="color:#E1E4E8">/></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">link</span><span style="color:#B392F0"> rel</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"stylesheet"</span><span style="color:#B392F0"> href</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"https://fontawesome.com/3.2.1/css/font-awesome.css"</span><span style="color:#E1E4E8">/></span></span></code></pre></div>
<h4 id="meta">meta<a class="heading-anchor" href="#meta" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><code>&#x3C;meta/></code></p>
<p>It provides information about the document’s data, it’s data about data!</p>
<p>For example, if you want to provide information about the author who wrote the page, or a description for search engines and social previews, you can use the code below.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">meta</span><span style="color:#B392F0"> name</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">'author'</span><span style="color:#B392F0"> content</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">'Marilena'</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">meta</span><span style="color:#B392F0"> name</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"description"</span><span style="color:#B392F0"> content</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"A short summary of the page."</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p>⛔ You will still see <code>&#x3C;meta name="keywords"></code> in old tutorials. <strong>Do not bother with it</strong> — Google has ignored the keywords meta tag since 2009, and it has no effect on search engine optimization. <code>&#x3C;meta name="description"></code> is the one that matters, because search engines use it for the snippet under your result.</p>
<h4 id="style">style<a class="heading-anchor" href="#style" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><code>&#x3C;style>...&#x3C;/style></code></p>
<p>Is a special HTML element, you can use to add styles (CSS) to your web page. It helps you to modify the presentation and layout of your web page. In simple words, it allows you to customize characteristics like fonts, sizes, and colors so that your web page looks the way you prefer. Additionally, it is important to know that when you implement elements using <code>&#x3C;style></code> they may override other stylings you have probably added to your CSS (depending on your CSS rules specificity).</p>
<p>For example, if you want to apply green <code>color</code> to all <code>h1</code> (headings) and <code>font-size</code> 12px to all paragraphs on your web page you can use a style tag as seen below. This code will apply green color to all <code>h1</code> tags and a 12px font size to all paragraphs.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">style</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#85E89D">  h1</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    color</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">green</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#85E89D">  p</span><span style="color:#E1E4E8"> {</span></span>
<span class="line"><span style="color:#79B8FF">    font-size</span><span style="color:#E1E4E8">: </span><span style="color:#79B8FF">12</span><span style="color:#F97583">px</span><span style="color:#E1E4E8">;</span></span>
<span class="line"><span style="color:#E1E4E8">  }</span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">style</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h4 id="title">title<a class="heading-anchor" href="#title" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><code>&#x3C;title>...&#x3C;/title></code></p>
<p>The title tag is an HTML element used to define the title of a web page. It is placed within the <code>&#x3C;head></code> section of an HTML document and is not visible on the actual page but is displayed on the browser’s title bar or tab</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">title</span><span style="color:#E1E4E8">>Little Coding Things&#x3C;/</span><span style="color:#85E89D">title</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h3 id="body-elements">Body elements<a class="heading-anchor" href="#body-elements" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<p><code>&#x3C;body>...&#x3C;/body></code> </p>
<p>This <strong>required</strong> element is the container of all tags we use to create the structure — the appearance — of the document. Only one body element can be in each document. Anything contained in the body tag is displayed on the browser.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">body</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">>Hello there&#x3C;/</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>How are you today? Would you like to fill the form below and be a member?&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">form</span><span style="color:#E1E4E8">>...&#x3C;/</span><span style="color:#85E89D">form</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">button</span><span style="color:#E1E4E8">>Submit&#x3C;/</span><span style="color:#85E89D">button</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">>Little Coding Things Family Welcomes You!&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  ...</span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">body</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h4 id="navbar">navbar<a class="heading-anchor" href="#navbar" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><code>&#x3C;nav>...&#x3C;/nav></code></p>
<p>This tag defines a section of navigation links, such as all those in a navigation bar. It emphasizes the semantic structure of a web page, making navigation links more accessible and easier to identify for both users and search engines.</p>
<p>The provided code snippet shows how to create a simple navigation bar using the <code>&#x3C;nav></code> element. Inside the <code>&#x3C;nav></code> tag, an unordered list (<code>&#x3C;ul></code>) is used to organize navigation links as list items (<code>&#x3C;li></code>). Each list item contains an <code>&#x3C;a></code> tag, which represents a hyperlink. This structure is visually organized and semantically meaningful, as the <code>&#x3C;nav></code> element displays a block of navigational content, improving accessibility for screen readers and helping search engines understand the site’s structure. This layout is a basis for building user-friendly and responsive navigation menus.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">nav</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">ul</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>&#x3C;</span><span style="color:#85E89D">a</span><span style="color:#B392F0"> href</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"#home"</span><span style="color:#E1E4E8">>Home&#x3C;/</span><span style="color:#85E89D">a</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>&#x3C;</span><span style="color:#85E89D">a</span><span style="color:#B392F0"> href</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"#about"</span><span style="color:#E1E4E8">>About Us&#x3C;/</span><span style="color:#85E89D">a</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>&#x3C;</span><span style="color:#85E89D">a</span><span style="color:#B392F0"> href</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"#design"</span><span style="color:#E1E4E8">>Design&#x3C;/</span><span style="color:#85E89D">a</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>&#x3C;</span><span style="color:#85E89D">a</span><span style="color:#B392F0"> href</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"#contact"</span><span style="color:#E1E4E8">>Contact&#x3C;/</span><span style="color:#85E89D">a</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">ul</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">nav</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p>🔖 By default, the list has a vertical orientation as HTML documents naturally have a vertical flow of content. To style the navigation bar into a horizontal layout or add other design elements like spacing, colors, and hover effects, CSS must be applied. 🤔 ✨</p>
<h4 id="anchor">anchor<a class="heading-anchor" href="#anchor" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><code>&#x3C;a>...&#x3C;/a></code></p>
<p>We will use this tag If we want to create a hyperlink. It is necessary to include the <code>href=""</code> value where we set the address of the link we want to visit which can be an internal URL <code>href="./..."</code> or an external one <code>href="https://littlecodingthings.com/about-us/"</code>.</p>
<p>It is optional but really helpful to include <code>target="_blank"</code> value if we want our link to open in a different tab. Its default value is <code>target="_self"</code> and it opens the link to the current browsing context, the same page.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">a</span><span style="color:#B392F0"> href</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"./..."</span><span style="color:#B392F0"> target</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"_blank"</span><span style="color:#E1E4E8">>Check our new post&#x3C;/</span><span style="color:#85E89D">a</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">a</span><span style="color:#B392F0"> href</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"https://littlecodingthings.com/"</span><span style="color:#B392F0"> target</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"_blank"</span><span style="color:#E1E4E8">>Little Coding Things&#x3C;/</span><span style="color:#85E89D">a</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h4 id="address">address<a class="heading-anchor" href="#address" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><code>&#x3C;address>...&#x3C;/address></code></p>
<p>This HTML tag provides contact information about a person or an organization.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">>Contact with the author&#x3C;/</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">address</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">a</span><span style="color:#B392F0"> href</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"mailto:hello@littlecodingthings.com"</span><span style="color:#E1E4E8">>hello@littlecodingthings.com&#x3C;/</span><span style="color:#85E89D">a</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">address</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h4 id="article">article<a class="heading-anchor" href="#article" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><code>&#x3C;article>...&#x3C;/article></code></p>
<p>The article tag is used for specifying content independence, its content should be self-contained and have its own meaning. Examples of such usage could be a newspaper article, a forum or a blog post.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">article</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">>Explore India&#x3C;/</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">img</span><span style="color:#E1E4E8">/> </span><span style="color:#6A737D">&#x3C;!-- An image that shows India --></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">h2</span><span style="color:#E1E4E8">>India's Top Ten Attractions&#x3C;/</span><span style="color:#85E89D">h2</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>Here goes text about India's attractions&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">h2</span><span style="color:#E1E4E8">>India's Food&#x3C;/</span><span style="color:#85E89D">h2</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>Here goes text about India's cuisine&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">article</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">article</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">>Explore Tanzania&#x3C;/</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">img</span><span style="color:#E1E4E8">/> </span><span style="color:#6A737D">&#x3C;!-- An image that shows Tanzania --></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">h2</span><span style="color:#E1E4E8">>Tanzania's Top Ten Attractions&#x3C;/</span><span style="color:#85E89D">h2</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>Here goes text about Tanzania's attractions&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">h2</span><span style="color:#E1E4E8">>Tanzania's Food&#x3C;/</span><span style="color:#85E89D">h2</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>Here goes text about Tanzania's cuisine&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">article</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h4 id="button">button<a class="heading-anchor" href="#button" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><code>&#x3C;button>...&#x3C;/button></code></p>
<p>Defines a button we want to introduce to our document. It is interactive by the user and represents an action. It may contain text, icons, or even images. Setting <code>type="button"</code> matters because a <code>&#x3C;button></code> inside a <code>&#x3C;form></code> defaults to <code>type="submit"</code> — without it, clicking the button submits the form.</p>
<p>Below, you can see a button I create for you to understand it better. It would be nice to add CSS to make it prettier! 😉</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">button</span><span style="color:#B392F0"> type</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"button"</span><span style="color:#B392F0"> class</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"my-button"</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  Submit</span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">button</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h4 id="div">div<a class="heading-anchor" href="#div" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><code>&#x3C;div>...&#x3C;/div></code></p>
<p>The division tag is the most common tag and defines a section in the document. HTML5 introduced some new tags, like section and footer, to provide a more descriptive way of splitting a document’s contents. Before that, the div tag was the primary choice, and often resulted in a situation referred to as “div hell”.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  Lorem ipsum dolor sit amet consectetur adipisicing elit. Maxime mollitia,</span></span>
<span class="line"><span style="color:#E1E4E8">  molestiae quas vel sint commodi repudiandae consequuntur voluptatum laborum</span></span>
<span class="line"><span style="color:#E1E4E8">  numquam blanditiis harum quisquam eius sed odit fugiat iusto fuga praesentium</span></span>
<span class="line"><span style="color:#E1E4E8">  optio, eaque rerum! Provident similique accusantium nemo autem.</span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">div</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h4 id="footer">footer<a class="heading-anchor" href="#footer" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><code>&#x3C;footer>...&#x3C;/footer></code></p>
<p>It represents the content that appears at the bottom of a webpage and usually includes additional information such as contact details, navigation links, sitemaps, and copyright information.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">footer</span><span style="color:#E1E4E8">>...&#x3C;/</span><span style="color:#85E89D">footer</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h4 id="image">image<a class="heading-anchor" href="#image" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><code>&#x3C;img/></code></p>
<p>This tag helps us to insert an image into our document. It is necessary to include the <code>src</code> attribute that sets the path of the image we want to display on the browser. Additionally, the <code>alt</code> attribute plays a crucial role by providing information about the image. The information is utilized by screen readers, benefiting individuals with reading disabilities. It is also recommended by SEO guidelines and appears when the image fails to load correctly (e.g. broken image link cases). Further attributes that can be added include <code>width</code> and <code>height</code> allowing us to define the dimensions of our image. By using images we can beautify our content and make it more attractive and explanatory.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">img</span><span style="color:#B392F0"> src</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"source"</span><span style="color:#B392F0"> alt</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"alternative text"</span><span style="color:#B392F0"> style</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"width:100px; height:100px;"</span><span style="color:#E1E4E8">/></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">img</span><span style="color:#B392F0"> src</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"source"</span><span style="color:#B392F0"> alt</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"alternative text"</span><span style="color:#B392F0"> width</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"100"</span><span style="color:#B392F0"> height</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"100"</span><span style="color:#E1E4E8">/></span></span></code></pre></div>
<h4 id="heading">heading<a class="heading-anchor" href="#heading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><code>&#x3C;h1>...&#x3C;/h1></code> <code>&#x3C;h2>...&#x3C;/h2></code> <code>&#x3C;h3>...&#x3C;/h3></code> <code>&#x3C;h4>...&#x3C;/h4></code> <code>&#x3C;h5>...&#x3C;/h5></code> <code>&#x3C;h6>...&#x3C;/h6></code></p>
<p>We have six heading tags. From <code>&#x3C;h1></code> which is the biggest to <code>&#x3C;h6></code> which is the smallest based on their <code>font-size</code>. All headings have a default size, which can be modified using CSS. Headings are extremely important as they give emphasis and they provide brief information about our document.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">>...&#x3C;/</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">> </span><span style="color:#6A737D">&#x3C;!-- largest heading --></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">h2</span><span style="color:#E1E4E8">>...&#x3C;/</span><span style="color:#85E89D">h2</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">h3</span><span style="color:#E1E4E8">>...&#x3C;/</span><span style="color:#85E89D">h3</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">h4</span><span style="color:#E1E4E8">>...&#x3C;/</span><span style="color:#85E89D">h4</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">h5</span><span style="color:#E1E4E8">>...&#x3C;/</span><span style="color:#85E89D">h5</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">h6</span><span style="color:#E1E4E8">>...&#x3C;/</span><span style="color:#85E89D">h6</span><span style="color:#E1E4E8">> </span><span style="color:#6A737D">&#x3C;!-- smallest heading --></span></span></code></pre></div>
<h4 id="list">list<a class="heading-anchor" href="#list" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><code>&#x3C;li>...&#x3C;/li></code></p>
<p>We have the ordered <a href="/html-lists-made-easy-ordered-unordered-and-special-lists/"><code>&#x3C;ol></code> list</a> that can be either numerical or alphabetical and the unordered <code>&#x3C;ul></code> list that utilizes bullet points.</p>
<p>Additionally, there is a description <code>&#x3C;dl></code> list that is used when we want to display terms along with their corresponding descriptions. It consists of the <code>&#x3C;dl></code> tag (a description list) which requires two elements. The first one is a <code>&#x3C;dt></code> tag, the description term element, and the second one is the <code>&#x3C;dd></code> tag, representing the description itself.
Keep in mind, that the <code>&#x3C;dd></code> element has some <code>margin-left</code> set by default.</p>
<p>📝 Pay attention to the <strong>correct order</strong>, as <code>&#x3C;dt></code> tag always comes before <code>&#x3C;dd></code> tag.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">ol</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>First item&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Second item&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">ol</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">ul</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>First item&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">>Second item&#x3C;/</span><span style="color:#85E89D">li</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">ul</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">dl</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">dt</span><span style="color:#E1E4E8">>HTML&#x3C;/</span><span style="color:#85E89D">dt</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">dd</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    The HyperText Markup Language or HTML is the standard markup language</span></span>
<span class="line"><span style="color:#E1E4E8">    for documents designed to be displayed in</span></span>
<span class="line"><span style="color:#E1E4E8">    a web browser.</span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">dd</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">dt</span><span style="color:#E1E4E8">>CSS&#x3C;/</span><span style="color:#85E89D">dt</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">dd</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    Cascading Style Sheets is a style sheet</span></span>
<span class="line"><span style="color:#E1E4E8">    language used for describing the presentation of a document written</span></span>
<span class="line"><span style="color:#E1E4E8">    in a markup language such as HTML or XML.</span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">dd</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">dl</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h4 id="main">main<a class="heading-anchor" href="#main" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><code>&#x3C;main>...&#x3C;/main></code></p>
<p>It specifies the most significant content that is unique in the whole document and should not be repeated across multiple pages. It must also not contain repeated content such as headers, logos, forms, or links and it can’t be the child of other sections like headers, navbars, footers, or sidebar elements.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">main</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">>I am the main content&#x3C;/</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>I am the first paragraph of the text&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>I am the second paragraph of the text&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">main</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h4 id="paragraph">paragraph<a class="heading-anchor" href="#paragraph" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><code>&#x3C;p>...&#x3C;/p></code></p>
<p>We set it when we add a new paragraph to the document. It is commonly used to separate blocks of text into individual paragraphs, making it easier to organize, read, and understand.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  I am the first paragraph for your content.</span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  I am the second paragraph for your content.</span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h4 id="section">section<a class="heading-anchor" href="#section" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><code>&#x3C;section>...&#x3C;/section></code></p>
<p>This tag is used for separating an HTML document into distinct categories.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">>Making cake&#x3C;/</span><span style="color:#85E89D">h1</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">section</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">h2</span><span style="color:#E1E4E8">>Ingredients&#x3C;/</span><span style="color:#85E89D">h2</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>In order to make a cake we will need butter, flour, milk, cocoa and lemons.&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">section</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">section</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">h2</span><span style="color:#E1E4E8">>Baking&#x3C;/</span><span style="color:#85E89D">h2</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">>We bake the cake in a preheated oven for 50 min at 160 degrees.&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">section</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h4 id="span">span<a class="heading-anchor" href="#span" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><code>&#x3C;span>...&#x3C;/span></code></p>
<p>Is an <a href="/what-does-span-do-in-html-unlocking-its-full-potential/">inline container</a>. We use span when we want to manipulate a specific part inside another HTML element.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  My garden has beautiful</span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> style</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"color:green"</span><span style="color:#E1E4E8">>green&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  trees and</span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">span</span><span style="color:#B392F0"> style</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"color:yellow"</span><span style="color:#E1E4E8">>yellow&#x3C;/</span><span style="color:#85E89D">span</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  flowers.</span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">p</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h4 id="table">table<a class="heading-anchor" href="#table" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><code>&#x3C;table>...&#x3C;/table></code></p>
<p>When we want to insert a table into our document we can use the <code>&#x3C;table></code> tag. To add any essential components of a table we can use <code>&#x3C;tr></code> for rows,<code>&#x3C;th></code> for headings and <code>&#x3C;td></code> for cells.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">table</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">tr</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">th</span><span style="color:#E1E4E8">>Country&#x3C;/</span><span style="color:#85E89D">th</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">th</span><span style="color:#E1E4E8">>Capital&#x3C;/</span><span style="color:#85E89D">th</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">tr</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">tr</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">td</span><span style="color:#E1E4E8">>France&#x3C;/</span><span style="color:#85E89D">td</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">td</span><span style="color:#E1E4E8">>Paris&#x3C;/</span><span style="color:#85E89D">td</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">tr</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">tr</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">td</span><span style="color:#E1E4E8">>Greece&#x3C;/</span><span style="color:#85E89D">td</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">td</span><span style="color:#E1E4E8">>Athens&#x3C;/</span><span style="color:#85E89D">td</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">tr</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;</span><span style="color:#85E89D">tr</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">td</span><span style="color:#E1E4E8">>Italy&#x3C;/</span><span style="color:#85E89D">td</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">    &#x3C;</span><span style="color:#85E89D">td</span><span style="color:#E1E4E8">>Rome&#x3C;/</span><span style="color:#85E89D">td</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  &#x3C;/</span><span style="color:#85E89D">tr</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">table</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<h3 id="special-element-cases">Special element cases<a class="heading-anchor" href="#special-element-cases" data-heading-anchor="" aria-label="Copy link to this section">#</a></h3>
<h4 id="comment">comment<a class="heading-anchor" href="#comment" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><code>&#x3C;!-- your comment --></code></p>
<p>The HTML comment tag is really helpful as we use it to keep notes, which are not displayed on the browser when loaded. However, you have to be careful not to add any sensitive data inside a comment because even though it is not rendered in the browser’s view, it will show up to anyone who knows how to use the browser developer tools and check the HTML document elements.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span>&#x3C;!-- Here goes my comment --></span></span>
<span class="line"><span></span></span>
<span class="line"><span>&#x3C;!--</span></span>
<span class="line"><span>  Here goes my comment when it is</span></span>
<span class="line"><span>  more than one line</span></span>
<span class="line"><span>--></span></span></code></pre></div>
<h4 id="script">script<a class="heading-anchor" href="#script" data-heading-anchor="" aria-label="Copy link to this section">#</a></h4>
<p><code>&#x3C;script>...&#x3C;/script></code></p>
<p>The script tag is commonly known as a special container. It is basically a playground where we can include a set of instructions — a script — that the browser can understand and follow. We can add the instructions inside the tag or link them to an external file that contains our code. In both cases, when the browser reads the HTML document and reaches the script tag, it will try to read and execute what’s included.</p>
<div class="code-block"><button type="button" data-copy-code aria-label="Copy code" aria-live="polite">Copy</button><pre class="shiki github-dark" style="background-color:#24292e;color:#e1e4e8" tabindex="0"><code><span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">script</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">  console.</span><span style="color:#B392F0">log</span><span style="color:#E1E4E8">(</span><span style="color:#9ECBFF">'Hey! Welcome to Little Coding Things squad!'</span><span style="color:#E1E4E8">);</span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;/</span><span style="color:#85E89D">script</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">script</span><span style="color:#B392F0"> src</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"our-script-file.js"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">script</span><span style="color:#E1E4E8">></span></span>
<span class="line"><span style="color:#E1E4E8">&#x3C;</span><span style="color:#85E89D">script</span><span style="color:#B392F0"> src</span><span style="color:#E1E4E8">=</span><span style="color:#9ECBFF">"https://littlecodingthings.com/non-existent-script-file.js"</span><span style="color:#E1E4E8">>&#x3C;/</span><span style="color:#85E89D">script</span><span style="color:#E1E4E8">></span></span></code></pre></div>
<p>Enjoyed this piece? We’ve got <a href="/html-formatting-elements-made-simple-with-easy-and-practical-examples/" title="more engaging content on HTML">more engaging content on HTML</a> make sure to check it out.</p>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/html-formatting-elements-made-simple-with-easy-and-practical-examples/">HTML Text Formatting Elements</a></li>
<li><a href="/html-lists-made-easy-ordered-unordered-and-special-lists/">HTML Lists: ol, ul and dl Explained</a></li>
<li><a href="/is-html-a-programming-language-find-out-now/">Is HTML a Programming Language? Find Out Now!</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Why Are Software Bugs Called Bugs?</title>
      <link>https://littlecodingthings.com/the-unique-origin-of-the-term-bug-in-software-development/</link>
      <guid isPermaLink="true">https://littlecodingthings.com/the-unique-origin-of-the-term-bug-in-software-development/</guid>
      <pubDate>Fri, 01 Mar 2024 12:30:00 GMT</pubDate>
      <description>A moth in a Harvard relay, a 1947 logbook entry, and why the note says the first *actual* case of a bug — the word was already decades old.</description>
      <category>Thoughts &amp; Theory</category>
      <content:encoded><![CDATA[<p>Hey there! Have you ever wondered how bugs became a thing in the computing universe? Let me spill the beans about the origin of the term bug in software development—it’s a hoot of a tale! 😄 So, picture this: Back in the day, computers were as big as a room and probably had more wires than a spaghetti bowl. Well, something hilariously unexpected happened. Here’s a brief history for you explaining why we often refer to issues in software as <strong>bugs</strong>.</p>
<p>First of all, let me introduce you to <strong>Grace Brewster Hopper</strong>. She was both an ultimate tech whiz 🪄 and a naval officer.</p>
<p><img src="/grace-hopper.webp" alt="Grace Hopper image" style="max-width:55%" class="img-narrow"></p>
<p>On September 9, 1947, her team was tinkering with the Harvard Mark II computer when BAM! You won’t believe what they found—it was a real-life moth(!) causing chaos inside the computer! It was trapped inside one of the computer’s relays as the cause of the malfunction.</p>
<p>The funny thing is that they didn’t just squash the poor moth and call it a day. Oh no! They decided to immortalize it, 📸 taping the moth into their logbook next to the note “First actual case of bug being found.” 🦋📔 And voila! That’s how the term ‘bug’ started its digital journey, describing any wonky stuff in computer land.</p>
<p>📌 Look closely at that word <strong>actual</strong>, because it gives the game away. Engineers were already calling faults ‘bugs’ long before 1947 — Thomas Edison was using the word that way in his letters back in 1878 — so the joke only works because everybody in that room already knew what a bug was. The moth didn’t invent the term. It was just the first time anyone got to point at a real one.</p>
<p><img src="/bug-post.webp" alt="The first bug ever caught in paper!"></p>
<p>It is quite interesting, how historical anecdotes like the “moth in the computer’s relays” have contributed to the terminology we use in the world of software and computing. From then on, the computer world couldn’t resist the charm of the word ‘bug’. It’s like the unexpected guest that never left! Whenever something goofy happens in software, hardware, or anything in between, we lovingly call it a ‘bug’.</p>
<p>Isn’t it just delightful how a tiny moth sparked a lingo revolution in the tech empire? The ‘bug’ tale is now part of our nerdy folklore, adding a sense of fun 😄 to the otherwise serious world of coding and fixing stuff.</p>
<p>Grace Brewster Hopper’s reaction to this little moth sparked a concept that echoed globally. So, let’s follow her lead and mimic her actions! We might repeat her success one day.</p>
<blockquote>
<p>IF IT’S A GOOD IDEA, GO AHEAD AND DO IT. IT’S MUCH EASIER TO APOLOGIZE THAN IT IS TO GET PERMISSION</p>
<p>Grace Brewster Hopper</p>
</blockquote>
<h2 id="keep-reading">Keep reading<a class="heading-anchor" href="#keep-reading" data-heading-anchor="" aria-label="Copy link to this section">#</a></h2>
<ul>
<li><a href="/did-you-know-why-are-browser-cookies-called-cookies/">Why are browser cookies called cookies?</a> — another name with a story behind it</li>
<li><a href="/javascript-testing-for-beginners-a-simple-practical-introduction/">Javascript Testing for Beginners</a> — how we catch bugs now that we can’t open the case and look</li>
<li><a href="/integration-and-unit-tests-how-to-choose-the-right-one/">Integration and Unit Tests: How to Choose the Right One</a> — picking the right net for the right bug</li>
</ul>]]></content:encoded>
    </item>
  </channel>
</rss>