HTML - Images, How to use <img> tag in HTML?

Ad Code

HTML - Images, How to use tag in HTML?

 


HTML - Images

Using <img> tag we can insert any image in our web page specify correct image file name in src attribute. The <img> tag is an empty tag, which means that, it can contain only list of attributes and it has no closing tag.

Syntax

<img src = "Image URL" ... attributes-list/>

Example

<!DOCTYPE html>
<html>
   <head>
      <title>Image tag Example</title>
   </head>	
   <body>
      <img src="assets/img/lem_line.gif">
   </body>	
</html>

Output



AttributeDescriptionHTML Compatibility
align
<img align="left|right|middle|top|bottom">
Alignment of the imageDeprecated in HTML 4.01, Obsolete in HTML 5
altAlternative text to display if image can not be displayedHTML 4.01, HTML 5
borderWidth of the border around the imageDeprecated in HTML 4.01, Obsolete in HTML 5
crossoriginEnumerated value indicating whether the image must be fetched using CORS. Can be the following values:
anonymous - means a cross-origin request is performed with no credentials
use-credentials - means a cross-origin request is performed with credentials
HTML 5
heightHeight of the image
In HTML 4.01, height can be in pixels
In HTML 5, height can be in either pixels or as a percentage
HTML 4.01, HTML 5
hspaceWhite space to insert to the left and right of image (expressed in pixels)Deprecated in HTML 4.01, Obsolete in HTML 5
ismapBoolean value indicating whether the image is part of a server-side mapHTML 4.01, HTML 5
longdescURL of a description of the imageHTML 4.01 (in HTML 5, use the <a> tag
nameName of the element (use the id attribute instead)Deprecated in HTML 4.01, Obsolete in HTML 5
srcURL of the imageHTML 4.01, HTML 5
widthWidth of the image (expressed in either pixels or percent)HTML 4.01, HTML 5
usemapPartial URL of an image map for the element. Partial URL starts with #HTML 4.01, HTML 5
vspaceWhite space to insert above and below the image (express in pixels)Deprecated in HTML 4.01, Obsolete in HTML 5



Image Width/Height Attributes

We can set image width and height using width and height attributes. We can specify width and height of the image in terms of either pixels or percentage of its actual size.

Example

<!DOCTYPE html>
<html>
   <head>
      <title>Set Image Width and Height</title>
   </head>	
   <body>
      <img src = "picts/rkt.jpg" alt = "Test Image" width = "150" height = "100"/>
   </body>
	
</html>

Output

Test Image

Image Border Attributes

We can specify border thickness in terms of pixels using border attribute. A thickness of 0 means, no border around the picture.

Example

<!DOCTYPE html>
<html>
   <head>
      <title>Set Image Width and Height</title>
   </head>	
   <body>
      <img src = "picts/rkt.jpg" alt = "Test Image" width = "150" height = "100" border="2"/>
   </body>
	
</html>

Output




Image Alignment Attributes

By default, image will align at the left side of the page, but we can use align attribute to set it in the center or right.

Example


<!DOCTYPE html>
<html>
   <head>
      <title>Set Image Width and Height</title>
   </head>	
   <body>
      <img src = "picts/rkt.jpg" alt = "Test Image" align = "center"/>
   </body>
	
</html>

Output

                                            Test Image


Post a Comment

0 Comments

Ad Code