Account
Categories

HTML Attributes


HTML attributes are special information written inside an HTML tag that provides extra details about the element, such as a link, image source, size, or style.

They are written inside the opening tag.

There are two types of attributes, which are listed as follows:

Required attributes

Required attributes are those attributes that must be used in an HTML tag for the element to work properly.

They provide important information to the element, such as src, href, and alt.

Syntax:

<tagname attribute="value">Content</tagname>

Example:

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

<img src="nature.jpg" alt="Nature Image">

Output:

Visit Google

Nature Image

Optional attributes

These attributes are not necessary for an HTML tag.

They are used to add extra styles or features to the element, such as style, title, and class.

Syntax:

<tagname attribute="value">Content</tagname>

Example:

<p style="color:blue;" title="Paragraph">
This is a paragraph
</p>

Output:

This is a paragraph