Html atttribute Example

Give any 5 example of html attribute?

What is HTML attributes?

Attributes provide extra information about the tags. It always comes in pair i.e. (atribute_name=”value”). We always separate the attribute name and value by “=”.

1. href Attribute

We use < a> tag to define hyperlink, between pages images and more. It is a most used element in the href attribute which specifies the direction of the links.

Welcome to our free tutorial site:!


< a href=“”>Welcome to our free tutorial < /a>

2. src Attribute

We define a source in the form of src attribute. We use src attribute along with a < img> tag to show the images on a website.
The tag used to define images in HTML.


< img src=“img/purpleflower.jpg”>

3. alt Attribute

The alt attribute provides the alternative text in case, the user is not able to view an image in the website.

If the website has an image, then the 2 most important reasons for images not been shown are –

  • The name of the image or the format of the image mentioned in the website is wrong.
  • The path of the image is wrong.


< img src=“tulips.jpg” width=“200” height=“320” alt=“Tulips abc” >

4. id Attribute

Id attribute is a way to group some elements and apply a particular style to it. id Name must be unique within the HTML document.


< style> #idexample{ border:2px solid hotpink;} < /style>

5. class Attribute

The class attribute is a way to group some elements and apply a particular style to it. It is similar to id but the main difference is that id must be unique in an HTML document while classes can have duplicate names.


< style> .classexample{ background-color:pink;} < /style>

  • All HTML elements can have attributes
  • Attributes provide additional information about elements
  • Attributes are always specified in the start tag
  • Attributes usually come in name/value pairs like: name=“value”
  1. The href Attribute

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

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

  1. 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 a slow connection, or an error in the src attribute, or if the user uses a screen reader.
flowers image

  1. The style Attribute

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

This is a red paragraph.

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