탐색

v2.1.0
폼

슬라이더

얇은 오목한 영역에 진주빛 손잡이를 배치한 네이티브 범위 입력 요소입니다.

이 페이지의 내용

슬라이더는 볼륨, 불투명도, 확대·축소 배율처럼 정확한 숫자보다 범위 안에서의 위치가 중요할 때 값을 선택하는 데 사용합니다. 네이티브 <input type="range">에 .slider를 적용하세요. 키보드 조작, 폼 값 처리, 터치 드래그는 브라우저가 담당하며, 클래스는 얇은 오목한 영역과 스위치에 쓰이는 것과 같은 진주빛 손잡이를 그립니다.

슬라이더

<label class="field">Volume <input type="range" class="slider" value="60"></label>
<label className="field">Volume <input type="range" className="slider" defaultValue="60" /></label>
<label class="field">Volume <input type="range" class="slider" value="60"></label>
<template>  <label class="field">Volume <input type="range" class="slider" value="60"></label></template>

#트랙 채우기

트랙의 시작점부터 손잡이까지 스크립트 없이 잉크색으로 채워집니다. Firefox는 이 구간을 기본 기능으로 그립니다. 다른 브라우저에서는 스타일시트가 스크롤 기반 애니메이션으로 손잡이 위치를 읽습니다. 입력 요소가 손잡이 위치를 측정하는 스크롤 컨테이너가 되고, 손잡이에 설정된 뷰 타임라인이 트랙을 따라 얼마나 이동했는지 나타내면 그 지점까지 트랙을 채웁니다. 두 방식 모두 지원되지 않으면 트랙은 비어 있는 오목한 영역으로 남고, 손잡이는 계속 값을 나타냅니다.

값 간격과 범위 제한

<label class="field">  Zoom <input type="range" class="slider" min="50" max="200" step="25" value="100"></label><label class="field">Opacity <input type="range" class="slider" value="35" disabled></label>
<>  <label className="field">    Zoom <input type="range" className="slider" min="50" max="200" step="25" defaultValue="100" />  </label>  <label className="field">    Opacity <input type="range" className="slider" defaultValue="35" disabled />  </label></>
<label class="field">  Zoom <input type="range" class="slider" min="50" max="200" step="25" value="100"></label><label class="field">Opacity <input type="range" class="slider" value="35" disabled></label>
<template>  <label class="field">    Zoom <input type="range" class="slider" min="50" max="200" step="25" value="100">  </label>  <label class="field">Opacity <input type="range" class="slider" value="35" disabled></label></template>

#세로 방향

slider-vertical은 슬라이더를 세로로 세우며, 가장 작은 값이 아래쪽 끝에 옵니다. 네이티브 입력 요소를 writing-mode: vertical-lr과 direction: rtl로 회전하므로 브라우저는 이를 세로 범위 입력으로 인식합니다. ArrowUp 키를 누르거나 위로 드래그하면 값이 커지고, 보조 기술은 세로 슬라이더로 읽습니다. 스타일시트가 모든 부분의 크기를 입력 요소 자체의 축을 기준으로 지정하므로 트랙, 채우기, 손잡이, 포커스, 비활성 상태, 터치 조작 영역은 가로 슬라이더와 같습니다.

길이는 지정된 높이를 따르며, 이 예시에서는 h(160)을 사용합니다. 높이를 지정하지 않으면 플랫폼의 범위 입력 요소 기본 길이를 사용합니다.

세로 방향

<label class="field items-center">  <input type="range" class="slider slider-vertical h(160)" value="70"> Bass</label><label class="field items-center">  <input type="range" class="slider slider-vertical h(160)" value="45"> Mid</label><label class="field items-center">  <input type="range" class="slider slider-vertical h(160)" value="60"> Treble</label><label class="field items-center">  <input type="range" class="slider slider-vertical h(160)" value="30" disabled> Gain</label>
<>  <label className="field items-center">    <input type="range" className="slider slider-vertical h(160)" defaultValue="70" /> Bass  </label>  <label className="field items-center">    <input type="range" className="slider slider-vertical h(160)" defaultValue="45" /> Mid  </label>  <label className="field items-center">    <input type="range" className="slider slider-vertical h(160)" defaultValue="60" /> Treble  </label>  <label className="field items-center">    <input type="range" className="slider slider-vertical h(160)" defaultValue="30" disabled /> Gain  </label></>
<label class="field items-center">  <input type="range" class="slider slider-vertical h(160)" value="70"> Bass</label><label class="field items-center">  <input type="range" class="slider slider-vertical h(160)" value="45"> Mid</label><label class="field items-center">  <input type="range" class="slider slider-vertical h(160)" value="60"> Treble</label><label class="field items-center">  <input type="range" class="slider slider-vertical h(160)" value="30" disabled> Gain</label>
<template>  <label class="field items-center">    <input type="range" class="slider slider-vertical h(160)" value="70"> Bass  </label>  <label class="field items-center">    <input type="range" class="slider slider-vertical h(160)" value="45"> Mid  </label>  <label class="field items-center">    <input type="range" class="slider slider-vertical h(160)" value="60"> Treble  </label>  <label class="field items-center">    <input type="range" class="slider slider-vertical h(160)" value="30" disabled> Gain  </label></template>
손잡이를 위아래로 드래그하거나, 손잡이에 포커스를 두고 방향키를 사용해 보세요.

범위 입력 요소를 회전할 수 없는 브라우저에서는 지정된 길이의 가로 슬라이더로 그려지며, 여전히 작동합니다. Chromium, Safari 17.4, Firefox는 회전을 지원합니다.

#접근성

  • field 레이블이나 aria-label로 슬라이더에 이름을 지정하세요.
  • 슬라이더에는 숫자가 표시되지 않습니다. 정확한 값이 중요하다면 슬라이더 옆에 값을 표시하거나 입력 필드에 type="number"를 사용하세요.
  • 터치 화면에서도 손잡이는 크기를 유지하며, 입력 요소의 터치 조작 영역은 트랙을 가로지르는 방향으로 총 44px입니다. 따라서 슬라이더의 모양은 바뀌지 않으면서도 손가락으로 조작할 공간이 충분합니다.

#클래스

클래스설명
slider가느다란 오목한 트랙에 진주처럼 빛나는 손잡이를 얹은 range 입력 요소입니다. 트랙의 시작점부터 손잡이까지 전경색으로 채웁니다.
slider-vertical최솟값이 아래쪽에 오는 세로 방향입니다. writing-mode: vertical-lr과 direction: rtl로 네이티브 입력을 회전시키므로 ArrowUp이 값을 높입니다. 길이는 지정한 높이 또는 플랫폼 기본 길이를 따릅니다.적용할 클래스는 slider입니다

#사용자 지정 속성

속성기본값설명
--slider-track.375rem트랙 두께
--slider-thumb1.125rem손잡이의 지름입니다. 터치 화면에서는 입력 요소가 트랙을 가로지르는 방향으로 44px까지 넓어지며, 손잡이 자체가 유일한 조작 영역인 범위 슬라이더에서는 손잡이가 최소 1.5rem입니다.
--slider-colorvar(--color-surface-inverse)채움 색상
--slider-backgroundvar(--color-surface-inset)채움 영역 아래의 트랙을 칠하는 색이나 그라데이션으로, 색상 선택기의 색상 트랙 같은 데 사용합니다.

#소스

@master/ui/components/slider.css
/* * Slider: a native range input: a thin well with a pearl thumb, the same thumb a switch has. * The part before the thumb fills with ink: Firefox draws it natively, and where scroll-driven animations * exist the thumb's own position in the track drives the fill, with no script. Elsewhere the track stays a well. * Sizes are logical, so slider-vertical only turns the input with writing-mode: vertical-lr and direction: rtl, * which the platform reads as a vertical range with its lowest value at the foot. * --slider-background is what the track is painted with under the fill: the well's tone, or a gradient such as * the hues of a color picker, which sets --slider-color to transparent so nothing covers it. */@property --slider-fill {  syntax: '<percentage>';  inherits: true;  initial-value: 0%;}@layer components.ui {  .slider {    --slider-track: .375rem;    --slider-thumb: 1.125rem;    --slider-color: var(--color-surface-inverse);    --slider-background: var(--color-surface-inset);    /* Room around the thumb for its shadow and its focus ring; the negative margin keeps the track on the edge. */    --slider-bleed: 5px;    display: block;    box-sizing: content-box;    inline-size: 100%;    block-size: var(--slider-thumb);    margin: calc(-1 * var(--slider-bleed));    padding: var(--slider-bleed);    border: 0;    background: transparent;    appearance: none;    cursor: pointer;    -webkit-tap-highlight-color: transparent;    &:focus-visible {      outline: none;    }    &::-webkit-slider-runnable-track {      block-size: var(--slider-track);      border-radius: 999px;      background: linear-gradient(90deg, var(--slider-color) var(--slider-fill), transparent 0), var(--slider-background);      box-shadow: var(--shadow-pressed);    }    &::-webkit-slider-thumb {      inline-size: var(--slider-thumb);      block-size: var(--slider-thumb);      margin-block-start: calc((var(--slider-track) - var(--slider-thumb)) / 2);      border: 0;      border-radius: 999px;      @apply --surface-thumb;      box-shadow: 0 0 0 .5px var(--color-line-strong), 0 1px 2px -.5px var(--color-shade-1), 0 2px 4px -1px var(--color-shade-2), 0 4px 8px -4px var(--color-shade-3);      appearance: none;      transition: box-shadow var(--duration-quick) var(--easing-glide), scale var(--duration-quick) var(--easing-glide);    }    &::-moz-range-track {      block-size: var(--slider-track);      border-radius: 999px;      background: var(--slider-background);      box-shadow: var(--shadow-pressed);    }    &::-moz-range-progress {      block-size: var(--slider-track);      border-radius: 999px;      background: var(--slider-color);    }    &::-moz-range-thumb {      inline-size: var(--slider-thumb);      block-size: var(--slider-thumb);      border: 0;      border-radius: 999px;      @apply --surface-thumb;      box-shadow: 0 0 0 .5px var(--color-line-strong), 0 1px 2px -.5px var(--color-shade-1), 0 2px 4px -1px var(--color-shade-2), 0 4px 8px -4px var(--color-shade-3);      transition: box-shadow var(--duration-quick) var(--easing-glide), scale var(--duration-quick) var(--easing-glide);    }    /*     * Under the pointer the thumb takes the firmer contour of a hovered control, the change its box-shadow     * transition is there for. Forced colors keep their own thumb.     */    @media (hover: hover) and (forced-colors: none) {      &:hover:not(:disabled)::-webkit-slider-thumb {        box-shadow: 0 0 0 .5px var(--color-line-mark), 0 1px 2px -.5px var(--color-shade-1), 0 2px 4px -1px var(--color-shade-2), 0 4px 8px -4px var(--color-shade-3);      }      &:hover:not(:disabled)::-moz-range-thumb {        box-shadow: 0 0 0 .5px var(--color-line-mark), 0 1px 2px -.5px var(--color-shade-1), 0 2px 4px -1px var(--color-shade-2), 0 4px 8px -4px var(--color-shade-3);      }    }    /* Held, the thumb grows a little under the finger, in either engine; each pseudo-element has a rule of its own. */    &:active:not(:disabled)::-webkit-slider-thumb {      scale: 1.08;    }    &:active:not(:disabled)::-moz-range-thumb {      scale: 1.08;    }    &:focus-visible::-webkit-slider-thumb {      outline: 2px solid var(--color-focus);      outline-offset: 2px;    }    &:focus-visible::-moz-range-thumb {      outline: 2px solid var(--color-focus);      outline-offset: 2px;    }    &:disabled {      opacity: .5;      cursor: not-allowed;    }    /*     * Upright: the inline axis runs down the page and right to left turns it, so the lowest value is at the     * foot, the arrow keys move up and down, and the fill rises from below. Its length is the height it is     * given, or the platform's own length of a range input when it is given none.     */    &.slider-vertical {      writing-mode: vertical-lr;      direction: rtl;      display: inline-block;      vertical-align: middle;      &::-webkit-slider-runnable-track {        background: linear-gradient(0deg, var(--slider-color) var(--slider-fill), transparent 0), var(--slider-background);      }    }    /*     * On touch the input reaches 44px across the track, into the room around it, so a finger has the target and     * the thumb keeps its size. Only the cross axis grows, so the slider never reaches over a control beside it.     */    @media (pointer: coarse) {      margin-block: calc((var(--slider-thumb) - 2.75rem) / 2);      padding-block: calc((2.75rem - var(--slider-thumb)) / 2);    }    @media (prefers-reduced-motion: reduce) {      &:active:not(:disabled)::-webkit-slider-thumb {        scale: none;      }      &:active:not(:disabled)::-moz-range-thumb {        scale: none;      }    }    /*     * The colors are set as the properties the tracks read, so the right-to-left and upright tracks, whose     * own rules come later, are painted in system colors too.     */    @media (forced-colors: active) {      forced-color-adjust: none;      --slider-color: Highlight;      --slider-background: Canvas;      &::-webkit-slider-runnable-track {        background: linear-gradient(90deg, var(--slider-color) var(--slider-fill), transparent 0) Canvas;        box-shadow: inset 0 0 0 1px CanvasText;      }      &.slider-vertical::-webkit-slider-runnable-track {        background: linear-gradient(0deg, var(--slider-color) var(--slider-fill), transparent 0) Canvas;      }      &::-webkit-slider-thumb {        background: ButtonText;        box-shadow: none;      }      &::-moz-range-track {        background: Canvas;        box-shadow: inset 0 0 0 1px CanvasText;      }      &::-moz-range-thumb {        background: ButtonText;        box-shadow: none;      }      /* The input opts out of forced colors, so the focus ring is given the system's own. */      &:focus-visible::-webkit-slider-thumb {        outline-color: Highlight;      }      &:focus-visible::-moz-range-thumb {        outline-color: Highlight;      }      /* Disabled, the fill and the thumb take the system's disabled ink, which the input's opt-out would keep from them. */      &:disabled {        --slider-color: GrayText;      }      &:disabled::-webkit-slider-thumb {        background: GrayText;      }      &:disabled::-moz-range-thumb {        background: GrayText;      }    }  }  /*   * The fill. The input is the scroll container the thumb is measured in, so a view timeline on the thumb   * reads how far along the track it is; the input runs a one-property animation on that timeline and the   * track paints up to it. Clipping stays outside the bleed, so the thumb's shadow and focus ring are whole.   */  @supports (view-timeline: --slider-thumb inline) and (timeline-scope: --slider-thumb) {    .slider {      overflow: hidden;      timeline-scope: --slider-thumb;      /* Longhands: a shorthand would reset the timeline, and tools that fold one into it write a value no browser reads. */      animation-name: slider-fill;      animation-timing-function: linear;      animation-fill-mode: both;      animation-timeline: --slider-thumb;      animation-range: contain;      &::-webkit-slider-thumb {        view-timeline: --slider-thumb inline;        view-timeline-inset: var(--slider-bleed);      }      /* Right to left, the value grows toward the left: the reading and the paint both turn around. */      &:dir(rtl) {        animation-direction: reverse;      }      &:dir(rtl)::-webkit-slider-runnable-track {        background: linear-gradient(270deg, var(--slider-color) var(--slider-fill), transparent 0), var(--slider-background);      }      /* Upright, the timeline runs down the input and the value up it, in a page of either direction. */      &.slider-vertical {        animation-direction: reverse;      }      &.slider-vertical::-webkit-slider-runnable-track {        background: linear-gradient(0deg, var(--slider-color) var(--slider-fill), transparent 0), var(--slider-background);      }    }  }}@keyframes slider-fill {  from {    --slider-fill: 100%;  }  to {    --slider-fill: 0%;  }}