Input range slider progress for Chrome browser
Asked Answered
C

3

7

I am working on an input type range slider. I found out that the Chrome version of input[type=range]::-moz-range-thumb is input[type=range]::-webkit-slider-thumb .

Now, I want the same for input[type=range]::-moz-range-progress.

I have tried input[type=range]::-webkit-slider-progress , input[type=range]::-webkit-slider-runnable-progress .

Still not working so far. Any alternative?

Coraliecoraline answered 15/1, 2021 at 15:23 Comment(4)
Have you tried ::-webkit-progress-value { background-color: orange; }Contentment
@Contentment No, but I just did and it didn't work.Coraliecoraline
With input[type=range]::-webkit-progress-value { background-color: orange; } add input[type=range] { -webkit-appearance: none; } - developer.mozilla.org/en-US/docs/Web/CSS/…Contentment
::-webkit-progress-value is only for <progress /> elements not input types of range.Winna
F
9

It is totally possible with CSS only.

This dude has done it: https://codepen.io/ShadowShahriar/pen/zYPPYrQ

HTML:

<main>
    <input type="range" class="win10-thumb" />
    <input type="range" class="win10-thumb" min="0" max="100" value="25" step="5" />
    <input type="range" class="win10-thumb" disabled value="64" />
    <input type="range" />
    <input type="range" min="0" max="100" value="40" step="5" />
    <input type="range" disabled value="80" />
</main>

CSS:

html,
body {
    height: 100%;
}

* {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

body {
    display: grid;
    place-items: center;
}

main {
    display: flex;
    flex-direction: column;
    gap: 2.2em;
    padding: 1em 0;
}

html::before {
    content: "";
    position: fixed;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    background: radial-gradient(circle at center, #fff, #fafafa);
    display: block;
}

/* === range theme and appearance === */
input[type="range"] {
    font-size: 1.5rem;
    width: 12.5em;
}

input[type="range"] {
    color: #ef233c;
    --thumb-height: 1.125em;
    --track-height: 0.125em;
    --track-color: rgba(0, 0, 0, 0.2);
    --brightness-hover: 180%;
    --brightness-down: 80%;
    --clip-edges: 0.125em;
}

input[type="range"].win10-thumb {
    color: #2b2d42;

    --thumb-height: 1.375em;
    --thumb-width: 0.5em;
    --clip-edges: 0.0125em;
}

@media (prefers-color-scheme: dark) {
    html {
        background-color: #000;
    }

    html::before {
        background: radial-gradient(circle at center, #101112, #000);
    }

    input[type="range"] {
        color: #f07167;
        --track-color: rgba(255, 255, 255, 0.1);
    }

    input[type="range"].win10-thumb {
        color: #3a86ff;
    }
}

/* === range commons === */
input[type="range"] {
    position: relative;
    background: #fff0;
    overflow: hidden;
}

input[type="range"]:active {
    cursor: grabbing;
}

input[type="range"]:disabled {
    filter: grayscale(1);
    opacity: 0.3;
    cursor: not-allowed;
}

/* === WebKit specific styles === */
input[type="range"],
input[type="range"]::-webkit-slider-runnable-track,
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    transition: all ease 100ms;
    height: var(--thumb-height);
}

input[type="range"]::-webkit-slider-runnable-track,
input[type="range"]::-webkit-slider-thumb {
    position: relative;
}

input[type="range"]::-webkit-slider-thumb {
    --thumb-radius: calc((var(--thumb-height) * 0.5) - 1px);
    --clip-top: calc((var(--thumb-height) - var(--track-height)) * 0.5 - 0.5px);
    --clip-bottom: calc(var(--thumb-height) - var(--clip-top));
    --clip-further: calc(100% + 1px);
    --box-fill: calc(-100vmax - var(--thumb-width, var(--thumb-height))) 0 0
        100vmax currentColor;

    width: var(--thumb-width, var(--thumb-height));
    background: linear-gradient(currentColor 0 0) scroll no-repeat left center /
        50% calc(var(--track-height) + 1px);
    background-color: currentColor;
    box-shadow: var(--box-fill);
    border-radius: var(--thumb-width, var(--thumb-height));

    filter: brightness(100%);
    clip-path: polygon(
        100% -1px,
        var(--clip-edges) -1px,
        0 var(--clip-top),
        -100vmax var(--clip-top),
        -100vmax var(--clip-bottom),
        0 var(--clip-bottom),
        var(--clip-edges) 100%,
        var(--clip-further) var(--clip-further)
    );
}

input[type="range"]:hover::-webkit-slider-thumb {
    filter: brightness(var(--brightness-hover));
    cursor: grab;
}

input[type="range"]:active::-webkit-slider-thumb {
    filter: brightness(var(--brightness-down));
    cursor: grabbing;
}

input[type="range"]::-webkit-slider-runnable-track {
    background: linear-gradient(var(--track-color) 0 0) scroll no-repeat center /
        100% calc(var(--track-height) + 1px);
}

input[type="range"]:disabled::-webkit-slider-thumb {
    cursor: not-allowed;
}

/* === Firefox specific styles === */
input[type="range"],
input[type="range"]::-moz-range-track,
input[type="range"]::-moz-range-thumb {
    appearance: none;
    transition: all ease 100ms;
    height: var(--thumb-height);
}

input[type="range"]::-moz-range-track,
input[type="range"]::-moz-range-thumb,
input[type="range"]::-moz-range-progress {
    background: #fff0;
}

input[type="range"]::-moz-range-thumb {
    background: currentColor;
    border: 0;
    width: var(--thumb-width, var(--thumb-height));
    border-radius: var(--thumb-width, var(--thumb-height));
    cursor: grab;
}

input[type="range"]:active::-moz-range-thumb {
    cursor: grabbing;
}

input[type="range"]::-moz-range-track {
    width: 100%;
    background: var(--track-color);
}

input[type="range"]::-moz-range-progress {
    appearance: none;
    background: currentColor;
    transition-delay: 30ms;
}

input[type="range"]::-moz-range-track,
input[type="range"]::-moz-range-progress {
    height: calc(var(--track-height) + 1px);
    border-radius: var(--track-height);
}

input[type="range"]::-moz-range-thumb,
input[type="range"]::-moz-range-progress {
    filter: brightness(100%);
}

input[type="range"]:hover::-moz-range-thumb,
input[type="range"]:hover::-moz-range-progress {
    filter: brightness(var(--brightness-hover));
}

input[type="range"]:active::-moz-range-thumb,
input[type="range"]:active::-moz-range-progress {
    filter: brightness(var(--brightness-down));
}

input[type="range"]:disabled::-moz-range-thumb {
    cursor: not-allowed;
}
Finery answered 27/7, 2022 at 15:22 Comment(1)
How to add borderRadius?Bury
S
2

On Internet Explorer you can use ::-ms-fill-lower to do this thing and firefox supports ::-moz-range-progress, but on chrome this is not possible only using css.

However, there is a good example below using JS. It changes the background of the range element using linear-gradient. https://codepen.io/duplich/pen/qjYQEZ

Seabee answered 8/7, 2021 at 2:19 Comment(0)
D
1

Simply use accent-color

input[type="range"] {
  accent-color : red;
}
<input type="range">
Dimitrovo answered 17/12, 2023 at 10:30 Comment(1)
doesn't work with the use of appearance : none; to customize track and thumb elementsAnyway

© 2022 - 2024 — McMap. All rights reserved.