UI / 092

Segmented selection

選択肢を並べる
排他的な選択肢を、横に並んだボタンのように見せます。

実際のHTML・CSSで描かれた見本です。

ラボで詳しく試す ↗

ひとつ試すなら

どこが変わるかを観察して、似た表現と見比べてみよう。

こんなときに

表示方法や、少数の条件の切り替え。

仕組みと使い方

ラジオボタンのグループ名をそろえると、一つだけ選べます。

セグメント選択radioタブ風
実装コードを見る
<style>
.sample{width:100%;height:100%;min-height:190px;display:grid;place-items:center;position:relative;overflow:hidden;box-sizing:border-box;font-family:Arial,'Hiragino Kaku Gothic ProN',Meiryo,sans-serif;color:#20211d;background:#f1f0e9;padding:22px}.sample *{box-sizing:border-box}.sample button,.sample input,.sample summary{font:inherit}.sample button,.sample summary,.sample label{touch-action:manipulation}.sample :focus-visible{outline:3px solid #6050bf;outline-offset:5px}.sample small{font-size:10px;line-height:1.5}.sample .editable{margin:0}.sample svg{max-width:100%;height:auto}
.sample fieldset{border:0;display:flex;padding:5px;background:#dedfd6;border-radius:10px;gap:4px}.sample legend{font-size:12px;margin-bottom:13px;text-align:center}.sample label{position:relative;cursor:pointer}.sample input{position:absolute;opacity:0}.sample span{display:block;padding:12px 16px;font-size:12px;border-radius:6px}.sample input:checked+span{background:white;box-shadow:0 1px 4px #0002}.sample input:focus-visible+span{outline:3px solid #6050bf}
</style>
<div class="sample">
<fieldset><legend>サンプルの表示密度</legend><label><input type="radio" name="density" checked><span>ゆったり</span></label><label><input type="radio" name="density"><span>きっちり</span></label></fieldset>
</div>