0Pricing
Tailwind CSS Academy · บทเรียน

ชุดสีของ Tailwind

สำรวจระบบสีทั้งหมดของ Tailwind ตั้งแต่เฉด 50 ถึง 950 และใช้สีพื้นหลังด้วยยูทิลิตี bg-*

ชุดสีของ Tailwind เป็นบทเรียน Tailwind CSS Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Tailwind CSS Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Tailwind CSS Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Overview of the Color Palette

Tailwind's default color palette contains 22 named color families, each with 11 shades numbered from 50 to 950. The families include neutrals (slate, gray, zinc, stone, neutral), warm tones (red, orange, amber, yellow), cool tones (lime, green, emerald, teal, cyan, sky, blue, indigo, violet), and vibrant accents (purple, fuchsia, pink, rose). Every shade is pre-approved for use in your design system.

<!-- Using different color families -->
<div class="bg-slate-100">Slate 100</div>
<div class="bg-blue-500">Blue 500</div>
<div class="bg-emerald-600">Emerald 600</div>
<div class="bg-rose-400">Rose 400</div>

Understanding Shade Numbers

Shade numbers communicate lightness: 50 is nearly white (a faint tint), 100–300 are light pastels, 400–600 are vibrant mid-tones, 700–800 are dark and saturated, and 900–950 are nearly black. As a rule of thumb, use 50–200 for backgrounds, 400–600 for icons and accents, and 700–900 for text to guarantee readable contrast on white.

<div class="bg-blue-50 p-4">Shade 50 — near-white background</div>
<div class="bg-blue-200 p-4">Shade 200 — light accent</div>
<div class="bg-blue-500 p-4 text-white">Shade 500 — vivid button color</div>
<div class="bg-blue-700 p-4 text-white">Shade 700 — dark hover state</div>
<div class="bg-blue-950 p-4 text-white">Shade 950 — deep background</div>

Applying Background Colors

Apply background colors with the bg-{color}-{shade} utility. This sets CSS background-color on the element. Use a light shade like bg-indigo-50 for subtle section backgrounds, a mid-tone like bg-indigo-600 for primary buttons, and a dark shade like bg-indigo-950 for footer and sidebar backgrounds. Always pair with a text color that provides sufficient contrast.

<!-- Section with subtle tint -->
<section class="bg-indigo-50 py-16 px-6">
  <h2 class="text-indigo-900 text-2xl font-bold">Features</h2>
</section>

<!-- Primary button -->
<button class="bg-indigo-600 hover:bg-indigo-700 text-white px-6 py-2 rounded">
  Call to Action
</button>

Special Color Values

Beyond the numbered palette, Tailwind provides several special color keywords. bg-white and bg-black set pure white and black. bg-transparent makes the background transparent (inherits parent). bg-current uses the element's current text color as the background. bg-inherit explicitly inherits the background from the parent element.

<div class="bg-white p-4">White background</div>
<div class="bg-black text-white p-4">Black background</div>
<div class="bg-transparent border border-gray-300 p-4">
  Transparent (shows parent background)
</div>

Color Families: Warm vs Cool

Choosing between warm and cool colors affects the emotional tone of your design. Warm colors (red, orange, amber, yellow) convey energy, urgency, and warmth — great for alerts, sale badges, and warning states. Cool colors (blue, indigo, teal, cyan) convey trust, calm, and professionalism — ideal for primary actions, data dashboards, and corporate applications.

<!-- Warm: urgency/alert -->
<div class="bg-amber-100 border-l-4 border-amber-500 text-amber-800 p-4">
  Limited time offer!
</div>

<!-- Cool: trust/primary -->
<div class="bg-blue-100 border-l-4 border-blue-500 text-blue-800 p-4">
  Your data is encrypted and secure.
</div>

Neutral Grays: Slate vs Gray vs Zinc

Tailwind has five neutral gray families: slate (blue-gray tint), gray (neutral), zinc (slightly warm), neutral (pure neutral), and stone (warm tan). The choice between them is subtle but matters for branding. Slate suits tech and developer products. Gray works universally. Stone suits natural, earthy brands. Pick one and use it consistently throughout your project.

<p class="text-slate-700">Slate gray — cool, tech-forward</p>
<p class="text-gray-700">Gray — universal neutral</p>
<p class="text-zinc-700">Zinc — slightly warm neutral</p>
<p class="text-stone-700">Stone — earthy warmth</p>

Building a Color-Coded Status System

A practical use of Tailwind's color families is building a status indicator system. Map semantic states to color families: success to green, warning to yellow, error to red, info to blue, and neutral to gray. Use the 100 shade for the background and the 700 shade for text to ensure both contrast and visual coherence.

<div class="flex flex-col gap-2">
  <span class="bg-green-100 text-green-700 px-3 py-1 rounded-full text-sm font-medium">Success</span>
  <span class="bg-yellow-100 text-yellow-700 px-3 py-1 rounded-full text-sm font-medium">Warning</span>
  <span class="bg-red-100 text-red-700 px-3 py-1 rounded-full text-sm font-medium">Error</span>
  <span class="bg-blue-100 text-blue-700 px-3 py-1 rounded-full text-sm font-medium">Info</span>
  <span class="bg-gray-100 text-gray-700 px-3 py-1 rounded-full text-sm font-medium">Neutral</span>
</div>

Background Opacity Modifier

The slash opacity modifier works for background colors too. bg-blue-600/20 applies the blue-600 color at 20% opacity, creating a translucent tint effect. This is commonly used for overlay backgrounds, frosted glass effects, and colored highlight backgrounds behind content without completely obscuring what is behind them.

<!-- Translucent modal backdrop -->
<div class="fixed inset-0 bg-gray-900/50 flex items-center justify-center">
  <div class="bg-white rounded-xl p-8 shadow-2xl">
    Modal content
  </div>
</div>

Choosing Primary and Accent Colors

A common pattern is to choose one primary color for main interactive elements and one accent color to highlight key information. For example, indigo as primary and amber as accent. Both colors are already present in Tailwind's palette, so you immediately have a full spectrum of shades without configuring anything.

<!-- Primary action: indigo -->
<button class="bg-indigo-600 hover:bg-indigo-700 text-white px-6 py-2 rounded-lg">
  Primary Action
</button>

<!-- Accent highlight: amber -->
<span class="bg-amber-400 text-amber-900 text-xs font-bold px-2 py-0.5 rounded">
  NEW
</span>

Dark Mode Background Colors

In dark mode, backgrounds shift from light to dark shades. Use the dark: prefix to set background colors for dark theme. A typical pattern: main background bg-white dark:bg-gray-900, card surface bg-gray-50 dark:bg-gray-800, and elevated elements bg-white dark:bg-gray-700. This three-level elevation system creates depth in dark UIs.

<body class="bg-white dark:bg-gray-900">
  <div class="bg-gray-50 dark:bg-gray-800 rounded-xl p-6">
    <div class="bg-white dark:bg-gray-700 rounded-lg p-4">
      Elevated card in both themes
    </div>
  </div>
</body>

Extending the Palette

If the default palette does not match your brand, extend it in tailwind.config.js under theme.extend.colors. You can add entirely new color families with custom shades, or add a single brand color. Once defined, the new color is available with every Tailwind utility: bg-brand-500, text-brand-700, border-brand-300, etc.

// tailwind.config.js
module.exports = {
  theme: {
    extend: {
      colors: {
        brand: {
          50: '#f0f9ff',
          500: '#0ea5e9',
          900: '#0c4a6e',
        },
      },
    },
  },
};

Quick Check

Test your understanding of Tailwind CSS Mastery concepts from this lesson.

Lesson Recap

In this lesson you learned: Tailwind's 22 color families each have 11 shades from 50 (light) to 950 (dark), bg-{color}-{shade} applies background color and the /opacity modifier adds transparency, and warm colors convey urgency while cool colors convey trust. Next up we create gradients with Tailwind's gradient background utilities.

คำถามที่พบบ่อย

บทเรียน “ชุดสีของ Tailwind” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “ชุดสีของ Tailwind” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Tailwind CSS Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Tailwind CSS Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “ชุดสีของ Tailwind”

สำรวจระบบสีทั้งหมดของ Tailwind ตั้งแต่เฉด 50 ถึง 950 และใช้สีพื้นหลังด้วยยูทิลิตี bg-* คุณปฏิบัติ Tailwind CSS Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Tailwind CSS Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Tailwind CSS Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน

บทเรียน “ชุดสีของ Tailwind” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Tailwind CSS Academy นี้ได้ไหม

ได้ บทเรียน Tailwind CSS Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. ชุดสีของ Tailwind
  2. การไล่ระดับสีพื้นหลัง
  3. ตัวปรับความทึบและสี
  4. ขนาด ตำแหน่ง และการทำซ้ำพื้นหลัง
← กลับไปที่ Tailwind CSS Academy