# カスタムチェックボックスのCSS実装

> appearance: noneでブラウザ標準の見た目を外し、input要素自体をデザインするチェックボックス。キーボード操作もラベル連動もそのまま生きます。

- カテゴリ: フォーム
- URL: https://www.css-dictionary.com/recipes/custom-checkbox/

## HTML

```html
<fieldset class="prefs">
  <legend>通知の設定</legend>
  <label class="check">
    <input type="checkbox" checked />
    メールで受け取る
  </label>
  <label class="check">
    <input type="checkbox" />
    プッシュ通知で受け取る
  </label>
</fieldset>
```

## CSS

```css
.prefs {
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 1px solid #e2d8c2;
  border-radius: 8px;
  width: fit-content;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.check input {
  appearance: none; /* 標準の見た目を外してinput自体を装飾する */
  margin: 0;
  width: 18px;
  height: 18px;
  border: 2px solid #cbbfa5;
  border-radius: 4px;
  background: #fff;
  display: inline-grid;
  place-content: center;
  transition: background-color 0.15s, border-color 0.15s;
}

.check input::before {
  content: "";
  width: 10px;
  height: 10px;
  background: #fff;
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
  transform: scale(0);
  transition: transform 0.15s;
}

.check input:checked {
  background-color: #b0413e;
  border-color: #b0413e;
}

.check input:checked::before {
  transform: scale(1);
}

.check input:focus-visible {
  outline: 2px solid #b0413e;
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .check input, .check input::before { transition: none; }
}
```

## 仕組みの解説

昔の定番だった「inputを隠してspanを装飾」ではなく、appearance: none でinput要素自体を直接デザインします。要素を差し替えないので、クリック・スペースキー・label連動・:checked などの標準動作がすべてそのまま使えます。チェックマークは ::before の clip-path で描き、:checked で scale(0)→scale(1) に切り替えて表示します。

## 実装のポイント

色を変えたいだけなら accent-color: #b0413e; の1行で済みます。形まで変えたいときにこのレシピを使ってください。

## AIに依頼するときの文例

appearance: noneを使ったカスタムチェックボックスを作ってください。inputを隠すのではなくinput自体を装飾し、チェックマークは::beforeとclip-pathで描画、:checkedで表示、focus-visibleのリングも付けてください。

## 使っているプロパティ

- [appearance](https://www.css-dictionary.com/property/appearance.md)
- [place-content](https://www.css-dictionary.com/property/place-content.md)
- [border-radius](https://www.css-dictionary.com/property/border-radius.md)
- [transition](https://www.css-dictionary.com/property/transition.md)
- [pseudo-focus-visible](https://www.css-dictionary.com/property/pseudo-focus-visible.md)

