Kumail.pk is a Free Platform of

Attributes of Image Tag

Attributes of Image Tag: Images and backgrounds give a visual appeal to the websites. Sometimes images can present a better understanding than long and uninteresting texts. Images can be inserted in an HTML document by using tag. This does not create a copy of image. Instead, it only creates a reference to original image placed somewhere in the computer’s storage. The tag is an empty tag which means that it does not require a closing tag. It contains ve attributes out of which two are required and three are optional.

Attributes of Image Tag

 

HTML <img> src Attribute

❮ HTML <img> tag

Example

An image is marked up as follows:

<img src=”img_girl.jpg” alt=”Girl in a jacket” width=”500″ height=”600″>

Try it Yourself »


Definition and Usage

The required src attribute specifies the URL of the image.

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.

Note: A broken link icon and the alt text are shown if the browser cannot find the image. 

Syntax

<img src=”URL“>

Attribute Values

ValueDescription
URLThe URL of the image.

Possible values:

  • An absolute URL – points to another web site (like src=”http://www.example.com/image.gif”)
  • A relative URL – points to a file within a web site (like src=”image.gif”)
 

Apply for Free E-Certification

E-Certification