Tailwind CSS v4 — Utility-First CSS Framework

Học Tailwind CSS v4.3 (2026) — Oxide Engine, CSS-first config, OKLCH colors, container queries, 3D transforms. Từ cơ bản đến practical.

Tailwind CSS là gì?

Tailwind CSS = utility-first CSS framework — thay vì viết CSS riêng cho từng component, bạn dùng hàng trăm class nhỏ (flex, pt-4, text-lg) ngay trong HTML để build giao diện nhanh và nhất quán.

Khác biệt cốt lõi so với Bootstrap / Material UI:

Tailwind CSSBootstrap
Triết lýUtility-first — build từ class nhỏComponent-first — dùng component có sẵn
CustomizationDesign system trong config → build ra classGhi đè CSS variable
File outputChỉ class bạn dùng (tree-shake)Cả thư viện hoặc import từng phần
HTMLNhiều class hơn, nhưng CSS file nhỏ hơnÍt class hơn, CSS file to hơn
Design systemBạn tự định nghĩa màu, spacing, font...Có sẵn, ghi đè nếu cần
"Nhồi nhét class vào HTML" — đúng hay sai?Đúng là HTML dài hơn về visual. Nhưng bạn không phải đặt tên class — không phải nghĩ tên cho <div class="card__header--highlighted">, không CSS file riêng cho từng component. Đổi giao diện mà không sợ break CSS ở chỗ khác. Đây là trade-off mà Tailwind chọn.

v4.0 — Oxide Engine rewrite

Tailwind CSS v4 là bản viết lại từ đầu bằng Rust (Oxide Engine) — thay đổi toàn diện cách Tailwind hoạt động bên dưới:

Oxide Engine (Rust)

Build nhanh gấp 5x, incremental build nhanh gấp 100x. Scan file Rust-native, không phụ thuộc JS nữa.

CSS-first config

Không còn tailwind.config.js. Dùng @theme, @utility, @custom-variant trực tiếp trong CSS. IDE autocomplete vẫn chạy ngon qua LSP.

Automatic content detection

Không cần content array nữa. Tailwind tự scan tất cả file trong project, tự biết class nào cần generate.

OKLCH + P3 color

Color space mặc định là OKLCH — perceptually uniform, chính xác hơn sRGB. Hỗ trợ P3 wide gamut — màu rực rỡ hơn trên màn hình hiện đại.

Code thay đổi dễ thấy

/* v3 — @tailwind directives */
@tailwind base;
@tailwind components;
@tailwind utilities;

/* v4 — single import */
@import "tailwindcss";
/* v3 — tailwind.config.js */
module.exports = {
  theme: {
    extend: { colors: { brand: '#1e40af' } }
  }
}

/* v4 — CSS-first config trong file CSS */
@import "tailwindcss";

@theme {
  --color-brand: #1e40af;
  --color-brand-light: oklch(0.7 0.15 250);
}

Tất cả token định nghĩa trong @theme đều tự động expose thành CSS custom properties — dùng được ở mọi nơi: var(--color-brand).

Installation

# Vite
npm install tailwindcss @tailwindcss/vite

# Next.js (PostCSS plugin vẫn hỗ trợ)
npm install tailwindcss @tailwindcss/postcss

# Nuxt
npx nuxi module add @nuxtjs/tailwindcss

# CDN — dùng thử nhanh (không khuyến nghị production)
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
/* main.css — file CSS chính */
@import "tailwindcss";

@theme {
  --color-primary: oklch(0.55 0.2 250);
}
<!-- Hello World — dùng thử ngay -->
<div class="min-h-screen flex items-center justify-center bg-gray-100">
  <div class="bg-white p-8 rounded-2xl shadow-lg text-center">
    <h1 class="text-3xl font-bold text-primary mb-4">
      Tailwind CSS v4
    </h1>
    <p class="text-gray-600">Utility-first CSS, Rust-powered.</p>
  </div>
</div>

Version timeline

Phiên bảnThời gianHighlights
v4.0Tháng 01/2025Oxide Engine (Rust), CSS-first config, OKLCH, auto content detection, container queries, 3D transforms, radial/conic gradients
v4.1Tháng 04/2025text-shadow utilities, mask utilities, CSS-first @plugin, improved LSP
v4.2Giữa 2025Màu mới (mauve, olive, mist, taupe), logical properties (pbs-*, mbs-*...), webpack plugin, import aliases
v4.3Tháng 05/2026Scrollbar styling (scrollbar-thin, scrollbar-thumb-*, scrollbar-track-*), container-size, zoom, tab-size
Câu PV:"Tailwind CSS v4 — điểm mới nào quan trọng nhất?"

"Ba thứ thay đổi toàn bộ trải nghiệm: (1) Oxide Engine viết bằng Rust — build nhanh gấp 5x, incremental 100x. (2) CSS-first config — bỏ tailwind.config.js, dùng @theme + @utility ngay trong CSS. (3) OKLCH color space mặc định — màu đồng đều hơn về mặt perceptive, hỗ trợ P3 wide gamut."

Vì sao chọn Tailwind thay vì raw CSS?

Đây là câu hỏi phỏng vấn cực hay gặp khi bạn ghi Tailwind vào CV:

Tốc độ viết code

Không chuyển tab HTML ↔ CSS liên tục. Thấy element → thêm class ngay. Không đặt tên class dài dòng.

Design system nhất quán

Spacing scale (p-4, p-6, p-8), color palette, font size — tất cả limited choices. Không có padding: 13px tự chế.

Bundle siêu nhỏ

Chỉ class được dùng mới vào CSS output. Production bundle thường 3–5 KB gzipped.

Team collaboration

Không cần đọc CSS file của đồng đội để hiểu component. HTML là single source of truth.
Câu PV:"So sánh Tailwind với CSS Modules và Styled Components."

Tailwind: Utility-first, viết class trong HTML, bundle nhỏ vì class shared, design system built-in. Học hơi dốc lúc đầu vì phải nhớ tên class.

CSS Modules: Viết CSS bình thường, scope local tự động. Quen thuộc với dev CSS truyền thống. Nhưng không có design system constraint → dễ drift style.

Styled Components: CSS-in-JS, style gắn với component React. Dynamic style dễ hơn. Nhưng runtime overhead, bundle to hơn.

Tailwind CSS v3 vs v4 — khác biệt chính

v3v4
EngineJavaScript (PostCSS)Rust (Oxide Engine)
Configtailwind.config.jsCSS @theme block
Content detectionManual content arrayAutomatic
Color spacesRGBOKLCH (P3-ready)
Import@tailwind base/components/utilities@import "tailwindcss"
Token exposureManual CSS varAuto expose all tokens
Container queriesPlugin (@tailwindcss/container-queries)Built-in
3D transformsKhông cóBuilt-in (rotate-x-*, rotate-y-*, rotate-z-*)
GradientsLinear onlyRadial + conic (bg-radial-*, bg-conic-*)
Text shadowPluginBuilt-in (v4.1)
ScrollbarPluginBuilt-in (v4.3)

Lộ trình học

TrangNội dung
1. Layout & SpacingDisplay, position, container queries, flexbox, grid, spacing, sizing, overflow, scrollbar — 19 bài tập thực hành
2. Typography & ColorsFont, text size, color OKLCH, text shadow (v4.1), opacity, dark mode
3. Backgrounds & BordersBackground color/image/gradient (radial/conic v4.0), border, outline, ring, divide
4. Effects & FiltersShadow, blur, backdrop, transform, transition, animation, 3D transforms (v4.0)
5. Responsive DesignBreakpoints, container queries (@container), mobile-first, logical properties (v4.2)
6. Dark Mode & Themingdark: variant, @custom-variant, color-scheme, system preference
7. Customization v4@theme, @utility, @custom-variant, @plugin, extend/override
8. Practical ProjectXây dựng landing page hoàn chỉnh bằng Tailwind CSS v4
9. Câu hỏi phỏng vấn50+ Q&A Tailwind CSS cho dev frontend
Cách học hiệu quả nhất: Mỗi section có bài tập (có lời giải). Đừng chỉ đọc — mở CodePen hoặc project riêng và code theo từng bài tập. Tailwind là framework phải viết nhiều mới nhớ class.
Bắt đầu: 1. Layout & Spacing — 19 bài tập từ căn bản đến nâng cao.

© 2026 .NET Fresher Guide. All rights reserved.

Về Trang Web

Hướng dẫn toàn diện để chuẩn bị phỏng vấn vị trí .NET Fresher với nội dung từ lý thuyết đến thực hành.