# Bad value X for attribute “ping” on element “a”: Must contain only “http” or “https” URLs.

> Canonical HTML version: https://rocketvalidator.com/html-validation/bad-value-x-for-attribute-ping-on-element-a-must-contain-only-http-or-https-urls
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

The `ping` attribute specifies a space-separated list of URLs that the browser should notify (via a small POST request) when a user follows a hyperlink. This is commonly used for click tracking and analytics. According to the HTML specification, every URL in the list must be a valid, non-empty URL that uses either the `http` or `https` scheme — no other schemes or relative paths are permitted.

This restriction exists for practical and security reasons. The `ping` mechanism is specifically designed for web-based tracking endpoints, so only web protocols make sense. Relative URLs are disallowed because the ping is sent as a separate request independent of normal navigation, and the specification requires absolute URLs to unambiguously identify the target server. Using invalid values won't produce the intended tracking behavior and will cause the browser to silently ignore the `ping` attribute entirely.

From an accessibility and standards compliance standpoint, ensuring valid `ping` values means your analytics will work reliably in browsers that support the attribute. Note that browser support varies — some browsers (notably Firefox) disable `ping` by default or hide it behind a preference — so you should not rely on it as your sole tracking mechanism.

## How to fix it

1. **Replace relative URLs with absolute URLs.** If you have a value like `/track` or `track.php`, prepend the full origin (e.g., `https://example.com/track`).
2. **Remove non-HTTP schemes.** Values like `mailto:someone@example.com` or `ftp://example.com/log` are not valid for `ping`.
3. **Ensure each URL in the list is properly formatted.** Multiple URLs must be separated by spaces (not commas or semicolons), and each one must be a complete `http` or `https` URL.

## Examples

### Incorrect: relative URL

```html
<a href="https://example.com" ping="/track">Visit Example</a>
```

The value `/track` is a relative URL, which is not allowed in the `ping` attribute.

### Incorrect: unsupported scheme

```html
<a href="https://example.com" ping="ftp://example.com/log">Visit Example</a>
```

The `ftp:` scheme is not permitted — only `http` and `https` are valid.

### Incorrect: comma-separated URLs

```html
<a href="https://example.com" ping="https://example.com/track, https://analytics.example.com/log">Visit Example</a>
```

Multiple URLs must be space-separated, not comma-separated. The commas make each URL invalid.

### Correct: single absolute URL

```html
<a href="https://example.com" ping="https://example.com/track">Visit Example</a>
```

### Correct: multiple space-separated absolute URLs

```html
<a href="https://example.com" ping="https://example.com/track https://analytics.example.com/log">Visit Example</a>
```

Each URL is a fully qualified `https` URL, and they are separated by a single space. Both will receive a POST request when the link is clicked (in browsers that support the `ping` attribute).
