DEV Community

Cover image for What is html attribute with examples ..
Ravi  kumar
Ravi kumar

Posted on

What is html attribute with examples ..

HTML attributes provide additional information about HTML elements. They are specified in the opening tag and consist of a name and a value, separated by an equals sign (=).

For example, in the following HTML code:

<a href="https://www.example.com">This is a link</a>
Enter fullscreen mode Exit fullscreen mode

The href attribute specifies the destination URL of the link. The value of the attribute, https://www.example.com, specifies where the link will take the user when they click on it.

Here are some other examples of HTML attributes:

  1. 'src' attribute in the img element, which specifies the source URL of an image.

  2. 'alt' attribute in the img element, which specifies an alternate text for an image.

  3. 'width' and 'height' attributes in the img element, which specify the width and height of an image in pixels.

  4. 'class' attribute in any HTML element, which can be used to specify a class name for an element.

  5. 'id' attribute in any HTML element, which can be used to specify a unique id for an element.

HTML attributes are always specified in the opening tag of an element and are used to provide additional information about the element. They can be used to control the appearance and behavior of an element, or to provide information about the element that can be used by a script.

Top comments (0)