Strict-Transport-Security Header Explained

What the HTTP Strict-Transport-Security header does and when it's used.

Published October 16, 2026

Strict-Transport-Security (HSTS) tells browsers to use only HTTPS for your domain for a given period, preventing downgrade and SSL-stripping attacks.

How it works

After the first HTTPS visit, browsers refuse HTTP automatically.

The Strict-Transport-Security header is part of the HTTP message and is case-insensitive in name.

In a real exchange

curl -i https://example.com/
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Where Strict-Transport-Security appears.

Practical examples

The header

Strict-Transport-Security: max-age=31536000; includeSubDomains; preload

Set or use it in code

add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

Inspect it

curl -sI https://example.com | grep -i 'strict-transport-security'

Common mistakes

  • Enabling includeSubDomains before all subdomains support HTTPS
  • Using a tiny max-age forever
  • Submitting to preload without being sure

Key takeaways

  • Strict-Transport-Security: Strict-Transport-Security (HSTS) tells browsers to use only HTTPS for your domain for a given period, preventing downgrade and SSL-stripping attacks.
  • Check it in browser DevTools → Network.
  • Test with curl -I before deploying.

FAQ

Can I undo HSTS?

Only after max-age expires, so test with a small value first.

Is Strict-Transport-Security case sensitive?

Header names are case-insensitive; values may not be.

More HTTP articles