HTML: Image Tag

By Xah Lee. Date: . Last updated: .

Image Tag

The image tag img is used to embed a image.

Example

<img src="i/venus_comb_32m-s289x217.jpg" alt="venus comb 32m-s289x217" width="289" height="217" />

Browser shows

venus comb 32m-s289x217

Supported Image Formats

as of 2026, most common image file formats supported by browsers are

img tag Attibutes

alt

Optional. A text description for the blind.

width

Optional. Width of image in pixels.

height

Optional. Height of image in pixels.

srcset

“source set”. For alternate image file sources. New around 2017.

srcset attribute

The srcset attribute is for inline image that has multiple versions each with different size or image quality, for browser to chose a right one for user's device (e.g. on desktop computer with huge screen or on mobile phone with tiny screen).

It is invented sometimes around 2015.

Value is list of items, separated by comma, each is of the form:

path DensityOrWidth

The DensityOrWidth is optional.

DensityOrWidth is either a “density”, of the form 1x, 2x, 3x, etc., or a width such as 800w, 1000w, 2000w .

Example

<img src="cat.jpg"
srcset="
cat_small.jpg 1x,
cat_mid.png 2x,
cat_big.png 3x"
alt="cat">

HTML image tags