EyeDropper

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The EyeDropper interface represents an instance of an eyedropper tool that can be opened and used by the user to select colors from the screen.

Constructor

EyeDropper()

Returns a new EyeDropper instance.

Instance methods

The EyeDropper interface doesn't inherit any methods.

EyeDropper.open()

Returns a promise that resolves to an object that gives access to the selected color.

Examples

Opening the eyedropper tool and sampling a color

This example shows how to open an eyedropper tool and wait for the user to either select a pixel from the screen, or press Escape to cancel the eyedropper mode.

HTML

html
<button id="start-button">Open the eyedropper</button> <span id="result"></span>

JavaScript

js
document.getElementById("start-button").addEventListener("click", () => {
  const resultElement = document.getElementById("result");

  if (!window.EyeDropper) {
    resultElement.textContent =
      "Your browser does not support the EyeDropper API";
    return;
  }

  const eyeDropper = new EyeDropper();

  eyeDropper
    .open()
    .then((result) => {
      resultElement.textContent = result.sRGBHex;
      resultElement.style.backgroundColor = result.sRGBHex;
    })
    .catch((e) => {
      resultElement.textContent = e;
    });
});

Result

Aborting the eyedropper mode

This example shows that the eyedropper mode can also be aborted before the user has selected a color or pressed Escape.

HTML

html
<button id="start-button">Open the eyedropper</button> <span id="result"></span>

JavaScript

js
document.getElementById("start-button").addEventListener("click", () => {
  const resultElement = document.getElementById("result");

  if (!window.EyeDropper) {
    resultElement.textContent =
      "Your browser does not support the EyeDropper API";
    return;
  }

  const eyeDropper = new EyeDropper();
  const abortController = new AbortController();

  eyeDropper
    .open({ signal: abortController.signal })
    .then((result) => {
      resultElement.textContent = result.sRGBHex;
      resultElement.style.backgroundColor = result.sRGBHex;
    })
    .catch((e) => {
      resultElement.textContent = e;
    });

  setTimeout(() => {
    abortController.abort();
  }, 2000);
});

Result

Specifications

Specification
EyeDropper API
# eyedropper-interface

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
EyeDropper
Experimental
Chrome – Full support
Chrome 95 (Release date: 2021-10-19)
footnote
footnote Before Chrome 120, the EyeDropper API is not available on ChromeOS. See bug 40720753.
footnote Available on Linux X11, but not available on Linux Wayland. See bug 40720753.
Edge – Full support
Edge 95 (Release date: 2021-10-21)
footnote
footnote Before Edge 120, the EyeDropper API is not available on ChromeOS. See bug 40720753.
footnote Available on Linux X11, but not available on Linux Wayland. See bug 40720753.
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 81 (Release date: 2021-11-04)
footnote
footnote Before Opera 106, the EyeDropper API is not available on ChromeOS. See bug 40720753.
footnote Available on Linux X11, but not available on Linux Wayland. See bug 40720753.
Safari – No support
Safari
footnote No support
Chrome Android – No support
Chrome Android
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote
footnote See bug 40791573
WebView on iOS – No support
WebView on iOS
footnote No support
EyeDropper() constructor
Experimental
Chrome – Full support
Chrome 95 (Release date: 2021-10-19)
footnote Full support
Edge – Full support
Edge 95 (Release date: 2021-10-21)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 81 (Release date: 2021-11-04)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – No support
Chrome Android
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support
open
Experimental
Chrome – Full support
Chrome 95 (Release date: 2021-10-19)
footnote Full support
Edge – Full support
Edge 95 (Release date: 2021-10-21)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 81 (Release date: 2021-11-04)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – No support
Chrome Android
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support
Secure context required
Experimental
Chrome – Full support
Chrome 96 (Release date: 2021-11-15)
footnote Full support
Edge – Full support
Edge 96 (Release date: 2021-11-19)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Chrome Android – No support
Chrome Android
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.