DXB Slider is a lightweight, customizable range slider component with a programmatically added number input. It's designed to be easy to implement, accessible, styleable, and supports both LTR and RTL layouts.
To use DXB Slider, include the CSS and JavaScript files in your project, and follow the usage instructions below.
Include the CSS in your <head>
tag:
<link rel="stylesheet" href="https://github.com/dxpr/DXB-Slider/blob/2.x/path/to/dxb-slider.min.css">
Add the HTML structure for your slider:
<div class="dxb-slider-container">
<label id="mySliderLabel" for="mySlider">Slider Label</label>
<div class="dxb-slider-wrapper">
<div class="dxb-slider-track">
<input type="range" id="mySlider" class="dxb-slider"
min="0" max="100" value="50" step="1"
data-dxb-slider
aria-labelledby="mySliderLabel">
</div>
</div>
</div>
Include the JavaScript at the end of your <body>
tag:
<script src="https://github.com/dxpr/DXB-Slider/raw/2.x/path/to/dxb-slider.min.js"></script>
The sliders will be automatically initialized for all elements with the data-dxb-slider
attribute, including those added dynamically after page load.
The sliders will automatically adjust for mobile devices, displaying the appropriate software keyboard (numeric or decimal) based on the slider's configuration.
To use the slider in RTL mode, add the dir="rtl"
attribute to the container:
<div class="dxb-slider-container" dir="rtl" lang="ar">
<!-- ... slider content ... -->
</div>
The slider will automatically adjust its layout for RTL, including:
For language-specific numerals, DXB Slider uses CSS font-variant-numeric
properties. Currently supported languages include:
lang="ar"
)lang="fa"
)lang="bn"
)lang="hi"
, lang="mr"
, lang="ne"
)Note: The language-specific numeral feature is currently fully supported in Firefox. Other browsers may have limited or no support for this feature. As browser adoption increases, this feature will become more widely available without any changes to the DXB Slider code.
You can customize the appearance of the slider by modifying the CSS variables in the :root
selector:
:root {
--dxb-slider-width: 270px;
--dxb-slider-height: 5px;
--dxb-slider-thumb-size: 20px;
--dxb-slider-primary-color: #0550e6;
--dxb-slider-secondary-color: #dadfe7;
}
Feature | DXB Slider | AlRangeSlider | Ion.RangeSlider | Simple Slider | Bootstrap Slider |
---|---|---|---|---|---|
File Size | 1 KB | 75 KB | 85 KB | 15 KB | 11 KB |
Dependency-free | ✅ | ❌ (jQuery) | ❌ (jQuery) | ❌ (jQuery) | ✅ (Optional) |
Supports Double Handle | ❌ | ✅ | ✅ | ❌ | ✅ |
RTL Support | ✅ | ❌ | ❌ | ❌ | ✅ |
Mobile Optimization | ✅ | ❌ | ✅ | ❌ | ✅ |
Accessibility Features | ✅ | ❌ | ❌ | ❌ | ✅ |
Built-in Themes/Skins | ❌ | ❌ | ✅ (6 skins) | ✅ | ✅ |
Touch Support | ✅ | ❌ | ✅ | ✅ | ✅ |
Comparison of range slider plugins based on key features.
DXB Slider is designed with accessibility in mind:
aria-labelledby
.aria-valuemin
, aria-valuemax
, aria-valuenow
) are dynamically updated to reflect the current state of the slider.aria-hidden="true"
) to avoid redundancy and potential confusion.DXB Slider is optimized for mobile devices, providing an enhanced user experience:
step
attribute includes decimals), a decimal keyboard is shown.pattern
attribute ensures that only valid numeric input is accepted.Q: How do I customize the slider's appearance?
A: You can customize the slider by modifying the CSS variables in the :root
selector. Refer to the Customization section for more details.
Q: Does DXB Slider support touch devices?
A: Yes, DXB Slider is designed to work on both desktop and touch devices.
Q: How do I enable RTL support?
A: Add the dir="rtl"
attribute to the container. Refer to the RTL Support section for more details.
Q: What browsers are supported?
A: DXB Slider supports all modern browsers. Note that language-specific numeral features are currently best supported in Firefox.
Q: How can I contribute to the project?
A: Contributions are welcome! Please open an issue or submit a pull request. Refer to the Contributing section for more details.
Q: How does DXB Slider handle input on mobile devices?
A: DXB Slider automatically displays the appropriate software keyboard (numeric or decimal) on mobile devices based on the slider's configuration. This ensures a smooth input experience for users on touch devices.
Q: Does DXB Slider support dynamically added content?
A: Yes, DXB Slider automatically detects and initializes new sliders added to the page after the initial load.
Q:Is DXB Slider really only 1KB?
A: Yes, DXB Slider's minified payload is only 894 bytes at the time of writing. This is possible due to modern browsers supprting CSS styling of native HTML range inputs. Feel free to count the bytes yourself:
This project is licensed under the GNU General Public License v2.0 (GPL-2.0) - see the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request.