HTML Attributes
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”
What are HTML Attributes?
HTML attributes are special words that provide additional information to an HTML element. Attributes are placed inside the element’s opening tag, and they are used to configure or adjust the element’s behavior. All attributes are made up of two parts: a name and a value −
Name: The attribute name is the keyword, also known as the attribute identifier, which defines a specific characteristic for the element in which it is using. For example, the paragraph element (in the below-given example) has an attribute “align”, which defines the alignment of the paragraph on the page.
Value: The attribute value is the data or information that defines the value to be set for that attribute. The value is assigned within the double quotes. For example, “left”, “center”, or “right” can be assigned to the “align” attribute with the paragraph tag (as shown in the below example).
<tag_name attribute=“Value“>…</tag_name>
<!DOCTYPE html>
<html>
<head>
<title>Example of HTML Attributes</title>
</head>
<body>
<p align=“left“>Left Aligned</p> <p align=“center“>Center Aligned</p> <p align=“right“>Right Aligned</p>
</body> </html>
The id Attribute
The id attribute of an HTML tag can be used to uniquely identify any element within an HTML page. There are two primary reasons that you might want to use an id attribute on an element −
If an element carries an id attribute as a unique identifier, it is possible to identify just that element and its content.
If you have two elements of the same name within a Web page (or style sheet), you can use the id attribute to distinguish between elements that have the same name.