탐색

v2.1.0
폼

색상 견본

가장자리를 섬세하게 다듬은 원형 견본으로 색상을 표시하거나 선택할 수 있습니다.

이 페이지의 내용

색상 견본은 색을 보여 주거나 선택할 수 있게 하는 요소입니다. --swatch로 색상을 지정하세요. 작은 원의 가장자리 안쪽에 아주 가는 선을 두르고 위쪽에 밝은 선을 더해, 흰 바탕의 흰색이나 검은 바탕의 검은색도 알아볼 수 있습니다. 네이티브 라디오 버튼을 <label> 요소로 감싸면 선택 항목이 됩니다. 선택된 견본에는 견본과 간격을 두고 잉크색 고리가 표시됩니다.

색상 견본

<div class="flex gap-lg" role="radiogroup" aria-label="Color">  <label class="swatch" style="--swatch: oklch(24% .004 265)">    <input class="swatch-input" type="radio" name="color" aria-label="Graphite">  </label>  <label class="swatch" style="--swatch: oklch(97% .002 265)">    <input class="swatch-input" type="radio" name="color" aria-label="Pearl" checked>  </label>  <label class="swatch" style="--swatch: oklch(58% .2 280)">    <input class="swatch-input" type="radio" name="color" aria-label="Indigo">  </label>  <label class="swatch" style="--swatch: oklch(66% .14 150)">    <input class="swatch-input" type="radio" name="color" aria-label="Moss">  </label>  <label class="swatch" style="--swatch: oklch(74% .15 70)">    <input class="swatch-input" type="radio" name="color" aria-label="Amber">  </label>  <label class="swatch" style="--swatch: oklch(66% .18 25)">    <input class="swatch-input" type="radio" name="color" aria-label="Coral" disabled>  </label></div>
<div className="flex gap-lg" role="radiogroup" aria-label="Color">  <label className="swatch" style={{ '--swatch': 'oklch(24% .004 265)' } as React.CSSProperties}>    <input className="swatch-input" type="radio" name="color" aria-label="Graphite" />  </label>  <label className="swatch" style={{ '--swatch': 'oklch(97% .002 265)' } as React.CSSProperties}>    <input className="swatch-input" type="radio" name="color" aria-label="Pearl" defaultChecked />  </label>  <label className="swatch" style={{ '--swatch': 'oklch(58% .2 280)' } as React.CSSProperties}>    <input className="swatch-input" type="radio" name="color" aria-label="Indigo" />  </label>  <label className="swatch" style={{ '--swatch': 'oklch(66% .14 150)' } as React.CSSProperties}>    <input className="swatch-input" type="radio" name="color" aria-label="Moss" />  </label>  <label className="swatch" style={{ '--swatch': 'oklch(74% .15 70)' } as React.CSSProperties}>    <input className="swatch-input" type="radio" name="color" aria-label="Amber" />  </label>  <label className="swatch" style={{ '--swatch': 'oklch(66% .18 25)' } as React.CSSProperties}>    <input className="swatch-input" type="radio" name="color" aria-label="Coral" disabled />  </label></div>
<div class="flex gap-lg" role="radiogroup" aria-label="Color">  <label class="swatch" style="--swatch: oklch(24% .004 265)">    <input class="swatch-input" type="radio" name="color" aria-label="Graphite">  </label>  <label class="swatch" style="--swatch: oklch(97% .002 265)">    <input class="swatch-input" type="radio" name="color" aria-label="Pearl" checked>  </label>  <label class="swatch" style="--swatch: oklch(58% .2 280)">    <input class="swatch-input" type="radio" name="color" aria-label="Indigo">  </label>  <label class="swatch" style="--swatch: oklch(66% .14 150)">    <input class="swatch-input" type="radio" name="color" aria-label="Moss">  </label>  <label class="swatch" style="--swatch: oklch(74% .15 70)">    <input class="swatch-input" type="radio" name="color" aria-label="Amber">  </label>  <label class="swatch" style="--swatch: oklch(66% .18 25)">    <input class="swatch-input" type="radio" name="color" aria-label="Coral" disabled>  </label></div>
<template>  <div class="flex gap-lg" role="radiogroup" aria-label="Color">    <label class="swatch" style="--swatch: oklch(24% .004 265)">      <input class="swatch-input" type="radio" name="color" aria-label="Graphite">    </label>    <label class="swatch" style="--swatch: oklch(97% .002 265)">      <input class="swatch-input" type="radio" name="color" aria-label="Pearl" checked>    </label>    <label class="swatch" style="--swatch: oklch(58% .2 280)">      <input class="swatch-input" type="radio" name="color" aria-label="Indigo">    </label>    <label class="swatch" style="--swatch: oklch(66% .14 150)">      <input class="swatch-input" type="radio" name="color" aria-label="Moss">    </label>    <label class="swatch" style="--swatch: oklch(74% .15 70)">      <input class="swatch-input" type="radio" name="color" aria-label="Amber">    </label>    <label class="swatch" style="--swatch: oklch(66% .18 25)">      <input class="swatch-input" type="radio" name="color" aria-label="Coral" disabled>    </label>  </div></template>

선택된 견본과 고리 사이의 간격에는 견본이 놓인 표면의 색을 적용합니다. 표면은 이 색을 --surface-color로 제공하므로 페이지, 볼록한 표면, 팝오버에서 같은 마크업을 사용할 수 있습니다.

#여러 색상 선택

체크박스를 사용하면 개수 제한 없이 선택할 수 있습니다. 선택 상태는 고리로 표시합니다. 모든 색상에서 잘 보이는 단일 기호가 없으므로 견본에는 체크 표시를 넣지 않습니다.

여러 색상 선택

<div class="sheet flex gap-md p-md" role="group" aria-label="Labels">  <label class="swatch swatch-lg" style="--swatch: oklch(58% .2 280)">    <input class="swatch-input" type="checkbox" name="label" aria-label="Indigo" checked>  </label>  <label class="swatch swatch-lg" style="--swatch: oklch(66% .14 150)">    <input class="swatch-input" type="checkbox" name="label" aria-label="Moss">  </label>  <label class="swatch swatch-lg" style="--swatch: oklch(74% .15 70)">    <input class="swatch-input" type="checkbox" name="label" aria-label="Amber" checked>  </label>  <label class="swatch swatch-lg" style="--swatch: oklch(66% .18 25)">    <input class="swatch-input" type="checkbox" name="label" aria-label="Coral">  </label></div>
<div className="sheet flex gap-md p-md" role="group" aria-label="Labels">  <label className="swatch swatch-lg" style={{ '--swatch': 'oklch(58% .2 280)' } as React.CSSProperties}>    <input className="swatch-input" type="checkbox" name="label" aria-label="Indigo" defaultChecked />  </label>  <label className="swatch swatch-lg" style={{ '--swatch': 'oklch(66% .14 150)' } as React.CSSProperties}>    <input className="swatch-input" type="checkbox" name="label" aria-label="Moss" />  </label>  <label className="swatch swatch-lg" style={{ '--swatch': 'oklch(74% .15 70)' } as React.CSSProperties}>    <input className="swatch-input" type="checkbox" name="label" aria-label="Amber" defaultChecked />  </label>  <label className="swatch swatch-lg" style={{ '--swatch': 'oklch(66% .18 25)' } as React.CSSProperties}>    <input className="swatch-input" type="checkbox" name="label" aria-label="Coral" />  </label></div>
<div class="sheet flex gap-md p-md" role="group" aria-label="Labels">  <label class="swatch swatch-lg" style="--swatch: oklch(58% .2 280)">    <input class="swatch-input" type="checkbox" name="label" aria-label="Indigo" checked>  </label>  <label class="swatch swatch-lg" style="--swatch: oklch(66% .14 150)">    <input class="swatch-input" type="checkbox" name="label" aria-label="Moss">  </label>  <label class="swatch swatch-lg" style="--swatch: oklch(74% .15 70)">    <input class="swatch-input" type="checkbox" name="label" aria-label="Amber" checked>  </label>  <label class="swatch swatch-lg" style="--swatch: oklch(66% .18 25)">    <input class="swatch-input" type="checkbox" name="label" aria-label="Coral">  </label></div>
<template>  <div class="sheet flex gap-md p-md" role="group" aria-label="Labels">    <label class="swatch swatch-lg" style="--swatch: oklch(58% .2 280)">      <input class="swatch-input" type="checkbox" name="label" aria-label="Indigo" checked>    </label>    <label class="swatch swatch-lg" style="--swatch: oklch(66% .14 150)">      <input class="swatch-input" type="checkbox" name="label" aria-label="Moss">    </label>    <label class="swatch swatch-lg" style="--swatch: oklch(74% .15 70)">      <input class="swatch-input" type="checkbox" name="label" aria-label="Amber" checked>    </label>    <label class="swatch swatch-lg" style="--swatch: oklch(66% .18 25)">      <input class="swatch-input" type="checkbox" name="label" aria-label="Coral">    </label>  </div></template>

#크기와 모양

색상 견본의 기본 크기는 24px입니다. swatch-sm은 16px로 목록이나 메뉴의 행에 사용하며, swatch-lg는 32px입니다. swatch-square는 칩과 같은 모서리를 가진 타일로, 팔레트나 토큰 표에 사용합니다. 입력 요소가 없는 견본은 색을 보여 주는 표시이므로 색상 이름 옆에 배치하세요.

크기와 모양

<div class="flex items-center gap-sm">  <span class="swatch swatch-sm" style="--swatch: oklch(58% .2 280)"></span>  <span class="swatch" style="--swatch: oklch(58% .2 280)"></span>  <span class="swatch swatch-lg" style="--swatch: oklch(58% .2 280)"></span>  <span class="swatch swatch-lg swatch-square" style="--swatch: oklch(58% .2 280)"></span>  <span class="swatch swatch-lg swatch-square" style="--swatch: linear-gradient(135deg, oklch(86% .07 280), oklch(88% .07 350))"></span></div><div class="flex items-center gap-xs text-sm fg-text-strong">  <span class="swatch swatch-sm" style="--swatch: oklch(66% .14 150)"></span> Moss <span class="fg-text-muted">oklch(66% .14 150)</span></div>
<>  <div className="flex items-center gap-sm">    <span className="swatch swatch-sm" style={{ '--swatch': 'oklch(58% .2 280)' } as React.CSSProperties}></span>    <span className="swatch" style={{ '--swatch': 'oklch(58% .2 280)' } as React.CSSProperties}></span>    <span className="swatch swatch-lg" style={{ '--swatch': 'oklch(58% .2 280)' } as React.CSSProperties}></span>    <span className="swatch swatch-lg swatch-square" style={{ '--swatch': 'oklch(58% .2 280)' } as React.CSSProperties}></span>    <span className="swatch swatch-lg swatch-square" style={{ '--swatch': 'linear-gradient(135deg, oklch(86% .07 280), oklch(88% .07 350))' } as React.CSSProperties}></span>  </div>  <div className="flex items-center gap-xs text-sm fg-text-strong">    <span className="swatch swatch-sm" style={{ '--swatch': 'oklch(66% .14 150)' } as React.CSSProperties}></span> Moss <span className="fg-text-muted">oklch(66% .14 150)</span>  </div></>
<div class="flex items-center gap-sm">  <span class="swatch swatch-sm" style="--swatch: oklch(58% .2 280)"></span>  <span class="swatch" style="--swatch: oklch(58% .2 280)"></span>  <span class="swatch swatch-lg" style="--swatch: oklch(58% .2 280)"></span>  <span class="swatch swatch-lg swatch-square" style="--swatch: oklch(58% .2 280)"></span>  <span class="swatch swatch-lg swatch-square" style="--swatch: linear-gradient(135deg, oklch(86% .07 280), oklch(88% .07 350))"></span></div><div class="flex items-center gap-xs text-sm fg-text-strong">  <span class="swatch swatch-sm" style="--swatch: oklch(66% .14 150)"></span> Moss <span class="fg-text-muted">oklch(66% .14 150)</span></div>
<template>  <div class="flex items-center gap-sm">    <span class="swatch swatch-sm" style="--swatch: oklch(58% .2 280)"></span>    <span class="swatch" style="--swatch: oklch(58% .2 280)"></span>    <span class="swatch swatch-lg" style="--swatch: oklch(58% .2 280)"></span>    <span class="swatch swatch-lg swatch-square" style="--swatch: oklch(58% .2 280)"></span>    <span class="swatch swatch-lg swatch-square" style="--swatch: linear-gradient(135deg, oklch(86% .07 280), oklch(88% .07 350))"></span>  </div>  <div class="flex items-center gap-xs text-sm fg-text-strong">    <span class="swatch swatch-sm" style="--swatch: oklch(66% .14 150)"></span> Moss <span class="fg-text-muted">oklch(66% .14 150)</span>  </div></template>

#접근성

  • 색상 자체에는 텍스트가 없으므로 모든 입력 요소에 접근 가능한 이름을 지정해야 합니다. 입력 요소에 aria-label="Indigo"를 지정하거나, 견본 옆에 보이는 텍스트를 aria-labelledby로 연결하세요. 이름에는 색상명을 쓰세요. 용도 자체를 전달하는 것이 중요할 때는 “위험”처럼 용도를 이름으로 쓰세요.
  • 선택 항목을 role="radiogroup" 또는 <fieldset>로 묶고 그룹에 레이블을 지정하세요. 같은 name을 공유하는 라디오 버튼 사이에서는 방향키로 이동할 수 있습니다.
  • 선택해도 견본의 색은 그대로이며 잉크색 고리가 표시됩니다. 키보드 포커스가 있으면 그 고리 바깥에 별도의 윤곽선이 표시됩니다.
  • 터치스크린에서는 원의 위치를 그대로 두고 원을 둘러싼 터치 영역을 44px로 넓힙니다. 한 견본의 터치 영역이 이웃 견본을 누르려던 탭을 가로채지 않도록 간격을 충분히 두세요. 기본 크기는 20px, 큰 견본은 12px, 작은 견본은 28px 이상입니다.

#클래스

클래스설명
swatch너비 24px의 원형 요소입니다. swatch-input을 감싼 레이블이나 단순한 표식으로 사용합니다.
swatch-input색상 견본 안의 라디오 버튼 또는 체크박스입니다. 컨트롤은 보이지 않게 원형 견본 전체를 덮습니다. 색상 자체에는 텍스트가 없으므로 접근 가능한 이름을 지정하세요.
swatch-sm16px이며 기본값은 24px입니다.적용할 클래스는 swatch입니다
swatch-lg32px이며 기본값은 24px입니다.적용할 클래스는 swatch입니다
swatch-square팔레트나 토큰 표에 쓰는 타일로, 칩과 같은 모서리 모양을 적용합니다.적용할 클래스는 swatch입니다

#사용자 지정 속성

속성기본값설명
--swatchcurrentColor색상 또는 임의의 배경 이미지
--swatch-size1.5rem지름

#소스 코드

@master/ui/components/swatch.css
/* * Swatch: a color as a thing to look at or to pick. Set the color with --swatch. * A swatch is a small disc with a hairline inside its edge, so white reads on white and black on black. * As a label around a radio or a checkbox it is a choice: the chosen one stands in a ring of ink, * a gap away, cut from the surface it sits on. */@layer components.ui {  .swatch {    --swatch: currentColor;    --swatch-size: 1.5rem;    position: relative;    display: inline-block;    flex: none;    width: var(--swatch-size);    height: var(--swatch-size);    margin: 0;    border-radius: 999px;    corner-shape: round;    background: var(--swatch);    /* An edge inside the disc and a line of light on its top, whatever the color. */    box-shadow: inset 0 0 0 .5px var(--color-line-on-color), inset 0 1px 0 var(--color-highlight-on-color);    vertical-align: middle;    -webkit-tap-highlight-color: transparent;    &:has(.swatch-input) {      cursor: pointer;      touch-action: manipulation;      transition-property: box-shadow, scale;      transition-duration: var(--duration-quick);      transition-timing-function: var(--easing-glide);    }    @media (hover: hover) {      &:has(.swatch-input:not(:disabled, :checked)):hover {        scale: 1.08;      }    }    &:has(.swatch-input:not(:disabled)):active {      scale: .94;      transition-duration: var(--duration-press);    }    /* Chosen: a 2px gap in the surface's own color, then a ring of ink. */    &:has(.swatch-input:checked) {      box-shadow:        inset 0 0 0 .5px var(--color-line-on-color), inset 0 1px 0 var(--color-highlight-on-color),        0 0 0 2px var(--surface-color, var(--color-surface-base)), 0 0 0 3.5px var(--color-text-strong);    }    &:has(.swatch-input:focus-visible) {      @apply --focus-ring;      outline-offset: 5px;    }    /* One that cannot be chosen fades to half, as every disabled control's picture does. */    &:has(.swatch-input:disabled) {      opacity: .5;      cursor: not-allowed;    }    /* Square: a tile with a chip's corner, for a palette or a token table. */    &.swatch-square {      border-radius: calc(var(--radius-chip) * var(--corner-scale));      corner-shape: var(--corner-shape);    }    &.swatch-sm { --swatch-size: 1rem; }    &.swatch-lg { --swatch-size: 2rem; }    @media (pointer: coarse) {      /* The disc keeps its size; the target around it grows to 44px. */      &:has(.swatch-input)::after {        content: '';        position: absolute;        inset: calc((var(--swatch-size) - 2.75rem) / 2);      }    }    /* Written with the weight of the hover and press rules above, so it outweighs them. */    @media (prefers-reduced-motion: reduce) {      &:has(.swatch-input:not(:disabled, :checked)):hover, &:has(.swatch-input:not(:disabled)):active {        scale: none;      }    }    /*     * The swatch keeps its color, so every edge it is given here is a system color. The chosen one stands in a     * ring of Highlight a gap of Canvas away, drawn as shadows, which leaves the outline to focus: as heavy as     * the rules above and written after them, so a chosen swatch that has focus shows both.     */    @media (forced-colors: active) {      outline: 1px solid CanvasText;      forced-color-adjust: none;      &:has(.swatch-input:checked) {        box-shadow: 0 0 0 2px Canvas, 0 0 0 4px Highlight;      }      &:has(.swatch-input:focus-visible) {        outline: 2px solid CanvasText;        outline-offset: 6px;      }      /* One that cannot be chosen is edged in the system's gray, as a disabled chip or scale cell is. */      &:has(.swatch-input:disabled) {        outline-color: GrayText;      }    }  }  /* The radio or checkbox covers the swatch invisibly: the label is the target, the input keeps the state. */  .swatch-input {    position: absolute;    inset: 0;    width: 100%;    height: 100%;    margin: 0;    padding: 0;    border: 0;    opacity: 0;    cursor: inherit;    appearance: none;  }}