Return to Video

HTML internal links

  • 0:00 - 0:03
    Links are
    a great way of connecting
  • 0:03 - 0:05
    one webpage to another webpage.
  • 0:05 - 0:07
    But they can also connect
    one part of a webpage
  • 0:07 - 0:09
    to another part of that same webpage,
  • 0:09 - 0:14
    especially on really long webpages,
    like for a table of contents.
  • 0:14 - 0:17
    I have now added
    a bunch more information to this page,
  • 0:17 - 0:20
    so that I could give you a
    history of the web,
  • 0:20 - 0:22
    and a history of HTML versions.
  • 0:22 - 0:26
    And I think it's enough content that
    it deserves a table of contents.
  • 0:26 - 0:29
    And I've started one up here,
    just an unordered list,
  • 0:29 - 0:33
    with list items
    with each of the section titles.
  • 0:33 - 0:35
    And I want to link each of these
    section titles,
  • 0:35 - 0:39
    so that you can click them,
    and just go to that part of the page.
  • 0:39 - 0:42
    To do that, I once again
    use the `` tag,
  • 0:42 - 0:45
    so I'll start by just
    wrapping this title
  • 0:45 - 0:49
    in the start and end tags for ``
  • 0:49 - 0:55
    Now, what should go
    as the href of this link?
  • 0:55 - 0:58
    Well, we need to somehow
    tell the browser
  • 0:58 - 1:00
    where to jump to in the webpage.
  • 1:00 - 1:03
    Some way of uniquely identifying
    that part of the page.
  • 1:03 - 1:06
    If you've learnt CSS selectors already,
  • 1:06 - 1:09
    you've actually seen
    how to do this, in fact.
  • 1:09 - 1:14
    We can do it by adding
    an `` attribute to a tag.
  • 1:14 - 1:19
    Let's scroll down
    and find the heading here.
  • 1:19 - 1:23
    And we'll add an `` attribute
    to this heading.
  • 1:23 - 1:25
    So I'm going to put my cursor in ``,
  • 1:25 - 1:27
    type `id = "`
  • 1:27 - 1:30
    and come up with
    a good identifier that's unique,
  • 1:30 - 1:33
    like "web-history".
  • 1:33 - 1:36
    Okay, let's scroll back up to the link.
  • 1:36 - 1:40
    And now, in order to tell the browser
    to go to this internal link,
  • 1:40 - 1:42
    we need to start with a hash sign,
  • 1:42 - 1:46
    and then type exactly the id
    like we typed it below.
  • 1:46 - 1:48
    Okay, so now,
  • 1:48 - 1:51
    pause this talk-through,
    and try clicking the link.
  • 1:51 - 1:56
    Go on, I will wait.
    Clicky-clicky!
  • 1:56 - 2:00
    Okay, did you see it scroll down
    to this section?
  • 2:00 - 2:01
    Then it worked!
  • 2:01 - 2:03
    We can add more links like that
  • 2:03 - 2:06
    by putting the id attributes on,
    on every heading,
  • 2:06 - 2:08
    and making `` tags
    that point at them.
  • 2:08 - 2:09
    But I'll leave that for you to try.
  • 2:09 - 2:12
    The big to remember
    is that the IDs must be unique,
  • 2:12 - 2:15
    because otherwise the browser
    won't know where to jump to.
  • 2:15 - 2:18
    So make them nice and descriptive.
Title:
HTML internal links
Video Language:
English
Duration:
02:19

English subtitles

Revisions