HTML Attributes

Attributes provide additional information about HTML elements. All HTML elements can have attributes. They are always specified in the start tag and usually come in name/value pairs like: name=”value”.

The href Attribute

HTML links are defined with the <a> tag and href attribute is used to specify the link address.

The href Attribute Example

<a href=””>Click here</a>

The src Attribute

HTML images are defined with the <img> tag. The src attribute is used to specify the filename of image source.

The src Attribute Example

<img src=”image_filename.jpg”>

The width and height Attributes

HTML images also have width and height attributes, which specifies the width and height of the image:

width and height Attributes Example

<img src=”image_filename.jpg” width=”300″ height=”400″>

The alt Attribute

The alt attribute specifies an alternative text to be used, if an image cannot be displayed. The value of the alt attribute can be read by screen readers.

The alt Attribute Example

<img src=”image_filename.jpg” alt=”Movie Poster”>

The style Attribute

The style attribute is used to specify the styling of an element, like color, font, size etc.

The style Attribute Example

<p style=”color:red”>My Paragraph.</p>

The title Attribute

A title attribute is added to the <p> element. The value of the title attribute will be displayed as a tooltip when you mouse over the paragraph:

The title Attribute Example

<p title=”my tooltip”>
My Paragraph.