SVG

stroke

用於設定 SVG 元素描邊樣式的通用類別。

ClassStyles
stroke-none
stroke: none;
stroke-inherit
stroke: inherit;
stroke-current
stroke: currentColor;
stroke-transparent
stroke: transparent;
stroke-black
stroke: var(--color-black); /* #000 */
stroke-white
stroke: var(--color-white); /* #fff */
stroke-red-50
stroke: var(--color-red-50); /* oklch(97.1% 0.013 17.38) */
stroke-red-100
stroke: var(--color-red-100); /* oklch(93.6% 0.032 17.717) */
stroke-red-200
stroke: var(--color-red-200); /* oklch(88.5% 0.062 18.334) */
stroke-red-300
stroke: var(--color-red-300); /* oklch(80.8% 0.114 19.571) */

範例(Examples)

基本範例(Basic example)

使用 stroke-indigo-500stroke-lime-600 等通用類別來變更 SVG 的描邊顏色:

<svg class="stroke-cyan-500 ...">  <!-- ... --></svg>

這對於設定像 Heroicons 這樣的圖示集樣式非常有用。

使用目前顏色(Using the current color)

使用 stroke-current 通用類別將描邊顏色設定為目前的文字顏色:

將滑鼠懸停在按鈕上以查看描邊顏色變化

<button class="bg-white text-pink-600 hover:bg-pink-600 hover:text-white ...">  <svg class="size-5 stroke-current ..." fill="none">    <!-- ... -->  </svg>  Download file</button>

使用自訂值(Using a custom value)

使用 stroke-[<value>] 語法,根據完全自訂的值來設定 stroke color

<svg class="stroke-[#243c5a] ...">  <!-- ... --></svg>

對於 CSS 變數,你也可以使用 stroke-(<custom-property>) 語法:

<svg class="stroke-(--my-stroke-color) ...">  <!-- ... --></svg>

這只是 stroke-[var(<custom-property>)] 的簡寫形式,會自動為你加上 var() 函式。

響應式設計(Responsive design)

stroke 通用類別前面加上像 md: 這樣的中斷點變體,讓該通用類別只在中型螢幕尺寸及以上時套用:

<svg class="stroke-cyan-500 md:stroke-cyan-700 ...">  <!-- ... --></svg>

變體文件中了解更多關於使用變體的資訊。

自訂你的主題(Customizing your theme)

使用 --color-* 主題變數來自訂專案中的 color 通用類別:

@theme {  --color-regal-blue: #243c5a; }

現在可以在標記中使用 stroke-regal-blue 通用類別:

<svg class="stroke-regal-blue">  <!-- ... --></svg>

主題文件中了解更多關於自訂主題的資訊。

Copyright © 2026 Tailwind Labs Inc.·商標政策(Brand)