<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Amit Joki's TIL]]></title><description><![CDATA[Amit Joki's TIL]]></description><link>https://til.amitjoki.com</link><generator>RSS for Node</generator><lastBuildDate>Wed, 08 Apr 2026 12:17:53 GMT</lastBuildDate><atom:link href="https://til.amitjoki.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Font Classes in TailwindCSS]]></title><description><![CDATA[Text is ubiquitous on the web. Websites must have a legible and appropriate font that suits their target audience. Styling the text to indicate the importance or to provide an emphasis helps in the readability of the website.
Font Family
The CSS prop...]]></description><link>https://til.amitjoki.com/font-classes-in-tailwindcss</link><guid isPermaLink="true">https://til.amitjoki.com/font-classes-in-tailwindcss</guid><category><![CDATA[Tailwind CSS]]></category><category><![CDATA[Tailwind CSS Tutorial]]></category><category><![CDATA[CSS]]></category><category><![CDATA[CSS3]]></category><category><![CDATA[CSS Frameworks]]></category><dc:creator><![CDATA[Amit Joki]]></dc:creator><pubDate>Sun, 02 Apr 2023 08:04:45 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1680327482495/d4b24f28-878d-4755-b22f-5b7036c7b5f3.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Text is ubiquitous on the web. Websites must have a legible and appropriate font that suits their target audience. Styling the text to indicate the importance or to provide an emphasis helps in the readability of the website.</p>
<h1 id="heading-font-family">Font Family</h1>
<p>The CSS property <code>font-family</code> takes a list of font family names that the browser will use to render the text based on font availability.</p>
<p>In general, font families can be broadly categorized into:</p>
<ul>
<li><p><a target="_blank" href="https://en.wikipedia.org/wiki/Serif">Serif fonts</a> - Fonts that help improve readability in non-screen texts like in newspapers.</p>
</li>
<li><p><a target="_blank" href="https://en.wikipedia.org/wiki/Sans-serif">Sans serif fonts</a> - Fonts that help improve readability in screen texts like on a PC or a Macbook or even Androids and iPhones.</p>
</li>
<li><p><a target="_blank" href="https://en.wikipedia.org/wiki/Monospaced_font">Monospace fonts</a> - Fonts that help improve readability in code.</p>
</li>
</ul>
<p>TailwindCSS offers classes for all these font types - <code>font-serif</code>, <code>font-sans</code>, <code>font-mono</code> respectively.</p>
<p>If you want a one-off font family for a particular text, we can do so by specifying an arbitrary font family name within <code>[]</code> after <code>font-</code></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">font-</span><span class="hljs-selector-attr">[<span class="hljs-string">'Impact'</span>]</span> <span class="hljs-selector-tag">becomes</span> <span class="hljs-selector-tag">font-family</span>: '<span class="hljs-selector-tag">Impact</span>';
<span class="hljs-comment">/* Spaces to be replaced with _ and use quotes like below */</span>
<span class="hljs-selector-tag">font-</span><span class="hljs-selector-attr">[<span class="hljs-string">'Times_New_Roman'</span>]</span> <span class="hljs-selector-tag">becomes</span> <span class="hljs-selector-tag">font-family</span>: '<span class="hljs-selector-tag">Times</span> <span class="hljs-selector-tag">New</span> <span class="hljs-selector-tag">Roman</span>';
</code></pre>
<h2 id="heading-theming">Theming</h2>
<p>TailwindCSS can be themed using <code>tailwind.config.js</code> The Font Family can be themed using <code>theme.extend.fontFamily</code> object. You can either override <code>sans</code>, <code>serif</code>, and <code>mono</code> if you want to continue using <code>font-sans</code>, <code>font-serif</code>, <code>font-mono</code> or if you want to include your own <code>font-{suffix}</code> you can do so too by specifying the <code>suffix</code> as key in <code>theme.extend.fontFamily</code> and value of type <code>String | String[]</code></p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Overriding 'font-sans' with String[] format</span>
<span class="hljs-string">'sans'</span>: [<span class="hljs-string">'Helvetica'</span>, <span class="hljs-string">'Arial'</span>, <span class="hljs-string">'sans-serif'</span>],

<span class="hljs-comment">// Creating 'font-brand' with String format</span>
<span class="hljs-string">'brand'</span>: <span class="hljs-string">'Helvetica, Arial, sans-serif'</span>,
</code></pre>
<p>In the below example, I add a <code>font-fancy</code> class which will use <code>cursive</code> font family.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// tailwind.config.js</span>
<span class="hljs-built_in">module</span>.exports = {
  <span class="hljs-attr">theme</span>: { 
    <span class="hljs-attr">extend</span>: {
      <span class="hljs-attr">fontFamily</span>: {
        <span class="hljs-string">'fancy'</span>: <span class="hljs-string">'cursive'</span>,
      }
    }
  }
}
</code></pre>
<p>Now let us put everything we've learned so far into action:</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"font-sans"</span>&gt;</span>Font Sans - The quick brown fox jumps over the lazy dog<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"font-serif"</span>&gt;</span>Font Serif - The quick brown fox jumps over the lazy dog<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"font-mono"</span>&gt;</span>Font Mono - The quick brown fox jumps over the lazy dog<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"font-['Impact']"</span>&gt;</span>Arbitrary font Impact - The quick brown fox jumps over the lazy dog<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"font-fancy"</span>&gt;</span>Font Fancy - The quick brown fox jumps over the lazy dog<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1680415481925/08020467-84ef-41a0-9709-9cf3e2460702.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-customizing-default-font">Customizing Default Font</h2>
<p>By default, TailwindCSS's default theme Preflight's <code>font-sans</code> will be applied to the <code>html</code> element.</p>
<p>To have a different default font, you can either</p>
<ol>
<li><p>Override <code>font-sans</code> in <code>theme.fontFamily</code></p>
</li>
<li><p>Override it explicitly like below (don't worry about <code>@layer base</code> stuff for now, it will be covered in one of the articles later. Technically you can get away by not using it but it is the best practice, the "why" of it will be covered later).</p>
<pre><code class="lang-css"> <span class="hljs-keyword">@layer</span> base {
   <span class="hljs-selector-tag">html</span> {
     <span class="hljs-attribute">font-family</span>: Roboto, system-ui, sans-serif;
   }
 }
</code></pre>
</li>
</ol>
<hr />
<h1 id="heading-font-size">Font Size</h1>
<p>The CSS property <code>font-size</code> sets the size of the font. Essentially, it lets you tell the browser how big you want your font to be displayed.</p>
<p>TailwindCSS has several in-built sizes which take the form <code>text-{size}</code> where <code>size</code> can be <code>xs, sm, base, lg, xl, 2xl, 3xl, 4xl, 5xl, 6xl, 7xl, 8xl, 9xl</code></p>
<p>We can also set an arbitrary value if required. Let's say we want our <code>font-size</code> to be <code>150px</code>, we can set it as <code>text-[150px]</code></p>
<h2 id="heading-theming-1">Theming</h2>
<p>We can theme the font sizes through <code>theme.extend.fontSize</code> object. Like with font family, we can override the existing built-in presets like <code>base</code> or add a completely new preset like <code>huge</code></p>
<pre><code class="lang-javascript"><span class="hljs-comment">// tailwind.config.js</span>
<span class="hljs-built_in">module</span>.exports = {
  <span class="hljs-attr">theme</span>: {
    <span class="hljs-attr">extend</span>: {
      <span class="hljs-attr">fontSize</span>: {
        <span class="hljs-attr">base</span>: <span class="hljs-string">'15px'</span>, <span class="hljs-comment">// overriding 'font-base'</span>
        <span class="hljs-attr">huge</span>: <span class="hljs-string">'50px'</span> <span class="hljs-comment">// creating 'font-huge' with font-size: 50px;</span>
      }
    }
  }
}
</code></pre>
<p>Let us now see all that we've learned in action</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-xs"</span>&gt;</span>Text Extra Small<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-sm"</span>&gt;</span>Text Small<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-base"</span>&gt;</span>Text Base/Regular<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-lg"</span>&gt;</span>Text Large<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-xl"</span>&gt;</span>Text Extra Large<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-2xl"</span>&gt;</span>Text 2xl<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-3xl"</span>&gt;</span>Text 3xl<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-4xl"</span>&gt;</span>Text 4xl<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-5xl"</span>&gt;</span>Text 5xl<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-6xl"</span>&gt;</span>Text 6xl<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-7xl"</span>&gt;</span>Text 7xl<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-8xl"</span>&gt;</span>Text 8xl<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-9xl"</span>&gt;</span>Text 9xl<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-huge"</span>&gt;</span>Text Huge<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-[150px]"</span>&gt;</span>150px Text<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1680419642874/80d080f6-a475-451a-af44-27d26ab9cbbf.png" alt class="image--center mx-auto" /></p>
<hr />
<h1 id="heading-font-style">Font Style</h1>
<p>There are only two classes - <code>italic</code> and <code>non-italic</code> with the latter used to reset <code>italic</code> at different breakpoints or states which we'll see later.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"non-italic"</span>&gt;</span>Non italic<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"italic"</span>&gt;</span>Italic<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1680419968579/6b743db9-ab8a-4ef4-a1d6-8b7f0ea7ff79.png" alt class="image--center mx-auto" /></p>
<hr />
<h1 id="heading-font-weight">Font Weight</h1>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Class Name</td><td>Font Weight</td></tr>
</thead>
<tbody>
<tr>
<td>font-thin</td><td>100</td></tr>
<tr>
<td>font-extralight</td><td>200</td></tr>
<tr>
<td>font-light</td><td>300</td></tr>
<tr>
<td>font-normal</td><td>400</td></tr>
<tr>
<td>font-medium</td><td>500</td></tr>
<tr>
<td>font-semibold</td><td>600</td></tr>
<tr>
<td>font-bold</td><td>700</td></tr>
<tr>
<td>font-extrabold</td><td>800</td></tr>
<tr>
<td>font-black</td><td>900</td></tr>
<tr>
<td>font-[1100] (arbitrary value)</td><td>1100 (arbitrary value)</td></tr>
</tbody>
</table>
</div><p>Arbitrary font-weights like <code>font-[1100]</code> are only applicable if the font supports it. Let us see the different font weights in action.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"font-thin"</span>&gt;</span>Font Thin - 100<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"font-extralight"</span>&gt;</span>Font Extra Light - 200<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"font-light"</span>&gt;</span>Font Light - 300<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"font-normal"</span>&gt;</span>Font Normal - 400<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"font-medium"</span>&gt;</span>Font Medium - 500<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"font-semibold"</span>&gt;</span>Font Semibold - 600<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"font-bold"</span>&gt;</span>Font Bold - 700<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"font-extrabold"</span>&gt;</span>Font Extra Bold - 800<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"font-black"</span>&gt;</span>Font Black - 900<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1680420324417/51092f24-dff2-47ea-83cc-4de215541115.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-theming-2">Theming</h2>
<p>Like others, you can theme font weight by <code>theme.extend.fontWeight</code> object. You can</p>
<ol>
<li><p>Override existing font-weight presets like <code>'thin': '200'</code></p>
</li>
<li><p>Create a new font-weight preset like <code>'thick': '900'</code></p>
</li>
</ol>
<hr />
<h1 id="heading-advanced">Advanced</h1>
<p>There are some rare-use cases where you might need to use <a target="_blank" href="https://tailwindcss.com/docs/font-smoothing">Font Smoothing</a> and <a target="_blank" href="https://tailwindcss.com/docs/font-variant-numeric">Font Variant Numeric</a>. It is left as an additional reading or an exercise.</p>
<hr />
<h1 id="heading-code">Code</h1>
<p>To make it easier to follow the series, I've created a Github Repository at <a target="_blank" href="https://github.com/AmitJoki/Learn-Tailwindcss">AmitJoki/Learn-Tailwindcss</a></p>
<p>The code used in this article can be found <a target="_blank" href="https://github.com/AmitJoki/Learn-Tailwindcss/blob/main/Fonts/index.html">here.</a></p>
]]></content:encoded></item><item><title><![CDATA[Introduction to TailwindCSS]]></title><description><![CDATA[TailwindCSS is a utility-first CSS framework packed with classes that can be composed to build any design, directly in your markup.

That's a lot of words to take in, isn't it? That's how TailwindCSS is defined by the official documentation.
Tailwind...]]></description><link>https://til.amitjoki.com/introduction-to-tailwindcss</link><guid isPermaLink="true">https://til.amitjoki.com/introduction-to-tailwindcss</guid><category><![CDATA[CSS]]></category><category><![CDATA[Tailwind CSS]]></category><category><![CDATA[Tailwind CSS Tutorial]]></category><category><![CDATA[CSS3]]></category><category><![CDATA[CSS Frameworks]]></category><dc:creator><![CDATA[Amit Joki]]></dc:creator><pubDate>Sat, 01 Apr 2023 03:09:38 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1680321461701/a757001c-d124-4601-ad5e-dcfd44fb8117.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<blockquote>
<p>TailwindCSS is a utility-first CSS framework packed with classes that can be composed to build any design, directly in your markup.</p>
</blockquote>
<p>That's a lot of words to take in, isn't it? That's how TailwindCSS is defined by the official documentation.</p>
<p><a target="_blank" href="https://tailwindcss.com/docs/installation">Tailwindcss Documentation</a> is excellent and should serve as your go-to manual for anything Tailwindcss. But its top-down structure, i.e. covering the high-level concepts first and then drilling down to the basics may intimidate people new to it.</p>
<p>In this series, we will take a bottom-up approach where we'll learn the rudimentary details in an opinionated structure and progress gradually to the high-level concepts. This helps in avoiding cognitive overload. Imagine having to write an essay on Shakespeare without knowing what the alphabets are!</p>
<p>I'll assume you have a basic working knowledge of CSS. If you want a refresher or are completely new to CSS and want to learn, you can do so with these excellent linked resources before hopping right back here to continue your journey towards mastering TailwindCSS.</p>
<ol>
<li><p><a target="_blank" href="https://web.dev/learn/css/">Learn CSS - web.dev</a></p>
</li>
<li><p><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Learn/CSS">Learn to style HTML using CSS</a></p>
</li>
</ol>
<hr />
<h1 id="heading-classes">Classes</h1>
<p>TailwindCSS is built on classes. We design by combining different classes. And what's more? TailwindCSS is clever enough to only include the styles for the classes we've used - which means faster load times, yay!</p>
<p>Let's take a quick look at what classes are.</p>
<p>The syntax of a class is as follows.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.className</span> { <span class="hljs-comment">/* It starts with a period followed by the class name */</span>
   <span class="hljs-attribute">propertyName</span>: proptertyValue;
   ....
   ....
}
</code></pre>
<p>A class is a way to combine different CSS properties and values under a single name. We can then apply all those styles to elements using the <code>class</code> attribute (or <code>className</code> attribute if you're working with React/JSX).</p>
<p>It is important to note we can add as many classes as we want, separated by a space and styles will be applied after rules of <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity">specificity</a> are taken into consideration.</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"className anotherClassName"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<hr />
<p>We now know the building blocks of TailwindCSS. It's just a bunch of different classes doing different things which when combined correctly can result in a beautiful design without having to write any of our own CSS.</p>
<p>Starting from the next article of the series, we will deep dive into the beautiful world of TailwindCSS and get some hands-on experience with its classes.</p>
]]></content:encoded></item></channel></rss>