html anchor link same page code example

Example 1: html a link to section on page

<!--1. create link tag with href containing "[#][section to direct] with name-->
<a href = #about-section>About</a>

<!--2. create identifier for the section you would like to navigate to with "id" = name-->
<section id = "about-section"> <h1>This is the about section</h1> </section>

Example 2: open link on same page html

<!-- Same Page: -->
<a href="google.com">Link</a>
<!-- Different Page: -->
<a href="google.com" target="_blank">Link</a>

Example 3: link to section on page html

<!-- #top is the ID of the div where u wanna link to -->
<a href="#top">Go back to the top!</a>

<div id="top"></div>

Example 4: link that scrolls down the page

<a href="#google"></a>

<div id="google"></div>

Tags:

Html Example