You can also set a hyperlink to a specific part of a web page. In order to implement this, you need to do two things:
id
attributeid
in the href
attribute in the <a>
tagHere are more detailed explanations.
These are the key points to set a unique address (id
) in the destination location:
id
attribute at the destination location (element)id
attribute can be any text (string value)id
can be used only one time in the same HTML file (on the same web page)These are the key points to set the address at the origin location:
id
in the href
attribute in the <a>
tag#
id
for the attribute value for href
in the <a>
tag. For example, if you set id="top"
for the target location of the web page, you can set the href
value like href="#top"
.You can also target a certain location on another web page as a hyperlink destination by adding a #id
value after the file path or URL. For example, if you want to add a link to the location with id="top"
in index.html, the code will be like the one below.
<a href=index.html#top></a>
More specifically, create two sections on the same web page and set hyperlinks to switch views like shown in the illustration below.
</body>
tag (the body end tag).
<!--Hyperlinks to Specific Location on Web Page-->
<section id="section_1" style="height:100vh;background-color:green">
<h1>Section 1</h1>
<a href="#section_2">Go to section 2</a>
</section>
<section id="section_2" style="height:100vh;background-color:yellow">
<h1>Section 2</h1>
<a href="#section_1">Go to section 1</a>
</section>
Open the chapter4.html file with a browser and check how the hyperlinks are working. The code you have implemented will result in the video shown below.
You can also set a hyperlink to a specific part of a web page. In order to implement this, you need to do two things:
id
attributeid
in the href
attribute in the <a>
tagHere are more detailed explanations.
These are the key points to set a unique address (id
) in the destination location:
id
attribute at the destination location (element)id
attribute can be any text (string value)id
can be used only one time in the same HTML file (on the same web page)These are the key points to set the address at the origin location:
id
in the href
attribute in the <a>
tag#
id
for the attribute value for href
in the <a>
tag. For example, if you set id="top"
for the target location of the web page, you can set the href
value like href="#top"
.You can also target a certain location on another web page as a hyperlink destination by adding a #id
value after the file path or URL. For example, if you want to add a link to the location with id="top"
in index.html, the code will be like the one below.
<a href=index.html#top></a>
More specifically, create two sections on the same web page and set hyperlinks to switch views like shown in the illustration below.
</body>
tag (the body end tag).
<!--Hyperlinks to Specific Location on Web Page-->
<section id="section_1" style="height:100vh;background-color:green">
<h1>Section 1</h1>
<a href="#section_2">Go to section 2</a>
</section>
<section id="section_2" style="height:100vh;background-color:yellow">
<h1>Section 2</h1>
<a href="#section_1">Go to section 1</a>
</section>
Open the chapter4.html file with a browser and check how the hyperlinks are working. The code you have implemented will result in the video shown below.