# HTML <img> Tag

## Example

How to insert an image:

<img src="smiley.gif" alt="Smiley face" height="42" width="42">
Try it Yourself »

More "Try it Yourself" examples below.

## Definition and Usage

The <img> tag defines an image in an HTML page.

The <img> tag has two required attributes: src and alt.

Note: Images are not technically inserted into an HTML page, images are linked to HTML pages. The <img> tag creates a holding space for the referenced image.

Tip: To link an image to another document, simply nest the <img> tag inside <a> tags.

## Browser Support

Element |  |  |  |  |
--- | --- | --- | --- | --- | ---
<img> | Yes | Yes | Yes | Yes | Yes

## Differences Between HTML 4.01 and HTML5

The following attributes: align, border, hspace, longdesc, and vspace are not supported in HTML5.

## Differences Between HTML and XHTML

In HTML the <img> tag has no end tag.

In XHTML the <img> tag must be properly closed.

## Attributes

= New in HTML5.

Attribute | Value | Description
--- | --- | ---
align | top bottom middle left right | Not supported in HTML5. Specifies the alignment of an image according to surrounding elements
alt | text | Specifies an alternate text for an image
border | pixels | Not supported in HTML5. Specifies the width of the border around an image
crossorigin | anonymous use-credentials | Allow images from third-party sites that allow cross-origin access to be used with canvas
height | pixels | Specifies the height of an image
hspace | pixels | Not supported in HTML5. Specifies the whitespace on left and right side of an image
ismap | ismap | Specifies an image as a server-side image-map
longdesc | URL | Not supported in HTML5. Specifies the URL to a document that contains a long description of an image
src | URL | Specifies the URL of an image
usemap | #mapname | Specifies an image as a client-side image-map
vspace | pixels | Not supported in HTML5. Specifies the whitespace on top and bottom of an image
width | pixels | Specifies the width of an image

## Global Attributes

The <img> tag also supports the Global Attributes in HTML.

## Event Attributes

The <img> tag also supports the Event Attributes in HTML.

## Try it Yourself - Examples

Insert images from different locations
How to insert images from another folder or from another web site.

Make a hyperlink of an image
How to add a hyperlink to an image.

Create an image map
How to create an image map, with clickable regions. Each region is a hyperlink.

## Related Pages

HTML tutorial: HTML Images

HTML DOM reference: Image Object

## Default CSS Settings

Most browsers will display the <img> element with the following default values:

## Example

img {
display: inline-block;
}
Try it Yourself »

### WEB HOSTING

UK Reseller Hosting

### WEB BUILDING

FREE Website BUILDER Free HTML5 Templates

### W3SCHOOLS EXAMS

HTML, CSS, JavaScript, PHP, jQuery, XML, and ASP Certifications

### SHARE THIS PAGE

### Color Picker

### HTML/CSS

HTML Tutorial HTML5 Tutorial CSS Tutorial CSS3 Tutorial Bootstrap Tutorial

### JavaScript

JavaScript Tutorial jQuery Tutorial jQuery Mobile Tutorial AngularJS Tutorial AJAX Tutorial JSON Tutorial

### Graphics

Canvas Tutorial SVG Tutorial Google Maps Tutorial

### Server Side

SQL Tutorial PHP Tutorial ASP Tutorial ASP.NET Tutorial VBScript Tutorial AppML Tutorial

### Web

Web Building Web Statistics Web Certification

### XML

XML Tutorial DTD Tutorial Schema Tutorial XML DOM Tutorial XPath Tutorial XSLT Tutorial XQuery Tutorial XSL-FO Tutorial RSS Tutorial WSDL Tutorial

### HTML/CSS

HTML Tag Reference HTML Event Reference HTML Color Reference CSS 1,2,3 Reference Bootstrap Reference

### JavaScript

JavaScript Reference HTML DOM Reference jQuery Reference jQuery Mobile Reference Google Maps Reference

### Server Side

PHP Reference SQL Reference ASP Reference VBScript Reference Razor Reference ASP.NET Reference

### XML

XML DOM Reference XSLT Reference XSL-FO Reference XPath Reference XQuery Reference Schema Reference RSS Reference SVG Reference

### HTML Charsets

HTML Character Sets HTML ASCII HTML ANSI HTML Windows-1252 HTML ISO-8859-1 HTML Symbols HTML UTF-8

### HTML/CSS

HTML Examples CSS Examples

### Browser Scripting

JavaScript Examples HTML DOM Examples jQuery Examples jQuery Mobile Examples AngularJS Examples AJAX Examples

### Server Scripting

PHP Examples ASP Examples VBScript Examples Razor Examples .NET Examples

### XML Languages

XML Examples DTD Examples XML DOM Examples XSL Examples XSLT Examples XPath Examples XQuery Examples Schema Examples RSS Examples SVG Examples