{"id":4278,"date":"2015-05-18T12:15:47","date_gmt":"2015-05-18T09:15:47","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=4278"},"modified":"2017-12-19T14:02:14","modified_gmt":"2017-12-19T12:02:14","slug":"html5-color-picker-example","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/","title":{"rendered":"HTML5 Color picker example"},"content":{"rendered":"<p>In this article I will show you how to create a Color Picker using HTML5 Canvas API.<\/p>\n<p>I&#8217;ll first present you the API we&#8217;ll use. Then we&#8217;ll create a <em>&#8220;color picker&#8221;<\/em> you can reuse in your applications.<\/p>\n<p>This article will not present the use of the new <code>&lt;input type=\"color\" \/&gt;<\/code>.<\/p>\n<h2>1. Introduction<\/h2>\n<p>The way to create a color picker is relatively easy.<\/p>\n<p>It consist in displaying an image, and retrieve the pixel color the user clicked on.<\/p>\n<p>The Canvas API, allow us to get some data from images with the <code>getImageData<\/code> method.<br \/>\n&nbsp;<br \/>\n[ulp id=&#8217;tgm4cmEWcKUikZNn&#8217;]<\/p>\n<h2>2. The Skeleton<\/h2>\n<h3>2.1 HTML Document<\/h3>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n&lt;head lang=&quot;en&quot;&gt;\r\n    &lt;meta charset=&quot;UTF-8&quot;&gt;\r\n    &lt;title&gt;&lt;\/title&gt;\r\n    &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot; \/&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;div id=&quot;colorpicker&quot;&gt;\r\n    &lt;canvas width=&quot;300&quot; height=&quot;300&quot;&gt;&lt;\/canvas&gt;\r\n&lt;\/div&gt;\r\n&lt;script src=&quot;script.js&quot;&gt;&lt;\/script&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>Then we need to find an image to create the color palette, this image will we displayed in the canvas element so it may have the dimensions of the canvas element (or vice versa).<\/p>\n<blockquote><p><strong>NOTE<\/strong> You can chose any image you want.<\/p><\/blockquote>\n<h3>2.2 Javascript File<\/h3>\n<p>So we will create the <code>script.js<\/code> file to add the image in the canvas element.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\/\/ first retrieve the canvas element\r\nvar canvasElement = document.querySelector('#colorpicker canvas');\r\n\/\/ Then get the 2D context of the Canvas\r\nvar canvasImage = canvasElement.getContext('2d');\r\n\r\n\/\/ Now create an image element\r\nvar image = new Image();\r\nimage.src = 'palette.png';\r\n\r\n\/\/ Just after the browser has finished to load the image we can add it in the canvas\r\nimage.addEventListener('load', function () {\r\n   canvasImage.drawImage(image, 0, 0);\r\n});\r\n<\/pre>\n<p>The script will just create the palette, now we need to handle the click :<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\/\/ first retrieve the canvas element\r\nvar canvasElement = document.querySelector('#colorpicker canvas');\r\n\/\/ Then get the 2D context of the Canvas\r\nvar canvasImage = canvasElement.getContext('2d');\r\n\r\n\/\/ Now create an image element\r\nvar image = new Image();\r\nimage.src = 'palette.png';\r\n\r\n\/\/ Just after the browser has finished to load the image we can add it in the canvas\r\nimage.addEventListener('load', function () {\r\n    canvasImage.drawImage(image, 0, 0);\r\n\r\n    \/\/ Handle the click on the palette\r\n    canvasElement.addEventListener('click', function (event) {\r\n        \/\/ Get the position of the mouse in the Canvas\r\n        var x = event.pageX - this.offsetLeft;\r\n        var y = event.pageY - this.offsetTop;\r\n\r\n        \/\/ Get the Image Data\r\n        var imageData = canvasImage.getImageData(x, y, 1, 1).data;\r\n\r\n        \/\/ Convert into readable variable\r\n        var Red = imageData&#x5B;0];\r\n        var Green = imageData&#x5B;1];\r\n        var Blue = imageData&#x5B;2];\r\n        var rgb = Red + ',' + Green + ',' + Blue;\r\n\r\n        \/\/ Display the result in the console\r\n        console.log(rgb);\r\n    });\r\n});\r\n<\/pre>\n<p>This is It !<\/p>\n<figure id=\"attachment_4344\" aria-describedby=\"caption-attachment-4344\" style=\"width: 800px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/html5_color_picker_example_1.png\"><img decoding=\"async\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/html5_color_picker_example_1.png\" alt=\"HTML5 Color picker example 1\" width=\"800\" height=\"600\" class=\"size-full wp-image-4344\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/html5_color_picker_example_1.png 800w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/html5_color_picker_example_1-300x225.png 300w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><figcaption id=\"caption-attachment-4344\" class=\"wp-caption-text\">HTML5 Color picker example 1<\/figcaption><\/figure>\n<p>The main usage is here, maybe a little styling, at least to change the cursor over the canvas.<\/p>\n<h3>2.3 Style with CSS<\/h3>\n<p>We will simply change the mouse cursor when it&#8217;s over the Canvas :<\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\ncanvas{\r\n    cursor:crosshair;\r\n}\r\n<\/pre>\n<p>The script is now finished &#8230;<\/p>\n<h2>3. Make it reusable<\/h2>\n<p>But the color picker is not very usable, so I will now present you how to create a color picker to set the color in an input element.<\/p>\n<h3>3.1 Create a wrapper function<\/h3>\n<p>As we want the color picker to be reusable, we need to create a function to manage picker :<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction colorPicker(){\r\n    \r\n    \/\/ first retrieve the canvas element\r\n    var canvasElement = document.querySelector('#colorpicker canvas');\r\n\r\n    \/\/ Then get the 2D context of the Canvas\r\n    var canvasImage = canvasElement.getContext('2d');\r\n\r\n    \/\/ Now create an image element\r\n    var image = new Image();\r\n    image.src = 'palette.png';\r\n\r\n    \/\/ Just after the browser has finished to load the image we can add it in the canvas\r\n    image.addEventListener('load', function () {\r\n        canvasImage.drawImage(image, 0, 0);\r\n        \r\n        \/\/ Handle the click on the palette \r\n        canvasElement.addEventListener('click', function (event) {\r\n            \/\/ Get the position of the mouse in the Canvas\r\n            var x = event.pageX - this.offsetLeft;\r\n            var y = event.pageY - this.offsetTop;\r\n\r\n            \/\/ Get the Image Data\r\n            var imageData = canvasImage.getImageData(x, y, 1, 1).data;\r\n            \r\n            \/\/ Convert into readable variable\r\n            var Red = imageData&#x5B;0];\r\n            var Green = imageData&#x5B;1];\r\n            var Blue = imageData&#x5B;2];\r\n            var rgb = Red + ',' + Green + ',' + Blue;\r\n            \r\n            \/\/ Display the result in the console\r\n            console.log(rgb);\r\n        });\r\n    });\r\n}\r\n<\/pre>\n<p>And call the function to make things still working &#8230;<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\ncolorPicker();\r\n<\/pre>\n<h3>3.2 Create the canvas picker on click<\/h3>\n<p>For sure you may want to use the picker when clicking on a button for example, so we will create the color picker in a floating div next to the mouse click.<\/p>\n<p>First we need to create the <code>show()<\/code> function and add it in the <code>colorPicker<\/code> function:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction colorPicker(){\r\n    \r\n    \/\/ Now create an image element\r\n    var image = new Image();\r\n    image.src = 'palette.png';\r\n\r\n    \/\/ Create a div element\r\n    \/\/ Create a canvas element in the div\r\n    var divElement = document.createElement('div'),\r\n        canvasElement = document.createElement('canvas'),\r\n        canvasImage;\r\n\r\n    \/\/ Get the mouse position\r\n    var event = window.event,\r\n        mouseX = event.pageX,\r\n        mouseY = event.pageY;\r\n\r\n    function show() {\r\n                   \r\n        divElement.style.width = image.width + 'px'; \/\/ The element width is the palette image width\r\n        divElement.style.height = image.height + 'px'; \/\/ The element height is the palette image height\r\n        divElement.className += 'colorpicker'; \/\/ Add the class colorpicker to the div element\r\n\r\n        divElement.style.position = 'absolute'; \/\/ The div position is absolute\r\n        divElement.style.top = mouseY + 'px'; \/\/ Top position is the mouse Y position \r\n        divElement.style.left = mouseX + 'px'; \/\/ Left position is the mouse X position \r\n        \r\n        canvasElement.width = image.width; \/\/ Canvas Width\r\n        canvasElement.height = image.height; \/\/ Canvas Height\r\n        canvasImage = canvasElement.getContext('2d');\r\n        canvasImage.drawImage(image, 0, 0); \/\/ Drow image in canvas\r\n\r\n        divElement.appendChild(canvasElement);\r\n\r\n        \/\/ Display element by append it to the body\r\n        document.querySelector('body').appendChild(divElement);\r\n    }\r\n\r\n    \/\/ Just after the browser has finished to load the image we can add it in the canvas\r\n    image.addEventListener('load', function () {\r\n        \r\n        \/\/ Display the palette\r\n        show();\r\n        \r\n        \/\/ Handle the click on the palette \r\n        canvasElement.addEventListener('click', function (event) {\r\n            \/\/ Get the position of the mouse in the Canvas\r\n            var x = event.pageX - this.offsetLeft;\r\n            var y = event.pageY - this.offsetTop;\r\n\r\n            \/\/ Get the Image Data\r\n            var imageData = canvasImage.getImageData(x, y, 1, 1).data;\r\n            \r\n            \/\/ Convert into readable variable\r\n            var Red = imageData&#x5B;0];\r\n            var Green = imageData&#x5B;1];\r\n            var Blue = imageData&#x5B;2];\r\n            var rgb = Red + ',' + Green + ',' + Blue;\r\n            \r\n            \/\/ Display the result in the console\r\n            console.log(rgb);\r\n        });\r\n    });\r\n}\r\n<\/pre>\n<p>The variables : <code>image<\/code>, <code>divElement<\/code>, <code>canvasElement<\/code> and <code>canvasImage<\/code> are only visible in the <code>colorPicker<\/code> function so i can manipulate them in all functions declared in the <em><code>colorPicker<\/code> closure<\/em>.<\/p>\n<p>Now you can create the picker next to a button clicked :<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\r\nvar btn = document.getElementById('btn1');\r\nbtn.addEventListener('click', function(){\r\n    colorPicker();\r\n});\r\n<\/pre>\n<h3>3.3 Remove picker on click<\/h3>\n<p>Ok, the color picker is displayed &#8220;<em>on demand<\/em>&#8221; &#8230; but we have to remove it, when the user has clicked on a color, or when the user click else where in the document.<\/p>\n<p>As we created a function <code>show<\/code> we will create a <code>remove<\/code> function :<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction remove(){\r\n    divElement.remove()\r\n}\r\n<\/pre>\n<p>And in the <em>click<\/em> on canvas event callback (at the end of the function), simply add a call to the <code>remove<\/code> function :<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\/\/ ---\r\n\/\/ Just after the browser has finished to load the image we can add it in the canvas\r\nimage.addEventListener('load', function () {\r\n    \r\n    \/\/ Display the palette\r\n    show();\r\n    \r\n    \/\/ Handle the click on the palette \r\n    canvasElement.addEventListener('click', function (event) {\r\n        \/\/ Get the position of the mouse in the Canvas\r\n        var x = event.pageX - this.offsetLeft;\r\n        var y = event.pageY - this.offsetTop;\r\n\r\n        \/\/ Get the Image Data\r\n        var imageData = canvasImage.getImageData(x, y, 1, 1).data;\r\n        \r\n        \/\/ Convert into readable variable\r\n        var Red = imageData&#x5B;0];\r\n        var Green = imageData&#x5B;1];\r\n        var Blue = imageData&#x5B;2];\r\n        var rgb = Red + ',' + Green + ',' + Blue;\r\n        \r\n        \/\/ Display the result in the console\r\n        console.log(rgb);\r\n\r\n        \/\/ The user has clicked a color, we can remove the picker\r\n        remove(); \r\n    });\r\n});\r\n\/\/ ---\r\n<\/pre>\n<p>In order to manage a sort of cancellation event, when the user click on the document but not on the canvas we add a <em>click<\/em> listener on window. This listener must be removed after element is removed.<\/p>\n<p>So edit the function as this :<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\/\/ ---\r\n\r\nfunction remove(){\r\n    divElement.remove();\r\n    \/\/ remove listener on window click\r\n    window.removeEventListener('click', remove);\r\n}\r\n\r\n\/\/ Just after the browser has finished to load the image we can add it in the canvas\r\nimage.addEventListener('load', function () {\r\n    \r\n    \/\/ Display the palette\r\n    show();\r\n    \r\n    \/\/ Handle the click on the palette \r\n    canvasElement.addEventListener('click', function (event) {\r\n        \/\/ Get the position of the mouse in the Canvas\r\n        var x = event.pageX - this.offsetLeft;\r\n        var y = event.pageY - this.offsetTop;\r\n\r\n        \/\/ Get the Image Data\r\n        var imageData = canvasImage.getImageData(x, y, 1, 1).data;\r\n        \r\n        \/\/ Convert into readable variable\r\n        var Red = imageData&#x5B;0];\r\n        var Green = imageData&#x5B;1];\r\n        var Blue = imageData&#x5B;2];\r\n        var rgb = Red + ',' + Green + ',' + Blue;\r\n        \r\n        \/\/ Display the result in the console\r\n        console.log(rgb);\r\n\r\n        \/\/ The user has clicked a color, we can remove the picker\r\n        remove(); \r\n    });\r\n\r\n    \/\/ It's a kind of cancellation a click\r\n    window.addEventListener('click', remove);\r\n});\r\n\/\/ ---\r\n<\/pre>\n<h3>3.4 Callback function<\/h3>\n<p>I think that the goal of a color picker is to retrieve a color, so we will add a call back function to our picker. This callback function will be called when the user choose a color :<\/p>\n<p>So add a parameter to the function signature :<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction colorPicker(onChoose){ \/* ...*\/ }\r\n<\/pre>\n<p>And in the <em>click<\/em> on canvas event callback, instead of logging the color simply call the callback, with the color &#8230; :<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\/\/ ---\r\n\/\/ Display the result in the console\r\nonChoose(rgb);\r\n\/\/ ---\r\n<\/pre>\n<p>And of course you need to edit the usage as this :<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar btn = document.getElementById('btn1');\r\nbtn.addEventListener('click', function(){\r\n   colorPicker(function(color){\r\n      console.log(color);\r\n   });\r\n});\r\n<\/pre>\n<h3>3.5 Convert to Hexadecimal<\/h3>\n<p>I&#8217;m don&#8217;t like the color value, I&#8217;d rather want to use a color in a hexadecimal value, so let&#8217;s create this color &#8230;<\/p>\n<p>As I don&#8217;t want to re-invent the wheel, I get the function to convert decimal value of the RGB into hexadecimal from this site : <a href=\"http:\/\/www.javascripter.net\/faq\/rgbtohex.htm\">http:\/\/www.javascripter.net\/faq\/rgbtohex.htm<\/a><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction rgbToHex(R,G,B) {return toHex(R)+toHex(G)+toHex(B)}\r\nfunction toHex(n) {\r\n   n = parseInt(n,10);\r\n   if (isNaN(n)) return &quot;00&quot;;\r\n   n = Math.max(0,Math.min(n,255));\r\n   return &quot;0123456789ABCDEF&quot;.charAt((n-n%16)\/16)  + &quot;0123456789ABCDEF&quot;.charAt(n%16);\r\n}\r\n<\/pre>\n<p>I added this two functions in the color picker and in the <em>click<\/em> on canvas event callback, I did this :<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\/\/ ---\r\n\r\n\/\/ Convert into readable variable\r\nvar Red = imageData&#x5B;0];\r\nvar Green = imageData&#x5B;1];\r\nvar Blue = imageData&#x5B;2];\r\n\r\n\/\/ Create HEXA Value\r\nvar color = rgbToHex(Red, Green, Blue);\r\n\r\n\/\/ Call the CallBack function with the color\r\ncallback('#'+color);\r\nremove();\r\n\r\n\/\/ ---\r\n<\/pre>\n<blockquote><p><strong>NOTE<\/strong>: I add the <code>#<\/code> character to make the color usable in HTML document.<\/p><\/blockquote>\n<figure id=\"attachment_4345\" aria-describedby=\"caption-attachment-4345\" style=\"width: 800px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/html5_color_picker_example_2.png\"><img decoding=\"async\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/html5_color_picker_example_2.png\" alt=\"HTML5 Color picker example 2\" width=\"800\" height=\"600\" class=\"size-full wp-image-4345\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/html5_color_picker_example_2.png 800w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/html5_color_picker_example_2-300x225.png 300w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><figcaption id=\"caption-attachment-4345\" class=\"wp-caption-text\">HTML5 Color picker example 2<\/figcaption><\/figure>\n<p>Voila ! The color picker is now reusable !<\/p>\n<h3>4. Download<\/h3>\n<div class=\"download\"><strong>Download<\/strong><br \/>\n    You can download the full source code of this example here: <a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/04\/html5_color_picker_example.zip\"><strong>HTML5 color picker example<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this article I will show you how to create a Color Picker using HTML5 Canvas API. I&#8217;ll first present you the API we&#8217;ll use. Then we&#8217;ll create a &#8220;color picker&#8221; you can reuse in your applications. This article will not present the use of the new &lt;input type=&#8221;color&#8221; \/&gt;. 1. Introduction The way to &hellip;<\/p>\n","protected":false},"author":46,"featured_media":914,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-4278","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-html5"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>HTML5 Color picker example - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"In this article I will show you how to create a Color Picker using HTML5 Canvas API. I&#039;ll first present you the API we&#039;ll use. Then we&#039;ll create a &quot;color\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"HTML5 Color picker example - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"In this article I will show you how to create a Color Picker using HTML5 Canvas API. I&#039;ll first present you the API we&#039;ll use. Then we&#039;ll create a &quot;color\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2015-05-18T09:15:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-12-19T12:02:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Remi Goyard\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@mimiz33\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Remi Goyard\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/\"},\"author\":{\"name\":\"Remi Goyard\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/ae15332f888fcdc376a8d4e03180e242\"},\"headline\":\"HTML5 Color picker example\",\"datePublished\":\"2015-05-18T09:15:47+00:00\",\"dateModified\":\"2017-12-19T12:02:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/\"},\"wordCount\":1763,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\",\"articleSection\":[\"HTML5\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/\",\"name\":\"HTML5 Color picker example - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\",\"datePublished\":\"2015-05-18T09:15:47+00:00\",\"dateModified\":\"2017-12-19T12:02:14+00:00\",\"description\":\"In this article I will show you how to create a Color Picker using HTML5 Canvas API. I'll first present you the API we'll use. Then we'll create a \\\"color\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"HTML5\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/html5\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"HTML5 Color picker example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/ae15332f888fcdc376a8d4e03180e242\",\"name\":\"Remi Goyard\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/caa839a88ba9d485eec370ff8e020c314f10fb2e4ddedb3424a4bf92198259b2?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/caa839a88ba9d485eec370ff8e020c314f10fb2e4ddedb3424a4bf92198259b2?s=96&d=mm&r=g\",\"caption\":\"Remi Goyard\"},\"description\":\"I'm a senior web architect. Passionated by new technologies, programming, devops tools, and agile methodologies. I really enjoy to coach, or teach, people who wants to learn programming, from beginners to skilled programmers. Involved in local developer communities, Java User Group, PHP User Group, or Javascript User Group, i like to share with others about experiences, news or business. Coding is FUN !\",\"sameAs\":[\"http:\/\/www.mimiz.fr\/\",\"http:\/\/fr.linkedin.com\/in\/remigoyard\/en\",\"https:\/\/x.com\/@mimiz33\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/remi-goyard\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"HTML5 Color picker example - Web Code Geeks - 2026","description":"In this article I will show you how to create a Color Picker using HTML5 Canvas API. I'll first present you the API we'll use. Then we'll create a \"color","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/","og_locale":"en_US","og_type":"article","og_title":"HTML5 Color picker example - Web Code Geeks - 2026","og_description":"In this article I will show you how to create a Color Picker using HTML5 Canvas API. I'll first present you the API we'll use. Then we'll create a \"color","og_url":"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_published_time":"2015-05-18T09:15:47+00:00","article_modified_time":"2017-12-19T12:02:14+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","type":"image\/jpeg"}],"author":"Remi Goyard","twitter_card":"summary_large_image","twitter_creator":"@mimiz33","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Remi Goyard","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/"},"author":{"name":"Remi Goyard","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/ae15332f888fcdc376a8d4e03180e242"},"headline":"HTML5 Color picker example","datePublished":"2015-05-18T09:15:47+00:00","dateModified":"2017-12-19T12:02:14+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/"},"wordCount":1763,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","articleSection":["HTML5"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/","url":"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/","name":"HTML5 Color picker example - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","datePublished":"2015-05-18T09:15:47+00:00","dateModified":"2017-12-19T12:02:14+00:00","description":"In this article I will show you how to create a Color Picker using HTML5 Canvas API. I'll first present you the API we'll use. Then we'll create a \"color","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/html5-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/html5\/html5-color-picker-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"HTML5","item":"https:\/\/www.webcodegeeks.com\/category\/html5\/"},{"@type":"ListItem","position":3,"name":"HTML5 Color picker example"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/ae15332f888fcdc376a8d4e03180e242","name":"Remi Goyard","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/caa839a88ba9d485eec370ff8e020c314f10fb2e4ddedb3424a4bf92198259b2?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/caa839a88ba9d485eec370ff8e020c314f10fb2e4ddedb3424a4bf92198259b2?s=96&d=mm&r=g","caption":"Remi Goyard"},"description":"I'm a senior web architect. Passionated by new technologies, programming, devops tools, and agile methodologies. I really enjoy to coach, or teach, people who wants to learn programming, from beginners to skilled programmers. Involved in local developer communities, Java User Group, PHP User Group, or Javascript User Group, i like to share with others about experiences, news or business. Coding is FUN !","sameAs":["http:\/\/www.mimiz.fr\/","http:\/\/fr.linkedin.com\/in\/remigoyard\/en","https:\/\/x.com\/@mimiz33"],"url":"https:\/\/www.webcodegeeks.com\/author\/remi-goyard\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/4278","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/46"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=4278"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/4278\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/914"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=4278"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=4278"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=4278"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}