How to Set the X-Frame-Options Header

X-Frame-Options prevents clickjacking by controlling whether your pages can be embedded in iframes. This guide shows how to add it across all major web servers and platforms.

Covers
X-Frame-Options, Clickjacking

The X-Frame-Options header prevents clickjacking attacks by telling browsers whether your page is allowed to be displayed inside an <iframe>, <frame>, or <embed> element. This guide shows how to set it on every major web server and platform.

Choosing the Right Value

ValueEffectWhen to Use
DENYNo framing by anyone, including same originDefault for most sites — use unless you embed your own pages in iframes
SAMEORIGINFraming allowed by same-origin pages onlyWhen your own application legitimately uses iframes across pages
Also Set CSP frame-ancestorsFor modern browsers, combine X-Frame-Options with Content-Security-Policy: frame-ancestors 'none' (equivalent to DENY). CSP is the modern standard; X-Frame-Options covers legacy IE11 as a fallback.

Set the Header on Your Server

Nginx

nginx
server { listen 443 ssl; server_name example.com; add_header X-Frame-Options "DENY" always; # ... rest of config }

Test and reload:

bash
sudo nginx -t && sudo systemctl reload nginx

Verifying the Header

bash
curl -I https://example.com | grep -i x-frame-options # Expected: x-frame-options: DENY

Or use the ShowDNS Security Headers Scanner.