탐색

v2.1.0
폼

라디오 버튼

여러 선택지 중 하나를 고르는 작고 둥근 버튼으로, 네이티브 라디오 입력에 적용합니다.

이 페이지의 내용

라디오 버튼은 작고 둥글며 안쪽이 오목합니다. 선택하면 안쪽이 색으로 채워지고 점이 나타납니다. 둥근 라디오 버튼은 ‘이 중 하나’를, 네모난 체크박스는 ‘이 중 원하는 항목 모두’를 뜻합니다. 네이티브 <input type="radio">에 .radio를 적용하고, 입력 요소와 해당 텍스트를 <label class="check">로 감싸 행 어디를 눌러도 선택할 수 있게 하세요.

라디오 버튼

<fieldset class="fieldset">  <legend class="fieldset-legend">Visibility</legend>  <label class="check">    <input type="radio" class="radio" name="visibility" value="public" checked> Public  </label>  <label class="check">    <input type="radio" class="radio" name="visibility" value="team"> Team only  </label>  <label class="check">    <input type="radio" class="radio" name="visibility" value="private"> Private  </label></fieldset>
<fieldset className="fieldset">  <legend className="fieldset-legend">Visibility</legend>  <label className="check">    <input type="radio" className="radio" name="visibility" value="public" defaultChecked /> Public  </label>  <label className="check">    <input type="radio" className="radio" name="visibility" value="team" /> Team only  </label>  <label className="check">    <input type="radio" className="radio" name="visibility" value="private" /> Private  </label></fieldset>
<fieldset class="fieldset">  <legend class="fieldset-legend">Visibility</legend>  <label class="check">    <input type="radio" class="radio" name="visibility" value="public" checked> Public  </label>  <label class="check">    <input type="radio" class="radio" name="visibility" value="team"> Team only  </label>  <label class="check">    <input type="radio" class="radio" name="visibility" value="private"> Private  </label></fieldset>
<template>  <fieldset class="fieldset">    <legend class="fieldset-legend">Visibility</legend>    <label class="check">      <input type="radio" class="radio" name="visibility" value="public" checked> Public    </label>    <label class="check">      <input type="radio" class="radio" name="visibility" value="team"> Team only    </label>    <label class="check">      <input type="radio" class="radio" name="visibility" value="private"> Private    </label>  </fieldset></template>

#라디오 버튼 그룹

같은 name 값을 가진 라디오 버튼은 하나의 그룹을 이룹니다. 하나를 선택하면 나머지 선택이 해제되며, 방향키로 그룹 안에서 선택을 옮길 수 있습니다. 그룹을 fieldset에 넣고 legend에 선택지가 답하는 질문을 적으세요.

#가로 배치

짧은 선택지 몇 개는 나란히 배치할 수 있습니다. 각 레이블이 어느 원에 속하는지 분명하도록 선택지 사이 간격을 원과 레이블 사이 간격보다 넓게 두세요.

가로 배치

<fieldset class="fieldset">  <legend class="fieldset-legend">Billing period</legend>  <div class="flex flex-wrap gap-lg">    <label class="check"><input type="radio" class="radio" name="period" checked> Monthly</label>    <label class="check"><input type="radio" class="radio" name="period"> Yearly</label>  </div></fieldset>
<fieldset className="fieldset">  <legend className="fieldset-legend">Billing period</legend>  <div className="flex flex-wrap gap-lg">    <label className="check">      <input type="radio" className="radio" name="period" defaultChecked /> Monthly    </label>    <label className="check"><input type="radio" className="radio" name="period" /> Yearly</label>  </div></fieldset>
<fieldset class="fieldset">  <legend class="fieldset-legend">Billing period</legend>  <div class="flex flex-wrap gap-lg">    <label class="check"><input type="radio" class="radio" name="period" checked> Monthly</label>    <label class="check"><input type="radio" class="radio" name="period"> Yearly</label>  </div></fieldset>
<template>  <fieldset class="fieldset">    <legend class="fieldset-legend">Billing period</legend>    <div class="flex flex-wrap gap-lg">      <label class="check"><input type="radio" class="radio" name="period" checked> Monthly</label>      <label class="check"><input type="radio" class="radio" name="period"> Yearly</label>    </div>  </fieldset></template>

#비활성화

라디오 버튼을 비활성화하면 원이 흐려지고 레이블은 비활성 상태의 글자색으로 바뀝니다. 선택지 하나만 비활성화하거나 fieldset을 비활성화해 그룹 전체를 비활성화할 수 있습니다.

비활성화

<fieldset class="fieldset">  <legend class="fieldset-legend">Region</legend>  <label class="check"><input type="radio" class="radio" name="region" checked> Tokyo</label>  <label class="check"><input type="radio" class="radio" name="region"> Frankfurt</label>  <label class="check">    <input type="radio" class="radio" name="region" disabled> Virginia, at capacity  </label></fieldset>
<fieldset className="fieldset">  <legend className="fieldset-legend">Region</legend>  <label className="check">    <input type="radio" className="radio" name="region" defaultChecked /> Tokyo  </label>  <label className="check"><input type="radio" className="radio" name="region" /> Frankfurt</label>  <label className="check">    <input type="radio" className="radio" name="region" disabled /> Virginia, at capacity  </label></fieldset>
<fieldset class="fieldset">  <legend class="fieldset-legend">Region</legend>  <label class="check"><input type="radio" class="radio" name="region" checked> Tokyo</label>  <label class="check"><input type="radio" class="radio" name="region"> Frankfurt</label>  <label class="check">    <input type="radio" class="radio" name="region" disabled> Virginia, at capacity  </label></fieldset>
<template>  <fieldset class="fieldset">    <legend class="fieldset-legend">Region</legend>    <label class="check"><input type="radio" class="radio" name="region" checked> Tokyo</label>    <label class="check"><input type="radio" class="radio" name="region"> Frankfurt</label>    <label class="check">      <input type="radio" class="radio" name="region" disabled> Virginia, at capacity    </label>  </fieldset></template>

#컨트롤 선택

라디오 버튼은 모든 선택지를 한꺼번에 보여 주며, 선택지마다 한 행을 차지합니다. 하나를 고르는 데 다음과 같은 컨트롤도 사용할 수 있습니다.

  • 보기 전환처럼 짧은 선택지 2~5개를 한 행에 배치할 때는 세그먼트 컨트롤을 사용하세요.
  • 선택지를 모두 표시하기 어렵거나 공간이 좁을 때는 셀렉트를 사용하세요.
  • 선택지마다 제목과 설명 한 문장이 필요할 때는 선택 옵션를 사용하세요.
  • 보기에 즉시 반영되는 필터에는 칩을 사용하세요.

#접근성

  • 그룹의 모든 라디오 버튼에 같은 name 값을 지정하세요. 이 값이 없으면 여러 라디오 버튼을 동시에 선택할 수 있고 방향키로 라디오 버튼 사이를 이동할 수 없습니다.
  • 탭으로 이동할 때 그룹에서 포커스가 멈추는 곳은 한 곳입니다. Tab 키를 누르면 선택된 라디오 버튼에 포커스가 가며, 선택된 항목이 없으면 첫 번째 라디오 버튼에 포커스가 갑니다. 그 위치에서 방향키로 이동할 수 있습니다.
  • 적절한 기본값이 있다면 해당 선택지를 처음부터 선택해 두세요. 아무것도 선택되지 않은 상태에서 시작한 그룹은 사용자가 한 번 선택하고 나면 그 상태로 되돌릴 수 없습니다.

#클래스

클래스설명
radio원형의 오목한 영역으로 표시하는 네이티브 type="radio" 입력 요소입니다.

#소스

@master/ui/components/radio.css
/* * Radio: a native input drawn as a small round well that fills with ink and shows a dot when chosen. * A circle says "one of these", where a checkbox's square says "any of these". * Wrap it with its text in a .check label, which checkbox.css defines, to make the whole row a target. */@layer components.ui {  .radio {    --check-size: 1.125rem;    position: relative;    display: inline-grid;    flex: none;    place-items: center;    width: var(--check-size);    height: var(--check-size);    /* Centres the control on the first line of a label that wraps. */    margin: max(0px, calc((1lh - var(--check-size)) / 2)) 0;    padding: 0;    border: 0;    border-radius: 999px;    corner-shape: round;    /* A small control needs a firmer edge than a surface to be found: one step, still half a pixel. The well is the checkbox's. */    @apply --check-well;    vertical-align: middle;    appearance: none;    /* Standing alone, as a switch does: a pointer, no double-tap zoom and no grey flash around the well. */    cursor: pointer;    touch-action: manipulation;    -webkit-tap-highlight-color: transparent;    transition-property: background-color, box-shadow;    transition-duration: var(--duration-quick);    transition-timing-function: var(--easing-glide);    /* The dot: a third of the circle, in the ink of the page behind it, at any size the well takes. */    &::after {      content: '';      width: calc(var(--check-size) / 3);      height: calc(var(--check-size) / 3);      border-radius: 999px;      corner-shape: round;      opacity: 0;      scale: .4;      background: var(--color-text-inverse);      /* The dot leaves at once and arrives with a short settle. */      transition: opacity var(--duration-press) linear, scale var(--duration-press) linear;    }    /* Forced colors draw the well with system colors; the hover's tokens, which are more specific, would show through. */    @media (hover: hover) and (forced-colors: none) {      &:hover:not(:checked, :disabled) {        @apply --check-well-hover;      }    }    &:checked {      @apply --check-ink;      &::after {        opacity: 1;        scale: 1;        transition: opacity var(--duration-quick) var(--easing-glide), scale var(--duration-base) var(--easing-glide);      }    }    &:focus-visible {      @apply --focus-ring;    }    /*     * Invalid: a required group left without a choice once the reader has tried to send the form, or aria-invalid.     * Every well of the group takes the danger edge a field takes; the field's error beside them says why.     */    &:is([aria-invalid="true"], :user-invalid):not(:checked, :disabled) {      box-shadow: var(--shadow-pressed), inset 0 0 0 .5px var(--color-danger), 0 0 0 .5px color-mix(in oklab, var(--color-danger) 45%, transparent);    }    &:disabled {      opacity: .5;      cursor: not-allowed;    }    @media (prefers-reduced-motion: reduce) {      &::after {        scale: 1;      }    }    /* Draw with system colors so the mark survives forced colors. */    @media (forced-colors: active) {      forced-color-adjust: none;      background: Field;      box-shadow: inset 0 0 0 1px FieldText;      &::after {        background: HighlightText;      }      &:checked {        background: Highlight;        box-shadow: none;      }      &:disabled {        opacity: 1;        box-shadow: inset 0 0 0 1px GrayText;      }      /* The danger edge is a theme color: the system's mark color says it here, as a field's outline does. */      &:is([aria-invalid="true"], :user-invalid):not(:checked, :disabled) {        box-shadow: inset 0 0 0 2px Mark;      }      /* Chosen and disabled: the fill takes the disabled system color, as a checkbox's does. */      &:disabled:checked {        background: GrayText;      }      &:focus-visible {        outline-color: Highlight;      }    }  }}