background img
Nov 30, 2018
17 Views
0 0

Images tag in HTML

Written by

It is very important to beautify the pictures while portraying many complex concepts in a simple way on your web page.

Images tag in HTML It is very important to beautify the pictures while portraying many complex concepts in a simple way on your web page. This tutorial will take you through simple steps to use images in your HTML pages.

Insert Image

You can insert any image by using the <img> tag in your web page. The following is the simple syntax for using this tag.

<img src = "Image URL" ... attributes-list/>

The <img> tag is an empty tag, which means that it can only contain a list of attributes and has no closing tag.

Example

To try following example, let’s keep our HTML file test.htm and image file logo.png in the same directory −

Live Demo

<!DOCTYPE html>
<html>

   <head>
      <title>Using Image in Webpage</title>
   </head>
	
   <body>
      <p>Simple Image Insert</p>
      <img src = "/html/logo.png" alt = "Logo Image" />
   </body>
	
</html>

This will produce the following result −

You can use a PNG, JPEG or GIF image file based on your comfort, but make sure you specify the correct image file name in the src attribute. The name of the image is always sensitive.

The height attribute is an essential feature that specifies an alternate text for an image, if the image can not be displayed.

Set Image Location

Usually we keep all the images in a separate directory in html. So let’s put the HTML file in my home directory. Inside a home directory, we create a subdirect image, where we will keep our image logo. png

Example

Assuming the location of our image is “/html/insert_image.html”, try the following example –

Live Demo

<!DOCTYPE html>
<html>

   <head>
      <title>Using Image in Webpage</title>
   </head>
	
   <body>
      <p>Simple Image Insert</p>
      <img src = "/html/logo.png" alt = "Logo Image" />
   </body>
	
</html>

This will produce the following result −

Set Image Width/Height

You can use the width and height attributes to set the width and height of the image depending on your requirement. You can specify the width and height of the image in terms of pixels or percent of its actual size.

Example

Live Demo

<!DOCTYPE html>
<html>

   <head>
      <title>Set Image Width and Height</title>
   </head>
	
   <body>
      <p>Setting image width and height</p>
      <img src = "/html/logo.png" alt = "Logo Image" width = "150" height = "100"/>
   </body>
	
</html>

This will produce the following result −

Set Image Border

By default, image will have a border around it, you can specify border thickness in terms of pixels using border attribute in HTML. A thickness of 0 means, no border around the picture in HTML.

[wp_ad_camp_6]

Example

Live Demo

<!DOCTYPE html>
<html>

   <head>
      <title>Set Image Border</title>
   </head>
	
   <body>
      <p>Setting image Border</p>
      <img src = "/html/logo.png" alt = "Logo Image" border = "3"/>
   </body>
	
</html>

This will produce the following result −

Set Image Alignment

By default, the image will be aligned to the left side of the page, but you can use alignment to set it to center or right.

[wp_ad_camp_7]

Example

Live Demo

<!DOCTYPE html>
<html>

   <head>
      <title>Set Image Alignment</title>
   </head>
	
   <body>
      <p>Setting image Alignment</p>
      <img src = "/html/logo.png" alt = "Logo Image" border = "3" align = "right"/>
   </body>
	
</html>

This will produce the following result −

Article Categories:
HTML

Leave a Reply

Your email address will not be published. Required fields are marked *


The maximum upload file size: 300 MB.
You can upload: image, audio, video, document, text, other.
Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded.