Text Color

Utilities for controlling the text color of an element.

Default class reference

Class
Properties
Preview 
text-transparentcolor: transparent;
Aa
text-currentcolor: currentColor;
Aa
text-black—tw-text-opacity: 1; color: rgba(0, 0, 0, var(—tw-text-opacity));
Aa
text-white—tw-text-opacity: 1; color: rgba(255, 255, 255, var(—tw-text-opacity));
Aa
text-gray-50—tw-text-opacity: 1; color: rgba(249, 250, 251, var(—tw-text-opacity));
Aa
text-gray-100—tw-text-opacity: 1; color: rgba(243, 244, 246, var(—tw-text-opacity));
Aa
text-gray-200—tw-text-opacity: 1; color: rgba(229, 231, 235, var(—tw-text-opacity));
Aa
text-gray-300—tw-text-opacity: 1; color: rgba(209, 213, 219, var(—tw-text-opacity));
Aa
text-gray-400—tw-text-opacity: 1; color: rgba(156, 163, 175, var(—tw-text-opacity));
Aa
text-gray-500—tw-text-opacity: 1; color: rgba(107, 114, 128, var(—tw-text-opacity));
Aa
text-gray-600—tw-text-opacity: 1; color: rgba(75, 85, 99, var(—tw-text-opacity));
Aa
text-gray-700—tw-text-opacity: 1; color: rgba(55, 65, 81, var(—tw-text-opacity));
Aa
text-gray-800—tw-text-opacity: 1; color: rgba(31, 41, 55, var(—tw-text-opacity));
Aa
text-gray-900—tw-text-opacity: 1; color: rgba(17, 24, 39, var(—tw-text-opacity));
Aa
text-red-50—tw-text-opacity: 1; color: rgba(254, 242, 242, var(—tw-text-opacity));
Aa
text-red-100—tw-text-opacity: 1; color: rgba(254, 226, 226, var(—tw-text-opacity));
Aa
text-red-200—tw-text-opacity: 1; color: rgba(254, 202, 202, var(—tw-text-opacity));
Aa
text-red-300—tw-text-opacity: 1; color: rgba(252, 165, 165, var(—tw-text-opacity));
Aa
text-red-400—tw-text-opacity: 1; color: rgba(248, 113, 113, var(—tw-text-opacity));
Aa
text-red-500—tw-text-opacity: 1; color: rgba(239, 68, 68, var(—tw-text-opacity));
Aa
text-red-600—tw-text-opacity: 1; color: rgba(220, 38, 38, var(—tw-text-opacity));
Aa
text-red-700—tw-text-opacity: 1; color: rgba(185, 28, 28, var(—tw-text-opacity));
Aa
text-red-800—tw-text-opacity: 1; color: rgba(153, 27, 27, var(—tw-text-opacity));
Aa
text-red-900—tw-text-opacity: 1; color: rgba(127, 29, 29, var(—tw-text-opacity));
Aa
text-yellow-50—tw-text-opacity: 1; color: rgba(255, 251, 235, var(—tw-text-opacity));
Aa
text-yellow-100—tw-text-opacity: 1; color: rgba(254, 243, 199, var(—tw-text-opacity));
Aa
text-yellow-200—tw-text-opacity: 1; color: rgba(253, 230, 138, var(—tw-text-opacity));
Aa
text-yellow-300—tw-text-opacity: 1; color: rgba(252, 211, 77, var(—tw-text-opacity));
Aa
text-yellow-400—tw-text-opacity: 1; color: rgba(251, 191, 36, var(—tw-text-opacity));
Aa
text-yellow-500—tw-text-opacity: 1; color: rgba(245, 158, 11, var(—tw-text-opacity));
Aa
text-yellow-600—tw-text-opacity: 1; color: rgba(217, 119, 6, var(—tw-text-opacity));
Aa
text-yellow-700—tw-text-opacity: 1; color: rgba(180, 83, 9, var(—tw-text-opacity));
Aa
text-yellow-800—tw-text-opacity: 1; color: rgba(146, 64, 14, var(—tw-text-opacity));
Aa
text-yellow-900—tw-text-opacity: 1; color: rgba(120, 53, 15, var(—tw-text-opacity));
Aa
text-green-50—tw-text-opacity: 1; color: rgba(236, 253, 245, var(—tw-text-opacity));
Aa
text-green-100—tw-text-opacity: 1; color: rgba(209, 250, 229, var(—tw-text-opacity));
Aa
text-green-200—tw-text-opacity: 1; color: rgba(167, 243, 208, var(—tw-text-opacity));
Aa
text-green-300—tw-text-opacity: 1; color: rgba(110, 231, 183, var(—tw-text-opacity));
Aa
text-green-400—tw-text-opacity: 1; color: rgba(52, 211, 153, var(—tw-text-opacity));
Aa
text-green-500—tw-text-opacity: 1; color: rgba(16, 185, 129, var(—tw-text-opacity));
Aa
text-green-600—tw-text-opacity: 1; color: rgba(5, 150, 105, var(—tw-text-opacity));
Aa
text-green-700—tw-text-opacity: 1; color: rgba(4, 120, 87, var(—tw-text-opacity));
Aa
text-green-800—tw-text-opacity: 1; color: rgba(6, 95, 70, var(—tw-text-opacity));
Aa
text-green-900—tw-text-opacity: 1; color: rgba(6, 78, 59, var(—tw-text-opacity));
Aa
text-blue-50—tw-text-opacity: 1; color: rgba(239, 246, 255, var(—tw-text-opacity));
Aa
text-blue-100—tw-text-opacity: 1; color: rgba(219, 234, 254, var(—tw-text-opacity));
Aa
text-blue-200—tw-text-opacity: 1; color: rgba(191, 219, 254, var(—tw-text-opacity));
Aa
text-blue-300—tw-text-opacity: 1; color: rgba(147, 197, 253, var(—tw-text-opacity));
Aa
text-blue-400—tw-text-opacity: 1; color: rgba(96, 165, 250, var(—tw-text-opacity));
Aa
text-blue-500—tw-text-opacity: 1; color: rgba(59, 130, 246, var(—tw-text-opacity));
Aa
text-blue-600—tw-text-opacity: 1; color: rgba(37, 99, 235, var(—tw-text-opacity));
Aa
text-blue-700—tw-text-opacity: 1; color: rgba(29, 78, 216, var(—tw-text-opacity));
Aa
text-blue-800—tw-text-opacity: 1; color: rgba(30, 64, 175, var(—tw-text-opacity));
Aa
text-blue-900—tw-text-opacity: 1; color: rgba(30, 58, 138, var(—tw-text-opacity));
Aa
text-indigo-50—tw-text-opacity: 1; color: rgba(238, 242, 255, var(—tw-text-opacity));
Aa
text-indigo-100—tw-text-opacity: 1; color: rgba(224, 231, 255, var(—tw-text-opacity));
Aa
text-indigo-200—tw-text-opacity: 1; color: rgba(199, 210, 254, var(—tw-text-opacity));
Aa
text-indigo-300—tw-text-opacity: 1; color: rgba(165, 180, 252, var(—tw-text-opacity));
Aa
text-indigo-400—tw-text-opacity: 1; color: rgba(129, 140, 248, var(—tw-text-opacity));
Aa
text-indigo-500—tw-text-opacity: 1; color: rgba(99, 102, 241, var(—tw-text-opacity));
Aa
text-indigo-600—tw-text-opacity: 1; color: rgba(79, 70, 229, var(—tw-text-opacity));
Aa
text-indigo-700—tw-text-opacity: 1; color: rgba(67, 56, 202, var(—tw-text-opacity));
Aa
text-indigo-800—tw-text-opacity: 1; color: rgba(55, 48, 163, var(—tw-text-opacity));
Aa
text-indigo-900—tw-text-opacity: 1; color: rgba(49, 46, 129, var(—tw-text-opacity));
Aa
text-purple-50—tw-text-opacity: 1; color: rgba(245, 243, 255, var(—tw-text-opacity));
Aa
text-purple-100—tw-text-opacity: 1; color: rgba(237, 233, 254, var(—tw-text-opacity));
Aa
text-purple-200—tw-text-opacity: 1; color: rgba(221, 214, 254, var(—tw-text-opacity));
Aa
text-purple-300—tw-text-opacity: 1; color: rgba(196, 181, 253, var(—tw-text-opacity));
Aa
text-purple-400—tw-text-opacity: 1; color: rgba(167, 139, 250, var(—tw-text-opacity));
Aa
text-purple-500—tw-text-opacity: 1; color: rgba(139, 92, 246, var(—tw-text-opacity));
Aa
text-purple-600—tw-text-opacity: 1; color: rgba(124, 58, 237, var(—tw-text-opacity));
Aa
text-purple-700—tw-text-opacity: 1; color: rgba(109, 40, 217, var(—tw-text-opacity));
Aa
text-purple-800—tw-text-opacity: 1; color: rgba(91, 33, 182, var(—tw-text-opacity));
Aa
text-purple-900—tw-text-opacity: 1; color: rgba(76, 29, 149, var(—tw-text-opacity));
Aa
text-pink-50—tw-text-opacity: 1; color: rgba(253, 242, 248, var(—tw-text-opacity));
Aa
text-pink-100—tw-text-opacity: 1; color: rgba(252, 231, 243, var(—tw-text-opacity));
Aa
text-pink-200—tw-text-opacity: 1; color: rgba(251, 207, 232, var(—tw-text-opacity));
Aa
text-pink-300—tw-text-opacity: 1; color: rgba(249, 168, 212, var(—tw-text-opacity));
Aa
text-pink-400—tw-text-opacity: 1; color: rgba(244, 114, 182, var(—tw-text-opacity));
Aa
text-pink-500—tw-text-opacity: 1; color: rgba(236, 72, 153, var(—tw-text-opacity));
Aa
text-pink-600—tw-text-opacity: 1; color: rgba(219, 39, 119, var(—tw-text-opacity));
Aa
text-pink-700—tw-text-opacity: 1; color: rgba(190, 24, 93, var(—tw-text-opacity));
Aa
text-pink-800—tw-text-opacity: 1; color: rgba(157, 23, 77, var(—tw-text-opacity));
Aa
text-pink-900—tw-text-opacity: 1; color: rgba(131, 24, 67, var(—tw-text-opacity));
Aa

Usage

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

Text Color - 图1

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

Changing opacity

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

Text Color - 图2

  1. <p class="text-purple-700 text-opacity-100 ...">The quick brown fox ...</p>
  2. <p class="text-purple-700 text-opacity-75 ...">The quick brown fox ...</p>
  3. <p class="text-purple-700 text-opacity-50 ...">The quick brown fox ...</p>
  4. <p class="text-purple-700 text-opacity-25 ...">The quick brown fox ...</p>
  5. <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.

  1. <p class="text-blue-600 md:text-green-600 ...">
  2. The quick brown fox...
  3. </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.

Text Color - 图3

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

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

  1. <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.

Text Color - 图4

  1. <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.

  1. <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.

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. - textColor: theme => theme('colors'),
  5. + textColor: {
  6. + 'primary': '#3490dc',
  7. + 'secondary': '#ffed4a',
  8. + 'danger': '#e3342f',
  9. + }
  10. }
  11. }

Variants

By default, only responsive, dark mode (if enabled), group-hover, focus-within, hover and focus variants are generated for text color utilities.

You can control which variants are generated for the text color utilities by modifying the textColor property in the variants section of your tailwind.config.js file.

For example, this config will also generate active variants:

  1. // tailwind.config.js
  2. module.exports = {
  3. variants: {
  4. extend: {
  5. // ...
  6. + textColor: ['active'],
  7. }
  8. }
  9. }

Disabling

If you don’t plan to use the text color utilities in your project, you can disable them entirely by setting the textColor property to false in the corePlugins section of your config file:

  1. // tailwind.config.js
  2. module.exports = {
  3. corePlugins: {
  4. // ...
  5. + textColor: false,
  6. }
  7. }

←Text Align Text Opacity→

Edit this page on GitHub