HTML Attributes Complete Reference

Last Updated : 2 Apr, 2026

HTML attributes are special words written inside the opening tag of an HTML element. They provide additional information about the element and help define its behavior, appearance, or purpose.

Parts of an HTML Attribute

Each HTML attribute consists of two main parts:

1. Attribute Name

The Attribute Name defines which property of an HTML element is being set, such as id, class, href, src, or style.

  • Specifies what property of the element is being defined.
  • Examples: id, class, href, src, style.

2. Attribute Value

The Attribute Value sets the specific value for an HTML attribute, written after = and enclosed in double quotes " ".

  • Specifies the value of that property.
  • Written after an equal sign =.
  • Always enclosed in double quotes " ".

Syntax:

<tag_name attribute_name="value"> Contents... </tag_name>
HTML
<html>
<body>
	<h1>HTML Attributes Example</h1>
	<img src="https://media.geeksforgeeks.org/wp-content/uploads/20241230152400887784/Salesforce-Governance-Model.webp" 
	alt="Example image" width="500">
</body>
</html>
  • src Attribute: Specifies the URL of the image to be displayed. In this example, the image is loaded from "https://www.example.com/image.jpg".
  • alt Attribute: Provides alternative text for the image, which is displayed if the image cannot be loaded. It also improves accessibility and SEO.
  • width Attribute: Sets the width of the image in pixels, making it responsive and visually appealing.

Types of HTML Attributes

HTML attributes can be categorized into different types based on their functionality. Some common types of attributes include:

  • Style attributes: Used to define the visual styling of elements, such as color, background, and font.
  • Event attributes: Used to specify actions that occur in response to user interactions, such as mouse clicks or key presses.
  • Attribute-element Attributes: Used to define the relationship between elements, such as the src attribute of the img element.
  • Form Attributes: Used to define the behavior of form elements, such as the action attribute of the form element.

Complete References

The complete list of HTML attributes are given below.

Attributes:

Description

acceptThis attribute can be used with <input> element only.
accept-charsetDefine character encoding and is used for form submission.
accesskeyThe keyboard shortcuts to activate/focus specific elements.
actionSpecify where the form data is to be sent to the server after submission of the form.