Rel noopener

Summarize this post with AI ChatGPT OR

rel noopener Explained: HTML Security Attributes Guide

rel noopener is the first of four HTML security attributes that close real holes in your pages — small additions to tags you already use that stop a link from letting a stranger’s page hijack your visitor’s tab, an image from leaking the private URL your visitor came from, an embedded widget from running scripts with your page’s privileges, and a browser’s helpful autofill from handing a credit-card number to the wrong form. Alongside it, referrerpolicy on links and media, sandbox on iframes, and autocomplete on form fields complete the set: four attributes, a few words each, and every one of those attacks stops at the attribute.

This guide covers all four HTML security attributes the way they actually work in 2026: what rel="noopener" stops and why every target="_blank" link needs it, the full rel value list and which ones search engines actually read, how referrerpolicy controls the Referer header (and why the default leaks more than you think), how sandbox turns an iframe into a padded cell you can unlock one permission at a time, and how autocomplete protects passwords and payment details without fighting password managers. Every example is a complete, runnable HTML document you can copy, open in a browser, and test.

Quick Takeaways

  • Every link with target="_blank" needs rel="noopener" (or rel="noopener noreferrer"). Without it, the page you link to can reach back through window.opener and redirect your page — the tabnabbing attack.
  • rel also carries SEO values search engines read: nofollow (do not pass ranking credit), sponsored (paid link), and ugc (user-generated content). Security and SEO values can be combined in one attribute: rel="noopener sponsored".
  • referrerpolicy controls how much of your page’s URL the browser sends to the next site. The modern default is strict-origin-when-cross-origin; use no-referrer on links to untrusted sites and on any page with private URLs.
  • sandbox on an <iframe> strips scripts, forms, popups, and top-level navigation by default. Add back only the permissions the embed needs with allow-scripts, allow-same-origin, and friends — never add allow-scripts and allow-same-origin together to an embed you do not trust.
  • autocomplete is a security attribute as well as a convenience one. autocomplete="off" is ignored by browsers on login fields, so use the real tokens instead: new-password for registration, current-password for login, one-time-code for 2FA, and cc-number only on genuine checkout forms.
  • All four attributes degrade gracefully: an old browser that does not understand them simply ignores them, so adding them costs nothing and breaks nothing.

1. Why HTML Needs Security Attributes

HTML was designed in an era when a web page was a document, not an application. The original tags assumed every link was friendly, every embedded frame was trustworthy, and every form field belonged to the page that drew it. None of those assumptions survived the modern web — and the fixes did not come as new tags. They came as attributes on the tags that already existed.

Four distinct threats grew out of those assumptions, and each one has an attribute-shaped answer:

Tabnabbing — the link that bites back. When your page links to another site with target="_blank", the new tab keeps a live reference to your page through window.opener. The destination page can use that reference to change your page’s address — typically to a pixel-perfect fake of your login page — while your visitor is looking the other way. The visitor switches back to your tab, sees a login form, types their password, and hands it to the attacker. Nothing about the link looked dangerous.

Referrer leakage — the URL that talks too much. Every time a browser follows a link, loads an image, or fetches a script from another site, it sends a Referer header carrying the URL of the page the request came from. That URL can contain a password-reset token, a private document ID, a search query, or a session parameter. The destination site — and every analytics script on it — receives all of it, silently.

Embedded content with full privileges. An <iframe> is a whole other page running inside yours. By default it can run scripts, submit forms, open popups, and navigate your visitor’s top-level window. A third-party widget, an ad, or a user-supplied embed gets all of that for free unless you restrict it.

Autofill in the wrong hands. Browsers remember passwords, addresses, and card numbers to save typing. That is a feature — until a form on a page the user does not fully trust asks for a field the browser is happy to fill, or a hidden field silently collects data the user never meant to give. The autocomplete attribute tells the browser exactly what each field is for, and which fields it should never fill.

The four attributes in this guide are the standard answers. They are small — a few words each — they work in every modern browser, and they fail safe: a browser that does not recognise one simply ignores it. There is no reason a page in 2026 should ship without them.

ThreatAttack in one lineThe attributeWhat it does
TabnabbingLinked page rewrites your tab via window.openerrel="noopener"Severs the opener link
Referrer leakagePrivate URLs sent to other sites in the Referer headerreferrerpolicyControls how much of the URL is sent
Malicious embedIframe scripts and navigation run with your page’s trustsandboxStrips iframe powers until you grant them
Autofill abuseBrowser fills sensitive fields on the wrong formautocompleteLabels each field; blocks filling where it must not happen

2. rel=”noopener” and rel=”noreferrer”: Stop Tabnabbing

The most important security attribute in HTML is also the easiest to forget. It lives on the humble link, and it fixes an attack most developers have never heard of — until it happens to their users.

Here is the attack, step by step. Your page has a link: <a href="https://example.com" target="_blank">Read more</a>. A visitor clicks it. The browser opens example.com in a new tab — and, because the link used target="_blank", the new page receives a reference to your page in the JavaScript property window.opener. That reference is a live handle on your tab: the destination page can read your page’s location, and — this is the dangerous part — it can set it. The attacker’s page runs one line of JavaScript, window.opener.location = "https://fake-login.example.com", and your tab silently navigates to a convincing copy of your login page. Your visitor, who never left your site in their mind, switches back to the tab, sees a login screen on what they believe is your site, and types their password into the attacker’s form.

The page the visitor opened did not need to be malicious-looking. It could be a legitimate-looking blog, a shortened link, or a site that was compromised after you linked to it. The vulnerability is in your link, not in theirs.

The fix is one word: rel="noopener". It tells the browser to open the new tab without an opener reference, so window.opener is null on the destination page and the attack cannot even start. Add noreferrer alongside it — rel="noopener noreferrer" — and the browser also strips the Referer header from the request, so the destination never learns which of your pages the visitor came from. Modern browsers now imply noopener behaviour for target="_blank" links, but you should still write the attribute explicitly: it protects visitors on older browsers, it documents the intent for the next developer, and automated security scanners flag links that lack it.

The rule is simple and absolute: every link with target="_blank" gets rel="noopener", with noreferrer added whenever the destination is a site you do not control. Internal links that open in the same tab need neither. Links that open in the same tab cannot tabnab, because there is no second tab and no opener to exploit.

This is a complete, runnable demonstration. Open it, click the link, and watch what the destination page can — and cannot — do to the page that linked to it.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Tabnabbing Demo — rel="noopener" in Action</title>
  <style>
    body { font-family: system-ui, sans-serif; max-width: 640px; margin: 2rem auto; padding: 0 1rem; line-height: 1.6; }
    .safe { background: #e8f5e9; border: 2px solid #2e7d32; padding: 1rem; border-radius: 8px; }
    .unsafe { background: #fdecea; border: 2px solid #c62828; padding: 1rem; border-radius: 8px; }
    a { font-weight: bold; }
    code { background: #f4f4f4; padding: 0.1em 0.35em; border-radius: 4px; }
  </style>
</head>
<body>
  <h1>Tabnabbing: the link that bites back</h1>

  <p>Both links below open the same destination in a new tab. The only
  difference is the <code>rel</code> attribute — and it is the difference
  between a safe link and an open door.</p>

  <div class="unsafe">
    <h2>Unsafe link — no protection</h2>
    <p><a href="https://example.com" target="_blank">Open example.com (unsafe)</a></p>
    <pre><code><a href="https://example.com" target="_blank"></code></pre>
    <p>The new tab receives <code>window.opener</code> — a live handle on
    <em>this</em> page. A hostile destination can redirect this tab with
    one line of JavaScript.</p>
  </div>

  <div class="safe">
    <h2>Safe link — protected</h2>
    <p><a href="https://example.com" target="_blank" rel="noopener noreferrer">Open example.com (safe)</a></p>
    <pre><code><a href="https://example.com" target="_blank" rel="noopener noreferrer"></code></pre>
    <p>The new tab gets <code>window.opener === null</code> and no Referer
    header. The destination cannot reach back to this page at all.</p>
  </div>

  <h2>How to test it yourself</h2>
  <p>Open this page, right-click the safe link, and inspect it — then run
  this snippet in the destination tab's console: <code>window.opener</code>.
  On the safe link it prints <code>null</code>. On the unsafe link it prints
  a live <code>Window</code> object pointing back at this page.</p>
</body>
</html>

One more detail worth knowing: rel="noopener" also has a performance side effect. A new tab that keeps an opener reference runs in the same process as the page that opened it on some browsers, which means a heavy page in the new tab can slow down yours. Severing the opener lets the browser put the new tab in its own process. Security and speed, from the same word.

3. The rel Values Cheat Sheet

rel does far more than security. It is a general-purpose label that tells the browser — and search engines — what the linked page is to yours. The values fall into three groups: security values, SEO values, and navigation values. They combine freely in one attribute, separated by spaces, and the order does not matter.

The SEO values are the ones with direct ranking consequences. nofollow tells search engines not to pass ranking credit to the linked page — use it for links you cannot vouch for, such as links in user comments. sponsored marks a paid link or advertisement, and ugc marks a link in user-generated content; Google introduced both in 2019 and expects them on the links they describe. Using nofollow on a paid link is accepted, but sponsored is the correct, specific value, and getting it right keeps you on the right side of Google’s link-spam rules.

rel valueGroupWhat it meansWhen to use it
noopenerSecurityNew tab gets no window.openerEvery target="_blank" link
noreferrerSecurityNo Referer header sent to the destinationLinks to sites you do not control
nofollowSEODo not pass ranking creditUntrusted links, comments, forums
sponsoredSEOThis is a paid link or adAffiliate links, sponsored posts
ugcSEOLink is user-generated contentComments, forum posts, reviews
externalHintLink leaves this siteStyling external links with CSS (a[rel~="external"])
openerSecurityExplicitly allow window.openerAlmost never — only when the new tab must control the opener
authorNavigationLink points to the author’s pageAuthor bylines
helpNavigationLink points to help documentationHelp links in apps and forms
licenseNavigationLink points to the content’s licenceFooter licence links
prev / nextNavigationLink is the previous / next page in a seriesPaginated articles and guides
alternateNavigationLink is an alternate version (language, feed, print)RSS feeds, translations, print versions

A link can carry several values at once, and real pages usually do. An affiliate link that opens in a new tab is rel="noopener sponsored". A link in a comment that opens in a new tab is rel="noopener ugc". A paid link in a comment is rel="noopener sponsored ugc". Write the security value first out of habit, then the SEO values — the browser does not care about order, but the next person reading your code will thank you.

One trap to avoid: rel="nofollow" does not make a link safe, and rel="noopener" does not affect SEO. They solve different problems, and a link can need both. The other trap is rel="opener", which explicitly opts back into the opener behaviour — it exists for the rare case where the new tab genuinely needs to control the page that opened it, such as an OAuth popup returning a token. If you do not know why you would use it, you do not need it.

4. referrerpolicy: Control What the Browser Tells Other Sites

Every request a browser makes to another site carries a Referer header — note the historic misspelling, baked into the HTTP standard since the 1990s — containing the URL of the page the request came from. That header exists so site owners can see where their traffic comes from, and analytics tools depend on it. The problem is that the URL it carries can be far more revealing than the page’s title.

Consider a password-reset link: https://example.com/reset?token=9f3a7c1e. If that page contains a link, an image, or a script loaded from another site, the full URL — token included — goes to that site in the Referer header. The same applies to private document URLs, search result pages carrying the query string, and admin pages with session parameters in the address bar. The destination site did not hack anything; your browser handed it the secret as a matter of routine.

referrerpolicy controls exactly how much of the URL the browser sends, and when. You can set it in three places: as an attribute on individual links, images, scripts, and iframes; as a <meta name="referrer" content="..."> tag that sets the default for the whole page; or as an HTTP Referrer-Policy header sent by your server, which overrides both. The attribute wins over the meta tag for that element, and the header wins over everything — so set the header if you control the server, the meta tag if you do not, and the attribute for the exceptions.

The values form a ladder from total silence to full disclosure:

referrerpolicy valueWhat the browser sendsBest for
no-referrerNothing, everLinks to untrusted sites; pages with tokens in the URL
no-referrer-when-downgradeFull URL, except when going from HTTPS to HTTPThe old default; still common, but leaks on same-protocol links
same-originFull URL to your own site, nothing to other sitesPrivate apps where cross-site referrers are never needed
strict-originOnly the origin (https://example.com) to every siteWhen the destination needs to know the source domain, nothing more
strict-origin-when-cross-originFull URL to your own site, origin only to other sitesThe modern default — use this unless you have a reason not to
originOnly the origin, to every site including your ownSimpler than strict-origin; loses the path even on same-origin requests
origin-when-cross-originFull URL to your own site, origin only to other sitesLike strict-origin-when-cross-origin but sends the origin even on HTTPS→HTTP downgrades
unsafe-urlFull URL to everyone, alwaysAlmost never — only for legacy analytics that genuinely need the full URL

The default in every modern browser is strict-origin-when-cross-origin: your own site sees the full URL, other sites see only your domain. That is a good default, and for most pages you do not need to change it. The cases that need an explicit policy are the ones where even the origin is too much (a link from a private admin page to an external site — use no-referrer), or where a specific link must carry the full URL to a trusted partner (use unsafe-url on that link only, and think twice).

This is a complete, runnable page showing all three levels — page default, per-link override, and per-image override — so you can see how they layer.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- Page-wide default: other sites see only our origin, never the path -->
  <meta name="referrer" content="strict-origin-when-cross-origin">
  <title>referrerpolicy — Controlling the Referer Header</title>
  <style>
    body { font-family: system-ui, sans-serif; max-width: 640px; margin: 2rem auto; padding: 0 1rem; line-height: 1.6; }
    code { background: #f4f4f4; padding: 0.1em 0.35em; border-radius: 4px; }
    .card { border: 1px solid #ddd; border-radius: 8px; padding: 1rem; margin: 1rem 0; }
  </style>
</head>
<body>
  <h1>referrerpolicy in three layers</h1>

  <div class="card">
    <h2>1. Page default (this page)</h2>
    <p>The <code><meta name="referrer"></code> tag in the head sets
    <code>strict-origin-when-cross-origin</code> for everything on this
    page: same-origin requests carry the full URL, cross-origin requests
    carry only the origin.</p>
  </div>

  <div class="card">
    <h2>2. Per-link override — send nothing</h2>
    <p><a href="https://example.com" referrerpolicy="no-referrer">Visit example.com</a>
    — this link sends no Referer header at all, overriding the page default.
    Use it for links from pages with tokens or private IDs in the URL.</p>
    <pre><code><a href="https://example.com" referrerpolicy="no-referrer"></code></pre>
  </div>

  <div class="card">
    <h2>3. Per-image override — origin only</h2>
    <p>Images leak referrers too. An image from another site sends your
    page's URL unless you stop it:</p>
    <pre><code><img src="https://cdn.example.com/logo.png"
     alt="Partner logo"
     referrerpolicy="no-referrer"></code></pre>
    <img src="https://via.placeholder.com/320x80?text=Partner+logo"
         alt="Partner logo" referrerpolicy="no-referrer" width="320" height="80">
  </div>

  <h2>How to verify it</h2>
  <p>Open your browser's developer tools, go to the Network tab, click a
  link, and inspect the request headers on the destination. With
  <code>no-referrer</code> there is no <code>Referer</code> header at all;
  with <code>strict-origin-when-cross-origin</code> a cross-origin request
  shows only the origin.</p>
</body>
</html>

A note on the server-side option, because it is the strongest one: if you control your server or your hosting panel, send the policy as an HTTP header — Referrer-Policy: strict-origin-when-cross-origin — and it applies to every page and every resource, including pages where you forgot the meta tag. In Apache it is one line in .htaccess; in Nginx, one add_header line. Do that, and use the attribute only for the exceptions.

5. sandbox: Lock Down Embedded Content

An <iframe> is a page within a page — and by default it arrives with almost the same powers as the page that embedded it. It can run JavaScript, submit forms, open popups, navigate the visitor’s top-level window, and, if it is same-origin, reach into your page’s DOM. That is a lot of trust to extend to a third-party widget, an advertisement, or a piece of user-supplied content.

sandbox takes all of it away. Add the bare attribute — <iframe sandbox src="..."> — and the embedded page runs in a padded cell: no scripts, no forms, no popups, no plugins, no top-level navigation, and no access to your page’s storage or DOM, even if the embedded page is from your own domain. It is the single most powerful security attribute in HTML, and the safest way to embed content you did not write.

Then you add back exactly the permissions the embed needs, one token at a time. Each token unlocks one capability and nothing else:

sandbox tokenWhat it allowsWhen to use it
allow-scriptsJavaScript runs inside the iframeInteractive widgets, maps, embeds that need JS
allow-same-originIframe keeps its real origin (storage, cookies, DOM access if same-origin)Your own pages embedded in your own site
allow-formsForms can be submittedEmbedded contact or search forms
allow-popupsLinks and scripts can open new windowsEmbeds with share or help links
allow-popups-to-escape-sandboxPopups open without sandbox restrictionsRare — popups that must behave like normal tabs
allow-top-navigationIframe can navigate the top-level windowOnly for embeds you fully trust
allow-top-navigation-by-user-activationIframe can navigate the top level, but only after a real user clickSafer version of the above
allow-modalsalert(), confirm(), prompt() workAlmost never — modals in embeds are usually an attack
allow-downloadsThe iframe can trigger downloadsEmbedded document viewers
allow-orientation-lock, allow-pointer-lock, allow-presentation, allow-storage-access-by-user-activationNarrow device and storage permissionsMedia players, games, storage-dependent widgets

The golden rule — the one that has its own warning in the HTML specification — is never combine allow-scripts with allow-same-origin on an embed you do not fully trust. Together, those two tokens let the embedded page remove its own sandbox attribute and escape the cell entirely. It is the equivalent of locking the door and taping the key to it. If the embed needs scripts, serve it from a different origin so allow-same-origin cannot help it; if it needs same-origin access, do not give it scripts. Pick one.

A second rule: a sandboxed iframe is still an iframe, and the embedded page still knows it is being framed. If the content is genuinely hostile — a phishing page, a drive-by download — no sandbox token makes it safe to show your visitors. Sandbox restricts what the embed can do; it does not make a malicious page benign. Do not embed content you would not link to.

This is a complete, runnable example: a page embedding a small interactive widget in a sandbox, with only the permissions it needs — scripts on, same-origin off, forms on — and a second embed with no permissions at all to show the contrast.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>sandbox — Locking Down an Embedded Page</title>
  <style>
    body { font-family: system-ui, sans-serif; max-width: 720px; margin: 2rem auto; padding: 0 1rem; line-height: 1.6; }
    iframe { width: 100%; height: 220px; border: 2px solid #333; border-radius: 8px; }
    code { background: #f4f4f4; padding: 0.1em 0.35em; border-radius: 4px; }
    .note { background: #fff8e1; border-left: 4px solid #f9a825; padding: 0.75rem 1rem; }
  </style>
</head>
<body>
  <h1>sandbox: least privilege for iframes</h1>

  <h2>Widget embed — scripts and forms only</h2>
  <p>This embed needs JavaScript and a form, and nothing else. It cannot
  navigate this page, open popups, or touch our storage:</p>
  <pre><code><iframe src="widget.html"
        sandbox="allow-scripts allow-forms"
        title="Feedback widget"></iframe></code></pre>
  <iframe src="https://example.com" sandbox="allow-scripts allow-forms" title="Feedback widget"></iframe>

  <h2>Static embed — no permissions at all</h2>
  <p>With a bare <code>sandbox</code> attribute the embed cannot run scripts,
  submit forms, or navigate anywhere. Use this for content that only needs
  to be seen:</p>
  <pre><code><iframe src="https://example.com"
        sandbox
        title="Static preview"></iframe></code></pre>
  <iframe src="https://example.com" sandbox title="Static preview"></iframe>

  <div class="note">
    <strong>Never do this with untrusted content:</strong>
    <code>sandbox="allow-scripts allow-same-origin"</code> — together,
    those two tokens let the embedded page remove its own sandbox and
    escape. Give an untrusted embed scripts <em>or</em> same-origin access,
    never both.
  </div>

  <h2>Always add a title</h2>
  <p>An iframe without a <code>title</code> is announced to screen-reader
  users as a mystery frame. Describe the embed — "Feedback widget",
  "Map of our office" — so assistive technology can name it.</p>
</body>
</html>

Note the src="https://example.com" in the example is a placeholder for whatever you actually embed — a widget, a map, a video, a document preview. The sandbox attribute works the same regardless of the source. Also note that sandbox works alongside allow (the Permissions Policy attribute for camera, microphone, geolocation and friends) and loading="lazy" — the three attributes solve three different problems and combine without conflict.

6. autocomplete: The Attribute That Protects Your Users’ Data

autocomplete is the attribute most developers get wrong, because its name suggests a convenience feature and its most famous value — off — no longer does what people think it does. It is, in reality, a security control: it tells the browser exactly what each field contains, so the browser can fill the right data into the right field — and, just as importantly, refuse to fill the wrong data into the wrong one.

The problem it solves is real. Browsers remember passwords, addresses, and card numbers, and they offer to fill them whenever a form looks like the one they were saved on. A page that labels its fields vaguely — or not at all — invites the browser to guess. The browser guesses wrong in two dangerous ways: it fills a credit-card number into a field on a page that only asked for a name, or it fills saved credentials into a lookalike form on a phishing page that copied your layout. Precise autocomplete tokens remove the guessing.

The second problem is autocomplete="off" itself. Developers add it to login and payment forms hoping to stop the browser saving sensitive data. Browsers ignore it on login, password, and credit-card fields — deliberately, because password managers are safer than asking users to memorise passwords, and because disabling autofill pushes users toward weaker, reused passwords. If you want a field left alone, you need the right token, not off:

autocomplete valueWhat it tells the browserUse it on
offDo not autofill this field (browsers may ignore it on credentials)Search boxes, one-off inputs, CAPTCHA-adjacent fields
onAutofill allowed; browser guesses the field’s purposeGeneric fallback only — prefer a specific token
nameThe user’s full nameName fields
emailEmail addressEmail fields
usernameUsername or account nameLogin username fields
current-passwordThe password for this account, right nowLogin password fields
new-passwordA password the user is creatingRegistration and password-change forms
one-time-codeA one-time code (2FA / SMS / email)Verification code fields — also lets mobile browsers offer the code from the SMS
cc-name, cc-number, cc-exp, cc-cscCardholder name, card number, expiry, security codeGenuine checkout forms only
cc-exp-month, cc-exp-yearExpiry month / year separatelySplit expiry inputs
street-address, address-line1, postal-code, country-nameAddress partsCheckout and shipping forms
telPhone numberPhone fields

The tokens that matter most for security are three. new-password on registration and password-change forms tells the browser to offer a generated strong password instead of filling an old one — and it stops the browser filling the user’s current password into a “new password” field, which is a classic bug that locks users out. current-password on login forms tells the browser this field takes the existing password, so it fills the right credential and never a newly generated one. one-time-code on verification fields is the only token that lets mobile browsers suggest the code straight from an incoming SMS, which is both more convenient and more secure than asking users to memorise and retype six digits.

There are also fields the browser must never fill, and autocomplete is how you say so. A honeypot field designed to catch bots should carry autocomplete="off" so a real browser never fills it and a bot that fills everything gives itself away. A field asking for a one-off value — a promo code, a reference number, a coupon — should be off too, so the browser does not offer a saved address into it. And a field that collects something sensitive but non-standard, such as a security answer or a recovery key, should be off with a clear label explaining why.

This is a complete, runnable example: a registration form and a login form, each labelled so the browser — and any password manager — can do exactly the right thing.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>autocomplete — Labelling Forms So Browsers Fill Them Right</title>
  <style>
    body { font-family: system-ui, sans-serif; max-width: 560px; margin: 2rem auto; padding: 0 1rem; line-height: 1.6; }
    form { border: 1px solid #ddd; border-radius: 8px; padding: 1.25rem; margin: 1.5rem 0; }
    label { display: block; font-weight: bold; margin: 0.75rem 0 0.25rem; }
    input { width: 100%; box-sizing: border-box; padding: 0.6rem; border: 1px solid #999; border-radius: 4px; font-size: 1rem; }
    button { margin-top: 1rem; padding: 0.6rem 1.25rem; font-size: 1rem; cursor: pointer; }
    code { background: #f4f4f4; padding: 0.1em 0.35em; border-radius: 4px; }
  </style>
</head>
<body>
  <h1>autocomplete: label every field by its purpose</h1>

  <form action="/register" method="post" autocomplete="on">
    <h2>Create an account</h2>

    <label for="reg-name">Full name</label>
    <input type="text" id="reg-name" name="name" autocomplete="name" required>

    <label for="reg-email">Email address</label>
    <input type="email" id="reg-email" name="email" autocomplete="email" required>

    <label for="reg-username">Choose a username</label>
    <input type="text" id="reg-username" name="username" autocomplete="username" required>

    <label for="reg-password">Choose a password</label>
    <!-- new-password: the browser offers a generated strong password
         instead of filling the saved login password -->
    <input type="password" id="reg-password" name="password"
           autocomplete="new-password" required>

    <button type="submit">Create account</button>
  </form>

  <form action="/login" method="post" autocomplete="on">
    <h2>Log in</h2>

    <label for="login-user">Username or email</label>
    <input type="text" id="login-user" name="username" autocomplete="username" required>

    <label for="login-pass">Password</label>
    <!-- current-password: the browser fills the saved password for
         THIS account — never a generated one -->
    <input type="password" id="login-pass" name="password"
           autocomplete="current-password" required>

    <button type="submit">Log in</button>
  </form>

  <form action="/verify" method="post">
    <h2>Two-factor verification</h2>
    <label for="otp">Six-digit code</label>
    <!-- one-time-code: mobile browsers offer the code from the SMS -->
    <input type="text" id="otp" name="code" autocomplete="one-time-code"
           inputmode="numeric" maxlength="6" required>
    <button type="submit">Verify</button>
  </form>

  <h2>What not to do</h2>
  <p><code>autocomplete="off"</code> on a login form does not stop the
  browser saving the password — browsers ignore it there on purpose.
  Use <code>current-password</code> and <code>new-password</code> instead,
  and reserve <code>off</code> for genuinely one-off fields such as promo
  codes and honeypot inputs.</p>
</body>
</html>

One final note on autocomplete: it is an accessibility feature as much as a security one. Screen readers and switch-control users rely on the same field labels to navigate a form, and a form whose fields are correctly tokenised is a form that works for password managers, autofill, and assistive technology alike. Getting it right once pays off in three directions.

7. Putting It All Together: A Secure Page Template

The four attributes rarely appear alone. A real page has external links, embedded content, and a form — often all three. Here is a single complete document that uses every attribute in this guide in its proper place: safe external links, a sandboxed embed, a referrer policy for the page, and a form whose fields are correctly labelled. Copy it as a starting point and adapt the values to your own pages.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- Page-wide referrer policy: other sites see only our origin -->
  <meta name="referrer" content="strict-origin-when-cross-origin">
  <title>Secure Page Template — HTML Security Attributes</title>
  <style>
    body { font-family: system-ui, sans-serif; max-width: 680px; margin: 2rem auto; padding: 0 1rem; line-height: 1.6; }
    iframe { width: 100%; height: 200px; border: 2px solid #333; border-radius: 8px; }
    form { border: 1px solid #ddd; border-radius: 8px; padding: 1.25rem; margin: 1.5rem 0; }
    label { display: block; font-weight: bold; margin: 0.75rem 0 0.25rem; }
    input { width: 100%; box-sizing: border-box; padding: 0.6rem; border: 1px solid #999; border-radius: 4px; font-size: 1rem; }
    button { margin-top: 1rem; padding: 0.6rem 1.25rem; font-size: 1rem; cursor: pointer; }
  </style>
</head>
<body>
  <h1>A page that uses all four HTML security attributes</h1>

  <h2>External links — safe by default</h2>
  <p>Read the full specification on
    <a href="https://html.spec.whatwg.org/" target="_blank"
       rel="noopener noreferrer">the WHATWG HTML Standard</a>,
    and see our <a href="/guides/forms">forms guide</a> for the companion
    techniques.</p>

  <h2>Embedded content — sandboxed</h2>
  <p>The map below runs with scripts only. It cannot navigate this page,
  open popups, or read our storage:</p>
  <iframe src="https://example.com/map" title="Office location map"
          sandbox="allow-scripts" loading="lazy"></iframe>

  <h2>Sign up — fields labelled for the browser</h2>
  <form action="/signup" method="post">
    <label for="name">Full name</label>
    <input type="text" id="name" name="name" autocomplete="name" required>

    <label for="email">Email address</label>
    <input type="email" id="email" name="email" autocomplete="email" required>

    <label for="password">Choose a password</label>
    <input type="password" id="password" name="password"
           autocomplete="new-password" required>

    <button type="submit">Create account</button>
  </form>

  <h2>Checklist for every new page</h2>
  <ul>
    <li>Every <code>target="_blank"</code> link has <code>rel="noopener"</code></li>
    <li>Links to sites you do not control also carry <code>noreferrer</code></li>
    <li>Paid and user-generated links carry <code>sponsored</code> or <code>ugc</code></li>
    <li>Referrer policy set — header if possible, meta tag if not</li>
    <li>Every iframe has <code>sandbox</code> with only the tokens it needs</li>
    <li>Never <code>allow-scripts</code> + <code>allow-same-origin</code> together on untrusted embeds</li>
    <li>Every form field has a specific <code>autocomplete</code> token</li>
    <li>Login uses <code>current-password</code>; registration uses <code>new-password</code></li>
  </ul>
</body>
</html>

Run through that checklist on every page you ship, and the four holes this guide opened with — tabnabbing, referrer leakage, privileged embeds, and autofill abuse — are closed before the page ever reaches a visitor.

8. Common HTML Security Mistakes

MistakeWhat happensFix
target="_blank" without rel="noopener"Linked page can redirect your tab via window.opener (tabnabbing)Add rel="noopener" to every new-tab link
noreferrer on internal linksYour own analytics lose the referrer for no benefitUse noreferrer only for links to sites you do not control
Paid links marked only nofollowGoogle expects sponsored on paid links; nofollow alone is vagueUse rel="sponsored" (plus noopener for new-tab links)
No referrer policy on pages with tokens in the URLPassword-reset and private URLs leak to third parties in the Referer headerSet Referrer-Policy: strict-origin-when-cross-origin (header) or a meta tag; no-referrer on the riskiest links
unsafe-url as a page-wide policyFull URLs sent to every third party, alwaysUse strict-origin-when-cross-origin by default; unsafe-url on single trusted links only
sandbox with no tokens on an embed that needs scriptsWidget renders dead — no interactivity at allAdd only the tokens the embed needs (allow-scripts, allow-forms)
allow-scripts + allow-same-origin together on untrusted embedsEmbedded page can remove its own sandbox and escapeNever combine them on untrusted content; serve scripted embeds from a different origin
Iframe without titleScreen readers announce an unnamed frameAdd a descriptive title to every iframe
autocomplete="off" on login formsBrowsers ignore it; users get no password-manager help and reuse weak passwordsUse current-password for login, new-password for registration
new-password on a login formBrowser offers a generated password where the existing one belongsLogin fields are always current-password
No autocomplete tokens at allBrowser guesses field purposes; card numbers and credentials land in the wrong fieldsGive every field its specific token
Trusting sandbox to make a malicious embed safeSandbox limits what an embed can do; a phishing page inside it is still a phishing pageDo not embed content you would not link to

Frequently Asked Questions

1. Is rel=”noopener” still necessary in 2026?

Yes. Modern browsers now imply noopener behaviour for target="_blank" links, but the attribute is still the correct, explicit way to declare it. It protects visitors on older browsers, it documents the intent for the next developer who reads your code, and automated security scanners — including the ones that audit your site for clients — flag links that lack it. It costs one word and there is no downside to writing it.

2. What is the difference between noopener and noreferrer?

noopener severs the window.opener link between the new tab and your page, which stops tabnabbing. noreferrer stops the browser sending the Referer header to the destination, which stops the destination learning which of your pages the visitor came from. They solve different problems and are usually used together on external links — rel="noopener noreferrer" — but a link can need one without the other: an internal link opened in a new tab needs noopener but has no reason to hide its referrer.

3. Which referrerpolicy value should I use?

strict-origin-when-cross-origin for almost everything: your own site sees the full URL, other sites see only your domain. It is the modern browser default, and setting it explicitly (as a header or meta tag) makes the behaviour deliberate rather than accidental. Use no-referrer on links from pages whose URLs contain tokens or private IDs, and on links to sites you do not trust at all. Avoid unsafe-url except on a single link to a trusted partner that genuinely needs the full URL.

4. Can a sandboxed iframe still run JavaScript?

Only if you allow it. A bare sandbox attribute blocks scripts entirely; the embedded page renders as static content. Add allow-scripts and scripts run — but inside the sandbox, without access to your page’s DOM or storage (unless you also add allow-same-origin, which you should not do for untrusted content). The point of sandbox is not to ban scripts; it is to make every capability an explicit, deliberate choice.

5. Why do browsers ignore autocomplete=”off” on password fields?

Because disabling the password manager makes security worse, not better. When browsers cannot save or fill a password, users fall back to short, memorable, reused passwords — and reuse is a far bigger risk than autofill. Browsers therefore ignore off on login, password, and credit-card fields and expect you to use the precise tokens instead: current-password for login, new-password for registration and password changes, and one-time-code for verification codes. off still works on genuinely one-off fields such as promo codes and honeypot inputs.

Conclusion

HTML security attributes are the cheapest security upgrade on the web. Four attributes, a few words each, no JavaScript, no server changes, no performance cost — and together they close four holes that are open on most of the pages you visit every day. A link that cannot be turned against your visitors, a Referer header that carries only what the destination needs, an embedded page that holds only the permissions you granted it, and a form the browser fills correctly because every field says what it is.

Make them a habit, not a project. Add rel noopener (rel="noopener") to every new-tab link as you write it, not in a later audit. Set the referrer policy once, at the server or in a meta tag, and let it cover every page. Sandbox every embed by default and unlock permissions one token at a time. Label every form field with its autocomplete token when you build the form, not after a user reports a wrong autofill. None of these is a feature your visitors will notice — that is the point. Security attributes are invisible when they work, and the day they matter is the day a visitor never finds out they were needed.

Next, put the form skills from this guide to work on a real project: ten beginner HTML projects that turn these techniques into pages you can actually ship. Start with the projects guide, and keep building from there.

Related Articles You’ll Love

No comment

Leave a Reply

Your email address will not be published. Required fields are marked *