The basic method: use an anchor tag with href
To make a link into words, wrap the text in an anchor tag — the HTML element that turns any text into something clickable. The tag is <a>, and it needs one piece of information: where the link should go. That location goes in the href attribute.
Here is the simplest form: <a href="https://example.com">Click here</a>. The text between the opening and closing tags — "Click here" in this case — is what the reader sees and clicks on. The href tells the browser where to send them.
You can use any text you want. Instead of "Click here", you might write <a href="https://example.com">Learn more about our pricing</a> or <a href="https://example.com">Visit our homepage</a>. The visible text and the destination are separate — one is what people read, the other is where they go.
Key Takeaways
- An anchor tag with an href attribute turns text into a clickable link: <a href="URL">visible text</a>.
- The visible text can be anything you want and does not have to match the URL it points to.
- Links to other websites must start with http:// or https://, but links to pages on your own site do not.
- You can open a link in a new tab by adding target="_blank" to the anchor tag.
- Descriptive link text helps both readers and search engines understand what the link leads to.
Where the link should point: absolute and relative URLs
The href can point to two different kinds of locations. An absolute URL includes the full web address and works from anywhere: <a href="https://www.wikipedia.org">Wikipedia</a>. This link works the same whether it is on your homepage, a blog post, or anywhere else on the internet.
A relative URL points to a file on your own website and only includes the path from your current location. If you are on your homepage and want to link to a page called "about.html" in the same folder, you write <a href="about.html">About Us</a>. If the page is in a subfolder called "pages", you write <a href="pages/about.html">About Us</a>.
Use absolute URLs when linking to other websites. Use relative URLs when linking between pages on your own site — they are shorter and still work if you move your site to a different domain later.
Opening links in a new tab or window
By default, a link opens in the same tab or window where the reader clicked it. If you want the link to open in a new tab instead, add the target attribute with the value _blank: <a href="https://example.com" target="_blank">Read more</a>.
This is useful when you are linking to another website and want the reader to stay on your page. It is less useful for links within your own site, since it can fragment the reader's browsing experience. Many readers expect internal links to stay in the same tab.
If you use target="_blank", consider adding rel="noopener noreferrer" as well: <a href="https://example.com" target="_blank" rel="noopener noreferrer">Read more</a>. This protects your site's security by preventing the linked page from accessing your browser's window object.
Writing link text that actually describes where it goes
The text inside the anchor tag should tell the reader what they will find when they click. "Click here" and "Read more" are vague — they do not explain what the reader is clicking to see. "Learn about our refund policy" and "Read the full article on climate change" are specific and useful.
Descriptive link text also helps search engines understand your site. When Google crawls your pages, it reads the link text to figure out what the destination page is about. A link that says "Our services" tells the search engine less than a link that says "Web design and hosting services".
Avoid writing the full URL as the visible text. <a href="https://example.com/pricing">https://example.com/pricing</a> is harder to read than <a href="https://example.com/pricing">View our pricing</a>. The href does its job invisibly — the visible text should be human-readable.
Linking to specific sections within a page
You can link directly to a heading or section on a page by using an anchor ID. First, add an id attribute to the heading you want to link to: <h2 id="pricing">Pricing</h2>. Then link to it using a hash symbol followed by the id: <a href="https://example.com#pricing">Jump to pricing</a>.
If the section is on the same page, you can skip the domain name: <a href="#pricing">Jump to pricing</a>. This is useful for long pages with a table of contents at the top, or for linking from one page to a specific section on another page.
The id must be unique on the page — no two elements should have the same id. Use lowercase letters, numbers, and hyphens in the id, and avoid spaces.
Styling links with CSS
By default, links appear in blue and underlined. You can change how they look using CSS. The simplest approach is to style the <a> tag directly in your stylesheet: a { color: green; text-decoration: none; } removes the underline and makes all links green.
You can also style links based on their state. a:hover applies styles when the reader hovers their mouse over the link, a:visited styles links the reader has already clicked, and a:active styles the moment the link is being clicked. For example: a:hover { color: darkgreen; text-decoration: underline; } makes links darker and underlined when you hover over them.
Keep in mind that readers expect links to look like links. If you remove the underline and use a color that does not stand out from regular text, some people will not realize the text is clickable. Maintain enough visual contrast so links are obvious.
Common mistakes and how to fix them
The most common mistake is forgetting the https:// at the start of an external URL. If you write <a href="example.com">Example</a> without the protocol, the browser treats it as a relative link and looks for a file called "example.com" on your own server instead of going to the website. Always include https:// for external links.
Another mistake is using vague link text like "Click here" or "More information". This makes the page harder to scan and does not help search engines or people using screen readers understand what the link leads to. Write text that describes the destination.
A third mistake is linking to the wrong page. Test every link you create by clicking it and confirming it goes where you intended. Broken or misdirected links frustrate readers and hurt your site's credibility.
Frequently Asked Questions
Can I put an image inside an anchor tag?
Yes. Wrap the image tag in an anchor tag the same way you would wrap text: <a href="https://example.com"><img src="image.jpg" alt="description"></a>. The image becomes clickable and links to the URL in the href.
What is the difference between href and src?
href is used in anchor tags to specify where a link goes. src is used in image and script tags to specify where a file is located. They serve different purposes in different tags.
How do I link to an email address?
Use mailto: before the email address: <a href="mailto:contact@example.com">Email us</a>. When clicked, this opens the reader's default email program with the address already filled in.
Can I use a button instead of a link?
A button and a link are different elements with different purposes. Use a link when you are navigating to a new page or section. Use a button when you are performing an action like submitting a form. If you want a button to look like a link, style it with CSS instead of changing the HTML.
Do I need to write the full URL every time?
No. For links within your own site, use relative URLs like href="about.html" or href="pages/contact.html". For links to other websites, use the full URL starting with https://.