What is HTML Attributes?
HTML attributes are special words used inside the opening tag of an element to give it additional information or customize its behavior.
Basic Example:
<a href=”https://www.google.com”>Visit Google</a>
HTML Attributes:
Attribute | Used With | Description |
---|---|---|
href |
<a> |
Specifies the URL of a link |
src |
<img> , <script> |
Specifies the image or file source |
alt |
<img> |
Provides alternative text for an image |
title |
Most elements | Shows tooltip text on hover |
id |
All elements | Unique identifier for an element |
class |
All elements | Assigns a CSS class or JavaScript hook |
style |
All elements | Adds inline CSS styling |
width / height |
<img> , <video> , etc. |
Sets dimensions |
HTML Points:
-
Attributes are always added to the opening tag
-
Attribute values should be inside quotes (usually double quotes
"
) -
Most attributes apply to specific tags only