Element Framework

Slider

  • HTML
  • JS
  • CSS
<ef-slider min="0" max="100" value="45"></ef-slider>
<ef-slider range min="0" max="100" from="25" to="75" min-range="1"></ef-slider>
<ef-slider show-input-field min="0" max="100" value="45"></ef-slider>
<ef-slider show-input-field range min="0" max="100" from="25" to="75" min-range="1"></ef-slider>

                  
ef-slider {
  width: 50%;
  margin: 5px 10px;
}

Basic usage

Sliders allow users to make selections from a range of values. The component's min and max values set the range. A default value can be set using the value attribute.

  • HTML
  • JS
  • CSS
<ef-slider min="0" max="100" value="60"></ef-slider>

                  
ef-slider {
  width: 50%;
  margin: 5px 10px;
}
<ef-slider min="0" max="100" value="60"></ef-slider>

To get the value of slider, access it using the value property.

<ef-slider id="level" value="1" min="0" max="10"></ef-slider>
var el = document.getElementById('level');
el.value; // "1"

You can add an event listener to the element for the value-changed event. The event will be triggered when users change the value of the slider.

Range slider

Add a range attribute to make the slider support from and to instead of a single value.

  • HTML
  • JS
  • CSS
<ef-slider min="0" max="100" from="10" to="50" range></ef-slider>

                  
ef-slider {
  width: 50%;
  margin: 15px 15px;
}

ef-slider:first-child {
  margin: 25px 15px 10px 15px;
}
<ef-slider min="0" max="100" from="10" to="50" range></ef-slider>

In range mode, the control will provide values between from and to. You can use from-changed and to-changed events to get notified when those values are changed.

In some use cases, you may need to set a minimum number of values between from and to. For example, you might want users to set at least 10 values in a range. To do that, set min-range to 10.

  • HTML
  • JS
  • CSS
<ef-slider min="0" max="100" from="10" to="50" range min-range="10"></ef-slider>

                  

                  
<ef-slider min="0" max="100" from="10" to="50" range min-range="10"></ef-slider>

Input Field

Input fields can be set to display on the side of slider. They show the current value of the slider and also allow users to set it with their keyboard.

  • HTML
  • JS
  • CSS
<ef-slider show-input-field min="0" max="100" value="40"></ef-slider>
<ef-slider show-input-field min="0" max="100" from="10" to="50" range></ef-slider>

                  
ef-slider {
  width: 50%;
  margin: 15px 15px;
}

ef-slider:first-child {
  margin: 25px 15px 10px 15px;
}
<ef-slider show-input-field min="0" max="100" value="40"></ef-slider>
<ef-slider show-input-field min="0" max="100" from="10" to="50" range></ef-slider>

Steps

The step attribute specifies the size of each increment or decrement on the slider control. By default, the slider will not show step marks but this can be set using show-steps.

  • HTML
  • JS
  • CSS
<ef-slider min="0" max="10" value="5" step="0.5" show-steps show-input-field></ef-slider>
<ef-slider min="0" max="100" from="60" to="80" step="20" range show-steps show-input-field></ef-slider>

                  
ef-slider {
  width: 50%;
  margin: 5px 10px;
}
<ef-slider min="0" max="10" value="5" step="0.5" show-steps show-input-field></ef-slider>
<ef-slider min="0" max="100" from="60" to="80" step="20" range show-steps show-input-field></ef-slider>

Customize colors

Colors of slider are managed by the theme but can be overridden using CSS variables.

  • HTML
  • JS
  • CSS
<!-- ELF supports Pride at Refinitiv -->
<ef-slider id="red" min="0" max="100" value="70"></ef-slider>
<ef-slider id="orange" min="0" max="100" value="80"></ef-slider>
<ef-slider id="yellow" min="0" max="100" value="95"></ef-slider>
<ef-slider id="green" min="0" max="100" value="90"></ef-slider>
<ef-slider id="blue" min="0" max="100" value="80"></ef-slider>
<ef-slider id="violet" min="0" max="100" value="70"></ef-slider>

                  
ef-slider {
  max-width: 50%;
}

#red {
  --thumb-color: #e40303;
}

#orange {
  --thumb-color: #ff8c00;
}

#yellow {
  --thumb-color: #ffed00;
}

#green {
  --thumb-color: #008026;
}

#blue {
  --thumb-color: #004dff;
}

#violet {
  --thumb-color: #750787;
}
CSS Variables Name Description
--track-color Slider track color
--thumb-color Color of slider thumb and filled track color
--step-color Slider step color
--input-field-width Set input field width
#red {
  --thumb-color:#e40303;
}
<ef-slider id="red" min="0" max="100" value="70"></ef-slider>

API Reference

Attributes

string
step
Specified size of increment or decrement jump between value.
string
min
Set minimum value of slider.
string
max
Slider maximum value of slider.
string
from
Uses with `range`. Low value of slider in range mode.
string
to
Uses with `range`. High value of slider in range mode
boolean
range
Set slider to range mode. Instead of a single value, slider will provide `from` and `to`.
boolean
show-steps
Show steps marker on slider.
"" | "readonly" | null
show-input-field
Show input number field.
string
min-range
Uses with `range`. Set minimum allowance value (distance) between `from` and `to`.
string
value
Value of slider. Not applicable in range mode.
boolean
readonly
Set readonly state
boolean
disabled
Set disabled state

Properties

string
step
Specified size of increment or decrement jump between value.
"1"
string
min
Set minimum value of slider.
"0"
string
max
Slider maximum value of slider.
"100"
string
from
Uses with `range`. Low value of slider in range mode.
"0"
string
to
Uses with `range`. High value of slider in range mode
"100"
boolean
range
Set slider to range mode. Instead of a single value, slider will provide `from` and `to`.
false
boolean
showSteps
Show steps marker on slider.
false
"" | "readonly" | null
showInputField
Show input number field.
string
minRange
Uses with `range`. Set minimum allowance value (distance) between `from` and `to`.
"0"
string
value
Value of slider. Not applicable in range mode.
"0"
boolean
readonly
Set readonly state
false
boolean
disabled
Set disabled state
false

Events

value-changed
Fired when the `value` changes.
from-changed
Fired when the `from` changes.
to-changed
Fired when the `to` changes.