HTML Academy
What is a link? The a tag
Links and images2/17
Back to the list of tasks
  • 1. What is a link? The a tag
  • 2. Relative addresses
  • 3. Absolute addresses
  • 4. Link to the file
  • 5. An in-page link
  • 6. The img tag for images
  • 7. Image formats, SVG format
  • 8. JPEG format
  • 9. PNG format
  • 10. GIF format
  • 11. Image dimensions
  • 12. alt attribute
  • 13. Image link
  • 14. The figure and figcaption tags, demonstrative material
  • 15. Links with a blank href, title attribute
  • 16. Summary of “Links and Images”
  • 17. Test: Cat tours travel agency gallery
Absolute addresses
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Relative addresses

Although our blog is on the web, but when we’re working on it, we do it on our computer—that is, locally. So we can test changed pages before publishing them, links to other blog pages should open the file on our computer, and not from somewhere on the Internet. You need to use a special address for these types of links, such as, for example:

<a href="day-2.html">Second blog entry</a>

This type of address is called relative. In contrast to “normal” addresses, it does not contain a full website address. In order to resolve a relative address and reach its destination, the browser must decode it. To do this, it typically starts with the position of the current page. For example, there are two files in the c:/blog folder:

c:/blog/
      |-index.html // This page is open in the browser
      |-inner.html

The page c:/blog/index.html is open in the browser, and it contains a link with a relative address inner.html. In order to follow this link, the browser looks at the location of the open page and replaces the last part in it:

c:/blog/index.html + inner.html // Replace the last part
c:/blog/inner.html              // Open this file

Relative addresses work not only for files on a computer, but also for pages on a network. If you were to publish the two files from the example on the Internet (without changing their relative position to each other), then the link would still work. The relative address inner.html on the page https://site.com/blog/index.html can be decoded as follows:

https://site.com/blog/index.html + inner.html // Replace the last part
https://site.com/blog/inner.html              // Open this address

Let’s add some more relative links to the main blog.

Comments

  • index.html
  • style.css
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>The website of a beginning coder</title> <link rel="stylesheet" href="style.css"> </head> <body> <header> <h1>The website of a beginning coder</h1> </header> <main> <nav> <h2>Recent Posts</h2> <ul> <li><a href="day-1.html">Day One. How I forgot to feed the cat</a></li> <!-- Add links inside the three items below --> <li>Day Two. I want to become a coder</li> <li>Day Three. My cat is offended at me</li> <li>Day Four. How I almost got sick</li> <li>Day Five. I am relaxing</li> <li>Day Six. How I failed to understand anything</li> <li>Day Seven. Muffin gave me an assignment</li> <li>Day Eight. It’s getting very serious</li> <li>Day Nine. Or more precisely night</li> <li>Day Ten. Summing up</li> <li>Day Eleven. Everything should be taken in moderation</li> </ul> </nav> <section> <p>Greetings to everyone! Welcome to my first site. Up until just recently I had no idea what a coder does for a living, but now I have found interactive courses in HTML and CSS and I have set myself the goal of becoming one. I even was assigned an instructor, Muffin, who does not allow me to slack off and will track my progress.</p> <p>My first assignment is to keep a diary and honestly write about all of my accomplishments.</p> </section> <section> Skills section </section> </main> <footer> Website footer </footer> </body> </html>
CSS
body { padding: 0 30px; font-size: 14px; line-height: 22px; font-family: "Georgia", serif; color: #222222; } h1 { font-size: 36px; line-height: normal; } h2 { font-size: 20px; line-height: normal; } a { color: #0099ef; text-decoration: underline; } ul { list-style: none; padding-left: 0; } footer { margin-top: 30px; }

What didn’t you like in this task?

Thanks! We’ll fix everything at once!

The code has changed, click “Refresh” or turn autorun on.

You’ve gone to a different page

Click inside the mini-browser to shift the focus onto this window.

100%
Goalscompleted
0

    Similar to the first item, add another three links to the table of contents for the blog.

    1. Link with relative address to the the second paragraph of day-2.html.
    2. Link with relative address to the the third paragraph of day-3.html.
    3. Link with relative address to the the fourth paragraph of day-4.html.

    Cookies ∙ Privacy ∙ License Agreement ∙ About ∙ Contacts ∙ © HTML Academy OÜ, 2019−2025

    VISAMastercard

    Log in

    or

    Forgot your password?

    Sign up

    Sign up

    or
    Log in

    Restore access

    Have you forgotten your password or lost access to your profile? Enter your email connected to your profile and we will send you a link to restore access.

    Forgot to connect your email to the profile? Email us and we’ll help.