Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Linking Pages

Now, let’s add a link to a second page from our index.html page.

We create links using the <a> tag and its href attribute. The <a> tag defines a hyperlink, and the href attribute specifies the link’s destination. You can use it to link to another page in your website or to an external website.

The syntax is:

<a href="URL">Text that will appear as the link</a>

Example

On your index.html page, below your paragraph, add:

<a href="page2.html">Link to page 2</a>

Full example:

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<h1>This is a Heading</h1>
<p>This is a paragraph.</p>

<p><a href="page2.html">Link to page 2</a></p>

</body>
</html>

Open index.html in a web browser to see the link in action.

Explanation

When you click “Link to page 2”, your page2.html file should open.

If page2.html were in a different folder, you would need to include the folder path. For example, if it were in a folder called pages, the href would look like:

<a href="pages/page2.html">Link to page 2</a>

Application

If you haven’t already, create a second page and link to it from index.html.