Stroke Width

Tailwind CSS version

v1.2.0+

Utilities for styling the stroke width of SVG elements.

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 Feather that are drawn entirely with strokes.

Stroke Width - 图1

  1. <svg class="stroke-current stroke-1 text-green-500 ..."></svg>
  2. <svg class="stroke-current stroke-2 text-green-500 ..."></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.

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

Stroke Width - 图2

all

Stroke Width - 图3

sm

Stroke Width - 图4

md

Stroke Width - 图5

lg

Stroke Width - 图6

xl

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

Stroke Width - 图7

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.

Responsive and pseudo-class 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. // ...
  5. - strokeWidth: ['responsive'],
  6. + strokeWidth: ['responsive', 'hover', 'focus'],
  7. }
  8. }

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

← Stroke   Screen Readers →