What Is The HTML Attributes

HTML Attributes ascribes give extra data about HTML components.

HTML Attributes

  • All HTML components can have ascribes
  • Properties give extra data about components
  • Properties are constantly determined in the beginning tag
  • Properties typically come in name/esteem sets like: name=”value”

The href Attribute

The <a> tag defines a hyperlink. The href attribute specifies the URL of the page the link goes to:


<a href=”https://www.examples.com”>Visit examples</a>

The src Attribute

The <img> tag is used to embed an image in an HTML page. The src attribute specifies the path to the image to be displayed:


<img src=”img_girl.jpg”>

There are two different ways to indicate the URL in the src trait:

  1. Supreme URL – Links to an outside picture that is facilitated on another site. Model: src=”https://www.examples.com/pictures/img_girl.jpg”.

Notes: External pictures may be under copyright. On the off chance that you don’t get consent to utilize it, you might be infringing upon intellectual property laws. Furthermore, you can’t handle outside pictures; it can unexpectedly be eliminated or changed.

  1. Relative URL – Links to a picture that is facilitated inside the site. Here, the URL does exclude the area name. On the off chance that the URL starts without a slice, it will be comparative with the current page. Model: src=”img_girl.jpg”. On the off chance that the URL starts with a slice, it will be comparative with the area. Model: src=”/pictures/img_girl.jpg”.

Tip: It is quite often best to utilize relative URLs. They won’t break on the off chance that you change space.

The width and height Attributes

The <img> tag should also contain the width and height attributes, which specifies the width and height of the image (in pixels):


<img src=”img_girl.jpg” width=”500″ height=”600″>

The alt Attribute

The required alt attribute for the <img> tag specifies an alternate text for an image, if the image for some reason cannot be displayed. This can be due to slow connection, or an error in the src attribute, or if the user uses a screen reader.


<img src=”img_girl.jpg” alt=”Girl with a jacket”>


See what happens if we try to display an image that does not exist:<img src=”img_typo.jpg” alt=”Girl with a jacket”>

The style Attribute

The style attribute is used to add styles to an element, such as color, font, size, and more.


<p style=”color:red;”>This is a red paragraph.</p>

The lang Attribute

You should always include the lang attribute inside the <html> tag, to declare the language of the Web page. This is meant to assist search engines and browsers.

The following example specifies English as the language:<!DOCTYPE html>
<html lang=”en”>


Country codes can also be added to the language code in the lang attribute. So, the first two characters define the language of the HTML page, and the last two characters define the country.

The following example specifies English as the language and United States as the country:<!DOCTYPE html>
<html lang=”en-US”>


The title Attribute

The title attribute defines some extra information about an element.

The value of the title attribute will be displayed as a tooltip when you mouse over the element:


<p title=”I’m a tooltip”>This is a paragraph.</p>

We Suggest: Always Use Lowercase Attributes

The HTML standard doesn’t need lowercase characteristic names.

The title characteristic (and any remaining credits) can be composed with capitalized or lowercase like title or TITLE.

Be that as it may, suggests lowercase credits in HTML, and requests lowercase ascribes for stricter record types like XHTML.

We Suggest: Always Quote Attribute Values

The HTML standard doesn’t need cites around characteristic qualities.

Be that as it may, suggests cites in HTML, and requests cites for stricter archive types like XHTML.


<a href=”https://www.examples.com/html/”>Visit our HTML tutorial</a>


<a href=https://www.examples.com/html/>Visit our HTML tutorial</a>


<p title=About examples>

Single or Double Quotes?

Twofold statements around characteristic qualities are the most widely recognized in HTML, however single statements can likewise be utilized.

In certain circumstances, when the characteristic worth itself contains twofold statements, it is important to utilize single statements:

<p title=’John “ShotGun” Nelson’>

Or vice versa:<p title=”John ‘ShotGun’ Nelson”>