HTML img tag generator with alt text, size and lazy loading

Fill in the image URL, alt text and size and get an img tag that loads well, with width and height to prevent layout shift, lazy loading and async decoding, an optional srcset and sizes, and warnings for empty alt text and lazy hero images.

Live demo · real result from this tool
Loading
Decoding
Fetch priority

Press Generate to create a result.

Processed on your device — nothing is uploaded.

How to use the image tag generator

  1. Enter the Image URL and the Alt text.
  2. Enter the image’s Width and Height in pixels. Use 0 to leave one out.
  3. Choose Loading (Lazy, Eager or Default), Decoding (Async, Sync or Default) and Fetch priority (Auto, High (hero image) or Low).
  4. Optionally fill srcset and sizes (with srcset) for responsive images, and a Class (optional).
  5. Copy the tag and read any notes under it.

What it does and when to use it

The img element looks simple, but a few attributes decide whether a page feels fast and whether everyone can understand it. alt gives the image a text equivalent for screen readers, search engines and broken connections. width and height stop the layout from jumping, a problem measured as Cumulative Layout Shift. loading="lazy" delays images until the visitor scrolls near them, and fetchpriority="high" moves an important image up the download queue.

Use this tool when you add images to hand-written pages, static templates or CMS blocks that accept raw HTML. When the image needs a visible caption, the HTML Figure & Caption Generator wraps it in figure and figcaption. For several file sizes and formats, the Responsive Image Srcset Generator builds the full srcset and a picture element.

How it works

The attributes are written in a fixed order: src, alt, width, height, srcset, sizes, loading, decoding, fetchpriority, class. Empty options are left out, so choosing Default for loading removes the attribute. Values are HTML-escaped, so quotes in alt text cannot break the tag. There is no preview, because it would only load a placeholder URL. Everything runs in your browser.

Worked examples

A content image further down the page, with srcset cleared:

<img src="/images/team-photo-800.jpg" alt="The ToolsRift team at the 2026 offsite in Goa" width="800" height="533" loading="lazy" decoding="async">

A hero image at 1600 × 900 with Loading Eager and Fetch priority High. The tag ends with width="1600" height="900" loading="eager" decoding="async" fetchpriority="high">.

Two notes at once. A decorative divider with empty alt, no size, Lazy loading and High priority produces a tag with alt="", no width or height, and loading="lazy" decoding="async" fetchpriority="high", plus two notes: that alt="" marks the image as decorative, and “Do not lazy-load a high-priority (above-the-fold) image.”

Limits and tips

  • Enter the real pixel size of the file, or at least its true aspect ratio.
  • When an image is the only content of a link, its alt text becomes the link’s name, so describe where the link goes.
  • To check alt text across a whole page, paste it into the HTML Validator, which lists every img without alt.

Frequently asked questions

What should I write in the alt text?
Write what the image tells a sighted visitor in this context, in a short sentence. For a team photo, say who is in it and where; for a chart, give the main finding. Skip words like "image of", because screen readers already announce it as an image. For a purely decorative image, leave alt empty.
Why is alt="" different from leaving alt out?
An empty alt tells screen readers to skip the image. Without any alt attribute, many screen readers read out the file name instead, such as "team-photo-800 dot jpg". The generator always writes the alt attribute, empty or not.
Do width and height make the image a fixed size?
Not if your CSS sets max-width 100% and height auto, which most sites do. The browser then uses the two numbers only to work out the aspect ratio and reserve space, so the text below does not jump when the image arrives.
When should I not use lazy loading?
For the main image at the top of the page, the one visible without scrolling. Lazy loading delays it, which slows the largest visible element. Set Loading to Eager and Fetch priority to High for that image, and keep Lazy for images further down.
What do srcset and sizes do?
srcset lists the same picture at several widths, and sizes tells the browser how wide the image will be shown. The browser then downloads the smallest file that looks sharp on that screen. sizes is only written when srcset is filled in.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close