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

      CodeSOD: A Unique Way to Primary Key

      July 22, 2025

      BrowserStack launches Figma plugin for detecting accessibility issues in design phase

      July 22, 2025

      Parasoft brings agentic AI to service virtualization in latest release

      July 22, 2025

      Node.js vs. Python for Backend: 7 Reasons C-Level Leaders Choose Node.js Talent

      July 21, 2025

      The best CRM software with email marketing in 2025: Expert tested and reviewed

      July 22, 2025

      This multi-port car charger can power 4 gadgets at once – and it’s surprisingly cheap

      July 22, 2025

      I’m a wearables editor and here are the 7 Pixel Watch 4 rumors I’m most curious about

      July 22, 2025

      8 ways I quickly leveled up my Linux skills – and you can too

      July 22, 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

      The Intersection of Agile and Accessibility – A Series on Designing for Everyone

      July 22, 2025
      Recent

      The Intersection of Agile and Accessibility – A Series on Designing for Everyone

      July 22, 2025

      Zero Trust & Cybersecurity Mesh: Your Org’s Survival Guide

      July 22, 2025

      Execute Ping Commands and Get Back Structured Data in PHP

      July 22, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      A Tomb Raider composer has been jailed — His legacy overshadowed by $75k+ in loan fraud

      July 22, 2025
      Recent

      A Tomb Raider composer has been jailed — His legacy overshadowed by $75k+ in loan fraud

      July 22, 2025

      “I don’t think I changed his mind” — NVIDIA CEO comments on H20 AI GPU sales resuming in China following a meeting with President Trump

      July 22, 2025

      Galaxy Z Fold 7 review: Six years later — Samsung finally cracks the foldable code

      July 22, 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 Best Hotels in Ranthambore: Luxury Stays Near the Tiger Reserve

    Related Posts

    News & Updates

    The best CRM software with email marketing in 2025: Expert tested and reviewed

    July 22, 2025
    News & Updates

    This multi-port car charger can power 4 gadgets at once – and it’s surprisingly cheap

    July 22, 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

    LibreOffice 25.8 Beta 2 Drops Support for Windows 7/8/8.1 and All 32-bit Systems

    Security

    CVE-2025-6772 – Eosphoros-AI Db-GPT Path Traversal Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-0505 – “Arista CloudVision Zero Touch Provisioning Privilege Escalation”

    Common Vulnerabilities and Exposures (CVEs)

    Dividing Collections with Laravel’s splitIn Helper

    Development

    Highlights

    Challenges in Selenium Automation Testing

    April 1, 2025

    Automation testing is an integral part of modern software development, enabling faster releases and more reliable applications. As web applications continue to evolve, the demand for robust testing solutions has increased significantly. Selenium, a powerful and widely used open-source testing framework, plays a crucial role in automating web browser interactions, allowing testing teams to validate
    The post Challenges in Selenium Automation Testing appeared first on Codoid.

    I found an AirTag wallet that’s functional, relatively affordable, and looks fantastic

    April 9, 2025

    CVE-2025-7830 – “Church Donation System SQL Injection Vulnerability”

    July 19, 2025

    CVE-2025-6899 – D-Link DI-7300G+/DI-8200G Os Command Injection Vulnerability

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

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