Attributes are used to define the supplementary properties of HTML elements. For instance, you need to specify the color and size of the font.
Attributes are mentioned in the opening tag and contain name/value pairs such as name=”value”. Always close the attribute values in quotation marks. You can use single or double quotes. However, double quotes are more popular.
<img src="Pictures/Flower.gif" height="50" width="40">
In this example, src is the attribute of the <img> tag.
Tip:
Attribute values are usually case-insensitive.
Some common HTML attributes:
It is used with the "<a>" tag and help you specify the address of the element (image/audio/page) you want to link.
<a href="https://www.google.com"> Visit Google </a>
These attributes are used to specify the height and width of the image in pixels.
<img src=”Sun.jpg” height=”100” width=”200”>
Sometimes, the web browser fails to display the images. There could be different reasons for that. For instance, an error in the src attribute or a bad connection. The alt attribute displays the alternate text for the image.
<img src=”Sun.jpg” alt=” This is a picture of Sun” height=”100” width=”200”>
It is used to specify the style i.e. font, size, and color.
<p style="color:blue;">You have used a style attribute. </p>
It displays the additional information about an element.
<p title="I'm a tooltip">This is a title attribute</p>
Tip:
The message you specify in the title attribute is showcased as a tooltip when you hover the mouse over it.