Fill

Utilities for styling the fill of SVG elements.

Class reference

ClassProperties
.fill-currentfill: currentColor;

Usage

Use .fill-current to set the fill color of an SVG to the current text color. This makes it easy to set an element’s fill color by combining this class with an existing text color utility.

Useful for styling icon sets like Zondicons that are drawn entirely with fills.

Fill - 图1

  1. <svg class="fill-current text-teal-500 inline-block h-12 w-12" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
  2. <path d="M18 9.87V20H2V9.87a4.25 4.25 0 0 0 3-.38V14h10V9.5a4.26 4.26 0 0 0 3 .37zM3 0h4l-.67 6.03A3.43 3.43 0 0 1 3 9C1.34 9 .42 7.73.95 6.15L3 0zm5 0h4l.7 6.3c.17 1.5-.91 2.7-2.42 2.7h-.56A2.38 2.38 0 0 1 7.3 6.3L8 0zm5 0h4l2.05 6.15C19.58 7.73 18.65 9 17 9a3.42 3.42 0 0 1-3.33-2.97L13 0z"/>
  3. </svg>

Customizing

Control which fill utilities Tailwind generates by customizing the theme.fill section of your tailwind.config.js file:

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. - fill: {
  5. - current: 'currentColor',
  6. - }
  7. + fill: theme =&gt; ({
  8. + 'red': theme('colors.red.500'),
  9. + 'green': theme('colors.green.500'),
  10. + 'blue': theme('colors.blue.500'),
  11. + })
  12. }
  13. }

Responsive and pseudo-class variants

By default, only responsive variants are generated for fill utilities.

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

For example, this config will also generate hover and focus variants:

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

Disabling

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

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