Linking to content on the same page
Web Design with HTML & CSS
🕑 This lesson will take about 5 minutes
We have already looked at how to link pages on a website. However, we can also link to different sections of a single web page. For example, if you have a long web page with lots of content, you can have a table of contents with links, allowing the user to click on a link that will take them to a certain part of that web page.
You can link to other elements on a web page such as a heading, paragraph, div, or image. In this lesson, we will look at how to link to different headings on a web page. We do this by giving headings an ID and then referencing that ID in links using the <a> tag.
Watch the video below which explains how to link to content on the same page, and then scroll down to see the sample code.
Here is the code for the example shown in the video. The ‘Welcome’, ‘About’, and ‘Contact Us’ links take the viewer to different sections of the same web page when clicked.
Next lesson: CSS nth-child() selector