Setting up Tailwind CSS used to require generating a tailwind.config.js file, configuring content paths, and writing multiple @tailwind directives. Tailwind CSS v4 streamlines everything with a high-speed engine, automatic template detection, and a CSS-first @theme block—plus built-in container queries with no extra plugins.
@import "tailwindcss"; → @theme { --color-brand: ...; } → bg-brand + @container Utilities
1. Install Tailwind CSS v4
Install Tailwind and its PostCSS plugin, then add one import line in your CSS file (such as src/app.css):
npm install tailwindcss @tailwindcss/postcss
@import "tailwindcss";
@theme {
--font-display: "Inter", sans-serif;
--color-campus-blue: oklch(0.58 0.21 255);
}
Every CSS variable you declare inside @theme becomes a real Tailwind utility class automatically—so --color-campus-blue unlocks classes like bg-campus-blue and text-campus-blue.
2. Use Built-In Container Queries
Instead of styling cards only by viewport width, Tailwind v4 includes native container queries out of the box using @container and @min-md:*:
<div class="@container">
<div class="grid grid-cols-1 @min-md:grid-cols-3 gap-4 p-4 rounded-xl bg-campus-blue text-white">
<div>ASP.NET Core Track</div>
<div>Python AI Track</div>
<div>SQL & Power BI Track</div>
</div>
</div>
Practice
- Define a custom
--color-accentvariable inside@themeand apply it withbg-accenton a student badge. - Place your
@containercard grid inside a narrow sidebar versus a wide main column to watch@min-md:grid-cols-3adapt automatically. - Remove any unused legacy
tailwind.config.jsfile when starting a clean Tailwind CSS v4 project.
Continue learning: Tailwind CSS Lessons and Practice.
References: Tailwind CSS Official Documentation.
No comments:
Post a Comment
Please do not enter any spam link in the comment box.