Skip to content
Tutorials Center
My learning

Topics

Lesson 17 of 36 ยท On-Page SEO

Image SEO: Alt Text, File Names, Formats and Speed

Optimize images for search and users: descriptive alt text, file names, modern formats, responsive srcset, lazy loading, captions and image sitemaps, with live HTML examples.

Images make pages more useful and appealing, and they bring visitors from image search. But they also have two risks: they can slow a page down, and they are invisible to machines unless you describe them. Image SEO means describing images clearly, choosing the right format and size, and delivering them efficiently.

Why images matter

  • Image search is a separate source of traffic for many topics: recipes, products, travel, design.
  • Accessibility: people using screen readers rely on text alternatives.
  • Page speed: images are often the largest files on a page, so they heavily affect loading time and layout stability.
  • Context for the topic: an image with good surrounding text helps engines understand what the page covers.

Alt text

The alt attribute is the text alternative of an image. It is shown if the image fails to load, read by screen readers and used by search engines to understand the picture.

HTML
<img src="/images/tomato-roots-circling-pot.jpg"
     alt="Tomato roots circling the inside of a plastic pot after the plant was removed"
     width="800" height="600">

Guidelines:

  • Describe the image's content and purpose in a short phrase or sentence. Say what a person who cannot see it would need to know.
  • Be specific: "Red cherry tomatoes on a vine" beats "tomatoes".
  • Include the topic phrase only if it is natural. Never stuff keywords.
  • Do not begin with "image of" or "picture of"; assistive technology already says it is an image.
  • Decorative images (pure ornament) should have an empty alt (alt=""), so screen readers skip them. Do not omit the attribute.
  • Images that are links: the alt should describe the destination or action ("Back to guides").
  • Images containing text: repeat the important text in the alt, or better, use real text in the page.
  • Charts and diagrams: give a short alt plus the full explanation in nearby text.

Try it: alt text audit

This live page checks every image in its own document and flags missing, empty, stuffed or weak alt text. Edit the images or alt values to see how the checks respond.

Alt text auditor

File names

Use descriptive, lowercase, hyphenated file names: tomato-roots-circling-pot.jpg, not IMG_20240812_0042.jpg. It is a small signal and helps you stay organized. Keep file names stable and avoid reusing one name for different images.

Formats and size

Choose the format by image type:

Format Best for Notes
JPEG Photographs Small files, no transparency
PNG Graphics with transparency, screenshots with text Larger for photos
SVG Logos, icons, simple illustrations Vector: sharp at any size, tiny, can be styled
WebP Photos and graphics Smaller than JPEG and PNG, widely supported
AVIF Photos Often the smallest, wide support
GIF Avoid Use video or animated WebP for animation

Rules:

  1. Resize before upload. Do not serve a 4000-pixel-wide photo in a 400-pixel slot.
  2. Compress. For photos, a moderate lossy quality setting is usually indistinguishable from the original.
  3. Serve modern formats with fallbacks when needed.
  4. Set width and height attributes so the browser reserves space and the layout does not jump (cumulative layout shift).

Responsive images and lazy loading

Different screens need different sizes. srcset and sizes let the browser pick, and loading="lazy" postpones off-screen images until the reader scrolls near them.

HTML
<img src="/images/tomato-800.webp"
     srcset="/images/tomato-400.webp 400w, /images/tomato-800.webp 800w, /images/tomato-1600.webp 1600w"
     sizes="(max-width: 600px) 100vw, 800px"
     width="800" height="533"
     alt="Ripe red tomatoes growing in a container"
     loading="lazy" decoding="async">

Never lazy-load the main image visible at the top of the page (often the largest contentful element). It should load first, and you can mark it as high priority with fetchpriority="high".

Use <picture> to offer alternatives:

HTML
<picture>
  <source type="image/avif" srcset="/images/tomato.avif">
  <source type="image/webp" srcset="/images/tomato.webp">
  <img src="/images/tomato.jpg" alt="Ripe red tomatoes growing in a container" width="800" height="533">
</picture>

Try it: estimate image weight

The program estimates transfer size for a page with and without optimization. The sizes are invented for the exercise; measure your own with the browser's network panel. It also shows why total weight matters more than any one file.

Python Page image weight estimate

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Context around the image

Search engines read text near an image: the caption, heading and paragraph. Put images next to the text that explains them. Use <figure> and <figcaption> when a caption helps the reader:

HTML
<figure>
  <img src="/images/roots.jpg" alt="Tomato roots circling a pot" width="800" height="600">
  <figcaption>Roots circling the pot show it is time to repot.</figcaption>
</figure>

Original photos, screenshots and charts that show real work add trust and are less likely to be duplicated across the web than stock images.

Image sitemaps and indexing

Engines find most images through the page's HTML. Make sure images are real img elements (or picture) with a src; images that exist only as CSS backgrounds are often not indexed as content. Do not block image folders in robots.txt if you want image search traffic. For images loaded in unusual ways, an image sitemap can list them, using the image extension of the sitemap format, with the page URL and the image URL. See the technical SEO chapter for sitemaps.

Common mistakes

  • Missing alt attributes, or the same alt on every image.
  • Huge uncompressed originals.
  • Lazy-loading the main image at the top.
  • Text baked into images instead of real text.
  • Images with no width and height, causing layout shifts.
  • Hotlinking images from other sites.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which alt text is best for a photo of tomato roots circling a pot?

    A specific, natural description serves screen reader users and search engines.
  2. 2. What should the alt attribute be for a purely decorative image?

    An empty alt tells assistive technology to ignore the image; omitting the attribute does not.
  3. 3. Why set width and height attributes on images?

    Reserved space prevents content from jumping as images load.
  4. 4. Which image should NOT be lazy-loaded?

    Above-the-fold images should load immediately; delaying them slows the visible page.

Summary

  • Write specific, natural alt text; use empty alt for decorative images.
  • Name files descriptively with hyphens and keep them stable.
  • Pick the right format (JPEG/WebP/AVIF for photos, SVG for vectors), resize and compress.
  • Use width, height, srcset, sizes and lazy loading (but not for the top image).
  • Surround images with relevant text and captions, and keep them crawlable.

Next: Internal Links and Anchor Text