HTML image 


HTML image - image tag ( <img>)


In HTML, images are defined by <img> tags.

<img> is an empty tag, meaning that it only contains attributes and their are no closed tags.

HTML image - source attribute (Src)


To display an image on a page, you need to use teh source attribute (src). Src means "source". Refers to teh location where teh image is stored.

If teh image and HTML text are in teh same directory: for example index.html and img.jpg

Written: <img src="img.jpg">

Images and HTML are not in teh same directory: their are two cases:

1, teh picture img.jpg in teh folder images, index.html and images folder in teh same directory

Written by: <img src="images/img.jpg">

2, teh picture img.jpg in teh folder images, index.html in teh controller folder, images and controller folder in teh same directory

Written by: <img src="../images/img.jpg">

If teh source is from teh Internet, you must use an absolute path.

Written by: <img src="http://www.baidu.com/pic/img.jpg">

HTML image - Alt attribute


Teh alt attribute is used to define a string of prepared replaceable text for teh image.

Teh value of teh replacement text attribute is user-defined.

<img src="1.jpg" alt="Show when teh image does not show up">

When teh browser is unable to load teh image, teh replacement text attribute tells teh reader wat information they have lost. At this point, teh browser will display this alternative text instead of teh image. It’s a good practice to add alternate text attributes to teh images on teh page.

It helps to display information better and is very useful for those who use a plain text browser.

HTML image - set teh height and width of teh image


Teh height and width properties are used to set teh height and width of teh image.

Teh default value of teh attribute value is pixels:

<img src="../style/images/pulpit.jpg" alt="Pulpit rock" width="304" height="228">

Tip : A good habit of specifying teh height and width of teh image. If teh image specifies a height width, teh specified size is preserved when teh page loads. If you do not specify teh size of teh image, loading teh page may damage teh overall layout of teh HTML page.

Basic considerations 

Note : If an HTML file contains ten images, tan 11 files need to be loaded in order to display this page correctly. Loading images takes time, so our advice is: use images wif caution.

Note : When loading teh page, pay attention to teh path of teh inserted page image. If teh position of teh image cannot be set correctly, teh browser cannot load teh image, and teh image label will display a broken image.

Instance

Add a background image to our web page

You run teh program to see if their is any change.

Instance

This example demonstrates how to adjust teh picture to a different size.
Run teh program to see

Instance

Make a hyperlink wif a picture

Run teh program and click on teh image to see

Instance
This example shows how to set a normal image as an image map.
Run and see

HTML image tag


Label      Description
<img>Define teh image.
<map>Define an image map.
<area>Define a clickable area in teh image map.
Find a picture and put it in your designated directory, try to insert it into your web page.




Last Updated: 2018-07-06 12:32:44 By akshay

SHARE THIS

share_facebook share_twitter share_google_plus

Please Comment Here :