SVG

Stroke Width

Utilities for styling the stroke width of SVG elements.

Quick reference

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

Basic usage

Setting the stroke width

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

Stroke Width - 图1

  1. <svg class="stroke-1 ..."></svg>
  2. <svg class="stroke-2 ..."></svg>

This can be useful for styling icon sets like Heroicons.


Applying conditionally

Hover, focus, and other states

Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:stroke-2 to only apply the stroke-2 utility on hover.

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

For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.

Breakpoints and media queries

You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:stroke-2 to apply the stroke-2 utility at only medium screen sizes and above.

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

To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.


Using custom values

Customizing your theme

By default, Tailwind includes stroke-width utilities for creating basic grids with up to 6 equal width rows. You can customize these values by editing theme.strokeWidth or theme.extend.strokeWidth in your tailwind.config.js file.

You have direct access to the stroke-width CSS property here so you can make your custom rows values as generic or as complicated and site-specific as you like.

tailwind.config.js

  1. module.exports = {
  2. theme: {
  3. extend: {
  4. strokeWidth: {
  5. '2': '2px',
  6. }
  7. }
  8. }
  9. }

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

Arbitrary values

If you need to use a one-off stroke-width value that doesn’t make sense to include in your theme, use square brackets to generate a property on the fly using any arbitrary value.

  1. <svg class="stroke-[2px]">
  2. <!-- ... -->
  3. </svg>

Learn more about arbitrary value support in the arbitrary values documentation.