「及時」模式:全新世代的 Tailwind CSS
Tailwind CSS on GitHub

Text Color

Utilities for controlling the text color of an element.

Default class reference

Class
Preview 
text-transparent
Aa
text-current
Aa
text-black
Aa
text-white
Aa
text-gray-50
Aa
text-gray-100
Aa
text-gray-200
Aa
text-gray-300
Aa
text-gray-400
Aa
text-gray-500
Aa
text-gray-600
Aa
text-gray-700
Aa
text-gray-800
Aa
text-gray-900
Aa
text-red-50
Aa
text-red-100
Aa
text-red-200
Aa
text-red-300
Aa
text-red-400
Aa
text-red-500
Aa
text-red-600
Aa
text-red-700
Aa
text-red-800
Aa
text-red-900
Aa
text-yellow-50
Aa
text-yellow-100
Aa
text-yellow-200
Aa
text-yellow-300
Aa
text-yellow-400
Aa
text-yellow-500
Aa
text-yellow-600
Aa
text-yellow-700
Aa
text-yellow-800
Aa
text-yellow-900
Aa
text-green-50
Aa
text-green-100
Aa
text-green-200
Aa
text-green-300
Aa
text-green-400
Aa
text-green-500
Aa
text-green-600
Aa
text-green-700
Aa
text-green-800
Aa
text-green-900
Aa
text-blue-50
Aa
text-blue-100
Aa
text-blue-200
Aa
text-blue-300
Aa
text-blue-400
Aa
text-blue-500
Aa
text-blue-600
Aa
text-blue-700
Aa
text-blue-800
Aa
text-blue-900
Aa
text-indigo-50
Aa
text-indigo-100
Aa
text-indigo-200
Aa
text-indigo-300
Aa
text-indigo-400
Aa
text-indigo-500
Aa
text-indigo-600
Aa
text-indigo-700
Aa
text-indigo-800
Aa
text-indigo-900
Aa
text-purple-50
Aa
text-purple-100
Aa
text-purple-200
Aa
text-purple-300
Aa
text-purple-400
Aa
text-purple-500
Aa
text-purple-600
Aa
text-purple-700
Aa
text-purple-800
Aa
text-purple-900
Aa
text-pink-50
Aa
text-pink-100
Aa
text-pink-200
Aa
text-pink-300
Aa
text-pink-400
Aa
text-pink-500
Aa
text-pink-600
Aa
text-pink-700
Aa
text-pink-800
Aa
text-pink-900
Aa

Usage

Control the text color of an element using the text-{color} utilities.

The quick brown fox jumps over the lazy dog.

<p class="text-purple-600 ..."></p>

Changing opacity

Control the opacity of an element’s text color using the text-opacity-{amount} utilities.

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.

The quick brown fox jumps over the lazy dog.

<p class="text-purple-700 text-opacity-100 ...">The quick brown fox ...</p>
<p class="text-purple-700 text-opacity-75 ...">The quick brown fox ...</p>
<p class="text-purple-700 text-opacity-50 ...">The quick brown fox ...</p>
<p class="text-purple-700 text-opacity-25 ...">The quick brown fox ...</p>
<p class="text-purple-700 text-opacity-0 ...">The quick brown fox ...</p>

Learn more in the text opacity documentation.

Responsive

To control the text color of an element at a specific breakpoint, add a {screen}: prefix to any existing text color utility. For example, use md:text-green-600 to apply the text-green-600 utility at only medium screen sizes and above.

<p class="text-blue-600 md:text-green-600 ...">
  The quick brown fox...
</p>

For more information about Tailwind’s responsive design features, check out the Responsive Design documentation.

Hover

To control the text color of an element on hover, add the hover: prefix to any existing text color utility. For example, use hover:text-blue-600 to apply the text-blue-600 utility on hover.

<button class="text-white hover:text-red-500 ...">
  Hover me
</button>

Hover utilities can also be combined with responsive utilities by adding the responsive {screen}: prefix before the hover: prefix.

<button class="... md:text-blue-500 md:hover:text-blue-600 ...">Button</button>

Focus

To control the text color of an element on focus, add the focus: prefix to any existing text color utility. For example, use focus:text-blue-600 to apply the text-blue-600 utility on focus.

<input class="text-green-900 focus:text-red-600 ...">

Focus utilities can also be combined with responsive utilities by adding the responsive {screen}: prefix before the focus: prefix.

<input class="... md:text-gray-900 md:focus:text-red-600 ...">

Customizing

Text Colors

By default, Tailwind makes the entire default color palette available as text colors.

You can customize your color palette by editing theme.colors in your tailwind.config.js file, or customize just your text colors in the theme.textColor section.

  // tailwind.config.js
  module.exports = {
    theme: {
-     textColor: theme => theme('colors'),
+     textColor: {
+       'primary': '#3490dc',
+       'secondary': '#ffed4a',
+       'danger': '#e3342f',
+     }
    }
  }

Variants

默認情況下, 只有 響應式、深色模式 (如果啟用)、group-hover、focus-within、hover 和 focus 的 text color 變化模式 (variants) 會產生。

tailwind.config.jsvariants 區塊中變更 textColor 屬性來決定有哪些變化模式會生成。

舉個例子來說,這個設定將會生成 響應式 和 active 的變化模式。

  // tailwind.config.js
  module.exports = {
    variants: {
      extend: {
        // ...
+       textColor: ['responsive', 'active'],
      }
    }
  }

Disabling

如果你不打算在專案中使用 text color 功能,可以在你的設定檔裡的 corePlugins 屬性中將 textColor 設定為 false 來停用功能:

  // tailwind.config.js
  module.exports = {
    corePlugins: {
      // ...
+     textColor: false,
    }
  }