Images

Images

How to insert image in a web page?

In HTML, images are defined with the <img> tag.

The <img> tag is empty, it contains attributes only, and does not have a closing tag.

The src attribute specifies the URL (web address) of the image:

<img src="url" alt="some_text">

The alt Attribute

The alt attribute specifies an alternate text for an image, if the image cannot be displayed.

The alt attribute provides alternative information for an image if a user for some reason cannot view it (because of slow connection, an error in the src attribute, or if the user uses a screen reader).

Example

<!DOCTYPE html>

<html>

<body>

<h2>Spectacular Mountain</h2>

<img src="pic_mountain.jpg" alt="Mountain View" style="width:304px;height:228px;">

 

</body>

</html>

Image Size - Width and Height

You can use the style attribute to specify the width and height of an image.

The values are specified in pixels (use px after the value):

Example

<img src="html5.gif" alt="HTML5 Icon" style="width:128px;height:128px;">

Alternatively, you can use width and height attributes. Here, the values are specified in pixels by default:

Example

<img src="html5.gif" alt="HTML5 Icon" width="128" height="128">

Using an Image as a Link

 To use an image as a link, simply nest the <img> tag inside the <a> tag:

 

Example

<a href="default.asp">

  <img src="smiley.gif" alt="HTML tutorial" style="width:42px;height:42px;border:0;">

</a>

Image Floating

Use the CSS float property to let the image float.

The image can float to the right or to the left of a text:

Example

<p>

<img src="smiley.gif" alt="Smiley face" style="float:right;width:42px;height:42px;">

The image will float to the right of the text.

</p>

 

<p>

<img src="smiley.gif" alt="Smiley face" style="float:left;width:42px;height:42px;">

The image will float to the left of the text.

</p>

Leave Comment

Important Topics

Title
Internet Interanet and Exranet
Internet
Domain
IP Address
HTTP
TCP / IP
FTP
Telnet
Client Server
HTML
Images
Hyperlinks
Lists
CSS