References

Beginner-friendly references for web development, with live, editable examples.

The HTML ping attribute

Attribute
In short

Following a link with a ping attribute sends a POST request to each http or https URL in it. The request body is PING, and a Ping-To header names the link's target. Firefox is the one major browser that doesn't send these requests unless a user turns on browser.send_pings.

Overview

The HTML ping attribute holds a list of URLs to notify when someone follows a hyperlink. The feature is called hyperlink auditing, and it works on <a> and <area> elements with an href.

Under the HTML standard, the browser splits the value on spaces, tabs and line breaks, skips every URL whose scheme isn't http or https, and sends a request to each one left. These requests can run in parallel with the navigation, independent of its result.

Each request uses the POST method, the header Content-Type: text/ping and the four-byte body PING. The standard has it carry credentials such as cookies, but no Referer header.

Nothing is sent until someone activates the link, so a click handler that calls preventDefault() cancels the ping along with the navigation. Browsers may also skip pings to honor a user's settings, such as ignoring every third-party ping URL.

Syntax

<a href="https://example.com/files/report-2026.pdf"
   ping="https://example.com/stats/download">2026 report (PDF)</a>

Values

Value
A space-separated list of URLs.

Example

Live example
<p>
  <a href="https://example.org/setup-guide/"
     ping="https://example.com/stats/outbound">Read the setup guide</a>
</p>
<p>
  <a href="https://example.com/files/report-2026.pdf"
     ping="https://example.com/stats/download
           https://example.org/collect">Download the 2026 report</a>
</p>
<img src="plans.png" usemap="#plans" alt="Basic and Pro plans" width="240" height="60">
<map name="plans">
  <area shape="rect" coords="0,0,120,60" href="https://example.com/plans/basic"
        ping="https://example.com/stats/plan" alt="Basic plan">
  <area shape="rect" coords="120,0,240,60" href="https://example.com/plans/pro"
        ping="https://example.com/stats/plan" alt="Pro plan">
</map>

Best practices

  • Read the Ping-To header on the server that receives the ping request. The request body says nothing about the link, so the target arrives only in that header, unless you add details to the ping URL's query string.
  • Separate ping URLs with spaces, never commas. A comma becomes part of the URL, so ping="a, b" sends its first request to an address ending in a comma.
  • Spell out each ping URL in full, starting with https:// or http://. A relative one such as /stats resolves against the page but fails validator.nu's check for HTTP(S) URLs.
  • Answer pings with an empty response. The browser throws away any body the server sends back and may close the connection once one starts to arrive.

Frequently asked questions

What is the ping attribute used for?
The ping attribute lets a site record which links people follow, for example to count clicks on outbound links.
What does a ping request look like?
A ping request is a POST with the body PING and a Ping-To header holding the link's target URL. A Ping-From header with the page's URL is added only when the ping URL shares the page's origin or the page isn't served over HTTPS.
Which browsers send ping requests?
Chrome 12, Edge 17, Safari 6 and later versions all send ping requests. Firefox sends none unless its browser.send_pings preference is true, and then it pings only the first http or https URL in the list.
Why use ping instead of a redirect for click tracking?
A ping lets users see the real destination URL, unlike a tracking redirect. It also lets the browser tell users about the extra requests and manage bandwidth so the target page loads faster.
Can I detect whether a browser will send ping requests?
Not reliably, because a browser can expose the ping property and still send nothing. Finding ping on HTMLAnchorElement.prototype shows only that the attribute is known.
Is a ping sent for links that open a new tab or download a file?
A target=_blank link counts as followed, so it gets a ping like any other link. The HTML standard's download steps don't mention pings, but Chrome sends one for a link with the download attribute, and so does Firefox with pings turned on.