html tutorial - Image <img> tag in HTML - html5 - html code - html form



image tag in html

Learn html - html tutorial - image tag in html - html examples - html programs

  • The HTML <img> tag represents an image in the html document.
  • There are two required attributes in <img> tag : src and alt.
  • The <img> tag belongs to Flow content, phrasing content, embedded content, palpable content.
  • The <img> tag supports Global attribute and Event attribute.

Syntax for <img> tag in HTML

<img src="Image URL" />

Differences between HTML 4.01 and HTML5 for <img> tag:

HTML 4.01

  • align, border, hspace and vspace attributes are supported.

HTML5

  • align, border, hspace, and vspace attributes are not supported in HTML5.

html code for image <img> tag in HTML

Tryit<!DOCTYPE html>
<html >
    <head>
        <title>Wikitechy img Tag</title>
    </head>
    <body>
        <img src="https://www.wikitechy.com/images/logo.png" alt="Wikitechy Logo"/>
    </body>
</html>

Code Explanation for <img> tag in HTML

code explanation for image tag

  1. <img> used to display an image into the document.
  2. src attribute used to define the location of the source image.
  3. alt attribute is used to set alternate text for the image in case the image does not displayed the alternate text will be shown.

Output of <img> tag in HTML

output for image tag

  1. The output shows the wikitechy logo image.

Attribute:

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

Browser Support for <img> tag in HTML

Yes Yes Yes Yes Yes

Related Searches to image tag in html