Skip to content
Related Articles

Related Articles

Improve Article

How to change an element color based on value of the color picker value on click?

  • Last Updated : 23 Jun, 2020

The HTML tag <input type =”color”> provides a user interface element, that let the user specify the color with the help of the visual color picker interface or by entering the color value into the text field in #rrggbb hexadecimal format. Only simple colors (without alpha channel) are allowed though CSS colors has more formats, e.g. color names, functional notations and a hexadecimal format with an alpha channel.



<!DOCTYPE html>
        <label for="colors">Color:</label>
        <input type="color" value="#ff0000" id="colors" />
<p>A Computer Science Portal For Geeks.</p>
            var colors;
            var defaultColor = "#0000ff";
            window.addEventListener("load", startup, false);
            function startup() {
                colors = document.querySelector("#colors");
                colors.value = defaultColor;
                colors.addEventListener("input", updateFirst, false);
                colors.addEventListener("change", updateAll, false);
            function updateFirst(event)
                var p = document.querySelector("p");
                if (p) 
            function updateAll(event) {
                document.querySelectorAll("p").forEach(function (p) 


Attention reader! Don’t stop learning now. Get hold of all the important Comcompetitivepetitve Programming concepts with the Web Design for Beginners | HTML  course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :