HTML Attributes

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.

Example :

<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:

Href:

It is used with the "<a>" tag and help you specify the address of the element (image/audio/page) you want to link.

Example

<a href="https://www.google.com"> Visit Google </a>

Height and width:

These attributes are used to specify the height and width of the image in pixels.

Example

<img  src=”Sun.jpg” height=”100” width=”200”>

Alt:

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.

Example

<img  src=”Sun.jpg” alt=” This is a picture of Sun” height=”100” width=”200”>

Style:

It is used to specify the style i.e. font, size, and color.

Example

<p style="color:blue;">You have used a style attribute. </p>

Title:

It displays the additional information about an element.

Example

<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.