28 November 2026

Tailwind CSS v4 for Beginners: CSS-First Themes with @theme and Container Queries

  Asp.Net CS By Example       28 November 2026

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.

Tailwind CSS v4 workflow

@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

  1. Define a custom --color-accent variable inside @theme and apply it with bg-accent on a student badge.
  2. Place your @container card grid inside a narrow sidebar versus a wide main column to watch @min-md:grid-cols-3 adapt automatically.
  3. Remove any unused legacy tailwind.config.js file when starting a clean Tailwind CSS v4 project.

Continue learning: Tailwind CSS Lessons and Practice.

References: Tailwind CSS Official Documentation.

logoblog

Thanks for reading Tailwind CSS v4 for Beginners: CSS-First Themes with @theme and Container Queries

Previous
« Prev Post

No comments:

Post a Comment

Please do not enter any spam link in the comment box.