Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the initial/starting POSITION of the slider handle/cursor?

Tags:

css

slider

I want to set the slider-cursor of my slider to the left at first: enter image description here

How to achieve this? The sample on the w3schools starts at the middle.

like image 261
ReyAnthonyRenacia Avatar asked Nov 16 '25 18:11

ReyAnthonyRenacia


2 Answers

Set the value tag to 1: value="1".

The minimum value of the slider is 1. This is defined by: min="1". When moving your slider to the most left the value will be set to 1 by your browser. To accomplish that this value will be set on initial/starting put the valuewhich is currently 50 to 1: value="1".

<input type="range" min="1" max="100" value="1" class="slider" id="myRange">

Not your question, but to be complete:

If you want to put it to the most right: You have to set the value to the maximum value available which is defined by max="100" in this case. Which means: put it to value="100".

The center of the slider is half of the max value which is in this case 50. The current value is set to 50 in your posted code snipped which sets the slider in the center on default.

like image 173
JeroenE Avatar answered Nov 18 '25 08:11

JeroenE


While trying @JeroenE method on my react app. The slider did not move from the position as I had hard coded it as a certain value.

This is where defaultValue comes in.

Set your defaultValue to set your range input starting point.

W3School docs here: https://www.w3schools.com/jsref/prop_range_defaultvalue.asp

like image 45
Devunderdog Avatar answered Nov 18 '25 07:11

Devunderdog



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!