Live Demo
ホバーで強調されます。クリックで選択状態が切り替わります。
Source Code
必要なコードをコピーして実装に利用できます。
HTML
<fieldset class="tbx-1038"><legend>表示するジャンル</legend><label><input type="checkbox" checked><span>Web</span></label><label><input type="checkbox"><span>Brand</span></label><label><input type="checkbox"><span>UI</span></label><label><input type="checkbox"><span>Motion</span></label></fieldset>
CSS
.tbx-1038{display:flex;justify-content:center;align-items:center;flex-wrap:wrap;gap:7px;border:0;padding:0;margin:0;font:600 12px/1.3 system-ui}
.tbx-1038 legend{width:100%;text-align:center;color:#6a7888;font-size:10px;font-weight:600;margin-bottom:11px}
.tbx-1038 label{cursor:pointer;position:relative}.tbx-1038 input{position:absolute;opacity:0;width:100%;height:100%;margin:0;cursor:pointer}
.tbx-1038 span{display:inline-flex;min-width:49px;justify-content:center;padding:10px 13px;border:1px solid #c9d6e2;border-radius:100px;background:#fff;color:#445d77;transition:background .22s,color .22s,transform .22s,border-color .22s}
.tbx-1038 label:is(:hover,:focus-within) span{border-color:#396e82;background:#e6f3f0;transform:translateY(-2px)}
.tbx-1038 input:checked+span{background:#17485a;color:#fff;border-color:#17485a}
.tbx-1038 input:focus-visible+span{outline:3px solid #db9b5e;outline-offset:2px}
@media(prefers-reduced-motion:reduce){.tbx-1038 span{transition:none}}
How to Use
HTMLを設置し、CSSを既存サイトのスタイルシートに追加します。既存クラスとの競合を避け、サイトの配色・サイズに合わせて調整してください。
Use Case
カテゴリーフィルターの選択UI・実績一覧のラベル
Technical Notes
ホバー非対応端末でも主要操作ができるようにし、キーボードフォーカス時の表示と動き軽減設定を確認してください。
Mobile:ホバーのない端末でも情報が欠落しない設計を基本とします。クリックで操作するサンプルはタップで確認できます。
Browser:最新のChrome・Firefox・Safari・Edge向けCSS。:has()を利用する素材は最新ブラウザを想定しています。
Reduced Motion:prefers-reduced-motion: reduceに対応。