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

Placeholder Color

Utilities for controlling the color of placeholder text.

Default class reference

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

Usage

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

<input class="placeholder-gray-500 ..." placeholder="jane@example.com">
<input class="placeholder-red-300 ..." placeholder="jane@example.com">

Changing opacity

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

<input class="placeholder-gray-500 placeholder-opacity-100 ..." placeholder="jane@example.com">
<input class="placeholder-gray-500 placeholder-opacity-75 ..." placeholder="jane@example.com">
<input class="placeholder-gray-500 placeholder-opacity-50 ..." placeholder="jane@example.com">
<input class="placeholder-gray-500 placeholder-opacity-25 ..." placeholder="jane@example.com">
<input class="placeholder-gray-500 placeholder-opacity-0 ..." placeholder="jane@example.com">

Learn more in the placeholder opacity documentation.

Responsive

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

<input class="placeholder-gray-500 md:placeholder-green-500" placeholder="jane@example.com">

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

Focus

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

<input class="placeholder-gray-600 focus:placeholder-gray-400 ..." placeholder="jane@example.com">

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

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

Customizing

Placeholder Colors

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

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

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

Variants

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

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

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

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

Disabling

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

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