Home

How to Link within the Same Page with HTML5

|
|  Updated:  
2016-03-26 14:03:46
HTML5 and CSS3 All-in-One For Dummies
Explore Book
Buy On Amazon

Links can help users navigate a single web page. Locations within web pages can be marked for direct access by links on the same page. Intradocument hyperlinks include such familiar features as

  • Back to Top links.

  • Tables of contents.

An intradocument hyperlink, also known as a named document link, uses a URL like this:

<a href="#top">Back to top</a>

The pound sign (#) indicates that you’re pointing to a spot on the same page, not on another page.

The listing shows how two anchor elements combine to link to a spot on the same page. (Documents that use intradocument links are usually longer. This document is short so you can easily see how to use the top anchor element.)

<!DOCTYPE html>
<html>
  <head>
    <title>Intradocument Hyperlinks at Work</title>
    <meta charset="UTF-8">
  </head>
  <body>
    <h1><a name="top"></a>Web-Based Training</h1>
    <p>Given the importance of the Web to businesses and other organizations, 
       individuals who seek to improve job skills, or fulfill essential job
       functions, are turning to HTML and XML for training, particularly to 
       HTML5. We believe this provides an outstanding opportunity for 
       participation in an active and lucrative adult and continuing education 
       market.</p>
    <p><a href="#top">Back to top</a></p>
  </body>
</html>

The figure shows how this HTML markup appears in a web browser. If the user clicks the Back to Top link, the browser jumps back to the top spot — marked by . The text for this example is short, but you can see how it works by resizing your browser window (making it tall and narrow) to display only two or three words per line of text.

image0.jpg

About This Article

This article is from the book: 

About the book author:

Ed Tittel is a 28-year veteran of the computer industry. A seasoned author and consultant, Ed has more than 140 books to his credit.

Chris Minnick is an accomplished author, teacher, and programmer. Minnick authored or co-authored over 20 books, including titles in the For Dummies series. He has developed video courses for top online training platforms and he teaches programming and machine learning to professional developers at some of the largest global companies.