How to use :not() in Tailwind CSS ? Last Updated : 17 Sep, 2024 Comments Improve Suggest changes Like Article Like Report In Tailwind CSS, the :not() selector is used to exclude specific elements from a set of CSS rules. It allows you to apply styles to all elements except those that match the specified selector, providing greater control and precision in styling complex layouts.CDN link:<script src="https://cdn.tailwindcss.com"></script>Syntax:[&:not(selector)]:( CSS property)Example 1: This example demonstrates the :not() selector in Tailwind CSS by applying styles to elements like h1, h2, and others, selectively excluding specific tags from certain styles for precise control. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=, initial-scale=1.0"> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="p-4"> <h1 class="text-blue-500 text-4xl [&:not(h2)]:text-red-500 [&:not(h1)]:text-2xl"> GeeksforGeeks </h1> <h2 class="text-green-500 text-4xl [&:not(h2)]:text-red-500 [&:not(h1)]:text-2xl"> GeeksforGeeks </h2> <h3 class="text-blue-500 text-4xl [&:not(h1)]:text-red-500 [&:not(h3)]:text-2xl"> GeeksforGeeks </h3> <p class="text-blue-500 text-4xl [&:not(p)]:text-red-500 [&:not(h1)]:text-2xl"> GeeksforGeeks </p> <div class="text-blue-500 text-4xl [&:not(h1)]:text-red-500 [&:not(h1)]:text-2xl"> GeeksforGeeks </div> </body> </html> Output: Example 2: In this example, we have used the :not() pseudo-selector to apply styling to child tags of the HTML div tag, we can see how the :not() selector is used for styling of h3 and h4 tags under div tag. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=, initial-scale=1.0"> <script src= "https://cdn.tailwindcss.com"> </script> </head> <body class="p-4"> <div class="[&>:not(h4)]:text-green-500 [&>:not(h4)]:text-5xl [&>:not(h3)]:text-cyan-700 [&>:not(h3)]:text-3xl"> <h3>GeeksforGeeks</h3> <h4>A Computer Science Portal For Geeks</h4> </div> </body> </html> Output: Comment More infoAdvertise with us Next Article How to use :not() in Tailwind CSS ? P pushpamkjha14 Follow Improve Article Tags : Web Technologies CSS Tailwind CSS CSS-Questions Similar Reads How to use calc() in Tailwind CSS? The calc() function in CSS allows you to perform calculations for property values dynamically. While Tailwind CSS doesnât directly support calc(), you can use it inline or with custom utilities.1. Using Inline StylesYou can use calc() directly within the style attribute for dynamic property values.H 2 min read How to Add Tailwind CSS to HTML ? Tailwind CSS is a utility-first framework offering pre-defined classes for rapid styling of HTML elements. It simplifies customization and accelerates web development workflows.Integration Options:CDN Integration: Quickly add Tailwind CSS via a CDN link in the <head> of your HTML.Using npm: In 3 min read How to use @apply directive in Tailwind-CSS ? Tailwind CSS is a popular utility-first CSS framework. It is a set of pre-defined CSS classes that can be used to quickly and easily style your HTML elements without having to write custom CSS code. The classes are organized into a set of utility classes that can be used to control the layout, spaci 3 min read How to Add New Colors in Tailwind CSS ? Tailwind CSS is a popular utility-first CSS framework that offers a wide range of pre-designed styles and classes to simplify the process of styling web applications. However, the default set of colors provided by Tailwind may not always meet the requirements of your project. In such cases, you may 4 min read Introduction to Tailwind CSS Tailwind CSS is a utility-first CSS framework that simplifies web development by providing a set of pre-designed utility classes. These utility classes enable you to build custom designs without writing any custom CSS, promoting consistency, scalability, and efficiency. Tailwind shifts the focus fro 4 min read Like