0% found this document useful (0 votes)
177 views7 pages

HTML - Images: Insert Image

The document discusses using images in HTML documents. It explains how to insert an image using the <img> tag, specifying the image source and attributes like alt text. It also covers setting the image location, size using width and height attributes, border thickness, and alignment. Images can also be used as hyperlinks by placing them within <a> tags.

Uploaded by

Fozia Noor Ijaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
177 views7 pages

HTML - Images: Insert Image

The document discusses using images in HTML documents. It explains how to insert an image using the <img> tag, specifying the image source and attributes like alt text. It also covers setting the image location, size using width and height attributes, border thickness, and alignment. Images can also be used as hyperlinks by placing them within <a> tags.

Uploaded by

Fozia Noor Ijaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

HTML – Images

Images are very important to beautify as well as to depict many complex concepts in simple way on your
web page. This tutorial will take you through simple steps to use images in your web pages.

Insert Image
You can insert any image in your web page by using <img> tag. Following is the simple syntax to use
this tag.

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

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

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

<!DOCTYPE html>
<html>

<head>
<title>Using Image in Webpage</title>
</head>

<body>
<p>Simple Image Insert</p>
<img src = "/html/images/test.png" alt = "Test Image" />
</body>

</html>

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

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

Set Image Location


Usually we keep all the images in a separate directory. So let's keep HTML file test.htm in our home
directory and create a subdirectory images inside the home directory where we will keep our image
test.png.

Example
Assuming our image location is "image/test.png", try the following example −
<!DOCTYPE html>
<html>

<head>
<title>Using Image in Webpage</title>
</head>

<body>
<p>Simple Image Insert</p>
<img src = "/html/images/test.png" alt = "Test Image" />
</body>

</html>

1
Set Image Width/Height
You can set image width and height based on your requirement using width and height attributes. You
can specify width and height of the image in terms of either pixels or percentage of its actual size.

Example

<!DOCTYPE html>
<html>

<head>
<title>Set Image Width and Height</title>
</head>

<body>
<p>Setting image width and height</p>
<img src = "/html/images/test.png" alt = "Test Image" width = "150"
height = "100"/>
</body>

</html>

Set Image Border


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

Example

<!DOCTYPE html>
<html>

<head>
<title>Set Image Border</title>
</head>

<body>
<p>Setting image Border</p>
<img src = "/html/images/test.png" alt = "Test Image" border = "3"/>
</body>

</html>

Set Image Alignment


By default, image will align at the left side of the page, but you can use align attribute to set it in the
center or right.

Example

<!DOCTYPE html>
<html>

<head>
<title>Set Image Alignment</title>
</head>

<body>
<p>Setting image Alignment</p>
2
<img src = "/html/images/test.png" alt = "Test Image" border = "3" align
= "right"/>
</body>

</html>

HTML - Image Links


We have seen how to create hypertext link using text and we also learnt how to use images in our
webpages. Now, we will learn how to use images to create hyperlinks.

Example
It's simple to use an image as hyperlink. We just need to use an image inside hyperlink at the place of
text as shown below −

<!DOCTYPE html>
<html>

<head>
<title>Image Hyperlink Example</title>
</head>

<body>
<p>Click following link</p>
<a href = "https://www.bisegrw.com" target = "_self">
<img src = "/images/logo.png" alt = "Gujranwala Board" border = "0"/>
</a>
</body>

</html>

HTML - Text Links


A webpage can contain various links that take you directly to other pages and even specific parts of a
given page. These links are known as hyperlinks.

Hyperlinks allow visitors to navigate between Web sites by clicking on words, phrases, and images. Thus
you can create hyperlinks using text or images available on a webpage.

Linking Documents
A link is specified using HTML tag <a>. This tag is called anchor tag and anything between the opening
<a> tag and the closing </a> tag becomes part of the link and a user can click that part to reach to the
linked document. Following is the simple syntax to use <a> tag.

<a href = "Document URL" ... attributes-list>Link Text</a>

Example
Let's try following example which links http://www.bisegrw.com at your page −

<!DOCTYPE html>
<html>

<head>
<title>Hyperlink Example</title>
3
</head>

<body>
<p>Click following link</p>
<a href = "https://www.bisegrw.edu.pk" target = "_self">Gujranwala
Board</a>
</body>

</html>

The target Attribute


We have used target attribute in our previous example. This attribute is used to specify the location
where linked document is opened. Following are the possible options −

Sr.No Option & Description

1
_blank

Opens the linked document in a new window or tab.

2
_self

Opens the linked document in the same frame.

3
_parent

Opens the linked document in the parent frame.

4
_top

Opens the linked document in the full body of the window.

5
targetframe

Opens the linked document in a named targetframe.

Example
Try following example to understand basic difference in few options given for target attribute.

<!DOCTYPE html>
<html>

<head>
<title>Hyperlink Example</title>
<base href = "https://www.bisegrw.edu.pk/">
</head>

<body>
<p>Click any of the following links</p>
<a href = "/html/index.htm" target = "_blank">Opens in New</a> |
<a href = "/html/index.htm" target = "_self">Opens in Self</a> |
<a href = "/html/index.htm" target = "_parent">Opens in Parent</a> |
<a href = "/html/index.htm" target = "_top">Opens in Body</a>
</body>
4
</html>

Use of Base Path


When you link HTML documents related to the same website, it is not required to give a complete URL
for every link. You can get rid of it if you use <base> tag in your HTML document header. This tag is
used to give a base path for all the links. So your browser will concatenate given relative path to this
base path and will make a complete URL.

Example
Following example makes use of <base> tag to specify base URL and later we can use relative path to
all the links instead of giving complete URL for every link.

<!DOCTYPE html>
<html>

<head>
<title>Hyperlink Example</title>
<base href = "https://www.bisegrw.edu.pk">
</head>

<body>
<p>Click following link</p>
<a href = "/html/index.htm" target = "_blank">HTML Tutorial</a>
</body>

</html>

Setting Link Colors


You can set colors of your links, active links and visited links using link, alink and vlink attributes of
<body> tag.

Example
Save the following and open it in any web browser to see how link, alink and vlink attributes work.

<!DOCTYPE html>
<html>

<head>
<title>Hyperlink Example</title>
<base href = "https://www.bisegrw.edu.pk">
</head>

<body alink = "#54A250" link = "#040404" vlink = "#F40633">


<p>Click following link</p>
<a href = "/html/index.htm" target = "_blank" >HTML Tutorial</a>
</body>

</html>

Download Links

5
You can create text link to make your PDF, or DOC or ZIP files downloadable. This is very simple; you
just need to give complete URL of the downloadable file as follows −

<!DOCTYPE html>
<html>

<head>
<title>Hyperlink Example</title>
</head>

<body>
<a href = "https://www.bisegrw.edu.pk page.pdf">Download PDF File</a>
</body>

</html>

Assignment Solution

<html>

<body>

<table style="width:100%" border="1">

<tr>

<th>Firstname</th>

<th>Lastname</th>

<th>Age</th> </tr>

<tr> <td>Jill</td>

<td>Smith</td>

<td>50</td>

</tr> <tr> <td>Eve

</td> <td>Jackson</td>

<td>94</td> </tr>

<tr> <td>John</td>

<td>Doe</td> <td>80</td>

</tr>

</table>

</body>

</html>

6
<html>

<head>

</head>

<body>

<table border="1">

<tr>

<td>

<p>This is a paragraph</p> <p>This is another paragraph</p> </td>

<td>This cell contains a table: <table> <tr> <td>1</td> <td>2</td>

</tr>

<tr>

<td>3</td> <td>4</td>

</tr>

</table>

</td>

</tr>

<tr> <td>This cell contains a list <ul> <li>car</li> <li>bike</li> <li>bicycle</li> </ul>
</td>

<td>HELLO</td>

</tr>

</table>

</body>

</html>

You might also like