Typography

color

用於控制元素文字顏色的通用類別。

ClassStyles
text-inherit
color: inherit;
text-current
color: currentColor;
text-transparent
color: transparent;
text-black
color: var(--color-black); /* #000 */
text-white
color: var(--color-white); /* #fff */
text-red-50
color: var(--color-red-50); /* oklch(97.1% 0.013 17.38) */
text-red-100
color: var(--color-red-100); /* oklch(93.6% 0.032 17.717) */
text-red-200
color: var(--color-red-200); /* oklch(88.5% 0.062 18.334) */
text-red-300
color: var(--color-red-300); /* oklch(80.8% 0.114 19.571) */
text-red-400
color: var(--color-red-400); /* oklch(70.4% 0.191 22.216) */

範例(Examples)

基本範例(Basic example)

使用 text-blue-600text-sky-400 等通用類別來控制元素的文字顏色:

The quick brown fox jumps over the lazy dog.

<p class="text-blue-600 dark:text-sky-400">The quick brown fox...</p>

變更不透明度(Changing the opacity)

使用顏色不透明度修飾符來控制元素的文字顏色不透明度:

The quick brown fox jumps over the lazy dog.

The quick brown fox jumps over the lazy dog.

The quick brown fox jumps over the lazy dog.

The quick brown fox jumps over the lazy dog.

<p class="text-blue-600/100 dark:text-sky-400/100">The quick brown fox...</p><p class="text-blue-600/75 dark:text-sky-400/75">The quick brown fox...</p><p class="text-blue-600/50 dark:text-sky-400/50">The quick brown fox...</p><p class="text-blue-600/25 dark:text-sky-400/25">The quick brown fox...</p>

使用自訂值(Using a custom value)

使用 text-[<value>] 語法,根據完全自訂的值來設定 text color

<p class="text-[#50d71e] ...">  Lorem ipsum dolor sit amet...</p>

對於 CSS 變數,你也可以使用 text-(<custom-property>) 語法:

<p class="text-(--my-color) ...">  Lorem ipsum dolor sit amet...</p>

這只是 text-[var(<custom-property>)] 的簡寫形式,會自動為你加上 var() 函式。

在 hover 時套用(Applying on hover)

color 通用類別前面加上像 hover:* 這樣的變體,讓該通用類別只在該狀態下套用:

將滑鼠移到文字上以查看預期行為

Oh I gotta get on that internet, I'm late on everything!

<p class="...">  Oh I gotta get on that  <a class="underline hover:text-blue-600 dark:hover:text-blue-400" href="https://en.wikipedia.org/wiki/Internet">internet</a>,  I'm late on everything!</p>

變體文件中了解更多關於使用變體的資訊。

響應式設計(Responsive design)

color 通用類別前面加上像 md: 這樣的中斷點變體,讓該通用類別只在中型螢幕尺寸及以上時套用:

<p class="text-blue-600 md:text-green-600 ...">  Lorem ipsum dolor sit amet...</p>

變體文件中了解更多關於使用變體的資訊。

自訂主題(Customizing your theme)

使用 --color-* 主題變數來自訂專案中的 color 通用類別:

@theme {  --color-regal-blue: #243c5a; }

現在可以在標記中使用 text-regal-blue 通用類別:

<p class="text-regal-blue">  Lorem ipsum dolor sit amet...</p>

主題文件中了解更多關於自訂主題的資訊。

Copyright © 2026 Tailwind Labs Inc.·商標政策(Brand)