Beautiful UI-Range input component, highly customisable, based on CSS variables.

Overview



UI-Range

CSS-Only Custom & Flexible

👉 Demos: Codepen 👈


A CSS-only component which is designed to work along-side the corresponding markup (examples below). This code here is designed to bring customizabiilty to the maximum for the range input element, extending the very basic native browser component, infusing it with extra features.

Features:

  • Extensive CSS variables usage = Much easier customization:
    • Track height, color, gradient
    • Progress color/gradient
    • Progress shadow
    • Thumb size, color & shadow
    • Ticks (per step) height, color, width, position, offset
    • Ticks count limit (30)
    • Ticks skipping (Prints tick every N tick)
    • Value text color when "active" (component hover)
    • Value background color
    • Cursor for hover & grabbing
    • RTL (right-to-left) support via dir=rtl attribute
  • Value is printed by default at all times
  • Value supports prefix and/or suffix
  • Minimum & maximum values are printed at the edges
  • Ticks are printed on each step, or every N step
  • Ticks automatically hidden if too many (too dense to be helpful)

In addition to all the root variables, a helper variable --is-left-most exists on the element itself, which can be helpful if it is desirable to visually distingush between left/right thumbs of a multi-range slider.

⚠️ --min & --max variables' values should be kept as integers (not floating-point) because a CSS trick using counters is used to print the values in a pseudo-element, and it only works for integers.


I must say that CSS is not yet good enough to make this code much cleaner. I had to rely on repeating the input's attributes in its parent node, as CSS style variables, because CSS is currently unable to extrapolate attibutes as variables.

Even if the above was possible, still, it would require passing varables from one sibling to another, or to a parent.

The element has all the information needed, but the oninput event is needed to keep things in-sync for the CSS to be "aware".

--text-value is needed along-side --value due to CSS inability to cast variables types. Technically it is possible with new Houdini, but it's not yet a norm in modern-browsers.


I intentionallyl did not use the native element, since it wasn't flexible enough (especially not cross-browser). Using

instead.

Install:

npm i @yaireo/ui-range

Usage:

Import CSS file via JS

import '@yaireo/ui-range'

Or via CSS @import

@import '@yaireo/ui-range'

For the SCSS version, use this path:

@yaireo/ui-range/ui-range.scss

Markup Example (single range):

">
<div class="range-slider" style='--min:0; --max:100; --value:75; --text-value:"75"; --suffix:"%"'>
  <input type="range" min="0" max="100" value="75" oninput="this.parentNode.style.setProperty('--value',this.value); this.parentNode.style.setProperty('--text-value', JSON.stringify(this.value))">
  <output>output>
  <div class='range-slider__progress'>div>
div>

Markup Example (double range):

">
<div class="range-slider flat" data-ticks-position='top' style='--min:-500; --max:500; --prefix:"$" --value-a:-220; --value-b:400; --text-value-a:"-220"; --text-value-b:"400";'>
  <input type="range" min="-500" max="500" value="-220" oninput="this.parentNode.style.setProperty('--value-a',this.value); this.parentNode.style.setProperty('--text-value-a', JSON.stringify(this.value))">
  <output>output>
  <input type="range" min="-500" max="500" value="400" oninput="this.parentNode.style.setProperty('--value-b',this.value); this.parentNode.style.setProperty('--text-value-b', JSON.stringify(this.value))">
  <output>output>
  <div class='range-slider__progress'>div>
div>

CSS Variables

CSS Variable Default Description
--thumb-size 22px The thumb arear which is used for grabbing the slider and moving
--value-active-color white value text color when the slider is active/hovered
--value-background transparent
--value-background-hover --primary-color
--primary-color #0366d6 The main color of the component
--value-offset-y --ticks-gap Vertical distance of the current numerical value from the slider
--track-height --thumb-size / 2
--progress-radius 20px Border radius of the slider
--fill-color --primary-color
--show-min-max none to hide the min/max values at the edges
--ticks-thickness 1px How wide each tick line is
--ticks-height 5px How tall each tick line is
--ticks-gap var(--ticks-height,0) Vertical gap between the ticks and the slider
--min-max-x-offset 10% Horizontal offset of min/max values (more to the inside or outside)
--min-max-opacity 0.5
--ticks-color silver
You might also like...

Label your form input like a boss with beautiful animation and without taking up space

#Label Better by Pete R. Label your form input like a boss with beautiful animation and without taking up space Created by Pete R., Founder of BucketL

Feb 5, 2022

Palette plugin using CSS variables for TailwindCSS

 Palette plugin using CSS variables for TailwindCSS

Palette plugin using CSS variables for TailwindCSS Adds a color palette (from 100 to 900) for each color of your tailwind configuration while using CS

Dec 28, 2022

A JavaScript library to apply light-dark theme in web pages with the help of css variables

A JavaScript  library to apply light-dark theme in web pages with the help of css variables

Theme Changer The simplest JavaScript library to apply light - dark theme in your website. First Check Out One Example How to use Files index.html sty

Dec 20, 2022

Pretty, customisable, cross browser replacement scrollbars

jScrollPane - cross browser custom scroll bars jScrollPane is a jQuery plugin which allows you to replace a browser's default scroll bars (on an eleme

Dec 15, 2022

Customisable javascript skeleton loader.

Customisable javascript skeleton loader.

JS Skeleton loader Simple but very powerful loader package built with full javascript. Installation To install this package, include index.js file int

Dec 1, 2022

Horizontal Timeline 2.0, a fully customisable jQuery plugin to create a dynamic timeline on the horizontal axis.

Horizontal Timeline 2.0 by yCodeTech Twitter @yCodeTech Current Version: 2.0.5.3 Quick Links: Setup | Options | Autoplay | Known Issues | Known Issues

May 29, 2022

Purple hats Desktop is a customisable, automated web accessibility testing tool that allows software development teams to find and fix accessibility problems to improve persons with disabilities (PWDs) access to digital services.

Purple hats Desktop is a customisable, automated web accessibility testing tool that allows software development teams to find and fix accessibility problems to improve persons with disabilities (PWDs) access to digital services.

Purple HATS Desktop Purple hats Desktop is a desktop frontend for Purple HATS accessibility site scanner - a customisable, automated web accessibility

May 11, 2023

Calculate the price range for property advertised on Domain and Real Estate.

Calculate the price range for property advertised on Domain and Real Estate.

Property Seeker Calculate the price range for property advertised on Domain and Real Estate. Install Chrome Firefox Edge Privacy All searches are perf

Dec 27, 2022

A modern, clean design can be customized and applied for a wide range of purposes

Gatsby starter for projects portfolio with Flotiq source Kick off your project with this hello-world boilerplate. This starter ships with the main Gat

Oct 4, 2022
Comments
  • Increase min-max distance before bringing min down

    Increase min-max distance before bringing min down

    This isn't an issue, but I need to increase the minimum distance between min and max thumbs.

    I have an range slider from 0 to 50 million, so, in case the chosen range is too next but higher values (eg. 30M and 32M), the labels are overlapping, instead bringing minimum value to bottom.

    Checking SASS, I've found a --thumbs--too-close variable that stores a clamp function, but can't understand how it's working. Maybe this isn't the right place. So, I want to know how can I reduce the min threshold between min-max thumbs.

    Thanks!

    help wanted 
    opened by RBFraphael 1
Releases(v2.1.15)
  • v2.1.15(Feb 6, 2021)

  • v2.1.14(Feb 4, 2021)

    • [BUGFIX] removed calc inside clamp, which is unneeded and causes CSSNANO to fail f544109

    https://github.com/yairEO/ui-range/compare/v2.1.13...v2.1.14

    Source code(tar.gz)
    Source code(zip)
  • v2.1.13(Jan 31, 2021)

    • [BUGFIX] CSSNANO appears to ruin the --tickIntervalPerc calculation by removing needed "()". moved that part into its own variable for isolation, ensuring correct ticks spread calculation ddba447

    https://github.com/yairEO/ui-range/compare/v2.1.12...v2.1.13

    Source code(tar.gz)
    Source code(zip)
  • v2.1.12(Jan 20, 2021)

  • v2.1.7(Jan 20, 2021)

    spent 3 hours of experimenting with np --yolo command so it would build & commit and css output instead of building only after pushing

    https://github.com/yairEO/ui-range/compare/v2.1.4...v2.1.7

    Source code(tar.gz)
    Source code(zip)
  • v2.1.4(Jan 20, 2021)

    • [bugfix] thumb was not in center in projects with global CSS "box-sizing" forcing non-"content-box" a006acc

    https://github.com/yairEO/ui-range/compare/v2.1.3...v2.1.4

    Source code(tar.gz)
    Source code(zip)
  • v2.1.3(Jan 20, 2021)

    • [BUGFIX] IMPORTANT - apparently the "files" path (package.json) was not working as intended and the CSS was not included in the last version 3af0d9e

    https://github.com/yairEO/ui-range/compare/v2.1.2...v2.1.3

    Source code(tar.gz)
    Source code(zip)
  • v2.1.2(Jan 20, 2021)

  • v2.1.1(Jan 20, 2021)

  • v2.1.0(Jan 20, 2021)

  • v2.0.1(Jan 3, 2021)

    • [BUGFIX] reset margins for input element (apparently has 2px default by user-agent) 19d1f3c
    • [BUGFIX] - input element has absolute position and in some situations does require "left:0" or else the input will be rendered at the wrong place 8c3b49a
      • d739ed7
    • [CHORE] - docs 66b4187

    https://github.com/yairEO/ui-range/compare/v2.0.0...v2.0.1

    Source code(tar.gz)
    Source code(zip)
  • v2.0.0(Jan 3, 2021)

    • 50% re-write with support for multi-range sliders and better variables control bdd7b75

    https://github.com/yairEO/ui-range/compare/99568fc1b65dd978c7cd8938d823ea9d7a5a796b...v2.0.0

    Source code(tar.gz)
    Source code(zip)
Owner
Yair Even Or
As a programmer I very much enjoy making front-end things like Components, CSS stuff, and beautiful javascript code. I also love growing plants very much
Yair Even Or
A lightweight (~2kB) library to create range sliders that can capture a value or a range of values with one or two drag handles

range-slider-input A lightweight (~2kB) library to create range sliders that can capture a value or a range of values with one or two drag handles. Ex

Utkarsh Verma 42 Dec 24, 2022
Generate release notes from git commit history either commit range or tag range.

Would you like to support me? Release Notes Generate release notes from git commit history either commit range or tag range. App Store Template Change

Numan 6 Oct 8, 2022
Quo is a (free) debugging companion app to help you debug dumped variables, the dumped variables will appear in this Quo client instead of the traditional way which is often tedious.

Quo is a debugging companion to help you debug dumped variables, the dumped variables will appear in this Quo client instead of via the traditional way which is often tedious.

Protoqol 33 Dec 25, 2022
A fast, vanilla JS customisable select box/text input plugin for modern browsers ⚡

choices A fast, vanilla, lightweight (~16kb gzipped ?? ), configurable select plugin for modern browsers. Similar to Select2 and Selectize but without

null 9 Aug 9, 2022
A phone input component that uses intl-tel-input for Laravel Filament

Filament Phone Input This package provides a phone input component for Laravel Filament. It uses International Telephone Input to provide a dropdown o

Yusuf Kaya 24 Nov 29, 2022
A JavaScript component that is a date & time range picker, no need to build, no dependencies except Moment.js, that is based on Dan Grossman's bootstrap-daterangepicker.

vanilla-datetimerange-picker Overview. A JavaScript component that is a date & time range picker, no need to build, no dependencies except Moment.js,

null 22 Dec 6, 2022
A beautiful, responsive, highly customizable and accessible replacement for JavaScript's popup boxes. Zero dependencies.Alerts ,dialogs

AsgarAlert (v1) for JS Install <script defer src="/asgar-alert.js"></script> Examples The most basic message: asgar("Hello world!"); A message signali

Asgar Aliyev 5 Dec 20, 2022
A Bootstrap plugin to create input spinner elements for number input

bootstrap-input-spinner A Bootstrap / jQuery plugin to create input spinner elements for number input. Demo page with examples Examples with floating-

Stefan Haack 220 Nov 7, 2022
Scrape tweets from Twitter search results based on keywords and date range using Playwright. Save scraped tweets in a CSV file for easy analysis

Tweet Harvest (Twitter Crawler) Tweet Harvest is a command-line tool that uses Playwright to scrape tweets from Twitter search results based on specif

Helmi Satria 33 Aug 9, 2023
A Masked Input Component based on Ant Design.

antd-input-mask A Masked Input Component based on Ant Design. Usage Example Contributing How to run PR template Issue template Developed by bem-te-vi

bem.te.vi 6 Oct 24, 2022