How to Change Background Color with Color Range Slider in HTML? Last Updated : 07 May, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report To Change the Background Color using an HTML rounded slider that dynamically changes the webpage's background as the slider thumb is moved along its track, giving a visual indication of the selected color. The approach provides a convenient method for customizing the visual appearance of the webpage in real-time. ApproachThe HTML document defines a slider that changes the webpage's background color when the slider thumb is moved.The slider input element is defined with the ID "myRange". It has a minimum value of 0, a maximum value of 100, and an initial value of 50. After getting the input, the function "changeBackgroundColor()" is called.The JavaScript function retrieves the value of a range slider with the id "myRange". It then constructs an HSL color string based on the slider's value, with full saturation and 50% lightness. Finally, it sets the background color of the entire web page's body to the generated color string. This function dynamically changes the webpage's background color as the user adjusts the slider.Example: Implementation of changing background color using HTML rounded slider. HTML <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Custom Rounded Range Slider</title> <style> body { background-color: yellow; } h1 { text-align: center; } .slidecontainer { width: 100%; } .custom-slider-range:hover { opacity: 1.2; } .custom-slider-range { -webkit-appearance: none; appearance: none; width: 100%; height: 25px; background: linear-gradient(to right, red, yellow, green); outline: none; opacity: 0.8; transition: opacity 0.4s; border-radius: 15px; } .custom-slider-range::-moz-range-thumb { width: 25px; height: 25px; background: #fff; border: 2px solid #000; border-radius: 50%; cursor: pointer; } </style> </head> <body> <h1>Change Background Color using HTML Rounded Slider</h1> <div class="slidecontainer"> <input type="range" min="1" max="100" value="50" class="custom-slider-range" id="myRange" oninput="changeBackgroundColor()"> </div> <script> function changeBackgroundColor() { let slider = document.getElementById("myRange"); let value = slider.value; let color = 'hsl(' + value + ', 100%, 50%)'; document.body.style.background = color; } </script> </body> </html> Output: Output Comment More infoAdvertise with us Next Article How to Change Brightness using HTML Range Slider ? V vishal_shevale Follow Improve Article Tags : HTML Similar Reads How to Change Background Color in HTML without CSS ? In HTML, you can change the background color of an element using the bgcolor attribute. However, it's important to note that the bgcolor attribute is deprecated in HTML5 and should be avoided in favor of using CSS for styling. This article will cover various methods to change the background color of 2 min read How to change Background Color in HTML ? The background color in HTML sets the visual backdrop behind your webpage content. Around 85% of beginner developers start by customizing background colors to enhance design and readability. Using CSS (Cascading Style Sheets), you can easily apply colors through the background-color property. This c 3 min read How to Change the Color of Range Slider in CSS? The color of a range slider refers to the visual appearance of its track and thumb. You can customize the range slider's color in CSS using properties like accent-color, which provides around 60â70% control for quick and consistent styling across modern browsers. For more detailed and precise custom 2 min read How to choose background color through color picker? In this project, we are going to change the background color with the help of the Color Picker.Glimpse of the Project:Approach:Create an HTML file in which we are going to add the text and a color picker which helps to change the background color of our web-page.Create a CSS style to give some anima 3 min read How to Change Brightness using HTML Range Slider ? HTML Range Slider is the value adjusting component that can also be used to dynamically adjust and change the brightness of various elements like Image. we will explore two different approaches to Changing brightness using an HTML range slider. These are the following approaches: Table of Content Us 3 min read How to Change Background Image in javaScript? This article will show you how to change the background color in JavaScript. Changing a background image in JavaScript involves modifying the style property of an HTML element to update its backgroundImage property. This can be done by selecting the element and setting its style.backgroundImage prop 2 min read Like