Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Never Stop Exploring (July 2025 Wallpapers Edition)

      June 30, 2025

      How AI further empowers value stream management

      June 27, 2025

      12 Top ReactJS Development Companies in 2025

      June 27, 2025

      Not sure where to go with AI? Here’s your roadmap.

      June 27, 2025

      I never thought I’d praise a kickstand power bank – until I tried this one

      June 30, 2025

      I replaced my work PC with this Alienware laptop – now I’m wondering why I hadn’t done this sooner

      June 30, 2025

      How to set up Alexa to receive notifications on Prime Day deals you want

      June 30, 2025

      How proxy servers actually work, and why they’re so valuable

      June 30, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      What’s the difference between named functions and arrow functions in JavaScript?

      June 30, 2025
      Recent

      What’s the difference between named functions and arrow functions in JavaScript?

      June 30, 2025

      Spring Boot + Swagger: A Complete Guide to API Documentation

      June 30, 2025

      Wire Room Math: AI + SME = (Less Compensation Paid) X (Headline Risk + Payment Errors)^2

      June 30, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Artix Linux: Introduzione di XLibre nelle Build Sperimentali

      June 30, 2025
      Recent

      Artix Linux: Introduzione di XLibre nelle Build Sperimentali

      June 30, 2025

      Orange Pi R2S Single Board Computer Running Linux: Introduction

      June 30, 2025

      vmstat – reports virtual memory statistics

      June 30, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»Using CSS Cascade Layers With Tailwind Utilities

    Using CSS Cascade Layers With Tailwind Utilities

    June 30, 2025

    Adam Wathan has (very cleverly) built Tailwind with CSS Cascade Layers, making it extremely powerful for organizing styles by priority.

    @layer theme, base, components, utilities;
    @import 'tailwindcss/theme.css' layer(theme);
    @import 'tailwindcss/utilities.css' layer(utilities);

    The core of Tailwind are its utilities. This means you have two choices:

    1. The default choice
    2. The unorthodox choice

    The default choice

    The default choice is to follow Tailwind’s recommended layer order: place components first, and Tailwind utilities last.

    So, if you’re building components, you need to manually wrap your components with a @layer directive. Then, overwrite your component styles with Tailwind, putting Tailwind as the “most important layer”.

    /* Write your components */
    @layer components {
      .component {
        /* Your CSS here */
      }
    }
    <!-- Override with Tailwind utilities --> 
    <div class="component p-4"> ... </div>

    That’s a decent way of doing things.

    But, being the bad boy I am, I don’t take the default approach as the “best” one. Over a year of (major) experimentation with Tailwind and vanilla CSS, I’ve come across what I believe is a better solution.

    The Unorthodox Choice

    Before we go on, I have to tell you that I’m writing a course called Unorthodox Tailwind — this shows you everything I know about using Tailwind and CSS in synergistic ways, leveraging the strengths of each.

    Shameless plug aside, let’s dive into the Unorthodox Choice now.

    In this case, the Unorthodox Choice is to write your styles in an unnamed layer — or any layer after utilities, really — so that your CSS naturally overwrites Tailwind utilities.

    Of these two, I prefer the unnamed layer option:

    /* Unnamed layer option */
    @layer theme, base, components, utilities; 
    
    /* Write your CSS normally here */ 
    .component { /* ... */ }
    /* Named layer option */
    /* Use whatever layer name you come up with. I simply used css here because it made most sense for explaining things */
    @layer theme, base, components, utilities, css; 
    
    @layer css {
      .component { /* ... */ }
    }

    I have many reasons why I do this:

    1. I don’t like to add unnecessary CSS layers because it makes code harder to write — more keystrokes, having to remember the specific layer I used it in, etc.
    2. I’m pretty skilled with ITCSS, selector specificity, and all the good-old-stuff you’d expect from a seasoned front-end developer, so writing CSS in a single layer doesn’t scare me at all.
    3. I can do complex stuff that are hard or impossible to do in Tailwind (like theming and animations) in CSS.

    Your mileage may vary, of course.

    Now, if you have followed my reasoning so far, you would have noticed that I use Tailwind very differently:

    • Tailwind utilities are not the “most important” layer.
    • My unnamed CSS layer is the most important one.

    I do this so I can:

    • Build prototypes with Tailwind (quickly, easily, especially with the tools I’ve created).
    • Shift these properties to CSS when they get more complex — so I don’t have to read messy utility-littered HTML that makes my heart sink. Not because utility HTML is bad, but because it takes lots of brain processing power to figure out what’s happening.

    Finally, here’s the nice thing about Tailwind being in a utility layer: I can always !important a utility to give it strength.

    <!-- !important the padding utility -->
    <div class="component !p-4"> ... </div>

    Whoa, hold on, wait a minute! Isn’t this wrong, you might ask?

    Nope. The !important keyword has traditionally been used to override classes. In this case, we’re leveraging on the !important feature in CSS Layers to say the Tailwind utility is more important than any CSS in the unnamed layer.

    This is perfectly valid and is a built-in feature for CSS Layers.

    Besides, the !important is so explicit (and used so little) that it makes sense for one-off quick-and-dirty adjustments (without creating a brand new selector for it).

    Tailwind utilities are more powerful than they seem

    Tailwind utilities are not a 1:1 map between a class and a CSS property. Built-in Tailwind utilities mostly look like this so it can give people a wrong impression.

    Tailwind utilities are more like convenient Sass mixins, which means we can build effective tools for layouts, theming, typography, and more, through them.

    You can find out about these thoughts inside Unorthodox Tailwind.

    Thanks for reading and I hope you’re enjoying a new way of looking at (or using) Tailwind!


    Using CSS Cascade Layers With Tailwind Utilities originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleCVE-2025–49144: Notepad++ vulnerability allows full system compromise
    Next Article How to Evaluate Jailbreak Methods: A Case Study with the StrongREJECT Benchmark

    Related Posts

    News & Updates

    I never thought I’d praise a kickstand power bank – until I tried this one

    June 30, 2025
    News & Updates

    I replaced my work PC with this Alienware laptop – now I’m wondering why I hadn’t done this sooner

    June 30, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    CVE-2025-49275 – Blogbyte PHP Remote File Inclusion Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Secure Your RAG Workflows with MongoDB Atlas + Enkrypt AI

    Databases

    CVE-2025-2566 – Kaleris NAVIS N4 ULC Java Deserialization RCE

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-5765 – Code-projects Laundry System Cross Site Scripting Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    Forget AGI – Meta is going after ‘superintelligence’ now

    June 11, 2025

    The company is also apparently in talks to invest more than $10 billion in Scale…

    Top Factors to Consider When Choosing the Right AI Service Provider

    May 2, 2025

    CVE-2025-3820 – Tenda W12 and i24 Remote Stack-Based Buffer Overflow

    April 23, 2025

    CVE-2025-51381 – KCM3100 LAN Authentication Bypass Vulnerability

    June 18, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.