🔰はじめての方へ

【保存版】Tailwind CSS チートシート|文字サイズ・余白・Flex・Grid・レスポンシブ対応まとめ

CSS
記事内に広告が含まれています。
スポンサーリンク

Tailwind CSSを使うたびに、

  • text-xlって何pxだっけ?
  • px-4って左右16pxだっけ?
  • justify-betweenとitems-centerが毎回ごっちゃになる……

そういうことで、よく表記方法を検索しているのですが、自分で作ってみようと思ってこの記事を書きました。

必要最低限のものだけを厳選しているので、実務や学習中の確認用として使ってください!

このチートシートでまとめている内容

  • Font Size(文字サイズ)
  • Font Weight(文字の太さ)
  • Spacing(余白)
  • Padding(内側の余白)
  • Margin(外側の余白)
  • Flexbox
  • justify / items(配置)
  • Gap(要素間の余白)
  • Width & Height(幅・高さ)
  • Display(表示方法)
  • Position(位置指定)
  • Border & Rounded(枠線・角丸)
  • Text(文字装飾)
  • Background(背景色)
  • Shadow & Opacity(影・透明度)
  • レスポンシブ(ブレークポイント)

目次から探したい項目をクリックしてください!


Tailwind CSSとは?

Tailwind CSSは、HTMLに直接クラスを書いてデザインを作るユーティリティファーストCSSフレームワークです。

<button class="bg-blue-500 text-white px-4 py-2 rounded-lg">
  ボタン
</button>

CSSファイルを書かなくても、クラスを組み合わせるだけで画面を作れるのが特徴です。


Font Size(文字サイズ)

クラスCSS
text-xsfont-size: 0.75rem  (12px)
text-smfont-size: 0.875rem  (14px)
text-basefont-size: 1rem  (16px)
text-lgfont-size: 1.125rem  (18px)
text-xlfont-size: 1.25rem  (20px)
text-2xlfont-size: 1.5rem  (24px)
text-3xlfont-size: 1.875rem  (30px)
text-4xlfont-size: 2.25rem  (36px)
text-5xlfont-size: 3rem  (48px)

よく使うサイズ感

  • text-sm:補足説明
  • text-base:本文
  • text-lg:小見出し
  • text-2xl:見出し
  • text-4xl:ヒーローエリア

Font Weight(文字の太さ)

クラスCSS
font-thinfont-weight: 100
font-lightfont-weight: 300
font-normalfont-weight: 400
font-mediumfont-weight: 500
font-semiboldfont-weight: 600
font-boldfont-weight: 700

実務でよく使うもの

font-normal
font-medium
font-semibold
font-bold

🌟 Spacing(余白)

Tailwindでは、Padding・Margin・Width・Heightなどで同じ数値体系を使います

数値CSS
00px
0.50.125rem (2px)
10.25rem (4px)
1.50.375rem (6px)
20.5rem (8px)
2.50.625rem (10px)
30.75rem (12px)
41rem (16px)
51.25rem (20px)
61.5rem (24px)
82rem (32px)
102.5rem (40px)
123rem (48px)
164rem (64px)
205rem (80px)
246rem (96px)

Padding(内側の余白)

クラス方向
p-4全方向
px-4左右
py-4上下
pt-4
pb-4
pl-4
pr-4

<div class="px-4 py-2">

左右16px、上下8pxになります。


Margin(外側の余白)

クラス方向
m-4全方向
mx-4左右
my-4上下
mt-4
mb-4
ml-4
mr-4
mx-auto中央寄せ
-mt-4マイナスマージン

よく使う例

class="mx-auto max-w-4xl"

コンテンツ中央寄せの定番です。


Flexbox

基本

クラスCSS
flexdisplay: flex
inline-flexdisplay: inline-flex
flex-row横並び
flex-col縦並び
flex-wrap折り返し
flex-nowrap折り返さない
flex-1残り領域を埋める
flex-auto自動伸縮
flex-none固定
grow拡大する
grow-0拡大しない
shrink縮小する
shrink-0縮小しない

justify / items

覚え方
  • justify-* → 横方向
  • items-* → 縦方向
クラス説明
justify-start左寄せ
justify-center中央
justify-end右寄せ
justify-between両端配置
justify-around均等配置
items-start上揃え
items-center中央揃え
items-end下揃え
items-baselineベースライン
items-stretch伸ばす

Gap(要素間の余白)

クラスCSS
gap-14px
gap-28px
gap-416px
gap-x-4横16px
gap-y-4縦16px

Width & Height

クラスCSS
w-full100%
w-screen100vw
w-autoauto
w-1/250%
w-1/333.333%
w-2/366.667%
w-1/425%
h-full100%
h-screen100vh
h-autoauto
min-h-screen最小高さ100vh

数値も使える

w-4  → width: 1rem
h-10 → height: 2.5rem

Spacingと同じルールです


Display

クラスCSS
blockblock
inline-blockinline-block
inlineinline
hiddennone
gridgrid

Position

クラスCSS
relativerelative
absoluteabsolute
fixedfixed
stickysticky
top-0top: 0
right-0right: 0
bottom-0bottom: 0
left-0left: 0
inset-0四方向0

Border & Rounded

クラスCSS
border1px
border-22px
border-t上だけ
rounded4px
rounded-md6px
rounded-lg8px
rounded-xl12px
rounded-full円形

Text

クラスCSS
text-left左寄せ
text-center中央
text-right右寄せ
text-white
text-black
text-gray-500グレー
text-red-500
underline下線
line-through打ち消し線
truncate1行省略
whitespace-nowrap改行禁止
leading-tight行間狭め
leading-normal標準

Background

クラスCSS
bg-white
bg-black
bg-gray-100薄いグレー
bg-transparent透明

Shadow & Opacity

クラスCSS
shadow
shadow-md
shadow-lg
shadow-noneなし
opacity-5050%
opacity-0非表示
opacity-100100%

レスポンシブ(ブレークポイント)

プレフィックス最小幅
sm:640px以上
md:768px以上
lg:1024px以上
xl:1280px以上
2xl:1536px以上

使用例

class="text-base sm:text-lg md:text-xl"
  • スマホ:16px
  • 640px以上:18px
  • 768px以上:20px

よく使う組み合わせ

<!-- 中央寄せ -->
<div class="flex items-center justify-center">

<!-- 横並び -->
<div class="flex items-center gap-2">

<!-- 左右に分ける -->
<div class="flex items-center justify-between">

<!-- 縦並び -->
<div class="flex flex-col gap-4">

<!-- カード -->
<div class="rounded-lg shadow-md p-4 bg-white">

<!-- テキスト省略 -->
<p class="truncate w-full">

<!-- レスポンシブ2カラム -->
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">

任意の値(Arbitrary Values)

用意されていない値を使いたい場合は [] を使います。

<div class="text-[1.2rem]">
<div class="p-[0.2em]">
<div class="mt-[10px]">
<div class="w-[200px]">
<div class="text-[#ff6600]">

覚え方

「Tailwindにないなら [] で書く」

これだけ覚えておけば困ることは少ないです。


個人的によく使うベスト10

flex
items-center
justify-between
gap-4
p-4
rounded-lg
shadow-md
w-full
text-gray-500
md:grid-cols-2

私みたいなやつは、正直CSSの方が書きやすいと思いますが、これを使えるようになるとファイルが減るので便利だなと思いました。

みなさんもぜひ活用してみてください!