• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

HTML & CSS How can i change body bgcolor by sliding slider ?


New Coder
Am I able to also change colour by sliding the same slider I use to change image size ?



        <p><-- low temp.</p><div class="slidecontainer">

        <input type="range" min="15" max="25" value="15" class="slider" id="Slider">

        </div><p>high temp. --></p>

        <img src="https://pngimg.com/uploads/silver/silver_PNG17187.png" id="Elon">

            const slider = document.getElementById('Slider');

            slider.addEventListener('input', handleChange);

            function handleChange(e) {
              const img = document.getElementById("Elon");
              const {value, max} = e.target;
              img.style.width = `${value*max}px`;
              img.style.height = `${value*max}px`;


Tnx a lot.
Last edited by a moderator:


Active Coder
You could make an array with keys between 15 and 25 and values of color hex codes, then every time it changes look up the corresponding value in the array and set the CSS of the item's color to that hex value.


Staff Team
Hi there!

Welcome to Code Forum!

From my understanding is that you would like to create a similar slider that you use to change the size for changing the colour, is that correct?

Moderator Note: I have edited your thread to include the code in the </>. Please remember that whenever you are posting any coding in the forums to use the </> formatting in the editor as posting code without the formatting violates our Code of Conduct which can be found by clicking here. Using the </> formatting will allow coders to easily copy and review your code. You can review more about how to add code into your postings by clicking here.