The simplest way to create a web link
A web link is made with a single line of HTML code called an anchor tag. The tag opens with <a>, contains the text you want readers to click, and closes with </a>. Between the opening tag and the text, you add an href attribute that tells the browser where to go when someone clicks.
The basic structure looks like this: <a href="https://example.com">Click here</a>. When a browser displays this code, readers see the words "Click here" in blue and underlined. Clicking those words takes them to example.com. That is the entire mechanism — the href attribute holds the destination, and the text between the tags is what appears on the page.
You can use this same pattern for any destination: another page on your own website, a page on someone else's website, an email address, or a file to download. The only thing that changes is what you put inside the href attribute.
Key Takeaways
- Every web link uses an anchor tag with an href attribute that contains the destination URL.
- Links to pages on your own site use relative paths like href="about.html", while links to other websites use full URLs like href="https://example.com".
- You can open a link in a new tab by adding target="_blank" to the anchor tag.
- Email links use href="mailto:name@example.com" and file downloads use href="filename.pdf" or the full path to the file.
Links to other websites versus your own pages
When you link to another website, you must use the complete web address, starting with https:// or http://. This is called an absolute URL. For example: <a href="https://www.wikipedia.org">Wikipedia</a>. The browser needs the full address because it is looking outside your own website.
When you link to a page on your own website, you can use a shorter path called a relative URL. If you have a file named about.html in the same folder as the page you are editing, the link is simply <a href="about.html">About Us</a>. If about.html is in a subfolder called pages, the link becomes <a href="pages/about.html">About Us</a>. Relative URLs are shorter and make your site easier to move or reorganize later.
The difference matters because browsers treat them differently. A relative URL tells the browser "look for this file starting from where we are right now." An absolute URL tells the browser "go to this exact address on the internet." Using the wrong one is the most common reason a link breaks.
Opening links in a new tab or window
By default, clicking a link replaces the current page with the destination. If you want the link to open in a new tab instead, add target="_blank" to the anchor tag. The code becomes <a href="https://example.com" target="_blank">Visit Example</a>. Now clicking the link opens the destination in a new tab while keeping your original page open in the background.
This is useful when you are linking to another website and want readers to stay on your page. It is less necessary for links within your own site, since readers expect those to replace the current page. Many websites link to external sources with target="_blank" and internal pages without it, so readers know what to expect.
A related attribute is rel="noopener noreferrer", which you should add whenever you use target="_blank" on a link to an external website. This prevents the destination page from accessing information about your site. The full code is <a href="https://example.com" target="_blank" rel="noopener noreferrer">Visit Example</a>.
Creating email links and download links
An email link lets readers send you a message by clicking a link. Instead of a web address in the href, you use mailto: followed by an email address. The code is <a href="mailto:contact@example.com">Email us</a>. Clicking this link opens the reader's default email program with your address already filled in as the recipient.
You can add a subject line to the email by including ?subject= after the address. For example: <a href="mailto:contact@example.com?subject=Website Inquiry">Email us</a>. When someone clicks this link, their email program opens with "Website Inquiry" already in the subject field.
Download links work like regular links to other websites, but they point to a file instead of a web page. If you have a PDF file named guide.pdf in a folder called downloads, the link is <a href="downloads/guide.pdf">Download our guide</a>. When readers click this link, their browser downloads the file instead of trying to display it. You can use this same pattern for Word documents, images, spreadsheets, or any other file type.
Making links descriptive and accessible
The text between the opening and closing anchor tags should describe where the link goes. Instead of writing <a href="about.html">Click here</a>, write <a href="about.html">Learn about our company</a>. Descriptive link text helps readers understand what they will find before they click, and it also helps search engines understand your site's structure.
Descriptive text is especially important for people using screen readers, which read web pages aloud to people with vision loss. A screen reader user might hear "link, click here" with no context about where the link goes. The same screen reader would say "link, learn about our company," which is much more useful. Writing clear link text benefits everyone.
Avoid using the URL itself as link text. Instead of <a href="https://example.com/products">https://example.com/products</a>, write <a href="https://example.com/products">Browse our products</a>. The URL is not a good description, and reading a long URL aloud is tedious for screen reader users.
Linking to a specific section within a page
You can link directly to a heading or section within a page using an anchor ID. First, add an id attribute to the heading you want to link to. For example: <h2 id="pricing">Pricing</h2>. Then create a link that points to that ID by adding a hash symbol and the ID name to the href. The code is <a href="pricing.html#pricing">See our pricing</a>.
If you are linking to a section on the same page, you can skip the filename. The code becomes <a href="#pricing">See our pricing</a>. When someone clicks this link, the page scrolls down to the heading with id="pricing". This is useful for long pages with multiple sections, because it lets readers jump directly to the part they want.
The ID name can contain letters, numbers, and hyphens, but it must start with a letter. Common practice is to use lowercase letters and hyphens instead of spaces, like id="frequently-asked-questions" instead of id="Frequently Asked Questions". The ID must be unique on the page — you cannot use the same ID twice.
Common mistakes and how to fix them
The most common mistake is forgetting the https:// when linking to an external website. If you write <a href="example.com">Example</a> instead of <a href="https://example.com">Example</a>, the browser treats it as a relative link and looks for a file named example.com on your own server. The link breaks silently — it does not show an error, it just goes nowhere.
Another common problem is using backslashes instead of forward slashes in file paths. Windows uses backslashes in folder paths, but web links always use forward slashes. If your file is in a folder called My Documents, the link should be <a href="my-documents/file.html">, not <a href="my-documents\file.html">. Backslashes break links on web servers.
Typos in filenames are also easy to miss. If your file is named about-us.html but you write href="about_us.html" with an underscore instead of a hyphen, the link breaks. Check that the filename in your href matches exactly, including capitalization, hyphens, underscores, and file extensions.
Frequently Asked Questions
Can I style a link to look different from the default blue and underline?
Yes, using CSS. You can change the color, remove the underline, add a background, or make the link change appearance when someone hovers over it. The CSS selector is a for all links, or you can target specific links by adding a class or ID to the anchor tag and styling that. Most websites customize their links to match their design.
What is the difference between href and src?
The href attribute is used in anchor tags to create links. The src attribute is used in image tags and script tags to load files. They serve different purposes — href creates a clickable link, while src loads a resource that displays or runs on the page. Using the wrong one will not work.
Do I need to add www to the beginning of a web address?
No. Modern websites work with or without www, so href="https://example.com" and href="https://www.example.com" both work. Most websites automatically redirect one to the other. You can use whichever form you prefer, but be consistent throughout your site.
How do I link to a PDF or other file on my server?
Use the same anchor tag as you would for a web page, but point to the file instead. If your PDF is in a folder called downloads, write <a href="downloads/guide.pdf">Download our guide</a>. The browser will download the file when someone clicks the link, or display it in the browser if the browser can show that file type.
What does it mean when a link is broken?
A broken link is one that goes nowhere because the destination does not exist or the path is wrong. This happens when you delete a page, move a file to a different folder without updating the link, or make a typo in the href. Broken links frustrate readers and hurt your search engine ranking, so test all your links regularly.