Every HTML Elements usually have attributes to it. An attribute will provide additional information to the HTML element. Attributes are written inside
HTML Attributes
Every HTML Elements usually have attributes to it. An attribute will provide additional information to the HTML element. Attributes are written inside the start tag of any elements, and it is written as name=”value”. For Example the body element has the bgcolor attribute. Now open up the same index.html file in a text editor and add the attribute bgcolor=”red” inside the body tag as follows:
<html>
<head>
<title>My First HTML</title>
</head>
<body bgcolor="red">
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<p>Hello World</p>
<p>This is a second paragraph and I'm putting <strong>Bold</strong> and <em>Emphasis</em> just to see if it works
</p>
</body>
</html>
Reload the file in your browser and you’ll see something like this below:We’ll learn another Element in HTML which is used to display images. The image element start and ends with <img /> tag. As of now you’ve noticed that every element opens up as <element> tag and closed as </element> tag, but the image element is slightly different and doesn’t have an end tag. Now download this image into your computer and save in the same folder MyWeb. Now edit index.html again and add the following code.
<html>
<head>
<title>My First HTML</title>
</head>
<body bgcolor="red">
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<p>Hello World</p>
<p>This is a second paragraph and I'm putting <strong>Bold</strong> and <em>Emphasis</em> just to see if it works
</p>
<img src="attribute.jpg" width="300" />
</body>
</html>
Here the img uses two attributes – the src and the width attribute. The former tells image element where the source of the image is? and the later tells image element about the width to be displayed. Try and experiment with the width and also height to see different results.
COMMENTS