Bookmarks, new tabs and downloads: control where a link leads
A long page needs shortcuts to its sections. Some links open another tab, and some offer a file to save. Learn the attributes behind these behaviours and test what the browser actually does.
Imagine a notebook with a small paper tab beside the revision section. You can open that section without turning every page. An HTML bookmark works through an element's id, a unique identifier within the document.
Give the destination an id and link to it with # followed by that exact value. The # part is called a fragment. The id itself does not contain the leading #.
HTML fragment — part of a document
<ahref="#practice">Go to practice</a><h2id="practice">Practice</h2>
Use meaningful ids without spaces, such as practice or before-you-start. Match the case exactly and do not repeat the same id on the page. A heading is often a sensible destination because it names the section readers are reaching.
Join the shortcut to its section
1Give the section a unique id
2Write # followed by that id in href
3Activate the link
4Check the destination and address fragment
A short page may already show the destination, so scrolling may be small or absent.
Complete program: session-guide.html
session-guide.html
<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><title>Practice Session Section Guide</title></head><body><h1id="top">Your practice session guide</h1><ul><li><ahref="#prepare">Before the session</a></li><li><ahref="#practice">Practice task</a></li></ul><h2id="prepare">Before the session</h2><p>Save one HTML page and write down a question.</p><h2id="practice">Practice task</h2><p>Explain the page to a partner and check one change.</p><p><ahref="#top">Return to the guide heading</a></p></body></html>
Browser previewDocument title: Practice Session Section Guide
This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here.
Expected result: two section shortcuts appear above the sections. In your own browser, clicking one normally adds its fragment to the address and moves towards the destination. A short page may already show the destination, so the visible movement can be small or absent. It does not need an artificial tall gap to become a valid bookmark.
Link to a section in another file
HTML fragment — part of a document
<ahref="session-guide.html#practice">Read the session practice task</a>
The browser opens session-guide.html and then looks for id="practice". If the file exists but that id does not, the page may load without the intended jump. Check the file path and fragment separately.
Id-based links are the modern approach. You may see named anchors in old pages; use ids on suitable existing elements for new work. An empty href points at the current document URL, and href="#" points to its top. Neither is a good placeholder for a future working action.
Target: where to open the destination
The target attribute chooses the browsing context, such as the current tab or a new one. A browser may use a tab or a window according to its settings.
Value
Meaning
_self
Open in the current context; the usual default
_blank
Request a new tab or window
_parent
Open in the parent frame context, when one exists
_top
Open in the top-level context, when frame restrictions permit
Most beginner pages need only the default _self. Avoid forcing a new tab for every ordinary link. If you use _blank, tell the reader so they can predict the result.
HTML fragment — part of a document
<ahref="https://example.com/"target="_blank"rel="noopener">Open the example site (new tab)</a>
Rel describes a relationship or handling rule for the link. Noopener prevents the newly opened page from receiving an opener reference to the original page. Modern browsers generally apply this protection to _blank automatically; writing it explicitly makes the intention clear. Noreferrer also suppresses the referrer information sent with the request and implies noopener. It is not required on every link; use it when that privacy behaviour is intended.
The lesson previews deliberately block outgoing navigation and new tabs. Save the program or use the example ZIP to test this behaviour in a normal browser tab.
Download: offer a file to save
The download attribute tells the browser that a link is intended as a download. An optional value suggests a filename. It does not create a file, convert its format or make the content private.
HTML fragment — part of a document
<ahref="files/practice-checklist.txt"download="my-practice-checklist.txt">Download the practice checklist (text file)</a>
The actual file still lives at files/practice-checklist.txt. The suggested downloaded name is my-practice-checklist.txt. The browser may adjust the name and may follow its settings or server headers when deciding what to do.
Download is generally supported for same-origin URLs and blob or data URLs. Same origin means the same scheme, host and port. Do not assume that adding download to any other website's PDF forces a download. Browser rules and response headers can change the outcome. For this lesson, use the supplied local example files; check served-site behaviour again when deploying.
Complete program: download-guide.html
The example ZIP includes files/practice-checklist.txt. If creating the folder yourself, put a plain text checklist there before testing the link.
download-guide.html
<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><title>Practice File Downloads</title></head><body><h1>Keep your practice checklist</h1><p><ahref="files/practice-checklist.txt"download="my-practice-checklist.txt">Download the practice checklist (text file)</a></p><p><ahref="session-guide.html#practice">Review the session practice task</a></p><p><ahref="https://example.com/"target="_blank"rel="noopener">Open the example site (new tab)</a></p></body></html>
Browser previewDocument title: Practice File Downloads
This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here.
Expected result: three links with three different purposes. Test them separately. The checklist file should be offered according to your browser's download handling, the session link should reach a section, and the external example should request another tab or window when internet access is available.
Problem and solution: a renamed section stops working
Problem: you change id="practice" to id="task", but leave the menu link as href="#practice".
Solution: update all links that refer to that identifier. Changing the visible heading words alone does not require changing the id. Keep stable, useful ids so previously shared section links keep working.
Common mistakes and useful tips
Including # inside the actual id value.
Reusing an id on several headings.
Assuming no visible scroll means the link is broken on a short page.
Claiming _blank always creates a window rather than a browser-chosen tab or window.
Expecting download to bypass another website's rules or protect a paid file.
Omitting the destination file from an upload.
Surprising readers with new tabs or unexplained file downloads.
Practice questions
Write the href that targets id="answers" on the current page.
How do you target that id in review.html?
Why must ids be unique within a document?
What does target="_blank" request?
Does download create a file or guarantee the behaviour of an unrelated website?
Build a page with two section shortcuts, a return-to-top link and a local text download. Check each destination and explain any browser download prompt you see.
Check your practice answers
href="#answers".
href="review.html#answers".
Each identifier should name one destination. Repetition makes references ambiguous and is invalid authoring.
A new browsing context, usually a tab or window according to browser settings.
No. The resource must exist, and browser, origin and server rules still apply.
Give each section a unique id, match the fragments and create the actual text file. Test in your own browser because the lesson previews restrict outgoing actions.
Interview questions
How does a same-page fragment link work?
The href contains # followed by the destination id. The browser resolves that fragment within the document and normally moves towards the matching element.
Why use noopener with a new-tab link?
It prevents the new page from receiving a reference through which it could access the opener relationship. Explicit noopener documents that intention even where modern _blank behaviour already supplies it.
How do noopener and noreferrer differ?
Noopener handles the opener reference. Noreferrer suppresses referrer information and also implies noopener. Choose based on the intended behaviour rather than treating the words as identical.
Is the download attribute access control?
No. It is a download hint, not authentication or payment protection. A service must check access separately before delivering a protected resource.
Quick revision
Link #name to a unique id="name".
Combine a filename and fragment for another page's section.
Use new tabs thoughtfully and label them clearly.
Downloads need real files and respect browser and server rules.