HTML Snippet
HTML Permissions Elements
Native <geolocation> and <usermedia> elements that handle permission flows without JavaScript.
Last updated: October 2026
Experimental feature: The <geolocation> and <usermedia> elements are proposals from the WICG (Web Incubator Community Group). They are behind feature flags in Chrome Canary and are not yet in production browsers. This page explains the concepts so you're ready when they ship.
Quick answer: These elements wrap content that needs permission. If the user grants access, the content renders. If they deny, fallback content shows. The autolocate and autoplaycamera attributes trigger the permission prompt automatically. The goal: eliminate the JavaScript-heavy permission flows currently required on every site.
🎬 Visual Reference
How the permission flow works — from trigger to result.
The browser shows the native permission prompt. The user clicks "Allow." The content inside <geolocation> or <usermedia> renders normally. No JavaScript needed.
The content is hidden. A fallback element (like a "Try again" button or an explanation) is shown instead. This is the recovery UI that used to require manual JavaScript.
The browser remembers the denial. On the next visit, the element renders fallback content. The user can re-prompt using the browser's built-in site settings — no custom recovery UI required.
Adding the autolocate attribute to <geolocation> (or autoplaycamera to <usermedia>) triggers the permission prompt as soon as the element renders.
The Problem: Permission Flows Are Painful
Today, handling location or camera permission requires a lot of JavaScript:
// Current JavaScript-based approach
async function getLocation() {
try {
// 1. Check if the API exists
if (!navigator.geolocation) {
showFallback("Your browser doesn't support location.");
return;
}
// 2. Check current permission state
const permission = await navigator.permissions.query({
name: "geolocation"
});
// 3. Handle denied state (need to instruct user)
if (permission.state === "denied") {
showRecoveryUI("Enable location in browser settings.");
return;
}
// 4. Request the position
navigator.geolocation.getCurrentPosition(
(position) => showMap(position.coords),
(error) => handleError(error)
);
} catch (err) {
showFallback(err.message);
}
}
That's ~25 lines of JavaScript just to handle one permission. And this code is repeated on every site that needs location.
The Solution: Native Permission Elements
The proposed elements handle the entire flow declaratively:
<geolocation autolocate>
<!-- This content renders only when location is granted -->
<my-map-component></my-map-component>
<!-- This fallback shows when permission is denied -->
<fallback>
<p>Location access is needed to show nearby stores.</p>
<button onclick="navigator.permissions.request... ">
Try again
</button>
</fallback>
</geolocation>
What the browser handles for you:
- Showing the permission prompt.
- Rendering the content when granted.
- Rendering fallback when denied.
- Remembering the user's choice across visits.
- Integrating with browser-level site settings for recovery.
The geolocation Element
<geolocation autolocate>
<nearby-stores></nearby-stores>
<fallback>
<p>We need your location to find nearby stores.</p>
<button id="retry-location">Enable location</button>
</fallback>
</geolocation>
Attributes:
autolocate— requests permission as soon as the element renders.- Without it, the element waits for a user gesture to trigger the prompt.
Children:
- Default content — shown when permission is granted.
<fallback>— shown when permission is denied.
The usermedia Element
<usermedia autoplaycamera audio>
<video id="preview" autoplay playsinline></video>
<button id="capture">Capture Photo</button>
<fallback>
<p>Camera access is needed for this feature.</p>
<button id="retry-camera">Enable camera</button>
</fallback>
</usermedia>
Attributes:
autoplaycamera— requests camera permission immediately.audio— also requests microphone access.
Children: Same as <geolocation> — default content plus optional <fallback>.
What This Replaces
Here's the same feature with the current JavaScript approach vs the native elements:
| Aspect | JavaScript (today) | Native Elements |
|---|---|---|
| Lines of code | ~25 | ~5 |
| Permission check | Manual | Automatic |
| Fallback UI | Manual | Declarative |
| Recovery flow | Manual | Browser-handled |
| Cross-browser consistency | Inconsistent | Standardized |
🎯 Production Alternative Today
While waiting for these elements to ship, use the Permissions API to build cleaner flows:
// Wrapper that mimics the future API
async function withPermission(permissionName, onGranted, onDenied) {
const status = await navigator.permissions.query({ name: permissionName });
status.onchange = () => {
if (status.state === "granted") onGranted();
else if (status.state === "denied") onDenied();
};
if (status.state === "granted") onGranted();
else if (status.state === "denied") onDenied();
else {
// Trigger the actual prompt via the relevant API
try {
await navigator.geolocation.getCurrentPosition(
() => onGranted(),
() => onDenied(),
{ timeout: 100 }
);
} catch {
onDenied();
}
}
}
// Usage — mirrors the future element-based approach
withPermission(
"geolocation",
() => showMap(),
() => showFallback()
);
This gives you the structure that the native elements will eventually provide.
⚠️ Common Mistakes
- Using these elements in production now. They are not yet supported. Use the Permissions API instead.
- Forgetting the
autolocateattribute. Without it, the element won't request permission automatically. - Not providing a
<fallback>. Users who deny permission will see a broken experience. Always include fallback content. - Expecting consistent behavior across browsers. The spec is still evolving. Test in Chrome Canary.
- Assuming the recovery flow is automatic. Users who deny still need browser-level settings to re-enable. Provide clear instructions.
- Ignoring privacy implications. Location and camera access are sensitive. Only request them when you genuinely need them.
❓ Frequently Asked Questions
What is the HTML geolocation element?
The <geolocation> element is a proposed HTML element that wraps location-requesting content. If the user grants permission, the content inside renders. If they deny, the content is hidden and you can provide fallback content. It replaces the JavaScript-heavy permission flows currently required.
What is the HTML usermedia element?
The <usermedia> element is a proposed HTML element that wraps content needing camera or microphone access. It handles the permission prompt, the recovery flow when access is denied, and the fallback UI — all without JavaScript.
Are the geolocation and usermedia elements supported in browsers?
As of 2026, these elements are experimental and behind feature flags in Chrome. They are part of a WICG proposal and are not yet in production. You can enable them in Chrome Canary to test.
Why would I use these elements instead of JavaScript?
Permission handling is the #1 source of user frustration. Native elements handle the entire flow: requesting, granting, denying, recovering from denial, and showing fallback UI. This eliminates hundreds of lines of JavaScript per project.
Should I use these elements in production now?
No. They are not yet standardized or widely supported. Use them in prototypes and prepare for adoption as browser support matures. In the meantime, use the Permissions API with JavaScript for production apps.