As a person you have attributes. Height, hair colour and so on.
HTML elements can have attributes as well. You have seen some of these already such as these from the introductory tutorial (no need to do anythign with these as you already did):
<img src="charlene.jpg" alt="A photo of Charlene"> <a href="index.html">First page</a> <div id="charlene">
The attributes always come as a word followed by an equals sign followed by something in quotes. The bit in the quotes is known as the value. So in the examples above:
- the src attribute has the value charlene
- the alt attribute has the value A photo of Charlene
- the href attribute has the value index.html
- the div element has an id attribute with the value charlene
Here is one to try. Open textonly.html in your editor. Add a new paragraph under the existing ones by pasting this code in:
<p title="The HTML title attribute is some text which will pop up if you hover">Hover over this paragraph.</p>
Save the page. Open it in a browser and hover over the new paragraph.
Elements and attributes
You may remember there is a title element which looks like this:
Now we have learned about the title attribute which is a different thing. This is why it is important that you understand the proper words for things in Web development. So make sure you know that:
- an HTML element is an object which normally appears on the Web page
- an attribute is like a property of an element and may modify that element or give extra information
You will use a LOT of elements and attributes soon.