由於 Tailwind 是用於建置客製化使用者介面的架構,因此從一開始就以自訂化為設計考量。

預設情況下,Tailwind 會在專案根目錄尋找選用的 tailwind.config.js 檔案,您可以在其中定義任何自訂化設定。

tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
  content: ['./src/**/*.{html,js}'],
  theme: {
    colors: {
      'blue': '#1fb6ff',
      'purple': '#7e5bef',
      'pink': '#ff49db',
      'orange': '#ff7849',
      'green': '#13ce66',
      'yellow': '#ffc82c',
      'gray-dark': '#273444',
      'gray': '#8492a6',
      'gray-light': '#d3dce6',
    },
    fontFamily: {
      sans: ['Graphik', 'sans-serif'],
      serif: ['Merriweather', 'serif'],
    },
    extend: {
      spacing: {
        '8xl': '96rem',
        '9xl': '128rem',
      },
      borderRadius: {
        '4xl': '2rem',
      }
    }
  },
}

設定檔的每個區段都是選用的,因此您只需指定想要變更的內容即可。任何遺漏的區段都將採用 Tailwind 的預設設定


建立設定檔

使用安裝 tailwindcss npm 套件時包含的 Tailwind CLI 工具,為你的專案產生一個 Tailwind 設定檔

npx tailwindcss init

這會在你的專案根目錄建立一個最小的 tailwind.config.js 檔案

tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [],
  theme: {
    extend: {},
  },
  plugins: [],
}

使用不同的檔案名稱

若要使用 tailwind.config.js 以外的名稱,請將其作為引數傳遞至命令列

npx tailwindcss init tailwindcss-config.js

使用自訂檔案名稱時,你需要在使用 Tailwind CLI 工具編譯 CSS 時,將其指定為命令列引數

npx tailwindcss -c ./tailwindcss-config.js -i input.css -o output.css

如果你將 Tailwind 用作 PostCSS 外掛程式,你需要在 PostCSS 設定中指定自訂設定路徑

postcss.config.js
module.exports = {
  plugins: {
    tailwindcss: { config: './tailwindcss-config.js' },
  },
}

或者,你可以使用 @config 指令指定自訂設定路徑

@config "./tailwindcss-config.js";

@tailwind base;
@tailwind components;
@tailwind utilities;

函式和指令 文件中深入了解 @config 指令。

使用 ESM 或 TypeScript

你也可以在 ESM 甚至 TypeScript 中設定 Tailwind CSS

/** @type {import('tailwindcss').Config} */
export default {
  content: [],
  theme: {
    extend: {},
  },
  plugins: [],
}

當你執行 npx tailwindcss init 時,我們會偵測你的專案是否為 ES 模組,並自動產生適當語法的設定檔。

你也可以使用 --esm 旗標明確產生 ESM 設定檔

npx tailwindcss init --esm

若要產生 TypeScript 設定檔,請使用 --ts 旗標

npx tailwindcss init --ts

產生 PostCSS 設定檔

如果你想在 tailwind.config.js 檔案旁也產生一個基本的 postcss.config.js 檔案,請使用 -p 旗標

npx tailwindcss init -p

這會在你的專案中產生一個 postcss.config.js 檔案,如下所示

postcss.config.js
module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
}

建立完整的預設設定

對於大多數使用者,我們建議你盡可能保持設定檔簡潔,只指定你想自訂的項目。

如果你希望建立一個包含所有 Tailwind 預設設定的完整設定檔,請使用 --full 選項

npx tailwindcss init --full

你會取得一個與 預設設定檔 相符的檔案,Tailwind 在內部使用。


設定選項

內容

content 區段是你設定所有 HTML 範本、JS 元件和任何包含 Tailwind 類別名稱的其他檔案路徑的地方。

tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    './pages/**/*.{html,js}',
    './components/**/*.{html,js}',
  ],
  // ...
}

內容設定 文件中了解有關設定內容來源的更多資訊。

佈景主題

theme 區段是您定義色彩盤、字型、字型大小、邊框大小、斷點的區段,也就是與網站視覺設計相關的任何內容。

tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
  // ...
  theme: {
    colors: {
      'blue': '#1fb6ff',
      'purple': '#7e5bef',
      'pink': '#ff49db',
      'orange': '#ff7849',
      'green': '#13ce66',
      'yellow': '#ffc82c',
      'gray-dark': '#273444',
      'gray': '#8492a6',
      'gray-light': '#d3dce6',
    },
    fontFamily: {
      sans: ['Graphik', 'sans-serif'],
      serif: ['Merriweather', 'serif'],
    },
    extend: {
      spacing: {
        '8xl': '96rem',
        '9xl': '128rem',
      },
      borderRadius: {
        '4xl': '2rem',
      }
    }
  }
}

主題設定指南 中深入了解預設主題以及如何自訂主題。

外掛程式

plugins 區段讓您可以向 Tailwind 註冊外掛程式,這些外掛程式可用於產生額外的公用程式、元件、基本樣式或自訂變體。

tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
  // ...
  plugins: [
    require('@tailwindcss/forms'),
    require('@tailwindcss/aspect-ratio'),
    require('@tailwindcss/typography'),
    require('tailwindcss-children'),
  ],
}

外掛程式撰寫指南 中深入了解如何撰寫您自己的外掛程式。

預設值

presets 區段讓您可以指定自己的自訂基本設定,而不是使用 Tailwind 的預設基本設定。

tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
  // ...
  presets: [
    require('@acmecorp/base-tailwind-config')
  ],

  // Project-specific customizations
  theme: {
    //...
  },
}

預設值文件 中深入了解預設值。

前綴

prefix 選項允許您為 Tailwind 所有產生的公用程式類別新增自訂前綴。這在 Tailwind 與現有 CSS 疊加時非常有用,因為可能會發生命名衝突。

例如,您可以透過設定 prefix 選項來新增 tw- 前綴,如下所示

tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
  prefix: 'tw-',
}

現在每個類別都會使用已設定的前綴產生

.tw-text-left {
  text-align: left;
}
.tw-text-center {
  text-align: center;
}
.tw-text-right {
  text-align: right;
}
/* etc. */

了解此前綴是在 任何 變體修改器之後新增非常重要。這表示具有回應式或狀態修改器的類別,例如 sm:hover:,仍然會 首先 具有回應式或狀態修改器,而自訂前綴會出現在冒號之後

<div class="tw-text-lg md:tw-text-xl tw-bg-red-500 hover:tw-bg-blue-500">
  <!-- -->
</div>

負值破折號修改器應在您的前綴之前新增,因此如果您已設定 tw- 為您的前綴,則 -mt-8 會變成 -tw-mt-8

<div class="-tw-mt-8">
  <!-- -->
</div>

前綴僅新增至 Tailwind 產生的類別;您的自訂類別不會新增任何前綴。

這表示如果您新增自訂公用程式如下所示

@layer utilities {
  .bg-brand-gradient { /* ... */ }
}

…產生的變體不會具有您設定的前綴

.bg-brand-gradient { /* ... */ }
.hover\:bg-brand-gradient:hover { /* ... */ }

如果您也想要為自訂公用程式加上前綴,只需將前綴新增至類別定義即可

@layer utilities {
  .tw-bg-brand-gradient { /* ... */ }
}

重要

important 選項可讓您控制 Tailwind 的公用程式是否應標記為 !important。當與具有高特異性選擇器的現有 CSS 搭配使用 Tailwind 時,這項功能非常實用。

若要將公用程式產生為 !important,請將設定選項中的 important 鍵設定為 true

tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
  important: true,
}

現在,Tailwind 的所有公用程式類別都將產生為 !important

.leading-none {
  line-height: 1 !important;
}
.leading-tight {
  line-height: 1.25 !important;
}
.leading-snug {
  line-height: 1.375 !important;
}
/* etc. */

這也適用於您使用 @layer utilities 指令在 CSS 中定義的任何自訂公用程式

/* Input */
@layer utilities {
  .bg-brand-gradient {
    background-image: linear-gradient(#3490dc, #6574cd);
  }
}

/* Output */
.bg-brand-gradient {
  background-image: linear-gradient(#3490dc, #6574cd) !important;
}

選擇器策略

important 設定為 true 可能會在整合將內嵌樣式新增到元素的第三方 JS 函式庫時造成一些問題。在這些情況下,Tailwind 的 !important 輔助工具會取代內嵌樣式,這可能會破壞您預期的設計。

為了解決此問題,您可以將 important 設定為 ID 選擇器,例如 #app

tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
  // ...
  important: '#app',
}

此組態會為您的所有輔助工具加上給定的選擇器前綴,實際上會提高其特殊性,而不會實際讓它們成為 !important

在您指定 important 選擇器後,您需要確保網站的根元素與其相符。使用上述範例,我們需要將根元素的 id 屬性設定為 app,才能讓樣式正常運作。

在您的組態全部設定完成,且您的根元素與 Tailwind 組態中的選擇器相符後,Tailwind 的所有輔助工具都會有足夠高的特殊性來取代專案中使用的其他類別,而不會干擾內嵌樣式

<html>
<!-- ... -->
<style>
  .high-specificity .nested .selector {
    color: blue;
  }
</style>
<body id="app">
  <div class="high-specificity">
    <div class="nested">
      <!-- Will be red-500 -->
      <div class="selector text-red-500"><!-- ... --></div>
    </div>
  </div>

  <!-- Will be #bada55 -->
  <div class="text-red-500" style="color: #bada55;"><!-- ... --></div>
</body>
</html>

在使用選擇器策略時,請務必確認包含根選擇器的範本檔案包含在您的內容組態中,否則在建置生產環境時,您的所有 CSS 都會被移除。

重要修改器

或者,您可以在開頭加上 ! 字元,讓任何輔助工具都變得重要

<p class="!font-medium font-bold">
  This will be medium even though bold comes later in the CSS.
</p>

! 始終會出現在輔助工具名稱的開頭,在任何變體之後,但在任何前綴之前

<div class="sm:hover:!tw-font-bold">

在您需要提高特殊性,因為您正在與一些您無法控制的樣式作戰的罕見情況下,這可能會很有用。

分隔符

separator 選項可讓您自訂用於將修改器(螢幕大小、hoverfocus 等)與工具程式名稱(text-centeritems-end 等)分隔的字元。

我們預設使用冒號 (:),但如果您使用不支援類別名稱中特殊字元的範本語言(例如 Pug),變更這個設定會很有用。

tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
  separator: '_',
}

核心外掛程式

corePlugins 區段可讓您完全停用 Tailwind 預設會產生的類別,如果您不需要它們來進行專案。

若要停用特定的核心外掛程式,請提供一個物件給 corePlugins,將那些外掛程式設定為 false

tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
  corePlugins: {
    float: false,
    objectFit: false,
    objectPosition: false,
  }
}

如果您想將哪些核心外掛程式列為安全清單,請提供一個陣列,其中包含您想使用的核心外掛程式清單

tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
  corePlugins: [
    'margin',
    'padding',
    'backgroundColor',
    // ...
  ]
}

如果您想要停用所有 Tailwind 的核心外掛程式,並僅將 Tailwind 用作處理您自己的自訂外掛程式的工具,請提供一個空陣列

tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
  corePlugins: []
}

以下是所有核心外掛程式的清單,以供參考

核心外掛程式說明
accentColoraccent-color 實用程式,例如 accent-green-800
accessibilitysr-onlynot-sr-only 實用程式
alignContentalign-content 實用程式,例如 content-between
alignItemsalign-items 實用程式,例如 items-center
alignSelfalign-self 實用程式,例如 self-end
animationanimation 實用程式,例如 animate-ping
appearanceappearance 實用程式,例如 appearance-none
aspectRatioaspect-ratio 實用程式,例如 aspect-square
backdropBlurbackdrop-blur 實用程式,例如 backdrop-blur-md
backdropBrightnessbackdrop-brightness 實用程式,例如 backdrop-brightness-100
backdropContrastbackdrop-contrast 實用程式,例如 backdrop-contrast-100
backdropFilterbackdrop-filter 實用程式,例如 backdrop-filter
backdropGrayscalebackdrop-grayscale 實用程式,例如 backdrop-grayscale-0
backdropHueRotatebackdrop-hue-rotate 實用程式,例如 backdrop-hue-rotate-30
backdropInvertbackdrop-invert 實用程式,例如 backdrop-invert-0
backdropOpacitybackdrop-opacity 實用程式,例如 backdrop-opacity-50
backdropSaturatebackdrop-saturate 實用程式,例如 backdrop-saturate-100
backdropSepiabackdrop-sepia 實用程式,例如 backdrop-sepia-0
backgroundAttachmentbackground-attachment 實用程式,例如 bg-local
backgroundBlendModebackground-blend-mode 實用程式,例如 bg-blend-color-burn
backgroundClipbackground-clip 實用程式,例如 bg-clip-padding
backgroundColorbackground-color 實用程式,例如 bg-green-800
backgroundImagebackground-image 實用程式,例如 bg-gradient-to-br
backgroundOpacitybackground-color 不透明度實用程式,例如 bg-opacity-25
backgroundOriginbackground-origin 實用程式,例如 bg-origin-padding
backgroundPositionbackground-position 實用程式,例如 bg-left-top
backgroundRepeatbackground-repeat 實用程式,例如 bg-repeat-x
backgroundSizebackground-size 實用程式,例如 bg-cover
blurblur 實用程式,例如 blur-md
borderCollapseborder-collapse 實用程式,例如 border-collapse
borderColorborder-color 實用程式,例如 border-e-green-800
borderOpacityborder-color 不透明度實用程式,例如 border-opacity-25
borderRadiusborder-radius 實用程式,例如 rounded-ss-lg
borderSpacingborder-spacing實用程式,例如 border-spacing-x-28
borderStyleborder-style實用程式,例如 border-dotted
borderWidthborder-width實用程式,例如 border-e-4
boxDecorationBreakbox-decoration-break實用程式,例如 decoration-clone
boxShadowbox-shadow實用程式,例如 shadow-lg
boxShadowColorbox-shadow-color實用程式,例如 shadow-green-800
boxSizingbox-sizing實用程式,例如 box-border
breakAfterbreak-after實用程式,例如 break-after-avoid-page
breakBeforebreak-before實用程式,例如 break-before-avoid-page
breakInsidebreak-inside實用程式,例如 break-inside-avoid
brightnessbrightness實用程式,例如 brightness-100
captionSidecaption-side實用程式,例如 caption-top
caretColorcaret-color實用程式,例如 caret-green-800
clearclear實用程式,例如 clear-left
columnscolumns實用程式,例如 columns-auto
containercontainer 元件
contentcontent實用程式,例如 content-none
contrastcontrast實用程式,例如 contrast-100
cursorcursor實用程式,例如 cursor-grab
displaydisplay實用程式,例如 table-column-group
divideColor介於元素之間的 border-color 公用程式,例如 divide-slate-500
divideOpacitydivide-opacity 公用程式,例如 divide-opacity-50
divideStyledivide-style 公用程式,例如 divide-dotted
divideWidth介於元素之間的 border-width 公用程式,例如 divide-x-2
dropShadowdrop-shadow 公用程式,例如 drop-shadow-lg
fillfill 公用程式,例如 fill-green-700
filterfilter 公用程式,例如 filter
flexflex 公用程式,例如 flex-auto
flexBasisflex-basis 公用程式,例如 basis-px
flexDirectionflex-direction 公用程式,例如 flex-row-reverse
flexGrowflex-grow 公用程式,例如 flex-grow
flexShrinkflex-shrink 公用程式,例如 flex-shrink
flexWrapflex-wrap 公用程式,例如 flex-wrap-reverse
floatfloat 公用程式,例如 float-right
fontFamilyfont-family 公用程式,例如 font-serif
fontSizefont-size 公用程式,例如 text-3xl
fontSmoothingfont-smoothing 公用程式,例如 antialiased
fontStylefont-style 公用程式,例如 italic
fontVariantNumericfont-variant-numeric 公用程式,例如 oldstyle-nums
fontWeightfont-weight 公用程式,例如 font-medium
forcedColorAdjustforced-color-adjust 公用程式,例如 forced-color-adjust-auto
間距gap 實用程式,例如 gap-x-28
gradientColorStopsgradient-color-stops 實用程式,例如 via-emerald-700
灰階grayscale 實用程式,例如 grayscale-0
gridAutoColumnsgrid-auto-columns 實用程式,例如 auto-cols-min
gridAutoFlowgrid-auto-flow 實用程式,例如 grid-flow-dense
gridAutoRowsgrid-auto-rows 實用程式,例如 auto-rows-min
gridColumngrid-column 實用程式,例如 col-span-6
gridColumnEndgrid-column-end 實用程式,例如 col-end-7
gridColumnStartgrid-column-start 實用程式,例如 col-start-7
gridRowgrid-row 實用程式,例如 row-span-6
gridRowEndgrid-row-end 實用程式,例如 row-end-7
gridRowStartgrid-row-start 實用程式,例如 row-start-7
gridTemplateColumnsgrid-template-columns 實用程式,例如 grid-cols-7
gridTemplateRowsgrid-template-rows 實用程式,例如 grid-rows-7
高度height 實用程式,例如 h-96
色相旋轉hue-rotate 實用程式,例如 hue-rotate-30
連字號hyphens 實用程式,例如 hyphens-manual
內嵌inset 實用程式,例如 end-44
反轉invert 實用程式,例如 invert-0
隔離isolation 等實用程式,例如 isolate
justifyContentjustify-content 等實用程式,例如 justify-center
justifyItemsjustify-items 等實用程式,例如 justify-items-end
justifySelfjustify-self 等實用程式,例如 justify-self-end
letterSpacingletter-spacing 等實用程式,例如 tracking-normal
lineClampline-clamp 等實用程式,例如 line-clamp-4
lineHeightline-height 等實用程式,例如 leading-9
listStyleImagelist-style-image 等實用程式,例如 list-image-none
listStylePositionlist-style-position 等實用程式,例如 list-inside
listStyleTypelist-style-type 等實用程式,例如 list-disc
marginmargin 等實用程式,例如 me-28
maxHeightmax-height 等實用程式,例如 max-h-44
maxWidthmax-width 等實用程式,例如 max-w-80
minHeightmin-height 等實用程式,例如 min-h-44
minWidthmin-width 等實用程式,例如 min-w-36
mixBlendModemix-blend-mode 等實用程式,例如 mix-blend-hard-light
objectFitobject-fit 等實用程式,例如 object-fill
objectPositionobject-position 等實用程式,例如 object-left-top
opacityopacity 等實用程式,例如 opacity-50
orderorder 等實用程式,例如 order-8
outlineColoroutline-color 等實用程式,例如 outline-green-800
outlineOffsetoutline-offset 等實用程式,例如 outline-offset-2
outlineStyleoutline-style 實用程式,例如 outline-dashed
outlineWidthoutline-width 實用程式,例如 outline-2
overflowoverflow 實用程式,例如 overflow-x-hidden
overscrollBehavioroverscroll-behavior 實用程式,例如 overscroll-y-contain
paddingpadding 實用程式,例如 pe-28
placeContentplace-content 實用程式,例如 place-content-between
placeItemsplace-items 實用程式,例如 place-items-center
placeSelfplace-self 實用程式,例如 place-self-end
placeholderColorplaceholder color 實用程式,例如 placeholder-red-600
placeholderOpacityplaceholder color opacity 實用程式,例如 placeholder-opacity-25
pointerEventspointer-events 實用程式,例如 pointer-events-none
positionposition 實用程式,例如 absolute
preflightTailwind 的基礎/重設樣式
resizeresize 實用程式,例如 resize-y
ringColorring-color 實用程式,例如 ring-green-800
ringOffsetColorring-offset-color 實用程式,例如 ring-offset-green-800
ringOffsetWidthring-offset-width 實用程式,例如 ring-offset-2
ringOpacityring-opacity 實用程式,例如 ring-opacity-50
ringWidthring-width 實用程式,例如 ring-4
rotaterotate 實用程式,例如 rotate-6
飽和saturate 實用程式,例如 saturate-100
縮放scale 實用程式,例如 scale-x-95
捲動行為scroll-behavior 實用程式,例如 scroll-auto
捲動邊界scroll-margin 實用程式,例如 scroll-me-28
捲動內距scroll-padding 實用程式,例如 scroll-pe-28
捲動對齊scroll-snap-align 實用程式,例如 snap-end
捲動停止scroll-snap-stop 實用程式,例如 snap-normal
捲動類型scroll-snap-type 實用程式,例如 snap-y
褐色sepia 實用程式,例如 sepia-0
大小size 實用程式,例如 size-0.5
傾斜skew 實用程式,例如 skew-x-12
間距「space-between」實用程式,例如 space-x-4
描邊stroke 實用程式,例如 stroke-green-700
描邊寬度stroke-width 實用程式,例如 stroke-1
表格配置table-layout 實用程式,例如 table-auto
文字對齊text-align 實用程式,例如 text-right
文字顏色text-color 實用程式,例如 text-green-800
文字裝飾text-decoration 實用程式,例如 overline
文字裝飾顏色text-decoration-color 實用程式,例如 decoration-green-800
文字裝飾樣式text-decoration-style 實用程式,例如 decoration-dotted
文字裝飾粗細text-decoration-thickness 實用程式,例如 decoration-4
文字縮排text-indent 實用程式,例如 indent-28
文字不透明度text-opacity 實用程式,例如 text-opacity-50
文字溢出text-overflow 實用程式,例如 overflow-ellipsis
文字轉換text-transform 實用程式,例如 lowercase
文字底線偏移量text-underline-offset 實用程式,例如 underline-offset-2
文字換行text-wrap 實用程式,例如 text-nowrap
觸控動作touch-action 實用程式,例如 touch-pan-right
轉換transform 實用程式(用於啟用轉換功能)
轉換原點transform-origin 實用程式,例如 origin-bottom-right
轉場延遲transition-delay 實用程式,例如 delay-200
轉場持續時間transition-duration 實用程式,例如 duration-200
轉場屬性transition-property 實用程式,例如 transition-colors
轉場計時函數transition-timing-function 實用程式,例如 ease-in
平移translate 實用程式,例如 translate-x-full
使用者選取user-select 實用程式,例如 select-text
垂直對齊vertical-align 實用程式,例如 align-bottom
可見性visibility 實用程式,例如 invisible
空白whitespace 實用程式,例如 whitespace-pre
寬度width 實用程式,例如 w-2.5
將變更will-change 實用程式,例如 will-change-scroll
斷字word-break 實用程式,例如 break-words
zIndexz-index 實用程式,例如 z-30

使用多種組態

對於需要使用不同 Tailwind 組態產生多個 CSS 檔案的專案,請使用 @config 指令來指定應為每個 CSS 進入點使用哪個組態檔案

@config "./tailwind.site.config.js";

@tailwind base;
@tailwind components;
@tailwind utilities;

函式和指令 文件中深入了解 @config 指令。


在 JavaScript 中參照

在您自己的用戶端 JavaScript 中參照您的組態值通常很有用,例如在 React 或 Vue 元件中動態套用內嵌樣式時存取一些您的佈景主題值。

為了簡化此操作,Tailwind 提供一個 resolveConfig 輔助函式,您可以使用它來產生組態物件的完全合併版本

import resolveConfig from 'tailwindcss/resolveConfig'
import tailwindConfig from './tailwind.config.js'

const fullConfig = resolveConfig(tailwindConfig)

fullConfig.theme.width[4]
// => '1rem'

fullConfig.theme.screens.md
// => '768px'

fullConfig.theme.boxShadow['2xl']
// => '0 25px 50px -12px rgba(0, 0, 0, 0.25)'

請注意,這會遞移式地引入許多我們的建置時間相依關係,導致更大的用戶端套件大小。為避免這種情況,我們建議使用 babel-plugin-preval 等工具在建置時產生組態的靜態版本。


TypeScript 類型

我們為 tailwind.config.js 檔案提供第一方的 TypeScript 類型,提供各種有用的 IDE 支援,讓您更容易變更設定,而無需經常參考文件。

使用 Tailwind CLI 產生的設定檔預設包含必要的類型註解,但若要手動設定 TypeScript 類型,只要在設定物件上方加入類型註解即可

tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    // ...
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}