Information Technology Topic

Creating Hyperlinks

  1. Read notes
  2. Flashcards
  3. Quiz
  4. Confident

Study focus - 3 things

  1. A hyperlink is clickable text or a picture with a destination, and the four destinations to know are another page, a spot in a page, an email address and a file
  2. For pages on your own site use a relative link: the file name for the same folder, folder/file going down and ../ going up
  3. Good link text says where the link goes (and the file type and size for downloads) instead of saying 'click here'

Section 1What a hyperlink is

A hyperlink (or just link) is something a visitor clicks to go somewhere. It has two parts: the link text or picture that people see and click, and the destination it leads to. In a web-design package you select the words or the picture, choose the insert-link command and enter the destination. Behind the scenes the package writes a short piece of code, something like this (our own practice example): <a href="about.html">About us</a> Here's the trick: the words between the tags are what people click, and the part after href is where they go. You do not need to memorise the tags. You need to know what to put as the destination. The syllabus asks for four kinds of destination: another web page, a spot in a page, an email address and your own files. The next notes take them in turn.

Section 2Links to another page

To link to another page on your own site, use a relative path, which describes where the file is compared with the page holding the link. Take a guesthouse site in Montego Bay with these files: index.html, about.html, rooms/single.html, rooms/double.html, images/beach.jpg, files/rate-card.pdf. From index.html: a page in the same folder is just the file name (about.html); a page in a subfolder is folder/file (rooms/double.html). From rooms/single.html: another page in the same folder is the file name (double.html); a page in the parent folder is ../ followed by the file (../index.html). Each ../ climbs up one folder. To link to a different website, use its full address, the whole web address starting with https://. Watch out: the path is worked out from the page that holds the link, not from the home page. The same file needs a different path on different pages.

Section 3Links to a spot in a page

A long page is easier to use if visitors can jump straight to a section. First give the target (the heading or paragraph you want to land on) a name. Packages call this a bookmark or an anchor, and in the code it is an id. Then make a link to that name. On the same page the link is just a hash sign and the name, such as #hours. From a different page you give the page and then the name: services.html#hours. Typical uses are a list of links at the top of a long page that jump to each section, and a 'back to top' link at the bottom. Easy to mix up: a link to a spot in the same page stays on the page and only scrolls. A link to a spot on another page opens that page and scrolls to the spot.

Section 4Links to an email address

A link can open a new email message instead of a page. The destination begins with mailto: followed by the address, for example mailto:orders@mandevillepharmacy.example (an invented address for practice). When a visitor clicks it, a new message opens in their email program with that address filled in. You can also add a subject, and even some body text, so the message arrives with a clear heading. A subject is added after a question mark: mailto:orders@mandevillepharmacy.example?subject=Refill. The visible link text can be the address itself or words such as 'Email the pharmacy'. Either way, the destination is what must start with mailto:.

Section 5Links to your own files

Any file that has an address can be linked, not only web pages: a PDF, a picture, a video or an audio file. Put the file in your site folder (for example a files folder) and link to it with a relative path, like files/rate-card.pdf. When a visitor clicks, the browser shows the file if it can. If it cannot display that type, the visitor is offered a choice to open or download it. Tell people what they are about to get. Put the file type and size in the link text, such as 'Rate card (PDF, 240 KB)' (an invented size). Someone on a slow connection will be glad to know before they click. A picture can be a link as well. That is how a thumbnail works: the small picture is wrapped in a link to the full-size picture.

Section 6Good links and a quick summary

Write clear, descriptive link text. 'Download the price list (PDF, 240 KB)' tells people where the link goes. 'Click here' tells them nothing and is useless to someone scanning the page. Use relative links for pages on your own site. They keep working if the whole site moves to a new domain, while a link written with the full address of your own old domain would break. Summary of the four kinds, with an example destination each: another page (contact.html); a spot in a page (#hours on the same page, or services.html#hours on another page); an email address (mailto:orders@mandevillepharmacy.example); a file (files/price-list.pdf).

Examples

A Montego Bay guesthouse site is stored like this: index.html, about.html, rooms/single.html, rooms/double.html, images/logo.png, images/beach.jpg and files/rate-card.pdf. (a) On index.html, write the links to rooms/double.html and to the rate card. (b) On rooms/single.html, write the link back to the home page. (c) On rooms/single.html, write the link to the double room page. (d) On rooms/single.html, write the link that shows beach.jpg. (e) A student typed images/beach.jpg on rooms/single.html and the picture does not appear. Explain why.

Work from the page that holds the link. (a) From index.html both files are below the current folder, so the links are rooms/double.html and files/rate-card.pdf. (b) rooms/single.html is one folder down, so go up one level: ../index.html. (c) double.html is in the same folder, so the file name is enough: double.html. (d) beach.jpg is in images, which is beside rooms, so go up one level and down into images: ../images/beach.jpg. (e) From rooms/single.html the path images/beach.jpg looks for rooms/images/beach.jpg, and there is no such folder. The ../ is missing. Watch out: a path that is right on index.html is often wrong on a page in a subfolder.

The services page (services.html) of a Mandeville pharmacy site holds these eight links: #hours, contact.html, mailto:orders@mandevillepharmacy.example?subject=Refill, files/price-list.pdf, https://www.example.org/health-tips, contact.html#map, about.html and files/vaccine-guide.pdf. (a) Name the kind of each link. (b) How many link to a file, how many to another page, and how many to a spot in a page? (c) Write good link text for the price list if it is a PDF of 240 KB. (d) What must be done on the services page before #hours can work? (e) Write the link another page would use to jump to that spot.

(a) #hours is a spot in the same page; contact.html is another page; the mailto link is an email address (with a subject added); files/price-list.pdf is a file; the https link is another website; contact.html#map is a spot in another page; about.html is another page; files/vaccine-guide.pdf is a file. (b) Files: 2. Other pages: 2 (contact.html and about.html; contact.html#map counts as a spot). Spots in a page: 2 (#hours and contact.html#map). That leaves 1 email link and 1 link to another website, so 2 + 2 + 2 + 1 + 1 = 8. (c) Something like 'Price list (PDF, 240 KB)', which says what it is and how big it is. 'Click here' would not. (d) The hours heading must be given a target name (a bookmark or id) called hours. (e) From another page the link is services.html#hours: the page, then the spot.

Now let's water it

Session runs notes to flashcards to quiz back-to-back.

Where this comes from