<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/Slider",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI6SliderV"
  },
  "title" : "Slider"
}
-->

# Slider

A control for selecting a value from a bounded linear range of values.

```
nonisolated struct Slider<Label, ValueLabel> where Label : View, ValueLabel : View
```

## Overview

A slider consists of a “thumb” image that the user moves between two
extremes of a linear “track”. The ends of the track represent the minimum
and maximum possible values. As the user moves the thumb, the slider
updates its bound value.

The following example shows a slider bound to the value `speed`. As the
slider updates this value, a bound [`Text`](/documentation/SwiftUI/Text) view shows the value updating.
The `onEditingChanged` closure passed to the slider receives callbacks when
the user drags the slider. The example uses this to change the
color of the value text.

```
@State private var speed = 50.0
@State private var isEditing = false

var body: some View {
    VStack {
        Slider(
            value: $speed,
            in: 0...100,
            onEditingChanged: { editing in
                isEditing = editing
            }
        )
        Text("\(speed)")
            .foregroundColor(isEditing ? .red : .blue)
    }
}
```

![An unlabeled slider, with its thumb about one third of the way from the](images/com.apple.SwiftUI/SwiftUI-Slider-simple@2x.png)

You can also use a `step` parameter to provide incremental steps along the
path of the slider. For example, if you have a slider with a range of `0` to
`100`, and you set the `step` value to `5`, the slider’s increments would be
`0`, `5`, `10`, and so on. The following example shows this approach, and
also adds optional minimum and maximum value labels.

```
@State private var speed = 50.0
@State private var isEditing = false

var body: some View {
    Slider(
        value: $speed,
        in: 0...100,
        step: 5
    ) {
        Text("Speed")
    } minimumValueLabel: {
        Text("0")
    } maximumValueLabel: {
        Text("100")
    } onEditingChanged: { editing in
        isEditing = editing
    }
    Text("\(speed)")
        .foregroundColor(isEditing ? .red : .blue)
}
```

![A slider with labels show minimum and maximum values of 0 and 100,](images/com.apple.SwiftUI/SwiftUI-Slider-withStepAndLabels@2x.png)

The slider also uses the `step` to increase or decrease the value when a
VoiceOver user adjusts the slider with voice commands.

## Topics

### Creating a slider

[`init(value:in:onEditingChanged:)`](/documentation/SwiftUI/Slider/init(value:in:onEditingChanged:))

Creates a slider to select a value from a given range.

[`init(value:in:step:onEditingChanged:)`](/documentation/SwiftUI/Slider/init(value:in:step:onEditingChanged:))

Creates a slider to select a value from a given range, subject to a
step increment.

### Creating a slider with labels

[`init(value:in:label:onEditingChanged:)`](/documentation/SwiftUI/Slider/init(value:in:label:onEditingChanged:))

Creates a slider to select a value from a given range, which displays
the provided label.

[`init(value:in:step:label:onEditingChanged:)`](/documentation/SwiftUI/Slider/init(value:in:step:label:onEditingChanged:))

Creates a slider to select a value from a given range, subject to a
step increment, which displays the provided label.

[`init(value:in:label:minimumValueLabel:maximumValueLabel:onEditingChanged:)`](/documentation/SwiftUI/Slider/init(value:in:label:minimumValueLabel:maximumValueLabel:onEditingChanged:))

Creates a slider to select a value from a given range, which displays
the provided labels.

[`init(value:in:step:label:minimumValueLabel:maximumValueLabel:onEditingChanged:)`](/documentation/SwiftUI/Slider/init(value:in:step:label:minimumValueLabel:maximumValueLabel:onEditingChanged:))

Creates a slider to select a value from a given range, subject to a
step increment, which displays the provided labels.

### Adding ticks to a slider

[`SliderTick`](/documentation/SwiftUI/SliderTick)

A representation of a tick in a slider, with associated value and
optional label.

[`SliderTickBuilder`](/documentation/SwiftUI/SliderTickBuilder)

A result builder that constructs `SliderTick`s for use when creating
a `Slider`.

[`SliderTickContentForEach`](/documentation/SwiftUI/SliderTickContentForEach)

A type of slider content that creates content by iterating over a collection.

[`TupleSliderTickContent`](/documentation/SwiftUI/TupleSliderTickContent)

Slider content created from a Swift tuple of slider content.

[`SliderTickContent`](/documentation/SwiftUI/SliderTickContent)

A type that provides content for a `SliderTickBuilder`.

### Deprecated initializers

[`init(value:in:onEditingChanged:label:)`](/documentation/SwiftUI/Slider/init(value:in:onEditingChanged:label:))

Creates a slider to select a value from a given range, which displays
the provided label.

[`init(value:in:step:onEditingChanged:label:)`](/documentation/SwiftUI/Slider/init(value:in:step:onEditingChanged:label:))

Creates a slider to select a value from a given range, subject to a
step increment, which displays the provided label.

[`init(value:in:onEditingChanged:minimumValueLabel:maximumValueLabel:label:)`](/documentation/SwiftUI/Slider/init(value:in:onEditingChanged:minimumValueLabel:maximumValueLabel:label:))

Creates a slider to select a value from a given range, which displays
the provided labels.

[`init(value:in:step:onEditingChanged:minimumValueLabel:maximumValueLabel:label:)`](/documentation/SwiftUI/Slider/init(value:in:step:onEditingChanged:minimumValueLabel:maximumValueLabel:label:))

Creates a slider to select a value from a given range, subject to a
step increment, which displays the provided labels.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)