Skip to content

What's New in v4

Tailwind CSS 4 เป็น การเขียนใหม่ตั้งแต่ต้น ที่เน้น:

  • Performance — เร็วขึ้นหลายเท่า
  • Simplicity — config ง่ายขึ้น
  • CSS Standards — ใช้ CSS ล้วนๆ ไม่พึ่ง JS

Engine ใหม่ที่เขียนด้วย Rust ทำให้:

  • เร็วขึ้นอย่างมาก ในการ build (ทีม Tailwind Labs ระบุว่าเร็วกว่าเดิมหลายเท่า)
  • ใช้หน่วยความจำน้อยลง
  • Incremental builds ทำงานได้ดีขึ้น
Terminal window
# Build time comparison
v3: ~500ms (cold start)
v4: ~50ms (cold start) 🚀

บอกลา tailwind.config.js ยินดีต้อนรับ @theme block

tailwind.config.js
module.exports = {
theme: {
extend: {
colors: {
primary: "#3490dc",
},
},
},
};
@import "tailwindcss";
@theme {
--color-primary: #3490dc;
}

ข้อดี: ไม่ต้อง restart dev server เมื่อเปลี่ยน theme!


ทุก design token เป็น CSS Variable โดยอัตโนมัติ

/* สามารถใช้ใน CSS ปกติได้เลย */
.custom-element {
color: var(--color-primary);
padding: var(--spacing-4);
}

Tailwind v4 ใช้ OKLCH เป็น default color format

/* ทำไมดีกว่า? */
/* - สีสม่ำเสมอกว่า hex/rgb */
/* - ปรับความสว่างได้ง่าย */
/* - รองรับ P3 color gamut */

ไม่ต้องติดตั้ง plugin อีกต่อไป:

<div class="@container">
<p class="@md:text-lg">Responds to container size!</p>
</div>

สิ่งที่เปลี่ยนแปลง

Section titled “สิ่งที่เปลี่ยนแปลง”
Featurev3v4
Configurationtailwind.config.js@theme block ใน CSS
Color formatHex, RGBOKLCH (default)
Import@tailwind base; etc.@import "tailwindcss"
Container queriesPluginBuilt-in
Performance~500ms~50ms 🚀
EngineJavaScriptRust (Oxide)

Do ✅Don’t ❌
ใช้ @theme สำหรับ custom valuesสร้าง tailwind.config.js
ใช้ @import "tailwindcss"ใช้ @tailwind base; แยก
ใช้ Container Queriesติดตั้ง container plugin
ใช้ OKLCH สำหรับสีใหม่แปลงสีเก่าทั้งหมด (ไม่จำเป็น)

  1. เริ่มจาก project ใหม่ — ลองใน project เล็กๆ ก่อน
  2. ไม่ต้องรีบแปลงสี — hex/rgb ยังใช้ได้
  3. Container Queries ฟรี! — ลบ plugin เก่าทิ้งได้
  4. IDE Update — ตรวจว่า IntelliSense extension เป็น version ล่าสุด