슬라이더는 볼륨, 불투명도, 확대·축소 배율처럼 정확한 숫자보다 범위 안에서의 위치가 중요할 때 값을 선택하는 데 사용합니다. 네이티브 <input type="range">에 .slider를 적용하세요. 키보드 조작, 폼 값 처리, 터치 드래그는 브라우저가 담당하며, 클래스는 얇은 오목한 영역과 스위치에 쓰이는 것과 같은 진주빛 손잡이를 그립니다.
트랙의 시작점부터 손잡이까지 스크립트 없이 잉크색으로 채워집니다. Firefox는 이 구간을 기본 기능으로 그립니다. 다른 브라우저에서는 스타일시트가 스크롤 기반 애니메이션으로 손잡이 위치를 읽습니다. 입력 요소가 손잡이 위치를 측정하는 스크롤 컨테이너가 되고, 손잡이에 설정된 뷰 타임라인이 트랙을 따라 얼마나 이동했는지 나타내면 그 지점까지 트랙을 채웁니다. 두 방식 모두 지원되지 않으면 트랙은 비어 있는 오목한 영역으로 남고, 손잡이는 계속 값을 나타냅니다.
slider-vertical은 슬라이더를 세로로 세우며, 가장 작은 값이 아래쪽 끝에 옵니다. 네이티브 입력 요소를 writing-mode: vertical-lr과 direction: rtl로 회전하므로 브라우저는 이를 세로 범위 입력으로 인식합니다. ArrowUp 키를 누르거나 위로 드래그하면 값이 커지고, 보조 기술은 세로 슬라이더로 읽습니다. 스타일시트가 모든 부분의 크기를 입력 요소 자체의 축을 기준으로 지정하므로 트랙, 채우기, 손잡이, 포커스, 비활성 상태, 터치 조작 영역은 가로 슬라이더와 같습니다.
길이는 지정된 높이를 따르며, 이 예시에서는 h(160)을 사용합니다. 높이를 지정하지 않으면 플랫폼의 범위 입력 요소 기본 길이를 사용합니다.
/* * 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),transparent0),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:000.5pxvar(--color-line-strong),01px2px-.5pxvar(--color-shade-1),02px4px-1pxvar(--color-shade-2),04px8px-4pxvar(--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:000.5pxvar(--color-line-strong),01px2px-.5pxvar(--color-shade-1),02px4px-1pxvar(--color-shade-2),04px8px-4pxvar(--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:000.5pxvar(--color-line-mark),01px2px-.5pxvar(--color-shade-1),02px4px-1pxvar(--color-shade-2),04px8px-4pxvar(--color-shade-3);}&:hover:not(:disabled)::-moz-range-thumb{box-shadow:000.5pxvar(--color-line-mark),01px2px-.5pxvar(--color-shade-1),02px4px-1pxvar(--color-shade-2),04px8px-4pxvar(--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:2pxsolidvar(--color-focus);outline-offset:2px;}&:focus-visible::-moz-range-thumb{outline:2pxsolidvar(--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),transparent0),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),transparent0) Canvas;box-shadow:inset0001px CanvasText;}&.slider-vertical::-webkit-slider-runnable-track{background:linear-gradient(0deg,var(--slider-color)var(--slider-fill),transparent0) Canvas;}&::-webkit-slider-thumb{background: ButtonText;box-shadow:none;}&::-moz-range-track{background: Canvas;box-shadow:inset0001px 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),transparent0),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),transparent0),var(--slider-background);}}}}@keyframes slider-fill {from{--slider-fill:100%;}to{--slider-fill:0%;}}