CCC-Web Worksheet

Uni of Portsmouth Logo

Addressing

We've discussed URLs and hyperlinks; how to form a URL and how to use the anchor tag to place links in HTML. Here we will build a simple HTML5 page and add some links to it.

Task 0: Preparation

  1. Create a folder for this week’s work: call it links. Place any files you create in it.
  2. Create a file called index.html that contains the following content: <!DOCTYPE html> <meta charset=UTF-8> <title>Hello Links World</title> <article> <section> <h1>My Favourite Websites:</h1> <ul id=extlinks> <li></li> </ul> </section> <section> <h1>Other pages on my site</h1> </section> </article>
  3. Load the file to check the default rendering.
  4. If any of this was new, record it in your discovery log.

Task 1: A list of your favourite links

In this task you will add links to your favourite websites to the list in the first section of the page.

In index.html notice the extlinks element. The ul tags indicate an unordered list, which is rendered as bullets by the browser. Each item in the list is surrounded by li list item tags thus: <li>Example list item.</li>.
  1. Find four websites that you like and make a note of their URLs in your discovery log.
  2. Add three more pairs of li tags to the ul in index.html, each on a new line. You should now have four empty list items.
  3. Between each pair of li tags, add an a tag to link to your chosen websites. Each link should use the syntax: <a href="URL">Link Text</a> where URL is the address of the website you want to link to, and Link Text is the text that will appear as the link in the browser.
  4. Check that the links work.

Task 2: Relative links

NB: When using a server, you can link to index.html with <a href="/"> but this link won't work if you're opening files from a local filesystem.

Task 3: Targets and fragments

  1. For each external link from Task 1, add a target attribute so the site opens in a new window (look up the exact syntax if needed).
  2. At the bottom of index.html, add a fragment link back to your list of external websites, e.g. <a href="#extlinks">Back to favourite websites</a>, then test by scrolling away from the list and clicking the link.

Task 4: Read, Discover, Experiment, Learn

You now have a basic understanding of links. Try the following for an extra challenge.

  1. Move about.html, studies.html, and music.html into a subfolder called pages, then update the relative links in index.html.
  2. On studies.html, link to work from previous weeks.
  3. Create a site-wide <nav> containing a <ul>; use CSS to display the list horizontally.
  4. Ensure all filenames (and matching links) use lowercase.
  5. Record everything new in your discovery log.