Skip to content

Links

Links are what make the web the web. Every time you click something and go somewhere new, that is a link. In HTML, they are made with the <a> tag.


The <a> tag

<a> stands for anchor. It wraps around the text you want to be clickable.

<a href="https://www.python.org">Visit the Python website</a>

Breaking that down:

  • <a> — the opening tag
  • href="https://www.python.org" — where the link goes. This is called an attribute.
  • Visit the Python website — the text the user sees and clicks
  • </a> — the closing tag

What is an attribute?

An attribute gives a tag extra information. It always lives inside the opening tag, and follows this format:

attribute-name="value"

The <a> tag needs href to know where to send the user. Without href, the link goes nowhere.

You will see attributes a lot from here on — they are how you give tags instructions beyond just "exist on the page".


Linking to another website

Use the full address, including https://:

<a href="https://www.wikipedia.org">Wikipedia</a>

Linking to another file on your own computer

If you have another HTML file in the same folder, just use the filename:

<a href="about.html">About Me</a>

No full URL needed — just the filename.


Try it in VSCode

Add this to your first.html:

<p>I learned Python before HTML. Read more on 
<a href="https://www.python.org">the official Python website</a>.</p>

Save and refresh. Click the link — it should open python.org.


Opening in a new tab

Add target="_blank" to open the link in a new tab so the user does not leave your page:

<a href="https://www.python.org" target="_blank">Python website</a>

Challenge

In VSCode, create a second file called about.html in the same folder as first.html. Put a heading and a short paragraph in it.

Then in first.html, add a link that goes to about.html:

<a href="about.html">Read about me</a>

Open first.html in your browser and click the link. Does it take you to your second page?


← Headings and Paragraphs    Next: Images →