Skip to content

Colors & Backgrounds

Tailwind มี color palette 22 สี แต่ละสี 11 shades (50-950):

<div class="bg-blue-500">Blue 500</div>
<div class="text-gray-900">Gray 900</div>
<div class="border-red-300">Red 300</div>
ColorUsage
slateNeutral cool
grayNeutral
zincNeutral warm
redError, danger
orangeWarning
amberWarning alt
yellowHighlight
greenSuccess
bluePrimary, info
indigoPrimary alt
purpleAccent
pinkAccent alt

<div class="bg-white">White</div>
<div class="bg-gray-100">Light gray</div>
<div class="bg-blue-500">Blue</div>
<div class="bg-transparent">Transparent</div>
<div class="bg-current">Current text color</div>

<p class="text-gray-900">Dark text</p>
<p class="text-gray-600">Muted text</p>
<p class="text-blue-500">Primary text</p>
<p class="text-white">White text</p>

ใช้ / ตามด้วยค่า opacity (0-100):

<div class="bg-black/50">50% opacity background</div>
<div class="bg-blue-500/75">75% opacity</div>
<div class="text-white/80">80% opacity text</div>
<div class="border-gray-900/10">10% opacity border</div>

Tailwind CSS 4 ใช้ OKLCH color space เป็น default:

@theme {
--color-brand: oklch(0.6 0.2 250);
/* lightness chroma hue */
}
PartRangeDescription
Lightness0-10=black, 1=white
Chroma0-0.37ความเข้มของสี
Hue0-360โทนสี (degrees)

ข้อดีของ OKLCH:

  • Gradients สวยกว่า ไม่มี “muddy” colors กลางทาง
  • Consistent perceived brightness
  • ดีสำหรับ dark mode

<div class="bg-gradient-to-r from-blue-500 to-purple-500">Left to right</div>
<div class="bg-gradient-to-br from-pink-500 via-red-500 to-yellow-500">
With via color
</div>
ClassDirection
bg-gradient-to-t↑ to top
bg-gradient-to-b↓ to bottom
bg-gradient-to-l← to left
bg-gradient-to-r→ to right
bg-gradient-to-tl↖ to top-left
bg-gradient-to-tr↗ to top-right
bg-gradient-to-bl↙ to bottom-left
bg-gradient-to-br↘ to bottom-right
<div
class="bg-gradient-to-r from-cyan-500 from-10% via-blue-500 via-30% to-violet-500"
>
Custom positions
</div>

<div class="bg-[url('/hero.jpg')] bg-cover bg-center bg-no-repeat">
Hero section
</div>
ClassEffect
bg-coverขยายเต็ม container
bg-containย่อให้พอดี
bg-centerจัดกึ่งกลาง
bg-no-repeatไม่ซ้ำ
bg-repeatซ้ำ (default)
bg-fixedparallax effect

<div
class="bg-white/30 backdrop-blur-md border border-white/20 rounded-2xl p-6"
>
Frosted glass effect
</div>
<h1
class="bg-gradient-to-r from-blue-500 to-purple-500 bg-clip-text text-transparent"
>
Gradient Text
</h1>