検索できるTailwind CSS v4チートシートです。クラス名や普通の言葉を入力すると、v4が生成する正確なCSSが表示されます。var(--spacing)の倍数からOKLCHのカラートークンまで対応し、@themeトークン、ブレークポイント、コンテナクエリ、動くflexとgridのボックス、全カラーパレット、ダークモード、v3からv4への名称変更も扱います。
このシートはTailwind CSS v4を対象としています(執筆時点の2026年10月の最新リリースはv4.3)。各クラスについて、v4が実際に書き出すCSSを示しています。v4では値の作り方が変わったため、これが重要です。余白は1つの--spacing変数の倍数になり、色はOKLCHで定義された--color-*変数になり、角丸、影、文字などのサイズは名前付きのテーマ変数から取得されます。ボックスに入力すると絞り込めます。クラス名、出力されるCSS、そして「center」「gradient」「sticky」のような普通の単語でも検索できます。
全243件を表示中
| クラス | v4で出力されるCSS |
|---|---|
| レイアウトと表示 | |
block | display: block; |
inline-block | display: inline-block; |
inline | display: inline; |
flex | display: flex; |
inline-flex | display: inline-flex; |
grid | display: grid; |
inline-grid | display: inline-grid; |
contents | display: contents; |
hidden | display: none; |
container | width: 100%; plus max-width: var(--breakpoint-sm) at sm, and so on for each breakpoint |
box-border | box-sizing: border-box; |
box-content | box-sizing: content-box; |
static | position: static; |
relative | position: relative; |
absolute | position: absolute; |
fixed | position: fixed; |
sticky | position: sticky; |
inset-0 | inset: calc(var(--spacing) * 0); |
inset-x-0 | inset-inline: calc(var(--spacing) * 0); |
top-4 | top: calc(var(--spacing) * 4); /* 1rem */ |
-top-2 | top: calc(var(--spacing) * -2); |
left-1/2 | left: calc(1/2 * 100%); |
z-10 | z-index: 10; |
z-50 | z-index: 50; |
isolate | isolation: isolate; |
overflow-hidden | overflow: hidden; |
overflow-auto | overflow: auto; |
overflow-x-auto | overflow-x: auto; |
aspect-video | aspect-ratio: var(--aspect-video); /* 16 / 9 */ |
aspect-square | aspect-ratio: 1 / 1; |
object-cover | object-fit: cover; |
object-contain | object-fit: contain; |
visible | visibility: visible; |
invisible | visibility: hidden; |
sr-only | position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border-width: 0; |
| フレックスボックス | |
flex-row | flex-direction: row; |
flex-col | flex-direction: column; |
flex-row-reverse | flex-direction: row-reverse; |
flex-wrap | flex-wrap: wrap; |
flex-nowrap | flex-wrap: nowrap; |
flex-1 | flex: 1; |
flex-auto | flex: auto; |
flex-initial | flex: 0 auto; |
flex-none | flex: none; |
grow | flex-grow: 1; |
grow-0 | flex-grow: 0; |
shrink-0 | flex-shrink: 0; |
basis-64 | flex-basis: calc(var(--spacing) * 64); |
basis-1/3 | flex-basis: calc(1/3 * 100%); |
order-2 | order: 2; |
order-first | order: -9999; |
order-last | order: 9999; |
| 配置と間隔 | |
justify-start | justify-content: flex-start; |
justify-center | justify-content: center; |
justify-end | justify-content: flex-end; |
justify-between | justify-content: space-between; |
justify-around | justify-content: space-around; |
justify-evenly | justify-content: space-evenly; |
items-start | align-items: flex-start; |
items-center | align-items: center; |
items-end | align-items: flex-end; |
items-baseline | align-items: baseline; |
items-stretch | align-items: stretch; |
self-center | align-self: center; |
self-end | align-self: flex-end; |
content-center | align-content: center; |
place-items-center | place-items: center; |
place-content-center | place-content: center; |
justify-items-center | justify-items: center; |
gap-4 | gap: calc(var(--spacing) * 4); /* 1rem */ |
gap-x-6 | column-gap: calc(var(--spacing) * 6); |
gap-y-2 | row-gap: calc(var(--spacing) * 2); |
| グリッド | |
grid-cols-3 | grid-template-columns: repeat(3, minmax(0, 1fr)); |
grid-cols-12 | grid-template-columns: repeat(12, minmax(0, 1fr)); |
grid-cols-[200px_1fr] | grid-template-columns: 200px 1fr; |
grid-cols-subgrid | grid-template-columns: subgrid; |
grid-rows-3 | grid-template-rows: repeat(3, minmax(0, 1fr)); |
col-span-2 | grid-column: span 2 / span 2; |
col-span-full | grid-column: 1 / -1; |
col-start-2 | grid-column-start: 2; |
row-span-2 | grid-row: span 2 / span 2; |
grid-flow-col | grid-auto-flow: column; |
grid-flow-dense | grid-auto-flow: dense; |
auto-rows-fr | grid-auto-rows: minmax(0, 1fr); |
auto-cols-max | grid-auto-columns: max-content; |
| 余白 | |
p-4 | padding: calc(var(--spacing) * 4); /* 1rem */ |
p-px | padding: 1px; |
p-[13px] | padding: 13px; |
p-(--card-pad) | padding: var(--card-pad); |
px-6 | padding-inline: calc(var(--spacing) * 6); |
py-2 | padding-block: calc(var(--spacing) * 2); |
pt-8 | padding-top: calc(var(--spacing) * 8); |
ps-4 | padding-inline-start: calc(var(--spacing) * 4); |
m-0 | margin: calc(var(--spacing) * 0); |
mx-auto | margin-inline: auto; |
mt-6 | margin-top: calc(var(--spacing) * 6); |
-mt-2 | margin-top: calc(var(--spacing) * -2); |
ms-auto | margin-inline-start: auto; |
space-y-4 | margin-block-end: calc(var(--spacing) * 4) on every child except the last (selector: > :not(:last-child)) |
space-x-2 | margin-inline-end: calc(var(--spacing) * 2) on every child except the last |
| サイズ | |
w-64 | width: calc(var(--spacing) * 64); /* 16rem */ |
w-full | width: 100%; |
w-1/2 | width: calc(1/2 * 100%); |
w-screen | width: 100vw; |
w-fit | width: fit-content; |
w-auto | width: auto; |
size-10 | width: calc(var(--spacing) * 10); height: calc(var(--spacing) * 10); |
h-12 | height: calc(var(--spacing) * 12); |
h-dvh | height: 100dvh; |
h-screen | height: 100vh; |
min-h-screen | min-height: 100vh; |
min-w-0 | min-width: calc(var(--spacing) * 0); |
max-w-md | max-width: var(--container-md); /* 28rem */ |
max-w-7xl | max-width: var(--container-7xl); /* 80rem */ |
max-w-prose | max-width: 65ch; |
max-w-screen-lg | max-width: var(--breakpoint-lg); |
| タイポグラフィ | |
text-xs | font-size: var(--text-xs); /* 0.75rem */ line-height: var(--tw-leading, var(--text-xs--line-height)); |
text-sm | font-size: var(--text-sm); /* 0.875rem */ line-height: var(--tw-leading, var(--text-sm--line-height)); |
text-base | font-size: var(--text-base); /* 1rem */ line-height: var(--tw-leading, var(--text-base--line-height)); |
text-xl | font-size: var(--text-xl); /* 1.25rem */ line-height: var(--tw-leading, var(--text-xl--line-height)); |
text-4xl | font-size: var(--text-4xl); /* 2.25rem */ line-height: var(--tw-leading, var(--text-4xl--line-height)); |
text-sm/6 | font-size: var(--text-sm); line-height: calc(var(--spacing) * 6); |
font-sans | font-family: var(--font-sans); |
font-mono | font-family: var(--font-mono); |
font-medium | font-weight: var(--font-weight-medium); /* 500 */ |
font-semibold | font-weight: var(--font-weight-semibold); /* 600 */ |
font-bold | font-weight: var(--font-weight-bold); /* 700 */ |
leading-tight | line-height: var(--leading-tight); /* 1.25 */ |
leading-6 | line-height: calc(var(--spacing) * 6); |
tracking-tight | letter-spacing: var(--tracking-tight); /* -0.025em */ |
tracking-wide | letter-spacing: var(--tracking-wide); |
text-left | text-align: left; |
text-center | text-align: center; |
text-right | text-align: right; |
uppercase | text-transform: uppercase; |
capitalize | text-transform: capitalize; |
italic | font-style: italic; |
underline | text-decoration-line: underline; |
no-underline | text-decoration-line: none; |
underline-offset-4 | text-underline-offset: 4px; |
decoration-2 | text-decoration-thickness: 2px; |
truncate | overflow: hidden; text-overflow: ellipsis; white-space: nowrap; |
line-clamp-3 | overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; |
text-balance | text-wrap: balance; |
text-pretty | text-wrap: pretty; |
whitespace-nowrap | white-space: nowrap; |
wrap-break-word | overflow-wrap: break-word; /* added in v4.1 */ |
tabular-nums | font-variant-numeric: tabular-nums; |
antialiased | -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; |
| 色と背景 | |
text-blue-600 | color: var(--color-blue-600); /* oklch(54.6% 0.245 262.881) */ |
bg-white | background-color: var(--color-white); /* #fff */ |
bg-slate-900 | background-color: var(--color-slate-900); |
bg-black/50 | background-color: color-mix(in oklab, var(--color-black) 50%, transparent); |
bg-[#4f98fb] | background-color: #4f98fb; |
bg-(--brand) | background-color: var(--brand); |
text-current | color: currentColor; |
bg-transparent | background-color: transparent; |
border-gray-200 | border-color: var(--color-gray-200); |
fill-current | fill: currentColor; |
accent-blue-600 | accent-color: var(--color-blue-600); |
caret-pink-500 | caret-color: var(--color-pink-500); |
bg-linear-to-r | background-image: linear-gradient(to right in oklab, var(--tw-gradient-stops)); /* simplified */ |
from-blue-500 | --tw-gradient-from: var(--color-blue-500); /* first stop */ |
to-violet-500 | --tw-gradient-to: var(--color-violet-500); |
bg-radial | background-image: radial-gradient(...stops); /* new in v4 */ |
bg-cover | background-size: cover; |
bg-center | background-position: center; |
bg-no-repeat | background-repeat: no-repeat; |
bg-clip-text | background-clip: text; |
| ボーダー、角丸、リング、アウトライン | |
border | border-style: var(--tw-border-style); border-width: 1px; /* color is currentColor in v4 */ |
border-2 | border-style: var(--tw-border-style); border-width: 2px; |
border-t | border-top-style: var(--tw-border-style); border-top-width: 1px; |
border-dashed | --tw-border-style: dashed; border-style: dashed; |
rounded-xs | border-radius: var(--radius-xs); /* 0.125rem */ |
rounded-sm | border-radius: var(--radius-sm); /* 0.25rem */ |
rounded-md | border-radius: var(--radius-md); /* 0.375rem */ |
rounded-lg | border-radius: var(--radius-lg); /* 0.5rem */ |
rounded-2xl | border-radius: var(--radius-2xl); /* 1rem */ |
rounded-full | border-radius: calc(infinity * 1px); |
rounded-t-lg | border-top-left-radius: var(--radius-lg); border-top-right-radius: var(--radius-lg); |
divide-y | border-bottom-width: 1px on every child except the last (selector: > :not(:last-child)) |
ring-1 | box-shadow: 0 0 0 1px currentColor; /* simplified; v4 default ring width is 1px */ |
ring-3 | box-shadow: 0 0 0 3px currentColor; /* the old v3 ring */ |
ring-blue-500 | --tw-ring-color: var(--color-blue-500); |
ring-offset-2 | --tw-ring-offset-width: 2px; |
outline | outline-style: var(--tw-outline-style); outline-width: 1px; |
outline-2 | outline-style: var(--tw-outline-style); outline-width: 2px; |
outline-offset-2 | outline-offset: 2px; |
outline-hidden | outline: 2px solid transparent; outline-offset: 2px; /* still visible in forced colors */ |
outline-none | --tw-outline-style: none; outline-style: none; |
| エフェクトとフィルター | |
shadow-2xs | box-shadow: 0 1px rgb(0 0 0 / 0.05); |
shadow-xs | box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); |
shadow-sm | box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1); |
shadow-md | box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1); |
shadow-lg | box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1); |
shadow-2xl | box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.25); |
shadow-none | box-shadow: 0 0 #0000; |
inset-shadow-sm | box-shadow: inset 0 2px 4px rgb(0 0 0 / 0.05); /* new in v4 */ |
opacity-50 | opacity: 50%; |
mix-blend-multiply | mix-blend-mode: multiply; |
blur-sm | filter: blur(var(--blur-sm)); /* 8px */ |
blur-xs | filter: blur(var(--blur-xs)); /* 4px */ |
backdrop-blur-md | backdrop-filter: blur(var(--blur-md)); /* 12px, frosted glass */ |
grayscale | filter: grayscale(100%); |
| トランジション、アニメーション、変形 | |
transition | transition-property: color, background-color, border-color, outline-color, opacity, box-shadow, transform, translate, scale, rotate, filter and more; transition-duration: 150ms; |
transition-colors | transition-property: color, background-color, border-color, outline-color, text-decoration-color, fill, stroke and gradient stops; 150ms |
duration-200 | transition-duration: 200ms; |
ease-out | transition-timing-function: var(--ease-out); /* cubic-bezier(0, 0, 0.2, 1) */ |
animate-spin | animation: var(--animate-spin); /* spin 1s linear infinite */ |
animate-pulse | animation: var(--animate-pulse); |
motion-reduce:animate-none | @media (prefers-reduced-motion: reduce) { animation: none; } |
scale-95 | --tw-scale-x: 95%; --tw-scale-y: 95%; scale: var(--tw-scale-x) var(--tw-scale-y); |
rotate-45 | rotate: 45deg; |
translate-x-4 | --tw-translate-x: calc(var(--spacing) * 4); translate: var(--tw-translate-x) var(--tw-translate-y); |
-translate-y-1/2 | --tw-translate-y: calc(calc(1/2 * 100%) * -1); translate: var(--tw-translate-x) var(--tw-translate-y); |
| インタラクション | |
cursor-pointer | cursor: pointer; /* v4 buttons default to cursor: default */ |
cursor-not-allowed | cursor: not-allowed; |
pointer-events-none | pointer-events: none; |
select-none | user-select: none; |
appearance-none | appearance: none; |
scroll-smooth | scroll-behavior: smooth; |
snap-x | scroll-snap-type: x var(--tw-scroll-snap-strictness); |
snap-start | scroll-snap-align: start; |
scroll-mt-20 | scroll-margin-top: calc(var(--spacing) * 20); |
resize-y | resize: vertical; |
touch-manipulation | touch-action: manipulation; |
| 状態とメディアのバリアント | |
hover:bg-blue-700 | @media (hover: hover) { &:hover { background-color: var(--color-blue-700); } } |
focus-visible:outline-2 | &:focus-visible { outline-width: 2px; ... } |
active:scale-95 | &:active { scale: 95%; } |
disabled:opacity-50 | &:disabled { opacity: 50%; } |
aria-disabled:opacity-50 | &[aria-disabled="true"] { opacity: 50%; } |
group-hover:underline | .group:hover & { text-decoration-line: underline; } (inside @media (hover: hover)) |
peer-checked:bg-blue-600 | .peer:checked ~ & { background-color: var(--color-blue-600); } |
md:flex | @media (width >= 48rem) { display: flex; } |
max-md:hidden | @media (width < 48rem) { display: none; } |
@md:flex-row | @container (width >= 28rem) { flex-direction: row; } |
dark:bg-slate-900 | @media (prefers-color-scheme: dark) { background-color: var(--color-slate-900); } |
print:hidden | @media print { display: none; } |
motion-safe:animate-spin | @media (prefers-reduced-motion: no-preference) { ... } |
*:p-2 | :where(& > *) { padding: calc(var(--spacing) * 2); } |
not-last:mb-2 | &:not(:last-child) { margin-bottom: ... } |
supports-[display:grid]:grid | @supports (display: grid) { display: grid; } |
bg-red-500! | background-color: var(--color-red-500) !important; |
表の読み方:初期値の--spacingは0.25remなので、calc(var(--spacing) * 4)は1remです。@themeでこの変数1つを変えれば、数値スケールを使うパディング、マージン、間隔、幅、高さがすべて一緒に変わります。生成されるCSSが長い場合(グラデーション、リング、トランジション)は、表では簡略版を示し、その旨を記載しています。
v4でユーティリティに値を与える方法は4つあり、どれを使っているかが分かれば、たいていの戸惑いは説明がつきます。
p-4、w-64、gap-3。設定なしで任意の整数が使え、p-2.5のような0.25刻みも使えます。値はcalc(var(--spacing) * n)になります。rounded-lg、shadow-md、text-xl、max-w-md。それぞれ--radius-lgや--container-mdのような変数を読み取ります。p-[13px]、grid-cols-[200px_1fr]、bg-[#4f98fb]。アンダースコアは空白の代わりです。bg-(--brand)はbg-[var(--brand)]のv4での短縮形です。v3ではbg-[--brand]と書いていました。w-1/2のような分数はcalc(1/2 * 100%)になり、bg-black/50のような不透明度の接尾辞は透明色とのcolor-mix()になるため、どの色形式でも機能します。
v4ではデザインシステムをCSSで設定します。@theme内で宣言した変数は、:root上のCSSカスタムプロパティになると同時に、ユーティリティクラスの元にもなります。変数の接頭辞によって、どのユーティリティに使われるかが決まります。
@import "tailwindcss";
@theme {
--font-display: "Satoshi", sans-serif; /* font-display */
--color-brand-500: oklch(65% 0.17 255); /* bg-brand-500, text-brand-500 ... */
--breakpoint-3xl: 120rem; /* 3xl: variant */
--spacing: 0.25rem; /* p-4 = 1rem */
--radius-card: 0.875rem; /* rounded-card */
}
| 名前空間 | 使われる先 | 例 |
|---|---|---|
--color-* | すべての色ユーティリティ(bg、text、border、fill、ring、影の色など) | bg-red-500 |
--spacing | パディング、マージン、間隔、幅、高さ、inset、translate | px-4 |
--font-* | フォントファミリー | font-sans |
--text-* | フォントサイズ(任意で--text-*--line-heightも) | text-xl |
--font-weight-* | フォントの太さ | font-bold |
--tracking-* / --leading-* | 字間/行の高さ | tracking-wide |
--breakpoint-* | レスポンシブのバリアント | sm:* |
--container-* | コンテナクエリのバリアントとmax-w-* | @sm:*, max-w-md |
--radius-* | 角丸 | rounded-sm |
--shadow-*, --inset-shadow-*, --drop-shadow-* | 影 | shadow-md |
--blur-* | ぼかしと背景のぼかし | blur-md |
--ease-* / --animate-* | タイミング関数/アニメーション | ease-out, animate-spin |
--perspective-* / --aspect-* | 3Dの遠近感/アスペクト比 | perspective-near, aspect-video |
既定の名前空間を丸ごと外すには、まず--color-*: initial;のようにinitialを設定し、そのあと自分の色だけを宣言します。JavaScriptの設定がまだある場合、v4は@config "./tailwind.config.js";で読み込めますが、corePlugins、safelist、separatorの各オプションはサポートされません。
ブレークポイントはモバイルファーストです。接頭辞のないクラスはすべての幅に適用され、md:flexは48rem以上で適用されます。v4は範囲構文width >= ...で出力します。
| 接頭辞 | 最小幅 | CSS | それ未満(max-*) |
|---|---|---|---|
sm: | 40rem (640px) | @media (width >= 40rem) | max-sm: = @media (width < 40rem) |
md: | 48rem (768px) | @media (width >= 48rem) | max-md: |
lg: | 64rem (1024px) | @media (width >= 64rem) | max-lg: |
xl: | 80rem (1280px) | @media (width >= 80rem) | max-xl: |
2xl: | 96rem (1536px) | @media (width >= 96rem) | max-2xl: |
重ねると範囲を指定できます。md:max-xl:flexは48rem以上80rem未満でのみ適用されます。一度きりのブレークポイントにはmin-[900px]:gridやmax-[600px]:hiddenを使います。ブレークポイントの追加や変更は@theme内の--breakpoint-*で行い、正しく並ぶようすべてremで統一しましょう。
コンテナクエリはv4に組み込まれています(v3ではプラグインが必要でした)。親要素に@containerを付け、子要素を@sm:、@md:などでスタイル指定します。ウィンドウではなく親要素の幅に反応するため、サイドバーにも広いメイン列にも置くカードにぴったりです。
<div class="@container">
<article class="flex flex-col @md:flex-row gap-4">
<img class="w-full @md:w-48 rounded-lg" src="..." alt="">
<div>...</div>
</article>
</div>
| バリアント | コンテナ幅 | バリアント | コンテナ幅 |
|---|---|---|---|
@3xs | 16rem (256px) | @2xl | 42rem (672px) |
@2xs | 18rem (288px) | @3xl | 48rem (768px) |
@xs | 20rem (320px) | @4xl | 56rem (896px) |
@sm | 24rem (384px) | @5xl | 64rem (1024px) |
@md | 28rem (448px) | @6xl | 72rem (1152px) |
@lg | 32rem (512px) | @7xl | 80rem (1280px) |
@xl | 36rem (576px) |
それぞれ@container (width >= ...)にコンパイルされます。「それ未満」には@max-md:を使い、範囲には@sm:@max-md:のように重ね、@container/sidebarでコンテナに名前を付けて@md/sidebar:で指定し、@min-[475px]:のような任意のサイズも使えます。コンテナのサイズはブレークポイントと同じ数値ではない点に注意してください。@mdは28remですが、md:は48remです。
下でレイアウトを選ぶと、ボックスが動きます。クリックに合わせてクラス文字列が更新されるので、そのままマークアップにコピーできます。
最もよく使うパターン:
flex items-center justify-between:ナビバーの行flex items-center justify-center(またはgrid place-items-center):1つの要素を中央に配置col-span-2と組み合わせたgrid grid-cols-3 gap-2shrink-0、残りを埋める要素にflex-1| 目的 | クラス |
|---|---|
| ブレークポイントなしのレスポンシブなカードグリッド | grid grid-cols-[repeat(auto-fill,minmax(16rem,1fr))] gap-6 |
| サイドバーとコンテンツ | grid md:grid-cols-[16rem_1fr] gap-8 |
| 短いページで下端に固定するフッター | ラッパーにflex min-h-dvh flex-col、mainにflex-1 |
| flexの行の中で省略表示されるテキスト | flexの子要素にmin-w-0、テキストにtruncate |
| モバイルでは縦積み、デスクトップでは横並び | flex flex-col md:flex-row gap-4 |
| 最後の要素を右端に寄せる | その要素にms-auto(またはml-auto) |
v4は既定のパレットをOKLCHで定義しており、広色域の画面ではより鮮やかな色を表示できます。下の各色見本は、Tailwind自身のテーマファイルにある正確な値で塗られています。クリックすると、そのoklch()値をコピーできます。濃淡は50から950まであります。*印の付いたパレット(mauve、olive、mist、taupe)はv4.2.0で追加されたため、それより前のv4リリースにはありません。黒と白は#000と#fffです。
bg-sky-500、text-sky-500/80のように使うか、自分のCSSではvar(--color-sky-500)として使います。組み合わせが読みやすいか確かめるにはカラーコントラストチェッカーを、同じ形式で独自のスケールを作るにはTailwindカラーパレットジェネレーターをお試しください。
初期設定では、dark:は@media (prefers-color-scheme: dark)を通じてOSの設定に従います。代わりにクラスや属性で切り替えたい場合(手動トグルなど)は、CSSで@custom-variantを使ってバリアントを上書きします。darkModeという設定キーはもうありません。
/* Class strategy: <html class="dark"> */
@custom-variant dark (&:where(.dark, .dark *));
/* Or a data attribute: <html data-theme="dark"> */
@custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *));
<div class="bg-white text-slate-900 dark:bg-slate-900 dark:text-slate-100">...</div>
手動トグルの場合は、ページが描画される前にクラスを設定します(<head>内に、保存された選択を読み取る小さなインラインスクリプトを置きます)。こうすれば、訪問者に違うテーマが一瞬表示されることはありません。3つ目の方法はdark:クラスをまったく使わないことです。@themeで--color-surfaceのような意味的なトークンを定義し、.darkの下で値を入れ替えれば、bg-surfaceのような1つのクラスが両方のテーマで機能します。
以下は公式のアップグレードガイドに基づいています。古い名前もまだ存在し、何も警告せずに異なる(小さい)結果を出すため、名称変更が特に重要です。
| v3 | v4 | 理由 |
|---|---|---|
shadow-sm | shadow-xs | すべてのサイズに名前が付くよう、スケールが1段階下にずれた |
shadow | shadow-sm | 同じずれ |
drop-shadow-sm / drop-shadow | drop-shadow-xs / drop-shadow-sm | 同じずれ |
blur-sm / blur | blur-xs / blur-sm | 同じずれ(backdrop-blur-*も) |
rounded-sm | rounded-xs | 同じずれ |
rounded | rounded-sm | 同じずれ |
outline-none | outline-hidden | v4のoutline-noneは本当にoutline-style: noneを設定するようになった |
ring(3px、blue-500) | ring-3と色を指定 | 単独のringはcurrentColorの1pxになった |
outline outline-2 | outline-2 | 幅のユーティリティ自体がsolidスタイルを設定するようになった |
bg-opacity-50(text-、border-、ring-、divide-、placeholder-opacityも) | bg-black/50 | 削除。スラッシュ修飾子を使う |
flex-shrink-0 / flex-grow | shrink-0 / grow | エイリアスを削除 |
overflow-ellipsis | text-ellipsis | エイリアスを削除 |
decoration-slice / decoration-clone | box-decoration-slice / box-decoration-clone | エイリアスを削除 |
bg-[--brand] | bg-(--brand) | CSS変数の新しい短縮形 |
!bg-red-500 | bg-red-500! | 重要度指定は末尾に付ける(旧形式は非推奨) |
first:*:pt-0 | *:first:pt-0 | 重ねたバリアントは左から右へ読むようになった |
tw-flex(接頭辞) | tw:flex | 接頭辞はバリアントのような形になり、先頭に付く |
名前は変わらず挙動だけが変わったもので、アップグレード時につまずきやすい点:
currentColorに変わったため、単独のborderは濃く見えます。border-gray-200のように色を追加してください。hover:は@media (hover: hover)で囲まれるため、タップしてもホバースタイルが残らなくなりました。cursor: defaultを設定するようになりました。指のカーソルにしたい場合はcursor-pointerを追加します。> :not(:last-child)に変わり、マージンが末尾側に移りました。間隔がおかしい場合は、flexかgridとgapに切り替えましょう。centerとpaddingのオプションはなくなりました。@utility container { margin-inline: auto; padding-inline: 2rem; }で拡張します。bg-linear-to-rになり、bg-radialとbg-conicが加わりました。公式のnpx @tailwindcss/upgradeツールが、ほとんどの名称変更を自動で処理します。きれいなブランチで実行して差分を確認しましょう。どのshadowクラスを同じ見た目のままにしたかったのかは、ツールには分からないためです。
このページには印刷用スタイルがあります。検索ボックスとボタンは非表示になり、表は小さい文字に縮み、カラーグリッドは色見本をまとめて保ちます。多くのブラウザーでは、印刷ダイアログで「背景のグラフィック」をオンにしないと色見本が空白で印刷されます。先に表を絞り込むと表示中の行だけが印刷されるので、自分が使うユーティリティだけの1枚のシートをすばやく作れます。
同じprint:バリアントは自分のプロジェクトでも使えます。ナビゲーションにprint:hidden、薄い文字にprint:text-black、カードにprint:break-inside-avoidを付ければ、印刷したページが読みやすくなります。
v4はCSSで設定します。@import "tailwindcss"でTailwindを読み込み、--color-brand-500や--breakpoint-3xlのようなデザイントークンを@themeブロック内で宣言します。JavaScriptの設定も@configディレクティブで読み込めますが、corePlugins、safelist、separatorの各オプションはサポートされません。
smは40rem(640px)、mdは48rem(768px)、lgは64rem(1024px)、xlは80rem(1280px)、2xlは96rem(1536px)です。モバイルファーストなので、md:flexは48rem以上で適用されます。ブレークポイント未満のスタイルにはmax-md:を使い、範囲を指定するにはmd:max-xl:のように重ねます。
影、角丸、ぼかしのスケールが1段階下にずれたためです。v3のshadow-smはv4のshadow-xs、v3のshadowはv4のshadow-sm、v3のrounded-smはv4のrounded-xs、v3のroundedはv4のrounded-smに当たります。古い名前もコンパイルできるのでエラーにはならず、1段階小さいサイズが出力されるだけです。
CSSに@custom-variant dark (&:where(.dark, .dark *));を追加します。すると、祖先要素にdarkクラスがあるときにdark:ユーティリティが適用されます。data属性を使いたい場合は、セレクターに[data-theme=dark]を使います。
いいえ。コンテナクエリは組み込まれています。親要素に@containerを付け、子要素に@sm:、@md:、@max-md:などのバリアントを使います。コンテナのサイズは@3xs(16rem)から始まり、ページのブレークポイントとは異なります。たとえば@mdは28remです。
padding: calc(var(--spacing) * 4)です。初期値の--spacingが0.25remなので1rem(既定のフォントサイズで16px)になります。余白スケールでは設定なしで任意の整数が使え、--spacingを変えればすべてが一度に拡縮されます。
表示
アイテムの配置
方向
折り返し
主軸
列数
交差軸
間隔
コピーしました
クラスをコピー
このチートシートを印刷
無料で始める · クレジットカード不要