Img tag in HTML5

Introduction 

 
The img element defines an image. The <img> tag is used to insert images in a document. The image is presented as part of the web page. But it is important to know that image is not a technically part of a web page. Generally, the Maximum browser supports only GIF, JPEG and PNG format. The HTML <img> tag is used for embedding images into an HTML document. The value given by the src attribute is the URL to the embedded image. The value of the alt attribute appears if the image cannot be loaded. To link an image to another document, you simply nest the <img> tag inside <a> tags.
 
Syntax
 
<img src="URL" alt="Text" />
 
src - Defines the address(URL) of the image.
 
alt - text to display if image not display.
 

Attributes

 
HTML tags can contain one or more attributes. Attributes are added to a tag to provide the browser with more information about how the tag should appear or behave. Attributes consist of a name and a value separated by an equals (=) sign, with the value surrounded by double-quotes.
 
There are 3 kinds of attributes that you can add to your HTML tags: Element-specific, global, and event handler content attributes.
 
Element-Specific Attributes
 
The following table shows the attributes that are specific to this tag/element.
 

Attributes Introduced by HTML5

 
Attributes Description             
src This attribute specifiesAddress of resource file using URL.
alt Alternate text. This specifies text to be used in casethe browser/user agent can't render the image.
ismap For imagemaps. See HTML map tag
usemap For imagemaps. See HTML map tag
width Specifies the width of the image.
height Specifies theheight of the image.
 
Global Attributes
 
The following attributes are standard across all HTML 5 tags.
 
HTML5Global Attributes
accesskey draggable style
class hidden tabindex
oncontextmenu ondblclick ondrag
contenteditable id title
contextmenu lang lang  
 
Event Handler Content Attributes
 
Here are the standard HTML 5 event handler content attributes.
 
Event Handler Content Attributes
onabort onerror* onmousewheel
onblur* onfocus* onpause
oncanplay onformchange onplay
oncanplaythrough onforminput onplaying
onchange oninput onprogress
onclick oninvalid onratechange
oncontextmenu onkeydown onreadystatechange
ondblclick onkeypress onscroll
ondrag onkeyup onseeked
ondragend onload* onseeking
ondragenter onloadeddata onselect
ondragleave onloadedmetadata onshow
ondragover onloadstart onstalled
ondragstart onmousedown onsubmit
ondrop onmousemove onsuspend
ondurationchange onmouseout ontimeupdate
onemptied onmouseover onvolumechange
onended onmouseup onwaiting
 
For example
  1. <!DOCTYPE html >  
  2. <html>  
  3.     <head>  
  4.         <title>Title of Document</title>  
  5.         <style type="text/css">  
  6.         .style1  
  7.         {  
  8.             font-size: large;  
  9.             font-family: Verdana;  
  10.         }  
  11.     </style>  
  12.     </head>  
  13.     <body>  
  14.         <h1>HTML5 img tag.</h1>  
  15.         <h2>Example of image. </h2>  
  16.         <img src="Image/Waterlilies.jpg" style="width: 211px" />  
  17.         <i>  
  18.             <br />  
  19.             <span class="style1">This is the flower.</span>  
  20.         </i>  
  21.         <br class="style1">  
  22.             <h2>Secongd Image.</h2>  
  23.             <img src="Image/Winter.jpg" style="width: 219px" />  
  24.         </body>  
  25.     </html>  
Internet Explorer
 
im1.gif 
 
FireFox
 
im2.gif
 
Making hyperlink of an image
 
The below html code displays image with hyperlink.
  1. <a href="http://www.vbdotnetheaven.com/">  
  2.     <img src="Image/Waterlilies.jpg" style="width: 211px" />  
  3. </a>  
Creating an image map
  1. <map name="planetmap">  
  2.     <area shape="rect" coords="0,0,82,126" alt="Sun" href="sun.htm" />  
  3.     <area shape="circle" coords="90,58,3" alt="Mercury" href="mercur.htm" />  
  4.     <area shape="circle" coords="124,58,8" alt="Venus" href="venus.htm" />  
  5. </map>