HTML Images

img Tag and the src Attribute

Images are added to a site using the < img > element, which has to carry at least two attributes: the src attribute, indicating the source of the image, and an alt attribute, which provides a description of the image.

<img src="logo.gif" alt="default text" / >

The src Attribute
The src attribute tells the browser where to find the image. The value is a URL and, just like the links, the URL can be an absolute URL or a relative URL.
The alt Attribute
The alt attribute must appear on every <img> element and its value should be a text description of the image.

The height and width Attributes

<img src="logo.gif" alt="default text" height="120" width="180" / >

Background Images

consider the following code for background image.

<title>HTML images</title>
<body background="image1.jpg">
<h3>text on background image</h3>
<p>Both gif and jpg files can be used as 
HTML backgrounds.</p>
<p>If the image is smaller than the page, 
the image will repeat

You may also like...