HTML Attributes

Written by

Aayushi Bansal

HTML attributes are the one which adds additional information to the main element or about the contents of an element.

They appear on the opening tag of the element and usually exist in pair i.e. a name and a value separated by an equals sign.

It is represented as, Name=”value”

For example,

<p lang="en-us">paragraph in English</p>

Here ‘lang’ is the attribute name and ‘en-us’ is the attribute value. 

The attribute name indicates what kind of extra information you are supplying about the element’s content. It should be written in lowercase.

The value is the information or setting for the attribute. It should be placed in double-quotes.

The href attribute:
This attribute is used for the link address and is defined in the <a> tag. For example, 

<a href=https://www.studymite.com> This is a StudyMite Homepage Link</a>


The src attribute:
HTML images are defined with the image tag. The filename of the image is specified in the src attribute. For example, 

<img src="imag_1.jpg">


Width and height attributes:
These attributes specify the width and height of the image. The width and height are specified in pixels by default. For example,

<img src="img_2.jpg width="400" height="600">


The alt attribute:
The alt attribute specifies an alternative text to be used if the image cannot be displayed. For example, 

<img src="img_flower.jpg" alt="The sunflower in the garden">

The style attribute:

This attribute is used to give styling and effects to the HTML content. The effects can be color, size, font, background color, etc. The style attribute is majorly a part of CSS but can be used in HTML as well. For example,

<p style=”color: blue”>This gives blue color to the text. </p>


There are many other attributes such as I’d, class, etc which we will study in the later chapters.

HTML Attributes