Stroke

Utilities for styling the stroke of SVG elements.

Class reference

Class
Properties
.stroke-currentstroke: currentColor;

Usage

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

Useful for styling icon sets like Feather that are drawn entirely with strokes.

Stroke - 图1

  1. <svg class="stroke-current text-purple-500 inline-block h-12 w-12" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
  2. <circle cx="8" cy="21" r="2" />
  3. <circle cx="20" cy="21" r="2" />
  4. <path d="M5.67 6H23l-1.68 8.39a2 2 0 0 1-2 1.61H8.75a2 2 0 0 1-2-1.74L5.23 2.74A2 2 0 0 0 3.25 1H1" />
  5. </svg>

Customizing

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

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. - stroke: {
  5. - current: 'currentColor',
  6. - }
  7. + stroke: theme => ({
  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 stroke utilities.

You can control which variants are generated for the stroke utilities by modifying the stroke 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. - stroke: ['responsive'],
  6. + stroke: ['responsive', 'hover', 'focus'],
  7. }
  8. }

Disabling

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

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

← Fill   Stroke Width →