HTML Links - HTML Internal Link

HTML internal link is linked within the same web page. This link can be an absolute path or relative path.

HTML internal link name is followed by the hash sign(#). You have to assign an id to refer section of your page, which is referred to as an internal link to the same page.

When you click on an internal anchor link, you will scroll automatically to the referred section and display it on your browser.

To understand internal link see the below examples.

  • <a href="#lession1">Lession.1</a> link can be referred as <a id="lession1">Introduction of Lession.1</a> automatically.

  • <a href="#lession2">Lession.2</a> link can be referred as <div id="lession2">Introduction of Lession.2</div> automatically.

Notes: You can not use name attribute instead of id attribute. Because name attribute not supported in HTML5. Use the id attribute instead of.

Example

<!DOCTYPE html>
<html>
<head>
</head>
<body>
  <a href="#lession1">Lession.1</a><br />
  <a href="#lession2">Lession.2</a><br />
  <a href="#lession3">Lession.3</a><br />
  <a href="#lession4">Lession.4</a><br />
  <br />

  <a id="lession1">Introduction of Lession.1</a>
  <p>This is sub topic.1</p>
  <p>This is sub topic.2</p>
  <p>This is sub topic.3</p>
  <p>This is sub topic.4</p>
  <br />
  <br />
  <div id="lession2">Introduction of Lession.2</div>
  <p>This is sub topic.1</p>
  <p>This is sub topic.2</p>
  <p>This is sub topic.3</p>
  <p>This is sub topic.4</p>
  <br />
  <br />
  <p id="lession3">Introduction of Lession.3</p>
  <p>This is sub topic.1</p>
  <p>This is sub topic.2</p>
  <p>This is sub topic.3</p>
  <p>This is sub topic.4</p>
  <br />
  <br />
  <article id="lession4">Introduction of Lession.4</article>
  <p>This is sub topic.1</p>
  <p>This is sub topic.2</p>
  <p>This is sub topic.3</p>
  <p>This is sub topic.4</p>
</body>
</html>

Run it...   »


Linking to parts of other documents

You can set target to specific sections of the other pages by adding the #id at the end of the href. After adding hash mark is known as a "fragment identifier". This helps a lot for example, you can link to the third section of this tutorial from anywhere else, you have to write

<a href="https://way2tutorial.com/html/html_internal_links.php#section-id">