How to Turn Your Passion into a Profitable Business
Entrepreneurship & Start-ups |
2025-03-08 10:33:19
Creating a slider in HTML involves using the <input>
element with the type
attribute set to "range"
. Here’s a simple example of how to create a basic slider:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Slider Example</title>
<style>
.slider {
width: 300px;
}
</style>
</head>
<body>
<h1>Simple Slider</h1>
<input type="range" min="0" max="100" value="50" class="slider" id="myRange">
<p>Value: <span id="sliderValue">50</span></p>
<script>
const slider = document.getElementById("myRange");
const output = document.getElementById("sliderValue");
slider.oninput = function() {
output.textContent = this.value;
}
</script>
</body>
</html>
<input type="range">
: This is the HTML element used to create the slider.min
: The minimum value of the slider.max
: The maximum value of the slider.value
: The initial value of the slider.class="slider"
: A CSS class for custom styling of the slider.<span>
element.min
, max
, and value
attributes as needed.This basic example should help you get started with sliders in HTML.