The EyeDropper API: Pick Any Pixel Color on the Screen

eyedropper dispensing essence on a white background, emphasizing precision application and product safety

Modern creative tools often include an eyedropper so you can sample a color from an illustration and reuse it elsewhere. The EyeDropper API brings that same idea to the web: it lets a web app enter an “eyedropper mode” where a user can click any pixel on their screen—even outside the browser window—and return the selected color.

What it does

With the EyeDropper API, your app can:

This makes it great for design tools, theme editors, drawing apps, and any UI that benefits from quick color sampling.

Security and privacy: why it’s designed this way

Sampling colors from the screen touches sensitive territory, so the API includes strong guardrails to prevent abuse:

Availability notes you shouldn’t ignore

MDN flags the EyeDropper API as:

That means it’s best used with feature detection and a fallback UI for unsupported environments.

				
					<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Eyedropper API Demo</title>
    <link href="style.css" rel="stylesheet" />
    <script src="eyedropperAPI.js" defer></script>
</head>
    
<body>
    <div class="container">
        <h1>EyeDropper API Demo</h1>
        <p>Click the button to pick a color from anywhere on your screen!</p>
    
        <!-- Button to trigger the EyeDropper -->
        <button id="pickColorBtn">Pick a Color</button>
    
        <!-- Area to display the selected color and its hex value -->
        <div class="result-area">
            <h2>Selected Color:</h2>
            <div id="colorSwatch" class="color-swatch"></div>
            <p>Hex Value: <span id="hexValue">N/A</span></p>
        </div>
    
        <p class="compatibility-note">
            Note: This API is experimental and works primarily in Chromium-based browsers (Chrome, Edge, Opera) over HTTPS.
        </p>
    </div>

</body>

</html>
				
			
				
					body {
    font-family: Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    background-color: #f4f4f4;
    color: #333;
}

.container {
    background-color: #fff;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    text-align: center;
    max-width: 500px;
    width: 90%;
}

h1 {
    color: #0056b3;
    margin-bottom: 20px;
}

p {
    margin-bottom: 25px;
    line-height: 1.6;
}

button {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 12px 25px;
    font-size: 1.1em;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

button:hover {
    background-color: #0056b3;
}

.result-area {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #eee;
}

.color-swatch {
    width: 80px;
    height: 80px;
    border: 2px solid #ccc;
    margin: 15px auto;
    border-radius: 50%;
    background-color: transparent;
    /* Default state */
    transition: background-color 0.3s ease;
}

#hexValue {
    font-weight: bold;
    color: #0056b3;
}

.compatibility-note {
    font-size: 0.85em;
    color: #666;
    margin-top: 40px;
}
				
			
				
					// Get references to DOM elements
const pickColorBtn = document.querySelector('#pickColorBtn');
const colorSwatch = document.querySelector('#colorSwatch');
const hexValueSpan = document.querySelector('#hexValue');

// Add an event listener to the button
pickColorBtn.addEventListener('click', async () => {
	// 1. Feature Detection: Check if the EyeDropper API is supported by the browser
	if (!window.EyeDropper) {
		alert(
			'Your browser does not support the EyeDropper API. Try Chrome, Edge, or Opera over HTTPS.'
		);
		return; // Exit if not supported
	}

	// 2. Instantiate EyeDropper: Create a new instance of the EyeDropper object
	const eyeDropper = new EyeDropper();

	try {
		// 3. Open the EyeDropper: Call the open() method to activate the eyedropper tool.
		// This method returns a Promise that resolves with the selected color's sRGBHex value.
		const { sRGBHex } = await eyeDropper.open();

		// 4. Update UI: If a color is successfully picked, update the color swatch and display its hex value.
		colorSwatch.style.backgroundColor = sRGBHex;
		hexValueSpan.textContent = sRGBHex;

		console.log(`Color picked: ${sRGBHex}`); // Log the selected color to the console
	} catch (error) {
		// 5. Error Handling: If the user cancels the eyedropper (e.g., by pressing Escape),
		// or if there's any other error, the Promise will reject.
		console.error('EyeDropper operation cancelled or failed:', error);
		hexValueSpan.textContent = 'N/A'; // Reset display
		colorSwatch.style.backgroundColor = 'transparent'; // Reset swatch
		alert('Color picking cancelled or an error occurred.');
	}
});

// Initial state for the color swatch (transparent)
colorSwatch.style.backgroundColor = 'transparent';
				
			

The key interface

The main interface is EyeDropper, which represents an eyedropper tool instance that you can open for the user to select a color from the screen.

If you’re building a creative or customization-focused web app, the EyeDropper API can make color picking feel native and effortless—just be sure to account for browser support and the secure-context requirement.

more posts:
Online video streaming platform and digital content management concept with media player interface, cloud library, and multimedia files on laptop, representing content distribution, video marketing
Code

Breaking into the Pipeline: Real-Time Frame Manipulation with the Insertable Streams for MediaStreamTrack API

The experimental Insertable Streams for MediaStreamTrack API closes a long-standing gap in web multimedia by treating live camera feeds as standard Web Streams. By piping individual VideoFrame objects through a TransformStream and recording the transformed output via MediaRecorder, developers can execute frame-by-frame processing—like real-time filtering, watermarking, and computer vision overlays—without relying on hidden canvas hacks.

Discover More »
Apps & Custom Software

What Building Our Own App Taught Us About Building Yours

When Hess WebTech built and launched Tericipe—an Android app that turns printed recipes into a searchable digital collection—in under three months, we had to live with every decision we usually advise clients on. From testing against real-world messy data and handling AI uncertainty to server-side payment security and post-launch maintenance, here are five crucial lessons from our own build that apply to almost any software project.

Discover More »