{"id":503,"date":"2024-01-18T10:25:43","date_gmt":"2024-01-18T16:25:43","guid":{"rendered":"https:\/\/frontendmasters.com\/blog\/?p=503"},"modified":"2024-11-14T15:46:12","modified_gmt":"2024-11-14T20:46:12","slug":"the-color-input-the-color-picker","status":"publish","type":"post","link":"https:\/\/frontendmasters.com\/blog\/the-color-input-the-color-picker\/","title":{"rendered":"The Color Input &#038; The Color Picker"},"content":{"rendered":"\n<p>HTML has <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Element\/input\/color\">a color input<\/a> that is pretty decent:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">input<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"color\"<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>That&#8217;s it. <a href=\"https:\/\/caniuse.com\/input-color\">Support across the board<\/a>. However, browsers can and do have different approaches to what happens when the input is used. <\/p>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-full is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"654\" height=\"718\" src=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/macos-color-input.png?resize=654%2C718&#038;ssl=1\" alt=\"\" class=\"wp-image-508\" style=\"width:274px;height:auto\" srcset=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/macos-color-input.png?w=654&amp;ssl=1 654w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/macos-color-input.png?resize=273%2C300&amp;ssl=1 273w\" sizes=\"auto, (max-width: 654px) 100vw, 654px\" \/><figcaption class=\"wp-element-caption\">macOS Chrome (has it&#8217;s own UI)<\/figcaption><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"946\" height=\"886\" src=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/macos-color-picker.png?resize=946%2C886&#038;ssl=1\" alt=\"\" class=\"wp-image-4427\" srcset=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/macos-color-picker.png?w=946&amp;ssl=1 946w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/macos-color-picker.png?resize=300%2C281&amp;ssl=1 300w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/macos-color-picker.png?resize=768%2C719&amp;ssl=1 768w\" sizes=\"auto, (max-width: 946px) 100vw, 946px\" \/><figcaption class=\"wp-element-caption\">macOS Firefox (uses the macOS system color picker)<\/figcaption><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"708\" height=\"608\" src=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/safari-color-picker.png?resize=708%2C608&#038;ssl=1\" alt=\"\" class=\"wp-image-4428\" srcset=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/safari-color-picker.png?w=708&amp;ssl=1 708w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/safari-color-picker.png?resize=300%2C258&amp;ssl=1 300w\" sizes=\"auto, (max-width: 708px) 100vw, 708px\" \/><figcaption class=\"wp-element-caption\">macOS Safari (has it&#8217;s own UI, allows you to open macOS system color picker)<\/figcaption><\/figure>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-full is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"652\" height=\"652\" src=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/windows-chrome-color-picker.png?resize=652%2C652&#038;ssl=1\" alt=\"\" class=\"wp-image-4429\" style=\"width:274px;height:auto\" srcset=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/windows-chrome-color-picker.png?w=652&amp;ssl=1 652w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/windows-chrome-color-picker.png?resize=300%2C300&amp;ssl=1 300w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/windows-chrome-color-picker.png?resize=150%2C150&amp;ssl=1 150w\" sizes=\"auto, (max-width: 652px) 100vw, 652px\" \/><figcaption class=\"wp-element-caption\">Windows Chrome (has it&#8217;s own UI) (Edge looks the same)<\/figcaption><\/figure>\n\n\n\n<p><\/p>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"873\" src=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/windows-firefox-color-picker.png?resize=1024%2C873&#038;ssl=1\" alt=\"\" class=\"wp-image-4430\" srcset=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/windows-firefox-color-picker.png?w=1024&amp;ssl=1 1024w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/windows-firefox-color-picker.png?resize=300%2C256&amp;ssl=1 300w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/windows-firefox-color-picker.png?resize=768%2C655&amp;ssl=1 768w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><figcaption class=\"wp-element-caption\">Window Firefox (uses the Windows system color picker)<\/figcaption><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"736\" height=\"1024\" src=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/chrome-android.png?resize=736%2C1024&#038;ssl=1\" alt=\"\" class=\"wp-image-4432\" srcset=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/chrome-android.png?w=736&amp;ssl=1 736w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/chrome-android.png?resize=216%2C300&amp;ssl=1 216w\" sizes=\"auto, (max-width: 736px) 100vw, 736px\" \/><figcaption class=\"wp-element-caption\">Chrome on Android (Pixel 8)<\/figcaption><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<figure class=\"wp-block-image size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"793\" height=\"1024\" src=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/safari-ios17.png?resize=793%2C1024&#038;ssl=1\" alt=\"\" class=\"wp-image-4433\" srcset=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/safari-ios17.png?w=793&amp;ssl=1 793w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/safari-ios17.png?resize=232%2C300&amp;ssl=1 232w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/safari-ios17.png?resize=768%2C992&amp;ssl=1 768w\" sizes=\"auto, (max-width: 793px) 100vw, 793px\" \/><figcaption class=\"wp-element-caption\">Safari on iOS 17<\/figcaption><\/figure>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><\/div>\n<\/div>\n\n\n\n<p>Ultimately: the user activates the input, may choose a color using the provided UI, and the color becomes the inputs value.<\/p>\n\n\n\n<p class=\"learn-more\">It&#8217;s not my favorite that you can <em>only<\/em> get 6-digit HEX colors in and out of it, like <code>#F06D06<\/code> and the like. No transparency, no other formats. I have a feeling display-p3 color formats like OKLCH will have a real popularity boom in coming years (because they are sweet: more colors, more logical) and we&#8217;ll start wanting better integration, like with color inputs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Eyedropper<\/h2>\n\n\n\n<p>Note that <em>some<\/em> of those color panels have an eyedropper function. Those are awfully handy. Sometimes the color I&#8217;m shooting for is right on my screen somewhere, and a color eyedropper is the fastest and easiest way to grab it. <\/p>\n\n\n\n<p>Turns out <a href=\"https:\/\/developer.chrome.com\/docs\/capabilities\/web-apis\/eyedropper\">there is a native API for an eyedropper<\/a>! You don&#8217;t <em>have<\/em> to use a color input to access an eyedropper. <\/p>\n\n\n\n<p>You can test for support like:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">if<\/span> (<span class=\"hljs-string\">\"EyeDropper\"<\/span> <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-built_in\">window<\/span>) {\n  \n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>And use it like:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-comment\">\/\/ used in case you need to cancel the experience<\/span>\n<span class=\"hljs-keyword\">const<\/span> abortController = <span class=\"hljs-keyword\">new<\/span> AbortController();\n\n<span class=\"hljs-keyword\">const<\/span> eyeDropper = <span class=\"hljs-keyword\">new<\/span> EyeDropper();\n\n<span class=\"hljs-keyword\">try<\/span> {\n  <span class=\"hljs-keyword\">const<\/span> result = <span class=\"hljs-keyword\">await<\/span> eyeDropper.open({ <span class=\"hljs-attr\">signal<\/span>: abortController.signal });\n  <span class=\"hljs-built_in\">console<\/span>.log(result.sRGBHex);\n} <span class=\"hljs-keyword\">catch<\/span> (e) {\n  <span class=\"hljs-built_in\">console<\/span>.error(e);\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Demo<\/h2>\n\n\n\n<div class=\"wp-block-cp-codepen-gutenberg-embed-block cp_embed_wrapper\"><iframe id=\"cp_embed_jOJVKya\" src=\"\/\/codepen.io\/anon\/embed\/jOJVKya?height=450&amp;theme-id=47434&amp;slug-hash=jOJVKya&amp;default-tab=result\" height=\"450\" scrolling=\"no\" frameborder=\"0\" allowfullscreen allowpaymentrequest name=\"CodePen Embed jOJVKya\" title=\"CodePen Embed jOJVKya\" class=\"cp_embed_iframe\" style=\"width:100%;overflow:hidden\">CodePen Embed Fallback<\/iframe><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Anywhere you use a color input, you might as well offer an eyedropper, too. <\/h2>\n\n\n\n<p>Test for support first, of course, but I think that statement above largely holds true. Offering a dedicated eyedropper button means saving users a step in case that&#8217;s what they are trying to do anyway.<\/p>\n\n\n\n<p>And using the native one is nice, as I find it&#8217;s generally a nicer color picker than anything integrated into app itself. Eyedroppers built into <em>very major<\/em> design tools like Adobe Photoshop and Figma largely only let you pick colors from inside the documents themselves, not from anywhere on the screen. Boooo. <\/p>\n\n\n\n<p>The demo above shows how a color input and eyedropper button can work together right next to each other. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Support<\/h2>\n\n\n\n<p>Support for color inputs is good across the board, but <a href=\"https:\/\/caniuse.com\/?search=eyedropper\">support for the EyeDropper API<\/a>, at the time of this writing, is just Chrome&#8217;n&#8217;friends. No Safari or Firefox. <\/p>\n\n\n\n<p>But the real UX story isn&#8217;t quite that clear. <\/p>\n\n\n\n<p>In Firefox, the color input opens the native color picker (both macOS and Windows) and that native picker has an eyedropper. So Firefox users have decently quick access if they need it. <\/p>\n\n\n\n<p>In Safari, the native color picker is an extra click away, but it&#8217;s still gettable. <\/p>\n\n\n\n<p>Chrome on Android has no support.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"alignright size-full is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"931\" height=\"1024\" src=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/example-picker-1.png?resize=931%2C1024&#038;ssl=1\" alt=\"\" class=\"wp-image-4436\" style=\"width:314px;height:auto\" srcset=\"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/example-picker-1.png?w=931&amp;ssl=1 931w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/example-picker-1.png?resize=273%2C300&amp;ssl=1 273w, https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/example-picker-1.png?resize=768%2C845&amp;ssl=1 768w\" sizes=\"auto, (max-width: 931px) 100vw, 931px\" \/><\/figure>\n<\/div>\n\n\n<p>I would have assumed iOS didn&#8217;t either, and it&#8217;s true that it doesn&#8217;t support the <code>EyeDropper<\/code> API, but in a quick play of iOS 17 on an iPhone 15, the native UI for a color picker has an eye dropper (!!). That&#8217;s pretty cool. I would think that brings Safari generally a lot closer to offering the API directly.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>HTML has a color input that is pretty decent: That&#8217;s it. Support across the board. However, browsers can and do have different approaches to what happens when the input is used. Ultimately: the user activates the input, may choose a color using the provided UI, and the color becomes the inputs value. It&#8217;s not my [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":573,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[81,80,31,3],"class_list":["post-503","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-post","tag-color","tag-eyedropper","tag-html","tag-javascript"],"acf":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/eyedropper-thumb.jpg?fit=1000%2C500&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/503","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/comments?post=503"}],"version-history":[{"count":18,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/503\/revisions"}],"predecessor-version":[{"id":4437,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/503\/revisions\/4437"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media\/573"}],"wp:attachment":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media?parent=503"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/categories?post=503"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/tags?post=503"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}