/    Sign up×
Reference /Pin to ProfileBookmark

The img tag, or Image Embed element, embeds an image in an HTML document.

Syntax

There are two attributes that are required for the <img> tag: src, which provides the URL of the image, and alt, which provides an alternate text for the image. Alt text is displayed if the image cannot be displayed for some reason. It is also read by screen readers and machines for SEO purposes.

<img src="path-to-image.jpg" alt="aletrnate description of the image" width="600" height="400">

Attributes

alt
Provides alternate, descriptive text for the image.

crossorigin
Allows images that are embedded from third-party sites to be used with canvas. Values: anonymous or use-credentials.

height
Provides the height of the image in pixels.

ismap
Designates that the image is a server-side image map.

loading
Utilizing the values eager or lazy, the loading attribute determines if the browser should load the <img> immediately or after certain conditions are met.

longdesc
Provides the URL that has a detailed description of the image.

referrerpolicy
Determines which referrer information is sent when fetching the <img>. Possible values: no-referrerno-referrer-when-downgradeoriginorigin-when-cross-origin, and unsafe-url.

sizes
Provides image sizes for different page layouts.

src
Provides the URL for the image.

srcset
Provides a list of image files which will be used in different situations, such as different browser sizes.

usemap
Designates that the image is a client-side image map.

width
Provides the width of the image in pixels.

Browser Compatibilty

Demos

Have a code example of <img>? Submit a codepen.io demo and we'll showcase it here

to submit a demo.
HTML
×

Success!

Help @reference spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 7.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ,
analytics: Fullres
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @qewfun,
tipped: live stream
amount: 5000 SATS,

tipper: @qewfun,
tipped: live stream
amount: 5000 SATS,

tipper: @qewfun,
tipped: live stream
amount: 5000 SATS,
)...