Stroke Width

Utilities for styling the stroke width of SVG elements.

Default class reference

Class
Properties
stroke-0stroke-width: 0;
stroke-1stroke-width: 1;
stroke-2stroke-width: 2;

Usage

Use the stroke-{width} utilities to set the stroke width of an SVG.

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

Stroke Width - 图1

  1. <svg class="stroke-current stroke-1 text-green-600 ..."></svg>
  2. <svg class="stroke-current stroke-2 text-green-600 ..."></svg>

Responsive

To control the stroke width of an SVG element at a specific breakpoint, add a {screen}: prefix to any existing width utility. For example, adding the class md:stroke-2 to an element would apply the stroke-2 utility at medium screen sizes and above.

  1. <svg class="stroke-1 md:stroke-2 ...">
  2. <!-- ... -->
  3. </svg>

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

Customizing

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

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. extend: {
  5. strokeWidth: {
  6. + '3': '3',
  7. + '4': '4',
  8. }
  9. }
  10. }
  11. }

Learn more about customizing the default theme in the theme customization documentation.

Variants

By default, only responsive variants are generated for stroke-width utilities.

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

Disabling

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

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

←StrokeScreen Readers→