Frontend Master

JavaScript Curriculum

Linking Things Together
+40 XP

Linking Things Together

easy
~25 min·40 XP

The Nexus portal needs navigation: links to the dashboard, the docs, and external tools like GitHub. You need to understand link anatomy before you can build any navigation system.

Linking Things Together

The <a> (anchor) element is arguably the most important element in HTML. It's what turns a collection of documents into a web — a network of interconnected pages. Every navigation bar, every button that takes you somewhere, every "read more" link is an anchor tag.

Anatomy of a Link

anchor.html
<a href="https://example.com" target="_blank" rel="noopener noreferrer">Visit Example</a>

Rendered:

URL type detected

Absolute URL

Security: Without rel="noopener", the opened page can access your page's window object and redirect it (tab-jacking). Always add rel="noopener noreferrer" with target="_blank".

💡Descriptive Link Text
Never write `<a href="...">click here</a>`. Screen reader users often navigate a page by listening to a list of all links — "click here" tells them nothing. Write links that describe their destination: "View Nexus Dashboard", "Read the CSS Grid guide", "Download invoice PDF".

Absolute vs Relative URLs

When you set the href attribute, you have two choices for how you write the path:

paths.html
Current file
/coffee/pages/menu.html
href value./specials.htmlrelative

Path resolution:

1

Start at the current file's location

/coffee/pages/menu.html

When to use each:

Use caseURL typeExample
Linking to another websiteAbsolutehttps://github.com
Linking to your own pagesRelative/about or ../contact
Linking within a pageFragment#section-id
EmailingMailtomailto:hello@nexus.io
ℹ️Root-Relative vs Truly Relative
`/about` is **root-relative** — it always means the `/about` path from the domain root, regardless of where the current page is. `./about` or just `about` is **truly relative** — it's relative to the current page's directory. For internal navigation, root-relative (`/about`) is usually safer and more predictable.

The target Attribute

target tells the browser where to open the linked document:

link-targets.html
target="_self"

Default behaviour. Navigates in the same tab, replacing the current page. The user's browser history updates normally.

<a href="/page" target="_self">Link</a>

What happens visually:

destination.html
← Page replaced in same tab

Security: noopener noreferrer

When you use target="_blank", the newly opened page gets access to the window.opener object — it can manipulate the original page with JavaScript. This is called a reverse tabnapping attack.

html
<!-- Vulnerable new tab can access window.opener --> <a href="https://external.com" target="_blank">Visit</a> <!-- Secure new tab is isolated --> <a href="https://external.com" target="_blank" rel="noopener noreferrer">Visit</a>

noreferrer also prevents the browser from sending the Referer header, which hides your page's URL from the destination site's analytics.

⚠️Modern Browsers
Modern browsers (Chrome 88+, Firefox 79+) automatically add `rel="noopener"` behaviour for `target="_blank"` links, even without the attribute. But you should still write it explicitly — it documents your intent and supports older browsers.

Challenge

Build a Nexus navigation snippet with three links: one absolute link to an external site opening in a new tab (with correct security attributes), one root-relative internal link, and one relative link to a sibling page — all with descriptive link text.

anchorhreftargetrelabsolute-urlrelative-urlaccessibilitysecurity
Linking Things Together | Nexus Learn