HTML Links, Buttons & Iframes
HTML links allow users to click their way from page to page. Buttons provide interactive triggers, and iframes display nested external web pages inside your document. Learn essential link attributes, tabnapping security architecture, and iframe sandbox security models.
Click Try it Yourself » to test HTML links, buttons, download attributes, and sandboxed iframes in the playground.
Example: Hyperlinks, Buttons & Sandboxed Iframes Overview
5.1 HTML Links & Key Attributes (href, target, rel, download)
HTML hyperlinks are defined with the <a> (anchor) element. The most important attribute is href, which indicates the destination address:
| Attribute | Value | Description |
|---|---|---|
href |
URL / File / Email / Tel | Specifies the target URL or action protocol (mailto:, tel:). |
target |
_self | _blank | _parent | _top |
Specifies where to display the linked response. _blank opens a new tab. |
rel |
noopener | noreferrer | nofollow |
Specifies the relationship between the current document and the linked URL. |
download |
[filename] | Instructs the browser to download the target URL file instead of navigating to it. |
Try It Yourself: HTML Link Attributes & Protocols
5.2 Tabnapping Security Architecture (rel="noopener noreferrer")
When you open an external page using target="_blank" without protection, the newly opened page gets access to your original page's window.opener object! Malicious pages can redirect your original tab to a fake login form—a vulnerability known as Reverse Tabnabbing.
Tabnapping Security Architecture: Unprotected vs Protected
rel="noopener"setswindow.openertonull, disconnecting the new window from your page.rel="noreferrer"prevents sending theHTTP Refererheader along with settingwindow.opener = null.
Try It Yourself: Secure External Tab Link
5.3 HTML Buttons (<button>) & Types
The <button> element defines a clickable button. Always specify the type attribute to avoid unexpected form submissions:
type="button"— A standard clickable button used for client-side JavaScript actions.type="submit"— Submits form payload data to the server endpoint.type="reset"— Resets all form inputs to their initial values.
Try It Yourself: Button Types & Click Handlers
5.4 HTML Iframes (<iframe>), Sandbox & Allow Feature Policy
An HTML iframe embeds an independent HTML document inside the current page. To secure embedded external pages, use the sandbox attribute:
Iframe Sandbox Security Isolation Layer
sandbox=""— Applies all restrictions (blocks scripts, forms, popups, same-origin access).allow-scripts— Allows the embedded iframe document to run JavaScript.allow-forms— Allows the iframe to submit forms.allow-same-origin— Allows the iframe content to retain its original domain origin cookies.
Try It Yourself: Sandboxed Iframe Embed
💻 Chapter 5 Hands-On Code Challenge
Build a Contact & Support Action Bar featuring secure external links with rel="noopener noreferrer", email triggers, telephone call buttons, interactive alert buttons, and a sandboxed iframe:
- Add a link with
target="_blank"andrel="noopener noreferrer". - Add a
mailto:email link and atel:phone link. - Add a file
downloadlink. - Add an interactive
<button>that triggers a JavaScript alert when clicked. - Embed a sandboxed
<iframe>withtitleand permission flags.
Chapter 5 Key Takeaways
- Links use
href; addtarget="_blank"andrel="noopener noreferrer"for secure external tab links. - Special
hrefprotocols includemailto:for emails andtel:for telephone calls. - The
downloadattribute instructs browsers to download the target resource file. - Buttons require explicit
type="button"to prevent accidental form submission. - The
sandboxattribute on<iframe>isolates third-party content to prevent security vulnerabilities.