img

< html‎ | elements
Jump to: navigation, search

img



Summary

The img element (<img>) embeds an image in a document. The <img> element can be nested in an <a> element to create an image that links to another page or section. Alternatives to the <img> element include setting the background-image property of an element.


Overview Table

DOM Interface HTMLImageElement

Examples

View live exampleThe following example shows how to use the img element to embed an image on a page.

HTML

<img src="logo.gif" width="420" height="120" alt="MyCorp Logo">



<img src="http://docs.webplatform.org/w/skins/webplatform/images/logo.svg" width="62" height="62" alt="Web Platform logo">

Usage

When using the IMG element to display a static image, specify the URL of the image file with the SRC attribute. When using the IMG element to display a video clip or VRML world, specify the URL with the DYNSRC attribute.

Notes

Remarks

This element does not fire the onfocus event when it receives the input focus, unless it has been associated with a MAP element. The following image and video file formats are supported:

  • .avi—Audio-Visual Interleaved (AVI)
  • .bmp—Windows Bitmap (BMP)
  • .emf—Windows Enhanced Metafile (EMF)
  • .gif—Graphics Interchange Format (GIF)
  • .png, .jpeg—Joint Photographic Experts Group (JPEG)
  • .mov—Apple QuickTime Movie (MOV)
  • .mpg, .mpeg—Motion Picture Experts Group (MPEG)
  • .png—Portable Network Graphics (PNG)
  • .wmf—Windows Metafile (WMF

Windows Internet Explorer 8 and later: in IE8 Standards mode, the title attribute is preferred over the alt attribute when specified as a pop-up tooltip for an img element. In addition, the value of the longDesc attribute depends on the current document compatibility mode.

The X Bitmap (XBM) file format is no longer supported as of Microsoft Internet Explorer 6 for Windows XP Service Pack 2 (SP2).

Windows Internet Explorer 9: setting the CLASS attribute of an image to msPinSite enables the user to drag the image to the Windows taskbar to pin the site. For more information, see Introduction to Pinned Sites.

Standards information


HTML information

{

Related specifications

Specification Status Related Changes
HTML 2.0 W3C Recommendation
HTML5 W3C Working Draft

Compatibility

Desktop

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic Support 1.0
1.0
1.0
5.12
1.0

Mobile

Feature Android BlackBerry Chrome for mobile Firefox Mobile (Gecko) IE Mobile Opera Mobile Opera Mini Safari Mobile
Basic support ? ? ? ? ? ? ? ?

See also

Related pages (MSDN)

This article contains content originally from external sources.

Portions of this content come from the Microsoft Developer Network: [Windows Internet Explorer API reference Article]