HTML Attributes

Last Updated : 2 May, 2026

HTML Attributes are special words used within the opening tag of an HTML element. They provide additional information about HTML elements. HTML attributes are used to configure and adjust the element's behaviour, appearance, or functionality in a variety of ways.

  • Each attribute has a name and a value, formatted as name="value".
  • Attributes tell the browser how to render the element or how it should behave during user interactions.
HTML

<html>
<head>
    <title>title>
head>
<body>
    <img src=
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/Geek_logi_-low_res.png" 
 style="width:350px; height:auto;">
body>
html>
  • Tag :
  • Attribute : src
  • Value of Attribute : "https://media.geeksforgeeks.org/wp-content/cdn-uploads/Geek_logi_-low_res.png"
  • Purpose : The tag is used for embedding images in an HTML page. The src attribute within the tag specifies the path to the image file you wish to display. This attribute is crucial as it directs the browser to the image’s location on the internet or a local directory.

Syntax:

content...

Components of Attribute

An HTML attribute consists of two primary components:

1. attribute_name: This is the name of the attribute, which specifies what kind of additional information or property you are defining for the element. Common attribute names include href, src, class, id, etc.

2. attribute_value: The value is assigned to the attribute to define the specific setting or behavior. It is always placed in quotes.

Types of HTML Attributes

HTML attributes can be broadly categorized based on their function and the type of elements they modify. For example -

Global Attributes

These attributes can be used with any HTML element (though their effects might vary based on the element):

AttributeDescription
classGroups elements and allows styling.
styleInline CSS styles.
contenteditableDetermines whether the content within the element is editable.
roleSpecifies the element’s accessibility role.
tabindexDetermines the order of focus during keyboard navigation.
idAssigns a unique identifier to an element, allowing targeting with CSS or JavaScript.
titleCreates a tooltip that appears when a user hovers over the element.
langSpecifies the language of the element’s content, aiding with translation and accessibility.

Some other main types of HTML attributes are: