After defining HTML5 Tags and Elements in the previous section, we are ready to learn HTML5 Attributes.
Actually HTML5 attributes add or provide more information about the HTML5 elements. All HTML elements can have attributes and they are always specified in the start tags. They usually come in pairs like: name =”value“.
Here are some HTML5 attributs:
- lang attribute: This is to declare the document language. lang is declared inside <html> tag. Declaring a language is important for accessibility applications (screen readers) and search engines. have a look at codes below and focus:
123456789<!DOCTYPE html><html lang="en-US"><head><title>Document</title></head><body></body></html>
The first two letters specify the language (en). If there is a dialect, use two more letters (US).
- title attribute: It displays a tool-tip on the screen while mouse hovers on the element. title can be added as attribute to the most of the tags, as below you can see that title attribute is added to the <p> element.
123<p title="codejow tooltip">This is Web Designing Tutorial from codejow.com</p>
- alt attribute: an alternative text when an image cannot be displayed on the screen.
1<img src="codejow.jpg" alt="codejow website" >
In the above code, if the image was not displayable because of any reason; the alt text will be displayed.
- size attributes: HTML images are defined with the <img> tag. The filename of the source (src), and the size of the image (width and height) are all provided as attributes; here width and height are the size attributes.
1<img src="codejow.jpg" width="104" height="142">
- href attribute: The links inside the HTML5 are declared inside the href attributes in the <a> tags.
1<a href="http://www.codejow.com">The link opens codejow website</a>
Next we will discuss More about HTML5 Tags and Elements in deep, stay tuned with CODEJOW.