New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Linking within a page using fragments

From: XHTML and HTML Essential Training

Video: Linking within a page using fragments

Remember when we talked about the parts of the URL? This part of the end called the fragment, this starts with the pound sign or the hash sign. That's what this lesson is about. This is about fragments and how to address them and how to create them in the page. So, a fragment is a part of a page. It's a link to a location within the page not necessarily at the top. Normally, when you have a link to a web page, it brings up the page all the way scrolled to the top of the page. Sometimes you might want to link to a page so, we scroll down a ways to a particular part of the page and that's called a fragment.

Linking within a page using fragments

Remember when we talked about the parts of the URL? This part of the end called the fragment, this starts with the pound sign or the hash sign. That's what this lesson is about. This is about fragments and how to address them and how to create them in the page. So, a fragment is a part of a page. It's a link to a location within the page not necessarily at the top. Normally, when you have a link to a web page, it brings up the page all the way scrolled to the top of the page. Sometimes you might want to link to a page so, we scroll down a ways to a particular part of the page and that's called a fragment.

So, let's look at how this works in a browser. This is a list of Retail Stores and this is from a book that I wrote with my sister Lynda a long time ago called Creative HTML Design, this was one of the examples from that book for this particular technique. And you'll notice that there is a list of states at the top. These are two letter State Abbreviations except for the one in Canada. Then there is a long, long list on the same page, all of these stores, and all of these different states. So, if I go on here and I click on say Illinois, it takes me to the part of the page, you see I've scroll down that is Illinois and these are the places we can buy those rubber stamps that we are talking about in the examples for that book.

Now I click on the top link and this takes me wholly back to the top of the page, so that I can look for maybe another state. So these are fragments, you will notice that the URL now because I clicked on the top link has the pound sign and the word top and when I hover over one of these top links, you'll see down at the bottom there that the URL is the whole URL to the page with the pound sign top at the end of it and when I hover over one of these other links, for the states, you'll see that down at the bottom in the status line, it shows the path to the page with the pound IL at the end of it.

So, those are the fragment links and we are at links to, if I click on this, is called the Named Anchor. This is anchor into the page and its' done with an anchor tag. Let's take a look at how this is done in the HTML. This is the XHTML for the same page and you'll notice it has the list of states here with these normal looking links a href= and then its got the pound sign and the two letter code within the href attribute. And this is how you link to a part of a page, this is called a fragment link and it's a relative URL, so it fills in the rest of the URL from where the page is located that has a link in it and it just sticks this at the end of it in the fragment part.

If there is already fragment part, it replaces it with this and so you get a link just down to that part of the page. If we scroll down here pass this links, you'll see the named anchors. This is a named anchor write here. See it says a name="AK" then the end of the begin tag and then it has the end tag for the anchor. You will notice that I made a separate end tag even though this anchor element is empty, I could have written it using the shortcut notation that we use in other places where we have a tag with no end tag and in modern browsers that would probably work.

At the time, I wrote this page which was a number of years ago, I try that and it didn't work in a lot of the browsers and so today, they probably work better but for this particular usage, I still write it the old way because I know that there may be some browsers out there with a short-hand notation doesn't work. So just to review, this is the named anchor and this is the target of a fragment link and it's an anchor tag with just the name attribute. So it doesn't have the href. It just has the name attribute and that makes it not a link.

It makes it a target for all links. It's a named target. And over here are the fragment links, there are also an anchor tag and a tag but this have an href attribute which makes it into a link and so the content of it, here the AK that will get underlined that will become the part that you click on with your mouse to go to that link. Then here you have the fragment URL, this is a relative URL. It gets tagged on to the end of the URL of the page where the link exist and it has just the fragment part so that it will link you down into that part of the page.

So looking out in the browser again, I can just click on that part, I'll click on AZ over here and that will take us to that part of the page. You see we'll it scrolled down, the scroll bar over there and I click on top and it takes us back to the top of the page. So that's how fragments and named anchors work.

Show transcript

This video is part of

Image for XHTML and HTML Essential Training
XHTML and HTML Essential Training

59 video lessons · 80108 viewers

Bill Weinman
Author

 
Expand all | Collapse all
  1. 5m 10s
    1. Welcome
      1m 16s
    2. Using the exercise files
      1m 23s
    3. Choosing a text editor
      2m 31s
  2. 15m 46s
    1. Introducing HTML and XHTML
      2m 53s
    2. Understanding versions of HTML and XHTML
      2m 25s
    3. Exploring a simple XHTML page
      4m 47s
    4. Understanding the structure of an XHTML document
      2m 58s
    5. Understanding document containers
      54s
    6. Creating and using templates
      1m 49s
  3. 42m 4s
    1. Understanding how empty space is formatted in XHTML
      2m 42s
    2. Using paragraph tags
      2m 42s
    3. Aligning paragraphs
      2m 49s
    4. Understanding block-level and inline tags
      1m 24s
    5. Controlling line breaks and spaces
      5m 43s
    6. Formatting text with phrase element tags
      3m 28s
    7. Formatting text with font markup elements
      3m 24s
    8. Adding document structure with headings
      3m 25s
    9. Formatting quotations and quote marks
      2m 19s
    10. Preserving pre-formatted text
      1m 30s
    11. Selecting a typeface
      4m 33s
    12. Selecting a type size
      2m 11s
    13. Using ordered and unordered lists
      5m 54s
  4. 7m 48s
    1. Using inline images
      3m 17s
    2. Flowing text around an image
      2m 4s
    3. Breaking lines around an image
      2m 27s
  5. 22m 34s
    1. Working with hyperlinks
      7m 46s
    2. Using relative URLs
      3m 5s
    3. Specifying a base URL
      2m 4s
    4. Linking within a page using fragments
      4m 28s
    5. Creating image links
      5m 11s
  6. 22m 56s
    1. Introducing tables
      4m 37s
    2. Formatting tables with CSS
      8m 50s
    3. Aligning images with tables
      5m 7s
    4. Reviewing an alternative solution using CSS
      4m 22s
  7. 14m 31s
    1. Introducing frames
      7m 56s
    2. Hiding frame borders
      3m 15s
    3. Creating inline frames using iFrame
      3m 20s
  8. 20m 50s
    1. Introducing forms: part 1
      10m 37s
    2. Introducing forms: part 2
      7m 45s
    3. Using CGI with forms
      2m 28s
  9. 25m 42s
    1. Introducing CSS
      3m 11s
    2. Understanding levels of inheritance
      6m 10s
    3. Learning CSS syntax
      11m 23s
    4. Using units of measure in CSS
      4m 58s
  10. 1h 45m
    1. Comparing table layout and CSS layout
      1m 25s
    2. Exploring the finished web site
      2m 37s
    3. Building a document header
      8m 18s
    4. Placing a banner and a contact button
      8m 13s
    5. Laying out a main menu
      6m 55s
    6. Creating a layout template: main body area
      13m 31s
    7. Creating a layout template: sidebar area
      5m 17s
    8. Creating a layout template: footer content
      4m 46s
    9. Building a main home page: main body content
      11m 24s
    10. Building a main home page: sidebar content
      8m 52s
    11. Creating a page with a menu, graphics, and formatted links
      13m 26s
    12. Creating a page containing an ordered list
      6m 44s
    13. Creating a page containing video
      10m 45s
    14. Touring the finished site
      3m 45s
  11. 53s
    1. Goodbye
      53s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold

Are you sure you want to delete this note?

No

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.