Skip to content

Links and Images

Links connect the web. Images make it beautiful. Together, they transform plain text into an engaging experience. In this tutorial, you’ll master both.

What you’ll learn:

  • Creating hyperlinks with the <a> element
  • Absolute vs. relative URLs
  • Special link types (email, phone, anchors)
  • Embedding images with the <img> element
  • Image alt text and accessibility
  • Responsive images with the srcset attribute

Prerequisites:


The anchor element <a> creates clickable links to other pages or websites.

Result

The href attribute specifies where the link goes. Notice:

  • Links are blue and underlined by default
  • Text inside the <a> tag is what users click
  • The URL comes after href="

External links go to websites outside your own. Always include the full URL:

Result

Always use https:// (or http://). Without it, browsers treat it as a relative link.

Internal links navigate within your own website. Use relative paths:

Result

Relative URL examples:

  • about.html — File in the same folder
  • pages/about.html — File in a subfolder
  • ../about.html — File in the parent folder
  • /about — File from the website root

Use mailto: to create email links:

Result

Adding ?subject=Hello automatically fills the email subject.

Use tel: to make clickable phone numbers:

Result

On mobile devices, this opens the phone dialer.

Link to specific sections within a page using anchor IDs:

Result

First create an ID with id="name", then link to it with href="#name".


Use target="_blank" to open links in a new tab:

Result

Add a tooltip that appears on hover:

Result

Images make your pages visual. The <img> element embeds images directly:

Result
AttributePurpose
srcPath to the image file (required)
altText if image doesn’t load (required)
widthImage width in pixels
heightImage height in pixels

The alt attribute is crucial for users with visual impairments who use screen readers.

<!-- Describes the image content -->
<img src="dog.jpg" alt="A golden retriever playing in a park">
<!-- Describes what the image shows -->
<img src="chart.jpg" alt="Bar chart showing sales growth from 2020 to 2024">
<!-- For decorative images that add no meaning, use empty alt -->
<img src="decoration.jpg" alt="">
<!-- Too vague -->
<img src="dog.jpg" alt="Image">
<!-- Redundant (already in caption) -->
<img src="dog.jpg" alt="Dogs"> <p>Dogs</p>
<!-- Missing entirely -->
<img src="dog.jpg">

You can wrap an image in a link:

Result

This makes the entire image clickable.


For modern responsive design, use srcset to serve different images on different screen sizes:

<img
src="image-small.jpg"
srcset="
image-small.jpg 480w,
image-medium.jpg 768w,
image-large.jpg 1024w
"
alt="A beautiful sunset"
width="400"
height="300"
>

This tells the browser which image to load based on screen width:

  • Phones see image-small.jpg
  • Tablets see image-medium.jpg
  • Desktops see image-large.jpg

Result

Create a page with links and images:

Result

Experiment with:

  1. Adding more internal links
  2. Creating email or phone links
  3. Changing image URLs to different images
  4. Creating anchor links to sections


  • <a> tags create clickable links with the href attribute
  • Use absolute URLs for external links, relative URLs for internal links
  • Special URLs: mailto: for email, tel: for phone, # for page anchors
  • <img> embeds images with required src and alt attributes
  • Alt text is essential for accessibility and SEO
  • target="_blank" opens links in new tabs
  • Responsive images use srcset for different screen sizes

Lists

Organize information with ordered and unordered lists. Continue →

Basic Structure

Learn semantic page structure with header, nav, main, and footer. Continue →