ping

Send tracking pings to specified URLs when a link is clicked. A transparent, declarative alternative to redirect-based or JavaScript click tracking.

Overview

The ping attribute on <a> elements sends background POST requests to one or more URLs when the link is clicked. The user navigates directly to the link's href destination while the tracking requests are sent asynchronously — no redirect delay, no JavaScript required.

Applies to: <a>

Values

ValueBehavior
Single URLSends one POST request on click
Space-separated URLsSends a POST to each URL on click

Basic Usage

Add one or more tracking URLs to the ping attribute. The browser sends POST requests to each URL when the link is clicked.

<!-- Single tracking URL --> <a href="/products/widget" ping="/analytics/click">Widget Product Page</a> <!-- Multiple tracking URLs (space-separated) --> <a href="/products/widget" ping="/analytics/click /third-party/track"> Widget Product Page </a>

Practical Examples

Common use cases include tracking outbound links, measuring CTA effectiveness, and notifying analytics services of navigation events.

<!-- Track outbound link clicks --> <nav> <a href="https://github.com/example/repo" ping="/track/outbound"> GitHub Repository </a> <a href="https://docs.example.com" ping="/track/outbound"> Documentation </a> </nav> <!-- Track CTA clicks in a marketing page --> <a href="/signup" ping="/analytics/cta-click?source=hero"> Start Free Trial </a>

What the Browser Sends

The POST request includes headers that identify both the page the user was on and the destination they are navigating to.

<!-- When the user clicks this link: --> <a href="/destination" ping="/track">Click me</a> <!-- The browser sends a POST to /track with these headers: Content-Type: text/ping Ping-From: https://example.com/current-page Ping-To: https://example.com/destination The body is the string "PING" The user navigates directly to /destination without delay -->

Comparison with Other Tracking

The ping attribute competes with two established tracking patterns: redirect URLs and JavaScript click handlers. It has advantages over both.

<!-- Redirect tracking (common but slower) --> <a href="/redirect?url=https://example.com&id=123">Example</a> <!-- User goes to /redirect first, then gets redirected to example.com --> <!-- JavaScript tracking (common but fragile) --> <a href="https://example.com" onclick="track('click', 123)">Example</a> <!-- Depends on JS loading; may miss clicks --> <!-- ping attribute (fastest, declarative) --> <a href="https://example.com" ping="/track?id=123">Example</a> <!-- User goes directly to example.com; ping is sent in background -->
ApproachUser DelayRequires JSVisible in SourceWorks if JS Fails
Redirect trackingYes (extra hop)NoURL is obscuredYes
JS click handlerMinimalYesBuried in scriptsNo
ping attributeNoneNoYes (in HTML)Yes

Transparency Advantage

Unlike JavaScript-based tracking, the ping attribute is visible in the page source. Privacy-conscious users, browser extensions, and auditing tools can see exactly which URLs receive tracking pings. This transparency was an intentional design goal of the specification.

Accessibility

  • The ping attribute has no effect on accessibility. Screen readers announce the link normally based on its text content and href.
  • The attribute does not change the link's visible destination or behavior from the user's perspective.
  • Keyboard activation (Enter) triggers the ping just as a mouse click does.

Limitations

  • Firefox disables ping by default. The browser.send_pings preference is false in Firefox, making the attribute unreliable for cross-browser analytics.
  • Privacy-focused browsers and extensions (uBlock Origin, Brave) may block ping requests entirely.
  • The POST body is just the string PING — you cannot send custom data. Any context must be encoded in the URL query string.
  • Only works on <a> elements. It does not apply to <button>, <form>, or programmatic navigation.
  • The Ping-From header is omitted in cross-origin requests when the referring page uses HTTPS and the ping URL uses HTTP (downgrade scenario).

See Also

  • referrerpolicy — control what referrer information is sent with requests
  • rel — link relationship types including noopener and noreferrer
  • <a> — the anchor element