Display a slider widget.
This supports int, float, date, time, and datetime types.
This also allows you to render a range slider by passing a two-element tuple or list as the value.
The difference between st.slider and st.select_slider is that slider only accepts numerical or date/time data and takes a range as input, while select_slider accepts any datatype and takes an iterable set of options.
st.slider(label, min_value=None, max_value=None, value=None, step=None, format=None, key=None, help=None, on_change=None, args=None, kwargs=None, *, disabled=False, label_visibility="visible")
A short label explaining to the user what this slider is for. The label can optionally contain Markdown and supports the following elements: Bold, Italics, Strikethroughs, Inline Code, Emojis, and Links.
This also supports:
Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by backslash-escaping them. E.g. 1\. Not an ordered list.
For accessibility reasons, you should never set an empty label (label="") but hide it with label_visibility if needed. In the future, we may disallow empty labels by raising an exception.
min_value (a supported type or None)
The minimum permitted value. Defaults to 0 if the value is an int, 0.0 if a float, value - timedelta(days=14) if a date/datetime, time.min if a time
max_value (a supported type or None)
The maximum permitted value. Defaults to 100 if the value is an int, 1.0 if a float, value + timedelta(days=14) if a date/datetime, time.max if a time
value (a supported type or a tuple/list of supported types or None)
The value of the slider when it first renders. If a tuple/list of two values is passed here, then a range slider with those lower and upper bounds is rendered. For example, if set to (1, 10) the slider will have a selectable range between 1 and 10. Defaults to min_value.
step (int, float, timedelta, or None)
The stepping interval. Defaults to 1 if the value is an int, 0.01 if a float, timedelta(days=1) if a date/datetime, timedelta(minutes=15) if a time (or if max_value - min_value < 1 day)
format (str or None)
A printf-style format string controlling how the interface should display numbers. This does not impact the return value. Formatter for int/float supports: %d %e %f %g %i Formatter for date/time/datetime uses Moment.js notation: https://momentjs.com/docs/#/displaying/format/
key (str or int)
An optional string or integer to use as the unique key for the widget. If this is omitted, a key will be generated for the widget based on its content. Multiple widgets of the same type may not share the same key.
An optional tooltip that gets displayed next to the slider.
An optional callback invoked when this slider's value changes.
An optional tuple of args to pass to the callback.
An optional dict of kwargs to pass to the callback.
An optional boolean, which disables the slider if set to True. The default is False. This argument can only be supplied by keyword.
label_visibility ("visible", "hidden", or "collapsed")
The visibility of the label. If "hidden", the label doesn't show but there is still empty space for it above the widget (equivalent to label=""). If "collapsed", both the label and the space are removed. Default is "visible". This argument can only be supplied by keyword.
(int/float/date/time/datetime or tuple of int/float/date/time/datetime)
The current value of the slider widget. The return type will match the data type of the value parameter.
import streamlit as st age = st.slider('How old are you?', 0, 130, 25) st.write("I'm ", age, 'years old')
And here's an example of a range slider:import streamlit as st values = st.slider( 'Select a range of values', 0.0, 100.0, (25.0, 75.0)) st.write('Values:', values)
This is a range time slider:import streamlit as st from datetime import time appointment = st.slider( "Schedule your appointment:", value=(time(11, 30), time(12, 45))) st.write("You're scheduled for:", appointment)
Finally, a datetime slider:import streamlit as st from datetime import datetime start_time = st.slider( "When do you start?", value=datetime(2020, 1, 1, 9, 30), format="MM/DD/YY - hh:mm") st.write("Start time:", start_time)
Check out our video on how to use one of Streamlit's core functions, the slider!
In the video below, we'll take it a step further and make a double-ended slider.
Still have questions?
Our forums are full of helpful information and Streamlit experts.