This article is the third part in a series of articles known as: "What is HTML?", if you have not read the first two articles before this one, then this article is of no further use to you. If you wish to go the previous article, go to this link:
http://somniumtuts.blogspot.com/2011/04/what-is-html-creating-basic-webpage.html
If you wish to go to the beginning of this entire series, click this link:
http://somniumtuts.blogspot.com/2011/04/what-is-html-basics-guide.html
In the second part of this series, we have read about how to insert an icon into your website using HTML, how to insert line breaks, paragraphs, section dividers, titles and background colors. In this article, we will see specifically how to insert images and how to create independent "clickable" areas on the image using "usemaps". We will also look into the explanations for the code that was written in the previous article. We shall go into depth of these codes and we'll try to explain them as best we can. We shall also talk about positioning text in this article.
Inserting images is not that much of a difficult thing to do, especially when you have the power of HTML in the grasp of your hand. With HTML, you can do almost anything to edit or insert items into your website.
You can insert images into the website by using the <img> tag, which like <br> and <hr> tags, do not have closing tags. Here is some code to show you how to insert an image into your website:
<html>
<head>
<title>
FXDepot Productions|The best place to learn computer stuff...
</title>
</head>
<body>
<img src="http://www.wormsandgermsblog.com/uploads/image/Dog%20face2.jpg/"
title="Dog's Face">
</body>
</html>
Here is how to above code will look like in a normal Chrome window:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimAmcOmEvpfdg9PuL1sNep2sghHs2PvlFpRYeFpjxrcxDuySTyhA4FE1yq03M1_sIAALwfcwXe9H7IhcaoD0aDDcb8oRG1KN2dMFVXXbegv1sVFbANFQpHNsgqXibUCPMTt_H-9KUgpe0/s320/Dog%2527s-Face.jpg) |
Dog's Face - The above code in the Chrome web browser |
What we have just down is insert an image from a URL in the Network itself. You can also do this by uploading your own image into any image hosting service and using the link they give you for the image as the Source for the HTML code.
What Happened?
According to the code above, we used the <img> tag and inserted an image from a location in the internet network using its URL. We added the "src" attribute to the <img> element. "Src" stands for "source" and we inserted the "image source" as the URL of the image itself. You can insert any image like this from the internet if you just have the URL. You can also insert images from your own computer. But there a few rules to be followed for doing so.
- First, you must put the HTML code you have written, content, images and the stuff in your website in just ONE folder. This will be known as your website's "root directory" from where all the images, graphics, text etc. are uploaded from.
- This will not work if you are writing the HTML code for your website, it is better to give a specific URL of the image when you're dealing with this.
If you wish to upload images from your own computer nonetheless, here's how to do it:
You're web hosting service, or the company that hosts your website on the internet, must have the ability to accept data into your website through FTP. You can find this out by either questioning them through FAQ, or contacting them directly.
Once you've got your FTP program downloaded, you must get the FTP host, username, password & port number details and then connect to your website. After that, you can continue uploading your HTML Code and images through this. If you wish to upload images from your computer itself, here is the code you have to write:
<html>
<head>
<title>
My Website
</title>
</head>
<body>
<img src="myimage.extension" title="My Image">
</body>
</html>
In the case of this above code, you have to replace "myimage" with the actual name of your image. You have to replace ".extension" with the actual extension of your image, namely: ".jpg", ".png" etc.
Then, along with the HTML code, you have to also upload your image into the website using the FTP server. Using this method, you can successfully import images from your computer to your website, without needing to upload your images into any image hosting services.
The "title" attribute is just an added detail. Whenever you hover your cursor over the image, the text added in the "title" attribute will appear.
Now, we shall talk about how to create "usemaps" for our images. Usemaps are just certain clickable areas within an image. For instance, if you wish to insert an image of you and your house by your side, and you want links within the image itself. One link goes to your profile on Facebook, and the other is a link to a real estate agent's website from where you bought your house from. But only one link can be inserted in an image normally (we will talk about the codes for that later). So how do you insert TWO links within the SAME image, in TWO DIFFERENT spots in the image?
And thus usemaps come into play. Here is how you do it!
<html>
<head>
</head>
<title>
Me & My House
</title>
<body>
<img src="meandmyhouse.jpg" title="Me and My House!" usemap="#meandmyhouse">
<map name="meandmyhouse">
<area shape="rect" coords="98,115,247,585" href="www.google.com" title="Me!">
<area shape="rect" coords="432,26,812,444" href="www.somniumtuts.blogspot.com" title="My House!">
</map>
</body>
</html>
Here we have used the "usemap" attribute to the <img> tag. What we've done here is we've written "#meandmyhouse", what this does is it defines a special name for the image that you plan to map. Then, we create a <map> tag, and using the "name" attribute, write down the name of the image we gave previously under the "usemap" attribute. Then we open the <area> tag, that defines the area you want mapped on the image for creating a specific link there. We also specify the shape we wish to use in defining the area. The several options are:
rectangle = "rect"
circle = "circle"
polygon = "polygon"
In this case we've used the "rect" value as the shape. We have written this within the "Shape" attribute of the <area> tag. Then within the "href" attribute, we write down the URL that we want as the link. Then, in the "title" attribute, we write the name that would appear if we hovered our cursor over the specific part of the image that we have particularly defined.
You can try this yourself with some other picture you have, and it is a really good experience. Custom navigation bars, independent advertisements, custom-made buttons etc.
How to Position Text
Positioning text isn't all that difficult, and can be achieved simply by applying some CSS code. Here is a simple example of the code:
<html>
<body>
<div style="text-align: centre;">
<p>I love to skate on Mount Everest!</p>
</div>
</body>
</html>
In this code above, we use both the <div> tag, and the "style" attribute, with the value "text-align" for positioning our specific text: "I love to skate on Mount Everest!".
The <div> tag is nothing but a layer, to which we assign attributes for content like texts, graphics, animations etc. within those <div> tags. Using the "text-align" attribute, we have three different options:
- centre
- left
- right
You can use this to position images and other stuff also.
Give us your feedback, and give some comments to help us improve our articles! Thank you!