<img>
HTML <img> Tag
Instance
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> </head> <body> <img src="/upload/course/000/000/010/580977768651f670.gif" alt="Smiley face" width="42" height="42"> </body> </html>
Run Example»
Click the "Run Instance" button to view the online instance
Browser support
All major browsers support the <img> tag.
Tag definition and usage instructions
<img> tag defines images in HTML pages.
<img> tags have two required attributes: src and alt.
Note: Technically speaking, the image is not inserted into the HTML page, but is linked to the HTML page. The <img> tag creates a placeholder for the referenced image.
Tip:Add a link to an image to another document by nesting an <img> tag within an <a> tag.
Differences between HTML 4.01 and HTML5
The following attributes are not supported in HTML5: align, border, hspace, longdesc, vspace.
In HTML 4.01, the following attributes: align, border, hspace, vspace are obsolete.
Differences between HTML and XHTML
In HTML, the <img> tag does not have a closing tag.
In XHTML, the <img> tag must be closed properly.
Attribute
New: New attribute in HTML5.
Attributes | Value | Description |
---|---|---|
align | top bottom middle left right | HTML5 is not supported. HTML 4.01 is deprecated. Specifies how images are arranged relative to surrounding text. |
alt | text | Specifies the alternative text for the image. |
border | pixels | HTML5 Not supported. HTML 4.01 is deprecated. Specifies the border around the image. |
crossoriginNew | #anonymous use-credentials | Set the cross-domain attributes of the image |
height | pixels | Specify the image's high. |
hspace | pixels | HTML5 Not supported. HTML 4.01 is deprecated. Specifies the margins on the left and right sides of the image. |
ismap | ismap | Specifies the image as a server-side image map. |
longdesc | URL | ##HTML5 Not supported. HTML 4.01 is deprecated. Points to a URL that contains a long image description document. |
URL | Specifies the URL to display the image.||
#mapname | Defines the image as a client-side image map.||
pixels | HTML5 Not supported. HTML 4.01 is deprecated. Specifies the margin at the top and bottom of the image. | |
pixels | Specifies the width of the image.