HTML Academy
alt attribute
Links and images13/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
The figure and figcaption tags, demonstrative material
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Image link

Muffin realized that there was no “About me” section on his website after a business meeting in Moscow. He has already given an assignment to his coders to create such a page, and we have been instructed to create a gallery with his photos.

We already know that there are links and pictures. Are we able to put one inside the other? Can we make an image become a clickable link?

Of course! To do this, you need to wrap the <img> tag in the <a> tag. For example:

<a href="http://catsby.com">
  <img src="cat.png" alt="Muffin">
</a>

Often hyperlinked image are used in galleries, where a smaller version of an image links to a full-size version or to a separate page with that image and a caption.

Now we will try to add hyperlinked images to our selfie gallery that will lead to separate pages displaying the respective photos.

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> <p>Blog</p> <nav> <a href="index.html">Return to home</a> </nav> </header> <main> <article> <h1>Day Fifteen. The Selfie Gallery</h1> <p>Today, Muffin came in again, and he said that he needed more selfies on his website for his business, just like the kind found on Instagram. We create a small selfie gallery with him. Clicking on the thumbnail opens a large image.</p> <p> <!-- Hyperlink the image below --> <img src="files/preview-1.jpg" alt="Picture of Muffin" width="115" height="77"> <img src="files/preview-2.jpg" alt="Picture of Muffin" width="115" height="77"> <img src="files/preview-3.jpg" alt="Picture of Muffin" width="115" height="77"> </p> </article> <aside> Your ad could go here </aside> </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: 20px; line-height: normal; } aside { margin: 20px 0; color: #c4c4c4; } a[href] { color: #0099ef; text-decoration-line: underline; }

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
    1. Hyperlink the first thumbnail with the address photo-1.html.
    2. Hyperlink the second thumbnail with the address photo-2.html.
    3. And hyperlink the third with the address photo-3.html.
    4. Click on any photo to go to a separate page displaying the respective full-size image.

    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.