HTML Images

 HTML IMAGE:-  

HTML img tag is used to display image on the web page. HTML img tag is an empty tag that contains attributes only, closing tags are not used in HTML image element. Let's see an example of HTML image.

  1. <h2>HTML Image Example</h2>  
  2. <img src="good_morning.jpg" alt="Good Morning Friends"/> 



Attributes of HTML tags:-

The src and alt are the two most important attributes of HTML image tag are given below-:

(1)  ALT-: 

The alt attribute defines an alternate text for the image, that can be displayed. The value of the alt attribute describes the image in words. The alt attribute is considered good for SEO prospective.

(2)  SRC-:
It is a necessary attribute that describes the source or path of the image. It instructs the browser where to look for the image on the server. The location of the image may be on the same directory or another service.

There are two ways to specify the URL in the src attribute:

1. Absolute URL - Links to an external image that is hosted on another website. Example: src="https://www.w3schools.com/images/img_girl.jpg".

Notes: External images might be under copyright. If you do not get permission to use it, you may be in violation of copyright laws. In addition, you cannot control external images; it can suddenly be removed or changed.

2. Relative URL - Links to an image that is hosted within the website. Here, the URL does not include the domain name. If the URL begins without a slash, it will be relative to the current page. Example: src="img_girl.jpg". If the URL begins with a slash, it will be relative to the domain. Example: src="/images/img_girl.jpg".

Tip: It is almost always best to use relative URLs. They will not break if you change domain.

(3) WIDTH-: 

It is an optional attribute which is used to specify the width to display the image. We should apply CSS in place of width attribute.

(4) HEIGHT-: 

It h3 the height of the image. The HTML height attribute also supports iframe, image and object elements. We should apply CSS in place of height attribute.

USE OF HEIGHT AND WIDTH ATTRIBUTE WITH IMG TAG:-

We have learnt abut how to insert an image in your Web Page, now we want to give some height and width to display image according to our requirement, then we can set height and width attributes of image.

Example:

  1. <img src="animal.jpg" height="180" width="300" alt="animal image">  

Comments

Popular posts from this blog

Html - Text Links, Image Links, E-mail Links

Html - Tables