HTML Img Tag
HTML Img Tag
HTML Img Tag
HTML CSS
Menu Log in
Example
How to insert an image:
Try it Yourself »
Images are not technically inserted into a web page; images are linked to web pages.
The <img> tag creates a holding space for the referenced image.
https://www.w3schools.com/tags/tag_img.asp 1/11
11/8/21, 2:52 AM HTML img tag
alt - Specifies an alternate text for the image, if the image for some reason cannot
HTML CSS
be displayed
Note: Also, always specify the width and height of an image. If width and height are not
specified, the page might flicker while the image loads.
Tip: To link an image to another document, simply nest the <img> tag inside an <a>
tag (see example below).
Browser Support
Element
Attributes
Attribute Value Description
https://www.w3schools.com/tags/tag_img.asp 2/11
11/8/21, 2:52 AM HTML img tag
cross-origin
HTML CSS
unsafe-url
ADVERTISEMENT
Global Attributes
The <img> tag also supports the Global Attributes in HTML.
Event Attributes
The <img> tag also supports the Event Attributes in HTML.
More Examples
https://www.w3schools.com/tags/tag_img.asp 3/11
11/8/21, 2:52 AM HTML img tag
HTML CSS
Example
Align image (with CSS):
Try it Yourself »
Example
Add image border (with CSS):
Try it Yourself »
Example
Add left and right margins to image (with CSS):
Try it Yourself »
https://www.w3schools.com/tags/tag_img.asp 4/11
11/8/21, 2:52 AM HTML img tag
HTML CSS
Example
Add top and bottom margins to image (with CSS):
Try it Yourself »
Example
How to insert images from another folder or from another web site:
Try it Yourself »
Example
How to add a hyperlink to an image:
<a href="https://www.w3schools.com">
<img src="w3html.gif" alt="W3Schools.com" width="100" height="132">
</a>
Try it Yourself »
Example
How to create an image map, with clickable regions. Each region is a hyperlink:
https://www.w3schools.com/tags/tag_img.asp 5/11
11/8/21, 2:52 AM HTML img tag
<img
src="workplace.jpg"
HTML CSS alt="Workplace" usemap="#workmap" width="400"
height="379">
<map name="workmap">
<area shape="rect" coords="34,44,270,350" alt="Computer"
href="computer.htm">
<area shape="rect" coords="290,172,333,250" alt="Phone" href="phone.htm">
<area shape="circle" coords="337,300,44" alt="Cup of coffee"
href="coffee.htm">
</map>
Try it Yourself »
Related Pages
HTML tutorial: HTML Images
Example
img {
display: inline-block;
}
Try it Yourself »
https://www.w3schools.com/tags/tag_img.asp 6/11