# HSTS

What is HSTS?

HSTS (HTTP Strict Transport Security) is a response header that tells the browser to use only [HTTPS](/glossary/https) for a site, for a period the site sets. Once a browser has seen it, it turns every `http://` link to that site into `https://` before sending anything, and it no longer lets the visitor click past a certificate error.

## How it works

The server sends the header on an HTTPS response:

```http
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
```

- `max-age` is how long, in seconds, the browser remembers the rule. Each response that carries the header starts the period again.
- `includeSubDomains` applies the rule to every subdomain as well.
- `preload` says the domain asks to be on the preload list that browsers ship with.

Browsers ignore the header when it arrives over plain HTTP, so it only takes effect after a first successful HTTPS visit. That first visit, if it starts on `http://`, is still exposed. The preload list closes the gap: a domain on it is treated as HTTPS-only before the browser has ever visited it. The list, run at hstspreload.org, sets its own requirements, including a long minimum `max-age` and both `includeSubDomains` and `preload`.

## Why it matters

Without HSTS, a visitor who types the bare domain or follows an old `http://` link makes one unencrypted request first. On an untrusted network, such as public Wi-Fi, an attacker can intercept that request and keep the visitor on a plain HTTP or fake version of the site. HSTS removes that request for every visit after the first.

## What can go wrong

- `includeSubDomains` goes out while some subdomain (an old admin panel, an internal tool) still serves only HTTP, and browsers that saw the header can no longer reach it.
- A long `max-age` cannot be taken back quickly. Turning HSTS off means sending `max-age=0` over HTTPS, and it only reaches browsers when they visit again.
- Preloading covers every subdomain, including internal ones, and hstspreload.org warns that removal from the list takes months to reach users.
- An expired or broken [SSL certificate](/glossary/ssl-certificate) on an HSTS site leaves visitors no way to click through, so the site is simply unreachable until it is fixed.

## Check it

The [Security headers checker](/tools/security-headers) shows whether a URL sends Strict-Transport-Security, alongside the other [security headers](/glossary/security-headers). It gives a one-time reading, so it is worth running again after a deploy or a server change.

Read this definition in a browser: https://ranetrace.com/glossary/hsts
