Slider
A Slider component for displaying current value and intervals in range.
When To Use
Used to input a value within a specified range.
Examples
- Basic ·
basic - Slider with InputNumber ·
input-number - Slider with icon ·
icon-slider - Customize tooltip ·
tip-formatter - Event ·
event - Graduated slider ·
mark - Vertical ·
vertical - Control visibility of Tooltip ·
show-tooltip - Reverse ·
reverse - Draggable track ·
draggableTrack - Multiple handles ·
multiple - Dynamic edit nodes ·
editable - Disabled per handle ·
disabled-handle - Custom semantic dom styling ·
style-class
API
Common props ref:Common props
| Property | Description | Type | Default | Version | Global Config |
|---|---|---|---|---|---|
| classNames | Customize class for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string> | - | 5.23.0 | |
| defaultValue | The default value of the slider. When range is false, use number, otherwise, use [number, number] | number | [number, number] | 0 | [0, 0] | × | |
| disabled | If true, the slider will not be interactive. This prop can also be an array to disable specific handles in range mode, e.g. [true, false, true] disables first and third handles. When any rendered handle is disabled, editable mode will be disabled | boolean | boolean[] | false | × | |
| keyboard | Support using keyboard to move handlers | boolean | true | 5.2.0+ | × |
| dots | Whether the thumb can only be dragged to tick marks | boolean | false | × | |
| included | Takes effect when marks is not null. True means containment and false means coordinative | boolean | true | × | |
| marks | Tick marks of Slider. The type of key must be number, and must be in closed interval [min, max]. Each mark can declare its own style | object | { number: ReactNode } | { number: { style: CSSProperties, label: ReactNode } } | × | |
| max | The maximum value the slider can slide to | number | 100 | × | |
| min | The minimum value the slider can slide to | number | 0 | × | |
| orientation | Orientation | horizontal | vertical | horizontal | × | |
| range | Enable dual thumb mode for range selection | boolean | range | false | × | |
| reverse | Reverse the component | boolean | false | × | |
| step | The granularity the slider can step through values. Must be greater than 0, and be divisible by (max - min). When step is null and marks exist, valid points will only be marks, min and max | number | null | 1 | × | |
| styles | Customize inline style for each semantic structure inside the component. Supports object or function. | Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties> | - | 5.23.0 | |
| tooltip | The tooltip related props | tooltip | - | 4.23.0 | × |
| value | The value of slider. When range is false, use number, otherwise, use [number, number] | number | [number, number] | - | × | |
| vertical | If true, the slider will be vertical. Simultaneously existing with orientation, orientation takes priority | boolean | false | × | |
| onChangeComplete | Fire when mouseup or keyup is fired | (value) => void | - | × | |
| onChange | Callback function that is fired when the user changes the slider's value | (value) => void | - | × | |
Style of the slider handle, please use styles.handle instead | CSSProperties | - | - | × | |
Callback fired when mouseup or keyup is fired, please use onChangeComplete instead | (value) => void | - | - | × | |
Style of the slider rail, please use styles.rail instead | CSSProperties | - | - | × | |
Style of the slider track, please use styles.track instead | CSSProperties | - | - | × |
range
| Property | Description | Type | Default | Version |
|---|---|---|---|---|
| draggableTrack | Whether range track can be dragged | boolean | false | - |
| editable | Dynamic edit nodes. Cannot be used with draggableTrack | boolean | false | 5.20.0 |
| minCount | The minimum count of nodes | number | 0 | 5.20.0 |
| maxCount | The maximum count of nodes | number | - | 5.20.0 |
tooltip
| Property | Description | Type | Default | Version |
|---|---|---|---|---|
| autoAdjustOverflow | Whether to automatically adjust the popup position | boolean | true | 5.8.0 |
| open | If true, Tooltip will always be visible; if false, it will never be visible, even when dragging or hovering | boolean | - | 4.23.0 |
| placement | Set Tooltip display position. Ref Tooltip | string | - | 4.23.0 |
| getPopupContainer | The DOM container of the Tooltip. The default behavior is to create a div element in the body | (triggerNode) => HTMLElement | () => document.body | 4.23.0 |
| formatter | Slider will pass its value to formatter, display its value in Tooltip, and hide the Tooltip when the returned value is null | value => ReactNode | null | IDENTITY | 4.23.0 |
Methods
| Name | Description | Version |
|---|---|---|
| blur() | Remove focus | |
| focus() | Get focus |
Semantic DOM
| Semantic node | Native description | Version |
|---|---|---|
root | Root element with relative positioning, height, margin, padding, cursor style and touch action control | 5.23.0 |
track | Track selection bar element with absolute positioning, background color, border radius and transition animation styles | 5.10.0 |
tracks | Multi-segment track container element with absolute positioning and transition animation styles | 5.10.0 |
rail | Background rail element with absolute positioning, background color, border radius and transition animation styles | 5.10.0 |
handle | Slider handle control element with absolute positioning, size, outline, user selection, background color, border shadow, border radius, cursor style and transition animation | 5.10.0 |
Semantic description source: vendor/components/slider/demo/_semantic.tsx
Design Token
Types, inheritance and declarations retain the pinned native source. Defaults are computed by the native theme and may be overridden by ConfigProvider; this table does not invent static defaults.
| Token | Type | Native description |
|---|---|---|
controlSize | number | Height of slider |
railSize | number | Height of rail |
handleSize | number | Size of handle |
handleSizeHover | number | Size of handle when hover |
handleLineWidth | number | string | Border width of handle |
handleLineWidthHover | number | string | Border width of handle when hover |
dotSize | number | Size of dot |
railBg | string | Background color of rail |
railHoverBg | string | Background color of rail when hover |
trackBg | string | Background color of track |
trackHoverBg | string | Background color of track when hover |
handleColor | string | Color of handle |
handleActiveColor | string | Border color of handle when active |
handleActiveOutlineColor | string | Outline color of handle when active |
handleColorDisabled | string | Color of handle when disabled |
dotBorderColor | string | Border color of dot |
dotActiveBorderColor | string | Border color of dot when active |
trackBgDisabled | string | Background color of track when disabled |
Declaration source: vendor/components/slider/style/index.ts
import type * as React from 'react';
import type { CSSObject } from '@ant-design/cssinjs';
import { unit } from '@ant-design/cssinjs';
import { FastColor } from '@ant-design/fast-color';
import { resetComponent } from '../../style';
import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';
import { genStyleHooks, mergeToken } from '../../theme/internal';
// Direction naming standard:
// Horizontal base:
// -0-------------
// vertical: part (水平时,垂直方向命名为 part)
// horizontal: full (水平时,水平方向命名为 full)
export interface ComponentToken {
/**
* @desc 滑动输入高度
* @descEN Height of slider
*/
controlSize: number;
/**
* @desc 轨道高度
* @descEN Height of rail
*/
railSize: number;
/**
* @desc 滑块尺寸
* @descEN Size of handle
*/
handleSize: number;
/**
* @desc 滑块尺寸(悬浮态)
* @descEN Size of handle when hover
*/
handleSizeHover: number;
/**
* @desc 滑块边框宽度
* @descEN Border width of handle
*/
handleLineWidth: number | string;
/**
* @desc 滑块边框宽度(悬浮态)
* @descEN Border width of handle when hover
*/
handleLineWidthHover: number | string;
/**
* @desc 滑块圆点尺寸
* @descEN Size of dot
*/
dotSize: number;
/**
* @desc 轨道背景色
* @descEN Background color of rail
*/
railBg: string;
/**
* @desc 轨道背景色(悬浮态)
* @descEN Background color of rail when hover
*/
railHoverBg: string;
/**
* @desc 轨道已覆盖部分背景色
* @descEN Background color of track
*/
trackBg: string;
/**
* @desc 轨道已覆盖部分背景色(悬浮态)
* @descEN Background color of track when hover
*/
trackHoverBg: string;
/**
* @desc 滑块颜色
* @descEN Color of handle
*/
handleColor: string;
/**
* @desc 滑块激活态边框色
* @descEN Border color of handle when active
*/
handleActiveColor: string;
/**
* @desc 滑块激活态外框色
* @descEN Outline color of handle when active
*/
handleActiveOutlineColor: string;
/**
* @desc 滑块禁用颜色
* @descEN Color of handle when disabled
*/
handleColorDisabled: string;
/**
* @desc 圆点边框颜色
* @descEN Border color of dot
*/
dotBorderColor: string;
/**
* @desc 圆点激活态边框颜色
* @descEN Border color of dot when active
*/
dotActiveBorderColor: string;
/**
* @desc 轨道禁用态背景色
* @descEN Background color of track when disabled
*/
trackBgDisabled: string;
}
interface SliderToken extends FullToken<'Slider'> {
marginFull: number | string;
marginPart: number | string;
marginPartWithMark: number | string;
}
Shared native props
Tips: The following generic properties apply to most antd components; those not supported are described separately.
| Property | Description | Type | Default |
|---|---|---|---|
| style | The additional style | CSSProperties | - |
| className | The additional css class | string | - |
| rootClassName | ClassName on the root element | string | - |
| autoFocus | Auto focus when component mounted, only effective for focusable elements like forms, links, etc. | boolean | false |
Install and reproduce an example
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23
Use ConfigProvider and native App; configure dayjs locale separately. Each example lists its complete source files and additional pinned dependencies in View code. Example names select demos, not universal component props. See the resource setup guide for theme, locale and SSR.
Native type references
The source viewer includes unchanged native implementations and the following source declarations. Inherited types remain in their native packages. English source comments are preserved as code reference.
vendor/components/slider/Context.tsvendor/components/slider/SliderTooltip.tsxvendor/components/slider/index.tsxvendor/components/slider/style/index.ts
Source and license
https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd
Original bilingual prose and executable examples are retained. Website-only embeds and token tables are expanded locally. Ant Design is MIT; separately listed dependency notices also apply. Upload previews block outbound requests and do not provide a backend.