Links: connect pages and offer useful destinations
A link lets a reader move to another resource. Build two pages that link to each other, write link text that explains the destination, and understand what email and telephone links really do.
Imagine a college corridor. A sign saying Library tells you where a doorway leads. On a web page, a link's words are that sign, and its address tells the browser where to go.
HTML uses the a element, also called an anchor, to make a link when it has an href attribute. Href supplies the destination address. The content between the tags is the link text or other linked content.
HTML fragment — part of a document
<ahref="link-session.html">View the practice session</a>
Here, a is the element name, href is the attribute, link-session.html is its value, and View the practice session is the visible label. The closing a ends the link. Without href, an a element is not a normal hyperlink to a destination.
Different destinations, the same basic idea
Destination
Example href
What to expect
Another file in the same folder
link-session.html
Open that HTML file
A full website address
https://example.com/
Request a page from that website
A section of this page
#practice
Move to the element with that id
An email address
mailto:club@example.com
Ask a configured email application to compose a message
A telephone number
tel:+15550100123
Offer the device's configured calling action
An address, also called a URL, identifies a resource or another supported destination. We will unpack its parts in the next chapter. A link does not need JavaScript to navigate.
Save two files together
Create a folder called link-practice. Save link-home.html and link-session.html inside it. Keep the spellings exactly as shown. Both pages need to exist; writing their names in href does not create them.
The lesson's browser previews show each document separately. To test movement between the files, use the example ZIP or save both programs locally and open link-home.html in your own browser.
Complete program: link-home.html
link-home.html
<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><title>Peer Practice Home</title></head><body><h1>Peer practice home</h1><p>Read the plan before joining the activity.</p><p><ahref="link-session.html">View the practice session</a></p></body></html>
Browser previewDocument title: Peer Practice Home
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 paragraphs appear below the heading. The second contains a link. Its usual default appearance is coloured and underlined, but styles and visited-link settings can change that appearance.
Complete program: link-session.html
link-session.html
<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><title>Peer Practice Session</title></head><body><h1>Practice one clear explanation</h1><p>Meet in Room 6 with one saved HTML page.</p><p><ahref="link-home.html">Return to peer practice home</a></p></body></html>
Browser previewDocument title: Peer Practice Session
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.
Open the home file and activate its link. The second page should appear, with a different tab title. Activate Return to peer practice home to go back. You can also use the browser's Back button. A return link and Back are not identical: the return link has a fixed destination, while Back follows your actual browsing history.
Follow a destination that really exists
1Save the home document
2Save the session document beside it
3Match the filename in href
4Test the forward and return links
The lesson preview is read-only for outgoing links. Test the downloaded files in your own browser.
Full addresses need their beginning
For a link to another website, write the full HTTPS address.
HTML fragment — part of a document
<p><ahref="https://example.com/">Open the example website</a></p>
Without https://, a value such as example.com is usually treated as a relative path, not automatically as that website. The browser may try to find a file or folder with that name under the current page's location.
HTTPS protects the connection to the named site when used correctly; it does not guarantee that the site's content or seller is trustworthy. Check destinations before sharing them with students.
Write useful link words
Prefer View the practice session to Click here. Readers should understand the purpose from the label and its surrounding text. Many people move through links with a keyboard or a reading tool, where repeated vague labels are difficult to distinguish.
Keep the text honest: a label saying Download checklist should not unexpectedly open a purchase page. If a link opens a new tab, warn readers in its text when practical. Target and downloads are covered in Chapter 18.
Email and telephone links
HTML fragment — part of a document
<p>Fictional club contact: <ahref="mailto:club@example.com">Email the practice club</a>.</p><p>Sample number: <ahref="tel:+15550100123">Call the sample help desk</a>.</p>
These are teaching placeholders, not a real support service. A mailto link does not send an email by itself. The reader may need to choose or configure an email application. A tel link does not guarantee a call; the device needs suitable calling support and the person remains in control.
For a real site, include visible contact details when useful so someone can copy them. Do not rely on a clickable action alone. Subject lines and other email parameters need correct URL encoding; do not paste private data into a link.
Links, buttons and keyboard use
Use a link for navigation to a destination. A button normally performs an action, such as submitting a form or opening an application control. A styled a can look like a button while still being a navigation link; its role comes from the element and behaviour.
Press Tab to move keyboard focus through links with href. Press Enter to activate the focused link. The focus outline shows where the next action will occur; do not remove that outline without a clear replacement. Never place a button or another link inside an a element. That creates conflicting interactive controls.
Problem and solution: the address looks correct but fails
Problem: the source says href="Link-Session.html", while the saved file is link-session.html. It works on one machine but fails after upload.
Solution: make the letter case match exactly. Many web servers distinguish uppercase and lowercase names. Also check the folder, spelling and extension. A file accidentally saved as link-session.html.txt is not the intended HTML file.
Common mistakes and useful tips
Omitting href and expecting ordinary link behaviour.
Leaving off https:// for an external website.
Using href="#" as a harmless placeholder: it can move the page to the top.
Assuming a destination file is created automatically.
Repeating Click here without explaining the destination.
Placing links inside other links or buttons inside links.
Expecting mailto to send a message or tel to work on every device.
Testing only with a mouse. Try Tab and Enter too.
Practice questions
Which element and attribute make a basic link?
Which part of an a element is normally the visible link label?
Why can href="example.com" fail to open the intended external site?
Does a mailto link send a message immediately?
How can a keyboard user reach and activate a normal link?
Save two complete HTML files together. Add a meaningful forward link and a return link, then check both directions and each browser tab title.
Check your practice answers
An a element with an href attribute.
The content between the opening and closing a tags.
Without a scheme such as https://, it is normally resolved as a relative path.
No. It requests a configured email application's compose action.
Reach it with Tab and activate it with Enter.
Match both actual filenames, keep the files in the intended folder, and use labels that name their destinations. Verify navigation in your own browser, not only the lesson preview.
Interview questions
What does href do?
It gives a link its destination. The browser resolves that address from the current document when necessary and follows it when the reader activates the link.
Why does meaningful link text matter?
It helps readers predict where they will go. It is especially useful when scanning a page or moving through links with a keyboard or reading tool.
When would you choose a button instead of a link?
Use a button for an action in the interface, such as submitting data. Use a link for navigation. Do not choose only by which default appearance you prefer.
Why should local links be tested after deployment too?
The server's file locations and case rules may differ from the local machine. Check that the deployed files actually exist at the addresses used by the links.
Quick revision
A with href creates a hyperlink.
Save the destination files; the link does not create them.
Use full HTTPS addresses for external websites.
Choose useful labels and check keyboard access.
Email and telephone links depend on the reader's configured applications.