A web page should be designed in such a way that a user can easily understand its contents and it should look attractive too. For this we can add graphics, images, photographs etc in our web pages. Not only these elements enhance the presentation of the web pages for its items but also it allures and attracts the users to browse the particular web page.
HTML supports static and animated both kinds of images. HTML accepts the image as GIF(Graphic Interchange Format), JPEG(Joint Photographic Experts Group) or BMP(Bitmap).
<IMG> Tag : <IMG> tag is used to add an image to the web page. It is an empty tag. It may start with <P> tag which is a container tag. When we enclose the <IMG> tag between <P> and </P> tags, a blank line is inserted before and after the image. The SRC (Source) attribute is used with <IMG> tag to specify the name and location of the image.
For example:
<P> <IMG Src = "flower.gif"></P>
Attributes of <IMG> tags :
- SRC
- ALIGN
- BORDER
- WIDTH
- HEIGHT
- HSPACE
- VSPACE
- ALT
SRC Attribute : This attribute specifies the location (source) of the image file. Syntax to use SRC attribute is as follow :
<IMG SRC = "Image file with URL">
For Example
<IMG Src = "C:\flower.gif">
ALIGN Attribute : This attribute is used to align the text and the image in a web page according to the specified alignment given with this attribute Align.
For the alignment of text we can use the following alignments.
TOP - It align the text to be displayed at the top, above the image
MIDDLE - It aligns the text to be displayed in the middle, with the image
BOTTOM - It aligns the text to be displayed at the bottom, below the page.
For the alignment of image we can use the following alignments.
LEFT - It aligns the image towards the left of the screen.
RIGHT - It aligns the image towards the right of the screen.
Syntax to use Align attribute is as follow :
<IMG Align = "top"/"middle"/"bottom"/"left"/"right">
For example :
<IMG SRC = "C:\flower.gif" Align = "middle">
or
<IMG SRC = "C:\flower.gif" Align = "right">
 |
Right alignment |
 |
Left Alignment |
BORDER Attribute : This attribute is used to specify the width of the border around the image. By default border is not set in the image but when we specify it with Border attribute, then it appears around the image. Width of the border depends on the value which we give with the Border attribute. Syntax to use Border attribute is as follow: <IMG SRC = "C:\flower.gif" Align = "top" border = "2">
If we want more thick border then we can increase the number more than "2" in that ratio in which the thickness is desired and if we want thin border then option is "1" because less than 2 is 1 only.
 |
In Notepad++
|
 |
In Browser |
WIDTH Attribute : This attribute is used to specify the width of the image in pixels or percentage, in comparison to its original size. The syntax is<IMG WIDTH = "Value/Percentage">
For example : <IMG SRC = "C:\flower.gif" Width = "50%">
or
<IMG SRC = "C:\flower.gif" Width = "300">
HEIGHT Attribute : This attribute is used to specify the height of the image in pixels or percentage, in comparison to its original size. The syntax to use Height attribute is
<IMG HEIGHT= "Value/Percentage">
For example : <IMG SRC = "C:\flower.gif" Height= "75%">
or
<IMG SRC = "C:\flower.gif" Height= "350">
HSPACE Attribute : This attribute is used to set the space towards left or right margin of the image. It specify the horizontal space between the text and image in numbers. Syntax to use HSPACE Attribute is
<IMG SRC = "C:\flower.gif" HSPACE= "2">
VSPACE Attribute : This attribute is used to set the space towards top or bottom margin of the image. It specify the vertical space between the text and image in numbers. Syntax to use VSPACE Attribute is
<IMG SRC = "C:\flower.gif" VSPACE= "3">
ALT Attribute : This attribute is used to assign an alternative text that will be displayed over the image when take the mouse on the image. The text given with Alt attribute is displayed on the image. (some browser may not support this feature). The syntax to use ALT Attribute is as follows :
<IMG SRC = "C:\flower.gif" ALT = "Flower">
 |
In notepad++ |
 |
In Browser |
TOP
Try it yourself editor