HTML· LESSON 05

Links & Images

Learn how to connect pages with links using the a tag and add pictures to a page with the img tag.

The <a> (anchor) element creates a link. The href attribute holds the destination, and the text between the tags is what the reader clicks.

HTML
PREVIEW Live result

Result:

Learn more at MDN Web Docs.

href can point to different places:

  • A full URL like https://osdc.dev links to Osdc website.
  • A file path like about.html links to another page in your project.
  • An id like #contact jumps to the element with id="contact" on the same page.
HTML
PREVIEW Live result

Result:

Contact

To open a link in a new tab, add target="_blank" and pair it with rel="noopener noreferrer".

HTML
PREVIEW Live result

Result:

Open in a new tab

Images with img

The <img> element displays an image. It’s self-closing (no </img>) and needs both of these attributes:

  • src: where the image file is, as a URL or a file path.
  • alt: a text description of the image.

src tells the browser what to show, and alt tells everyone else what it is.

HTML
PREVIEW Live result

Result:

A grey placeholder rectangle

Why alt matters

alt is read aloud by screen readers, and it’s shown in place of the image if the file fails to load. The path below is broken on purpose, so you’ll see the alt text.

HTML
PREVIEW Live result

Result:

A dog catching a frisbee at the beach

Putting it together

An image inside a link becomes clickable. It still needs both src and alt.

HTML
PREVIEW Live result

Result:

Visit MDN Web Docs

Try it yourself

Add a link to a site you like, then an <img> with both src and alt. Finally, wrap that image in an <a> to make it clickable.