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

      Sentry launches MCP monitoring tool

      August 14, 2025

      10 Benefits of Hiring a React.js Development Company (2025–2026 Edition)

      August 13, 2025

      From Line To Layout: How Past Experiences Shape Your Design Career

      August 13, 2025

      Hire React.js Developers in the US: How to Choose the Right Team for Your Needs

      August 13, 2025

      GPT-5 in GitHub Copilot: How I built a game in 60 seconds

      August 14, 2025

      Q1 2025 Innovation Graph update: Bar chart races, data visualization on the rise, and key research

      August 14, 2025

      Setting the Stage: Inside the Process of Bringing Christian Fleming’s Work to Life in Print, Web, and 3D

      August 14, 2025

      On Accessibility Conformance, Design Systems, and CSS “Base” Units

      August 14, 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

      PHP 8.5.0 Beta 1 available for testing

      August 14, 2025
      Recent

      PHP 8.5.0 Beta 1 available for testing

      August 14, 2025

      Age Calculator using PHP

      August 14, 2025

      Laravel Boost is released

      August 13, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      KDE Plasma 6 on Wayland: the Payoff for Years of Plumbing

      August 14, 2025
      Recent

      KDE Plasma 6 on Wayland: the Payoff for Years of Plumbing

      August 14, 2025

      FOSS Weekly #25.33: Debian 13 Released, Torvalds vs RISC-V, Arch’s New Tool, GNOME Perfection and More Linux Stuff

      August 14, 2025

      Ultimate ChatGPT-5 Prompt Guide: 52 Ideas for Any Task

      August 14, 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

    GPT-5 in GitHub Copilot: How I built a game in 60 seconds

    August 14, 2025
    News & Updates

    Q1 2025 Innovation Graph update: Bar chart races, data visualization on the rise, and key research

    August 14, 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-27754 – Joomla RSBlog! Stored Cross-Site Scripting (XSS) Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Using AI to fight climate change

    Artificial Intelligence

    CyberArk and HashiCorp Flaws Enable Remote Vault Takeover Without Credentials

    Development

    The Future of Indian E-Commerce is Here: Introducing Neonyte, Your Destination for Affordable Shopping

    Artificial Intelligence

    Highlights

    News & Updates

    Microsoft Authenticator is losing autofill but the tech giant already has a replacement

    May 15, 2025

    Autofill in Microsoft Authenticator is being discontinued soon. Microsoft wants users to switch to Edge…

    CVE-2025-4051 – Google Chrome DevTools Insufficient Data Validation Remote Code Execution

    May 5, 2025

    CVE-2025-6293 – Code-projects Hostel Management System SQL Injection

    June 19, 2025

    5 ways to manage your team more effectively in the AI-enabled enterprise

    April 7, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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