【コピペOK】CSSだけで作るトグルスイッチ8選|ON/OFFの切り替えボタンのデザイン

Web制作 — 2026.11.21

← 読み物の一覧に戻る

はじめに

  • 設定画面にiPhoneのようなON/OFFのスイッチを置きたい
  • チェックボックスのままだと見た目が古い
  • JavaScriptを使わずに、CSSだけで作りたい

そんなときに使える、トグルスイッチ(切り替えボタン)のデザインを8つまとめました。

どれもHTMLとCSSだけで動きます。 下のデモは実際に押して試せます。 コードはそのままコピーして使ってください。

トグルスイッチの仕組み

中身は普通のチェックボックスです。

  1. <input type="checkbox"> を見えなくする(消さずに透明にする)
  2. その隣の <span> でスイッチの見た目を作る
  3. :checked + span で、ONのときだけ色とつまみの位置を変える

<label> で全体を囲んでいるので、スイッチのどこを押しても切り替わります。 display: none で消すとキーボードで操作できなくなるので、opacity: 0 で透明にしています。

role="switch" を付けると、読み上げソフトが「スイッチ、オン」のように読みます。

PR・RYX のアプリ。RYX Wishlist(お気に入り・ほしい物リスト)。気になる商品をハートで保存できます。ゲストも保存・登録者数を表示・ノーコード。7日間の無料体験。App Store で見る

1. iPhone風のシンプルなトグルスイッチ

いちばんよく使う形です。丸いつまみが左右に動き、ONで緑になります。

特徴

  • どんなサイトにも合わせやすい
  • 色を1か所変えるだけでブランドの色にできる
  • 設定画面・通知のON/OFFに

HTML

<label class="switch">
  <input type="checkbox" role="switch" checked>
  <span class="switch-track"></span>
  <span class="switch-label">通知を受け取る</span>
</label>

CSS

.switch {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.switch-track {
  position: relative;
  width: 52px;
  height: 30px;
  border-radius: 999px;
  background: #d1d1d6;
  transition: background 0.25s;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  transition: transform 0.25s;
}
.switch input:checked + .switch-track {
  background: #34c759;
}
.switch input:checked + .switch-track::after {
  transform: translateX(22px);
}
.switch input:focus-visible + .switch-track {
  outline: 2px solid #007aff;
  outline-offset: 2px;
}

2. 四角いトグルスイッチ

角を小さくした形です。かっちりした管理画面や業務システムに合います。

特徴

  • 角丸を2px〜4pxにするだけ
  • 直線的なデザインのサイトになじむ
  • つまみも四角にそろえる

HTML

<label class="switch-square">
  <input type="checkbox" role="switch">
  <span class="switch-square-track"></span>
  <span>自動保存</span>
</label>

CSS

.switch-square {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}
.switch-square input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.switch-square-track {
  position: relative;
  width: 56px;
  height: 28px;
  border-radius: 4px;
  background: #c8c8c8;
  transition: background 0.2s;
}
.switch-square-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 2px;
  background: #fff;
  transition: transform 0.2s;
}
.switch-square input:checked + .switch-square-track {
  background: #111;
}
.switch-square input:checked + .switch-square-track::after {
  transform: translateX(28px);
}
.switch-square input:focus-visible + .switch-square-track {
  outline: 2px solid #008060;
  outline-offset: 2px;
}

3. ON/OFFの文字が入ったトグルスイッチ

スイッチの中に「ON」「OFF」を出します。色だけで状態を伝えないので、色の見分けが苦手な人にも分かります。

特徴

  • 状態が文字で分かる
  • 文字は疑似要素で出すのでHTMLは増えない
  • 幅は文字の長さに合わせて調整する

HTML

<label class="switch-text">
  <input type="checkbox" role="switch" checked>
  <span class="switch-text-track"></span>
</label>

CSS

.switch-text {
  display: inline-block;
  cursor: pointer;
}
.switch-text input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.switch-text-track {
  position: relative;
  display: block;
  width: 72px;
  height: 32px;
  border-radius: 999px;
  background: #bbb;
  transition: background 0.25s;
}
.switch-text-track::before {
  content: "OFF";
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}
.switch-text-track::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.25s;
}
.switch-text input:checked + .switch-text-track {
  background: #008060;
}
.switch-text input:checked + .switch-text-track::before {
  content: "ON";
  right: auto;
  left: 12px;
}
.switch-text input:checked + .switch-text-track::after {
  transform: translateX(40px);
}
.switch-text input:focus-visible + .switch-text-track {
  outline: 2px solid #111;
  outline-offset: 2px;
}

4. ダークモード切り替えのトグルスイッチ(太陽と月)

つまみの中に太陽と月の絵文字を出します。ダークモードの切り替えによく使われる形です。

特徴

  • 絵文字なので画像を用意しなくていい
  • ONで背景を夜の色に変える
  • 下の「JavaScriptで状態を取る」と組み合わせるとサイトの色を切り替えられる

HTML

<label class="switch-theme">
  <input type="checkbox" role="switch" aria-label="ダークモード">
  <span class="switch-theme-track"></span>
</label>

CSS

.switch-theme {
  display: inline-block;
  cursor: pointer;
}
.switch-theme input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.switch-theme-track {
  position: relative;
  display: block;
  width: 64px;
  height: 34px;
  border-radius: 999px;
  background: #8ecbf5;
  transition: background 0.3s;
}
.switch-theme-track::after {
  content: "☀️";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #fff;
  display: grid;
  place-items: center;
  font-size: 16px;
  transition: transform 0.3s;
}
.switch-theme input:checked + .switch-theme-track {
  background: #2c2f4a;
}
.switch-theme input:checked + .switch-theme-track::after {
  content: "🌙";
  background: #44476a;
  transform: translateX(30px);
}
.switch-theme input:focus-visible + .switch-theme-track {
  outline: 2px solid #111;
  outline-offset: 2px;
}

5. 線だけのトグルスイッチ

塗りを使わず、線だけで作ります。白い背景が多い、すっきりしたサイトに合います。

特徴

  • ONでつまみと線の色が変わる
  • 背景の色を選ばない
  • 線の太さは border の数字で変える

HTML

<label class="switch-line">
  <input type="checkbox" role="switch" checked>
  <span class="switch-line-track"></span>
  <span>メールマガジン</span>
</label>

CSS

.switch-line {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}
.switch-line input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.switch-line-track {
  position: relative;
  width: 52px;
  height: 28px;
  border: 2px solid #999;
  border-radius: 999px;
  box-sizing: border-box;
  transition: border-color 0.2s;
}
.switch-line-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #999;
  transition: transform 0.2s, background 0.2s;
}
.switch-line input:checked + .switch-line-track {
  border-color: #008060;
}
.switch-line input:checked + .switch-line-track::after {
  background: #008060;
  transform: translateX(24px);
}
.switch-line input:focus-visible + .switch-line-track {
  outline: 2px solid #111;
  outline-offset: 2px;
}

6. つまみがはみ出るトグルスイッチ(マテリアル風)

細い線の上を、大きめのつまみが動く形です。Androidのアプリでよく見ます。

特徴

  • 線を細く、つまみを大きくするだけ
  • つまみに影を付けて浮いて見せる
  • スマホでも押しやすい大きさ

HTML

<label class="switch-material">
  <input type="checkbox" role="switch">
  <span class="switch-material-track"></span>
  <span>位置情報</span>
</label>

CSS

.switch-material {
  display: inline-flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
}
.switch-material input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.switch-material-track {
  position: relative;
  width: 40px;
  height: 16px;
  border-radius: 999px;
  background: #bdbdbd;
  transition: background 0.2s;
}
.switch-material-track::after {
  content: "";
  position: absolute;
  top: 50%;
  left: -2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fafafa;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  transform: translateY(-50%);
  transition: transform 0.2s, background 0.2s;
}
.switch-material input:checked + .switch-material-track {
  background: #9fc9f5;
}
.switch-material input:checked + .switch-material-track::after {
  background: #1976d2;
  transform: translate(20px, -50%);
}
.switch-material input:focus-visible + .switch-material-track {
  outline: 2px solid #111;
  outline-offset: 6px;
}

7. 2つから選ぶ切り替えスイッチ(月払い・年払い)

料金表でよく見る「月払い/年払い」の切り替えです。中身はチェックボックス1つで、選んでいる側の文字が白くなります。

特徴

  • 2択ならチェックボックス1つで作れる
  • 料金表・表示の切り替えに
  • 選んでいる側が分かるよう背景を動かす

HTML

<label class="switch-segment">
  <input type="checkbox" role="switch" aria-label="年払いにする">
  <span class="switch-segment-track">
    <span>月払い</span>
    <span>年払い</span>
  </span>
</label>

CSS

.switch-segment {
  display: inline-block;
  cursor: pointer;
}
.switch-segment input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.switch-segment-track {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 200px;
  padding: 4px;
  border-radius: 999px;
  background: #e5e5e5;
  font-size: 14px;
  font-weight: 700;
}
.switch-segment-track::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: calc(50% - 4px);
  height: calc(100% - 8px);
  border-radius: 999px;
  background: #111;
  transition: transform 0.25s;
}
.switch-segment-track span {
  position: relative;
  padding: 8px 0;
  text-align: center;
  transition: color 0.25s;
}
.switch-segment-track span:first-child {
  color: #fff;
}
.switch-segment input:checked + .switch-segment-track::before {
  transform: translateX(100%);
}
.switch-segment input:checked + .switch-segment-track span:first-child {
  color: #111;
}
.switch-segment input:checked + .switch-segment-track span:last-child {
  color: #fff;
}
.switch-segment input:focus-visible + .switch-segment-track {
  outline: 2px solid #008060;
  outline-offset: 2px;
}

8. 立体的なトグルスイッチ

内側の影でへこんだ溝を、外側の影でふくらんだつまみを作ります。押した感じが出る形です。

特徴

  • box-shadow の inset で溝を作る
  • つまみにグラデーションで丸みを出す
  • ONの色は溝の中だけ変える

HTML

<label class="switch-3d">
  <input type="checkbox" role="switch" checked>
  <span class="switch-3d-track"></span>
</label>

CSS

.switch-3d {
  display: inline-block;
  cursor: pointer;
}
.switch-3d input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.switch-3d-track {
  position: relative;
  display: block;
  width: 64px;
  height: 32px;
  border-radius: 999px;
  background: #ddd;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.35);
  transition: background 0.25s;
}
.switch-3d-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(#fff, #e6e6e6);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
  transition: transform 0.25s;
}
.switch-3d input:checked + .switch-3d-track {
  background: #f5a623;
}
.switch-3d input:checked + .switch-3d-track::after {
  transform: translateX(32px);
}
.switch-3d input:focus-visible + .switch-3d-track {
  outline: 2px solid #111;
  outline-offset: 2px;
}

JavaScriptでONとOFFを受け取る

見た目はCSSだけで切り替わりますが、「ONになったら何かする」ときはJavaScriptで change を受け取ります。 状態は checked(ONなら true)で分かります。

下のデモは、スイッチをONにするとページが暗くなります。

HTML

<label class="switch">
  <input type="checkbox" role="switch" id="dark-mode">
  <span class="switch-track"></span>
  <span class="switch-label">ダークモード</span>
</label>
<p id="status">いまは OFF です</p>

JavaScript

const toggle = document.getElementById("dark-mode");
const status = document.getElementById("status");

toggle.addEventListener("change", () => {
  status.textContent = toggle.checked ? "いまは ON です" : "いまは OFF です";
  document.body.classList.toggle("is-dark", toggle.checked);
});

CSSは1つめのスイッチと同じものに、暗いときの色を足しています。

.is-dark { background: #1c1c1e; color: #f2f2f2; }
#status { width: 100%; text-align: center; margin: 0; }

フォームの中に置けば、ONのときだけ name の値が送られます。 送る値を決めたいときは <input type="checkbox" name="notify" value="on"> のように書きます。

うまく動かないとき

押しても切り替わらない

<input> と <span> の順番を見てください。 input:checked + .switch-track は「inputのすぐ後ろのspan」を指すので、間に別の要素があると効きません。

<label> で囲まずに作るときは、<label for="id"> と <input id="id"> の id をそろえます。

キーボードで操作できない

display: none や visibility: hidden で input を消すと、Tabキーで選べなくなります。 この記事のコードのように opacity: 0 と小さな幅で隠してください。 Tabで選んだときに枠が出るよう、:focus-visible の枠も残しています。

動きを止めたい人への配慮

OSの設定で「視差効果を減らす」をONにしている人には、動きを止めるのが親切です。

@media (prefers-reduced-motion: reduce) {
  .switch-track,
  .switch-track::after {
    transition: none;
  }
}

チェックボックスとトグルスイッチの使い分け

チェックボックス トグルスイッチ
向いている場面 送信ボタンを押してから決まるもの 押した瞬間に切り替わるもの
例 利用規約への同意・複数の項目から選ぶ 通知のON/OFF・ダークモード・自動保存
選べる数 いくつでも 1つのことのON/OFF

「保存」ボタンを押すまで反映されないフォームなら、チェックボックスのほうが伝わります。 チェックボックスのデザインはCSSだけで作るおしゃれなチェックボックス8選にまとめています。

さいごに

トグルスイッチは、チェックボックスに見た目をかぶせているだけです。 色・大きさ・角丸の数字を変えれば、サイトに合わせたスイッチになります。

ほかにも、コピペで使えるパーツをまとめています。

シェアXFacebookLINEはてブ

このパーツ、自分のサイトに入れたい方へ

記事のようなメニュー・アニメーション・UIを、お使いのサイト(WordPress・Shopify・STUDIO など)に組み込む作業を1パーツから引き受けます。制作会社さまのコーディングの外注も歓迎です。

Shopifyでストアを作りたい方は依頼から公開までの流れと費用相場もどうぞ。

1パーツから / 費用は作業の前にお見積り / 通常24時間以内に返信