Security headers explained: the browser instructions that defend your site
HTTP security headers are invisible lines that tell browsers how to treat your site. Which ones matter first, what they actually block, and what they cannot do.
Some of the cheapest protection a website can add is invisible to its visitors: a handful of lines sent with every page that tell each browser how it may treat your content. These are HTTP security headers. This guide covers what they are, which ones matter first, and - just as honestly - what they cannot do, grounded in OWASP's Secure Headers Project and MDN's practical security guides.
What security headers are
Every time your site answers a browser, the response carries headers alongside the page itself. The OWASP Secure Headers Project describes security headers as response headers your application can use to increase its security: once set, they restrict modern browsers from running into easily preventable vulnerabilities. Visitors never see them; the browser reads them and changes what it will allow - whether the page can be framed, whether HTTP connections are tolerated, what kinds of content may load.
The few worth knowing first
MDN's practical security guides list features in a recommended implementation order that weighs security impact against ease of implementation, and the pattern is useful for a small site:
- HSTS tells browsers to connect to your site only over HTTPS, even if someone follows an old http:// link. MDN rates its impact high and its difficulty low.
- Clickjacking protection controls whether your pages may be framed inside other sites, blocking a class of tricks where your page is hidden inside an attacker's. Again high impact, low difficulty.
- MIME type verification and a referrer policy are rated lower impact but also low difficulty - browsers stop guessing content types, and your URLs stop leaking to third parties.
- Content Security Policy gives fine-grained control over which code may load on your pages and mitigates cross-site scripting. MDN rates its impact high and its difficulty high - powerful, but plan it rather than improvising.
What they cannot do
Headers are instructions, and only browsers that choose to honor them enforce anything - they harden the visitor side, not the server. MDN's own framing is careful here: its guides do not cover every security scenario and cannot guarantee complete security, though following them makes sites significantly more secure. Headers sit alongside the other layers rather than replacing any: HTTPS encrypts the connection, a web application firewall filters hostile traffic before it arrives, and updates close the holes in your software.
How to add them safely
Where headers get set depends on your stack: many hosts and CDNs expose them in a dashboard or configuration file, and some platforms add a few for you. Two habits keep the work safe. First, check what you already send before adding anything - duplicating or contradicting an existing header helps nobody. Second, test after each change, especially with framing controls and CSP: a header that is too strict can block legitimate embeds or scripts, which is why MDN's difficulty ratings are worth respecting. Start with the low-difficulty, high-impact pair, verify nothing broke, and treat CSP as its own project.
FAQ
Do my visitors ever see security headers?
No. They are instructions from your server to the visitor's browser, read and enforced silently. Their effect shows up only as attacks that no longer work.
Do headers slow a website down?
They add a few lines of text to each response - negligible against the page itself - and the protections they enable, like HSTS skipping insecure connections, cost nothing per visit.
Which header should I set first?
MDN's recommended order balances impact against difficulty, and within it HSTS stands out: high impact, low difficulty, provided your site already serves HTTPS everywhere. Clickjacking protection is the natural second.
Can headers replace a firewall or updates?
No. Headers instruct browsers, a WAF filters traffic, and updates fix your software - three different jobs. A site needs its layers to cooperate, not to vote one another off.