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.
EyeDropper() Experimental
Returns a new EyeDropper instance.
The EyeDropper interface doesn't inherit any methods.
EyeDropper.open() Experimental
Returns a promise that resolves to an object that gives access to the selected 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.
<button id="start-button">Open the eyedropper</button> <span id="result"></span>
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;
});
});
This example shows that the eyedropper mode can also be aborted before the user has selected a color or pressed Escape.
<button id="start-button">Open the eyedropper</button> <span id="result"></span>
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);
});
| Specification |
|---|
| EyeDropper API> # eyedropper-interface> |
| 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 |
95 | 95 | No | 81 | No | No | No | No | No | No | No | No |
EyeDropper |
95 | 95 | No | 81 | No | No | No | No | No | No | No | No |
open |
95 | 95 | No | 81 | No | No | No | No | No | No | No | No |
secure_context_required |
96 | 96 | No | No | No | No | No | No | No | No | No | No |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/EyeDropper