HTML <geolocation> Tag

The <geolocation> element creates an interactive, browser-defined control for sharing the user’s location with the page. It provides a built-in UI, permission flow, and a DOM API (HTMLGeolocationElement) for reading position data and errors.

This is the tag documentation at /html/tags/geolocation. For the classic JavaScript Geolocation API tutorial (navigator.geolocation), see /html/geolocation.

Experimental · Limited availability.

Not Baseline. Prefer progressive enhancement with a fallback button that uses the Geolocation API until support is wider.

Under the hood.

Default behavior is like getCurrentPosition(). With watch, updates work like watchPosition().

HTML Syntax

syntax.html
<geolocation autolocate watch>fallback</geolocation>

Both start and end tags are required. Put fallback content between the tags for unsupported browsers.

Attributes

Besides global attributes, <geolocation> defines boolean attributes:

AttributeDescriptionTry it
autolocateBoolean. Request location on render only if permission was previously granted. Default: offTry it
watchBoolean. Continuously update as the device moves. Default: one-shotTry it
Fallback contentChildren shown when the element is not supported (message or button)Try it
langHelps the browser pick the control’s label languageGlobal attribute

Global Attributes

The <geolocation> tag also supports the Global Attributes in HTML.

Live Preview

Markup only in unsupported browsers shows the fallback. Supporting browsers replace it with the native control.

Experimental element. Expect the fallback button/message unless your browser supports it.

Preview

Basic · fallback button for unsupported browsers

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Element with Fallback

Unsupported browsers show the nested button; supporting ones show the native control.

HTML
<geolocation>
  <button id="fallback">Use location</button>
</geolocation>
<p id="output"></p>

<script>
  const output = document.querySelector("#output");
  if (typeof HTMLGeolocationElement === "function") {
    const geo = document.querySelector("geolocation");
    geo.addEventListener("location", () => {
      if (geo.position) {
        output.textContent =
          geo.position.coords.latitude + ", " +
          geo.position.coords.longitude;
      } else if (geo.error) {
        output.textContent = geo.error.message;
      }
    });
  } else {
    document.querySelector("#fallback").addEventListener("click", () => {
      navigator.geolocation.getCurrentPosition(
        (pos) => {
          output.textContent =
            pos.coords.latitude + ", " + pos.coords.longitude;
        },
        (err) => { output.textContent = err.message; }
      );
    });
  }
</script>
Try It Yourself

How It Works

  1. Nest a fallback <button> for browsers without the element.
  2. Feature-detect with typeof HTMLGeolocationElement === "function".
  3. Listen for location on the element when supported.
  4. Call navigator.geolocation from the fallback otherwise (see Geolocation API).

Example 2 — autolocate

Request location on render only if permission was already granted.

HTML
<geolocation autolocate>
  <p>Your browser doesn't support the Geolocation element.</p>
</geolocation>
Try It Yourself

How It Works

  1. Add the boolean autolocate attribute.
  2. Prior grant required — otherwise the attribute does nothing until activation.
  3. Keep fallback content for unsupported browsers.
  4. Still handle permission denial via the element’s error/position API.

Example 3 — watch Continuous Updates

Update coordinates as the device moves.

HTML
<geolocation watch>
  <button id="fallback-watch">Watch location</button>
</geolocation>
<p id="watch-output"></p>
Try It Yourself

How It Works

  1. Add boolean watch for continuous updates.
  2. Listen for location each time a new position arrives.
  3. Read geo.position or geo.error on the element.
  4. Fallback path: use navigator.geolocation.watchPosition() (see API tutorial).

Edge Cases & Pitfalls

quota

Max three per page

Browsers may disable all <geolocation> elements if more than three appear on one page.

blocking

Invalid / blocked controls

Anti-abuse rules can mark an element invalid (check isValid / invalidReason). Conscious user activation is required.

css

Strict styling limits

Contrast, font-size, and other CSS constraints apply. Violations can deactivate the control.

secure

Secure contexts

Location APIs need HTTPS (or localhost). Insecure origins will fail like the classic API.

api

Do not confuse with the tutorial URL

/html/geolocation is the Geolocation API guide. This page is the HTML tag at /html/tags/geolocation.

support

Always ship a fallback

Firefox and Safari may not support the element yet. Nest a button that uses navigator.geolocation.

Browser Support

The <geolocation> element is experimental HTML with limited availability. It is not a Node.js, Deno, or Bun API.

✓ Experimental · Limited

<geolocation>

Not Baseline. Early support in Chromium-based browsers (for example Chrome/Edge around 144+). Firefox and Safari: not supported yet — use a Geolocation API fallback.

30% Global support (approx.)
Google Chrome 144+
Supported (exp.)
Mozilla Firefox —
Not supported
Apple Safari —
Not supported
Microsoft Edge 144+
Supported (exp.)
Opera 131+
Supported (exp.)
Samsung Internet 31+
Check / rolling
Internet Explorer —
Not supported
<geolocation> Experimental

Bottom line: Treat as progressive enhancement. Link learners to /html/geolocation for the widely available JavaScript API.

Key Takeaways

  • Role: declarative browser control for sharing location.
  • Attrs: autolocate and watch (boolean).
  • Fallback: nest a button using the Geolocation API.
  • Learn more: /html/geolocation for the JS API.

One line: <geolocation> is an experimental declarative location control — always ship a Geolocation API fallback.

Default CSS Settings

Supporting browsers render a native control (for example a map-pin button). Styling is heavily constrained for accessibility and anti-spoofing:

default.css
/* Conceptual — exact UA styles vary */
geolocation {
  /* browser-defined interactive control */
  /* contrast, font-size, opacity, and other constraints apply */
}

Prefer minimal styling. Violating contrast or size rules can deactivate the control.

Frequently Asked Questions

The geolocation element creates a browser-defined interactive control that lets the user share their location with the page. It handles permissions UI and exposes position data through HTMLGeolocationElement.
When present, the browser may retrieve location as soon as the element is rendered — but only if permission was already granted. If permission was never granted, autolocate has no effect until the user activates the control.
When present, the browser updates location whenever the device position changes (like Geolocation.watchPosition). Without it, location is retrieved once (like getCurrentPosition).
The Geolocation API tutorial at /html/geolocation covers navigator.geolocation in JavaScript. This tag page documents the declarative <geolocation> element, which uses that API under the hood with a built-in control.
Yes. Put a message or a button between the tags. Unsupported browsers show that content; supporting browsers show the native control instead.
It is experimental with limited availability (for example Chromium-based browsers). Prefer the Geolocation API with your own UI until support is wider, or use progressive enhancement with a fallback button.

Next: head

Continue with the HTML head tag tutorial.

head tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful