<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nikolai Lehbrink</title>
    <description>The latest articles on DEV Community by Nikolai Lehbrink (@nikolailehbrink).</description>
    <link>https://dev.to/nikolailehbrink</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1352502%2F14ce7b85-b202-46b4-bb0e-bc197426a19f.jpeg</url>
      <title>DEV Community: Nikolai Lehbrink</title>
      <link>https://dev.to/nikolailehbrink</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nikolailehbrink"/>
    <language>en</language>
    <item>
      <title>Tailwind CSS v4 tips every developer should know</title>
      <dc:creator>Nikolai Lehbrink</dc:creator>
      <pubDate>Thu, 17 Jul 2025 14:35:52 +0000</pubDate>
      <link>https://dev.to/nikolailehbrink/tailwind-css-v4-tips-every-developer-should-know-i21</link>
      <guid>https://dev.to/nikolailehbrink/tailwind-css-v4-tips-every-developer-should-know-i21</guid>
      <description>&lt;p&gt;Over the past years, I've used Tailwind CSS in almost every web project I've undertaken. Along the way, I've picked up a few handy tips and tricks that I'd like to share.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common Practices
&lt;/h2&gt;

&lt;p&gt;Some scenarios that many people have probably encountered.&lt;/p&gt;

&lt;h3&gt;
  
  
  Targeting a single breakpoint
&lt;/h3&gt;

&lt;p&gt;Sometimes you wan't to style an element only for a specific breakpoint. I ended up writing classes, that targeted multiple breakpoints, only to style one in particular.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"bg-red-500 sm:bg-green-500 md:bg-red-500"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- ... --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However with the &lt;a href="https://tailwindcss.com/blog/tailwindcss-v3-2" rel="noopener noreferrer"&gt;release of Tailwind CSS v3.2&lt;/a&gt; and the &lt;a href="https://tailwindcss.com/blog/tailwindcss-v3-2#max-width-and-dynamic-breakpoints" rel="noopener noreferrer"&gt;implementation of dynamic breakpoints&lt;/a&gt; it is much easier to target a single breakpoint.&lt;/p&gt;

&lt;p&gt;You can stack responsive modifiers and achieve the same result with only one class selector.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"bg-red-500 sm:max-xl:bg-green-500"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- ... --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The same logic applies to breakpoint ranges.&lt;/p&gt;

&lt;h3&gt;
  
  
  Targeting Elements Not Included in Your Initial Markup
&lt;/h3&gt;

&lt;p&gt;Almost inevitable, you will encounter scenarios where some elements are not directly accessible in your static HTML markup because they are added during the build process or dynamically through JavaScript.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;When is this ever going to happen, you might ask?!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This often occurs with content generated by third-party tools or libraries.&lt;/p&gt;

&lt;p&gt;For example, I use a syntax highlighter called &lt;a href="https://shiki.style/" rel="noopener noreferrer"&gt;&lt;code&gt;Shiki&lt;/code&gt;&lt;/a&gt;, which generates the blocks of code you see on &lt;a href="https://www.nikolailehbr.ink/blog" rel="noopener noreferrer"&gt;my blog posts&lt;/a&gt;. They are wrapped in &lt;code&gt;&amp;lt;pre&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;code&amp;gt;&lt;/code&gt; tags and these elements still require styling to ensure they align with the overall design of the site.&lt;/p&gt;

&lt;p&gt;Here are two possible ways of dealing with this situation.&lt;/p&gt;

&lt;h4&gt;
  
  
  Use the &lt;code&gt;@apply&lt;/code&gt; directive
&lt;/h4&gt;

&lt;p&gt;You can use &lt;a href="https://tailwindcss.com/docs/functions-and-directives#apply" rel="noopener noreferrer"&gt;&lt;code&gt;@apply&lt;/code&gt;&lt;/a&gt; to inline any existing utility classes into your own custom CSS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.shiki&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="err"&gt;pre&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
    &lt;span class="err"&gt;@apply&lt;/span&gt; &lt;span class="err"&gt;scrollbar-thin&lt;/span&gt; &lt;span class="err"&gt;overflow-x-auto&lt;/span&gt; &lt;span class="err"&gt;bg-neutral-900;&lt;/span&gt;
    &lt;span class="err"&gt;code&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
      &lt;span class="err"&gt;@apply&lt;/span&gt; &lt;span class="err"&gt;block&lt;/span&gt; &lt;span class="err"&gt;w-fit&lt;/span&gt; &lt;span class="err"&gt;min-w-full;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="err"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Use arbitrary variants
&lt;/h4&gt;

&lt;p&gt;With the implementation of &lt;a href="https://tailwindcss.com/docs/hover-focus-and-other-states#using-arbitrary-variants" rel="noopener noreferrer"&gt;arbitrary variants&lt;/a&gt; in &lt;a href="https://tailwindcss.com/blog/tailwindcss-v3-1" rel="noopener noreferrer"&gt;Tailwind CSS v3.1&lt;/a&gt; it is possible to create custom variants directly in your HTML.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"[&amp;amp;&amp;gt;pre]:overflow-x-auto [&amp;amp;_code]:block ..."&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- &amp;lt;pre&amp;gt;
    &amp;lt;code&amp;gt;
      ...
    &amp;lt;/code&amp;gt;
  &amp;lt;/pre&amp;gt; --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Which selectors do the classes address?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this example, the selector &lt;code&gt;[&amp;amp;_code]&lt;/code&gt; targets all &lt;code&gt;&amp;lt;code&amp;gt;&lt;/code&gt; child elements and &lt;code&gt;[&amp;amp;&amp;gt;pre]&lt;/code&gt; specifically targets &lt;code&gt;&amp;lt;pre&amp;gt;&lt;/code&gt; elements that are direct children of the surrounding &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Customise containers with standard padding and autocentering
&lt;/h3&gt;

&lt;p&gt;Often times in web design, we do not wan't to scale or fit content to the outermost width of the viewport but rather have content inside a container which helps usability and helps the user to focus on the important part of the site.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://tailwindcss.com/docs/max-width#using-breakpoints-container" rel="noopener noreferrer"&gt;&lt;code&gt;container&lt;/code&gt; class&lt;/a&gt; in Tailwind CSS can be used to achieve just that, applying a &lt;code&gt;max-width&lt;/code&gt; to the specific element.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; A common case is centering the container on the page with side padding to keep content away from the viewport edges, especially on mobile devices.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container mx-auto px-4 sm:px-8 lg:px-16"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- ... --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code above achieves that functionality, but always having to centre the container yourself with the &lt;code&gt;mx-auto&lt;/code&gt; class and specify your own padding can lead to inconsistencies and is a rather tedious task. &lt;/p&gt;

&lt;p&gt;That's why in Tailwind CSS v4, you can adjust the &lt;code&gt;container&lt;/code&gt; utility directly with CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@utility&lt;/span&gt; &lt;span class="n"&gt;container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;@apply&lt;/span&gt; &lt;span class="n"&gt;mx-auto&lt;/span&gt; &lt;span class="n"&gt;px-4&lt;/span&gt; &lt;span class="n"&gt;sm&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;px-8&lt;/span&gt; &lt;span class="n"&gt;lg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;px-16&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This centers your container and adds consistent horizontal padding, all by simply extending the utility.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.nikolailehbr.ink/blog" class="crayons-btn crayons-btn--primary" rel="noopener noreferrer"&gt;I put a lot of effort into creating content that is informative, engaging, and useful for my readers. If you find it valuable...&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;Now, simply use the &lt;code&gt;container&lt;/code&gt; class and have the same result, without any further code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- ... --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Using theme values in JavaScript
&lt;/h3&gt;

&lt;p&gt;In Tailwind CSS v3, you could use the &lt;code&gt;resolveConfig&lt;/code&gt; function to access your theme values directly in JavaScript. In v4, this approach has changed: &lt;strong&gt;Tailwind now generates CSS variables for your theme values&lt;/strong&gt;, making it much easier (and more efficient) to use them in your code.&lt;/p&gt;

&lt;p&gt;Instead of importing and resolving your config, you can reference these CSS variables directly. For example, with &lt;a href="https://chakra-ui.com/" rel="noopener noreferrer"&gt;Chakra UI&lt;/a&gt;, you can style a component using a Tailwind theme color like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Box&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@chakra-ui/react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Box&lt;/span&gt; &lt;span class="na"&gt;sx&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;backgroundColor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;var(--color-emerald-500)&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  Themed with Tailwind CSS variable!
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Box&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you need to access the &lt;em&gt;resolved value&lt;/em&gt; of a CSS variable in JavaScript, you can use &lt;code&gt;getComputedStyle&lt;/code&gt; on the &lt;code&gt;document.documentElement&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;styles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getComputedStyle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;documentElement&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;shadow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getPropertyValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;--shadow-xl&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This new approach is simpler and helps reduce your bundle size, since you no longer need to import or resolve your Tailwind config in your application code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting width and height in one go
&lt;/h3&gt;

&lt;p&gt;Often, when browsing through tutorials on YouTube or other websites, you'll notice that many developers apply width and height classes separately to achieve &lt;em&gt;square dimensions&lt;/em&gt; for elements like icons or avatars.&lt;/p&gt;

&lt;p&gt;With the introduction of the &lt;code&gt;size-*&lt;/code&gt; utilities in &lt;a href="https://tailwindcss.com/blog/tailwindcss-v3-4#new-size-utilities" rel="noopener noreferrer"&gt;Tailwind CSS v3.4&lt;/a&gt;, setting both dimensions simultaneously has become much more straightforward.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"size-12 bg-red-500"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- ... --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Optimize Development
&lt;/h2&gt;

&lt;p&gt;Tips that should make your development with Tailwind CSS v4 easier.&lt;/p&gt;

&lt;h3&gt;
  
  
  Automatic wrapping of long class names
&lt;/h3&gt;

&lt;p&gt;With Tailwind CSS it is almost impossible to avoid writing long class names for certain elements. This should not be a problem, but the class names remain on one line and are not, for example, formatted and limited in length by Prettier and split over several lines. This means that developers often have to scroll horizontally for some time to find the right class.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The problem is so significant that it is &lt;a href="https://github.com/tailwindlabs/tailwindcss/discussions?discussions_q=is%3Aopen+sort%3Atop" rel="noopener noreferrer"&gt;rated as the top idea for Tailwind CSS on GitHub&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;But now there is a solution.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Github-User &lt;a href="https://github.com/ony3000" rel="noopener noreferrer"&gt;ony3000&lt;/a&gt; has created &lt;a href="https://dev.toprettier-plugin-classnames"&gt;prettier-plugin-classnames&lt;/a&gt;,&lt;br&gt;
which wraps long class names based on Prettier's &lt;code&gt;printWidth&lt;/code&gt; option. With a slightly extended configuration, it can be used in conjunction with &lt;a href="https://github.com/tailwindlabs/prettier-plugin-tailwindcss" rel="noopener noreferrer"&gt;prettier-plugin-tailwindcss&lt;/a&gt; to also automatically sort the classes.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;For more information on how to get the plugin up and running, I suggest you read the &lt;a href="https://github.com/ony3000/prettier-plugin-classnames?tab=readme-ov-file#installation1" rel="noopener noreferrer"&gt;installation instructions&lt;/a&gt;. Basically it's just a matter of installing the plugin, adding it to your &lt;code&gt;prettier.config.js&lt;/code&gt; and restarting your code editor.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I am using the plugin on this site with the following &lt;code&gt;prettier.config.js&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/** @type {import("prettier").Config} */&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;functions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cn&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;clsx&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cva&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Used to sort classes in strings provided to function calls (clsx, twMerge or cva)&lt;/span&gt;
  &lt;span class="na"&gt;tailwindFunctions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;functions&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="c1"&gt;// Used to wrap classes in strings provided to function calls (clsx, twMerge or cva)&lt;/span&gt;
  &lt;span class="na"&gt;customFunctions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;functions&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;tailwindStylesheet&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./app/app.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="c1"&gt;// https://github.com/ony3000/prettier-plugin-classnames?tab=readme-ov-file#ending-position&lt;/span&gt;
  &lt;span class="na"&gt;endingPosition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;absolute-with-indent&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;prettier-plugin-tailwindcss&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;prettier-plugin-classnames&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="c1"&gt;// Needed to make both plugins work together&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;prettier-plugin-merge&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;semi&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;tabWidth&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;singleQuote&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Adjusting Font Size in VS Code Intellisense Extension
&lt;/h3&gt;

&lt;p&gt;One of the reasons Tailwind CSS has become such a time-saving tool for me is undoubtedly the great &lt;a href="https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss" rel="noopener noreferrer"&gt;Intellisense extension for VS Code&lt;/a&gt;. It gives you autosuggestions for classes, but also pixel values according to your root font size, which can be very helpful.&lt;/p&gt;

&lt;p&gt;A common problem I ran into was that if I deviated from the default font size of 16px in my project, the pixel values displayed by the extension would not update accordingly and would always stick to the default font size of 16px.&lt;/p&gt;

&lt;p&gt;However, after a bit of research, I found that there is an option to change the font size used by the extension to your liking using the &lt;code&gt;rootFontSize&lt;/code&gt; setting.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"tailwindCSS.rootFontSize"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;17&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should now see the correct pixel values when you hover over the classes after changing the setting.&lt;/p&gt;

&lt;h3&gt;
  
  
  Automatic class sorting
&lt;/h3&gt;

&lt;p&gt;Maintaining a clean and organised codebase is essential for any development project. One useful feature that improves code clarity, especially when working with Tailwind CSS, is automatic class sorting.&lt;/p&gt;

&lt;h4&gt;
  
  
  Integration with Prettier
&lt;/h4&gt;

&lt;p&gt;The &lt;a href="https://github.com/tailwindlabs/prettier-plugin-tailwindcss" rel="noopener noreferrer"&gt;prettier-plugin-tailwindcss&lt;/a&gt; automatically organises Tailwind CSS classes in your files according to a predefined order, which not only improves readability, but also helps to maintain a consistent style across your project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Figrzofu0yilar4n18zaj.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Figrzofu0yilar4n18zaj.jpg" alt="Banner for prettier-plugin-tailwindcss"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;To learn more about how the classes are ordered and how to install the plugin, I suggest you read &lt;a href="https://tailwindcss.com/blog/automatic-class-sorting-with-prettier" rel="noopener noreferrer"&gt;the corresponding blog post&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  VS Code Extension Headwind
&lt;/h4&gt;

&lt;p&gt;There is also a &lt;a href="https://marketplace.visualstudio.com/items?itemName=heybourn.headwind" rel="noopener noreferrer"&gt;VS Code extension called Headwind&lt;/a&gt; which does basically the same thing but has a different ordering system. I used it for a while before I found out about the Prettier plugin.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I can't recommend using it as it's no longer maintained and there seem to be &lt;a href="https://github.com/heybourn/headwind/issues" rel="noopener noreferrer"&gt;some issues that won't get fixed&lt;/a&gt;. However there is a more &lt;a href="https://github.com/heybourn/headwind/issues/206" rel="noopener noreferrer"&gt;actively maintained fork&lt;/a&gt; of Headwind called "Tailwind Raw Reorder", which is also &lt;a href="https://marketplace.visualstudio.com/items?itemName=Trapfether.tailwind-raw-reorder" rel="noopener noreferrer"&gt;available on the Visual Studio Marketplace&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Design patterns
&lt;/h2&gt;

&lt;p&gt;Because I find myself implementing the same design patterns in many of my projects, here are some of them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Break elements out of typography plugin
&lt;/h3&gt;

&lt;p&gt;To ensure high quality typography standards for a project, I often rely on &lt;a href="https://github.com/tailwindlabs/tailwindcss-typography" rel="noopener noreferrer"&gt;Tailwind CSS's typography plugin&lt;/a&gt;, which provides some useful classes to get you up and running in no time.&lt;/p&gt;

&lt;p&gt;Recently I was creating a website for a side project and to make things a bit more interesting I wanted to break out some of the elements out of the typography container. At first I thought this could be achieved by using the &lt;code&gt;not-prose&lt;/code&gt; class as mentioned in &lt;a href="https://github.com/tailwindlabs/tailwindcss-typography?tab=readme-ov-file#undoing-typography-styles" rel="noopener noreferrer"&gt;the plugins README for undoing typography styles&lt;/a&gt;. However, this does not work for breaking elements out of the &lt;code&gt;prose&lt;/code&gt; container that sets a &lt;code&gt;max-width&lt;/code&gt;, which makes sense.&lt;/p&gt;

&lt;p&gt;A workaround for this is to set a negative &lt;code&gt;margin&lt;/code&gt; on the horizontal axis and break out elements that way.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"prose"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"not-prose md:-mx-16 lg:-mx-32 2xl:-mx-48"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- ... --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result is a section that extends beyond the plugin’s defined &lt;code&gt;max-width&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0fnz8482my3kfp6rpzp6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0fnz8482my3kfp6rpzp6.png" alt="Breakout section with negative margins"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Create gradient text with Tailwind CSS
&lt;/h3&gt;

&lt;p&gt;Many professional websites today use gradient headlines to grab the attention of visitors and give their pages a dynamic, modern look.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxpqxh1t8706pdbi0znbv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxpqxh1t8706pdbi0znbv.png" alt="Gradient heading on the frontpage of Supabase"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is how you can implement that in one line with Tailwind CSS v4.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"inline-block bg-linear-to-b from-neutral-500 to-neutral-300 bg-clip-text text-3xl text-transparent"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  This is a demo text
&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's all for now! Thanks for reading and I would really appreciate your feedback or hear about tips that you find worth sharing!&lt;/p&gt;

</description>
      <category>tailwindcss</category>
      <category>designsystem</category>
      <category>productivity</category>
      <category>css</category>
    </item>
  </channel>
</rss>
