Text Color

    Usage

    Control the text color of an element using the utilities.

    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-25">The quick brown fox ...</p>
    4. <p class="text-purple-700 text-opacity-0">The quick brown fox ...</p>

    Learn more in the .

    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.

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

    all

    sm

    Text Color - 图5

    md

    lg

    Text Color - 图7

    xl

    1. <div class="text-blue-600 sm:text-green-600 md:text-indigo-600 lg:text-red-600 xl:text-gray-900 ...">
    2. The quick brown fox...
    3. </div>

    The quick brown fox jumped over the lazy dog.

    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.

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

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

    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.

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

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

    Customizing

    By default Tailwind makes the entire 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. + 'danger': '#e3342f',
    7. + }
    8. }
    9. }

    By default, only responsive, 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 and group-hover variants:

    1. // tailwind.config.js
    2. module.exports = {
    3. variants: {
    4. // ...
    5. - textColor: ['responsive', 'hover', 'focus'],
    6. + textColor: ['responsive', 'hover', 'focus', 'active', 'group-hover'],
    7. }

      Text Opacity →