Attribute
A modifier of an HTML element that provides additional information about the element, defining its behaviour, appearance, or content.
Attributes are included within the opening tag of an element and usually consist of a name and a value.
Syntax:
<tagname attribute="value">Content</tagname>Common HTML Attributes
id: Assigns a unique identifier to an element (e.g.,
<div id="header">).class: Groups multiple elements by a common class name for styling or scripting (e.g.,
<p class="intro">).href: Specifies the URL for links in anchor (
<a>) tags (e.g.,<a href="https://example.com">Visit</a>).src: Defines the source URL for embedded content, like images (
<img src="image.jpg">) or videos.alt: Provides alternative text for images, improving accessibility (e.g.,
<img src="logo.jpg" alt="Company Logo">).style: Adds inline CSS to elements to control styling (e.g.,
<p style="color:blue;">Text</p>).
Purpose of HTML Attributes
Attributes give additional context and functionality to HTML elements, enabling developers to control aspects like styling, behaviour, accessibility, and content linking. They are essential for creating interactive, accessible, and well-structured web pages.