Learning Resources
HTML Attributes
What are HTML Attributes?
HTML attributes provide additional information about elements. They are always included in the opening tag and follow the format:
For example:
Here, href="https://www.example.com" is an attribute that defines the link destination.
Common HTML Attributes
1. The href Attribute (for Links)
Used in <a> (anchor) tags to specify the destination URL.
2. The src Attribute (for Images & Media)
Specifies the source (URL) of an image or media file.
3. The alt Attribute (for Images)
Provides alternative text if an image fails to load.
4. The title Attribute (Tooltip Text)
Displays a tooltip when hovering over an element.
5. The style Attribute (Inline CSS)
Used to apply CSS styles directly to an element.
6. The width and height Attributes (for Images & Videos)
Define the dimensions of an element.
7. The target Attribute (for Links)
Defines how a link should open.
_self(default) → Opens in the same tab_blank→ Opens in a new tab_parent→ Opens in the parent frame_top→ Opens in the full body of the window
8. The id Attribute (Unique Identifier)
Gives an element a unique ID, often used with CSS or JavaScript.
9. The class Attribute (For Styling Multiple Elements)
Used to assign a CSS class to multiple elements.
CSS Example:
10. The lang Attribute (Language Specification)
Defines the language of a document.
11. The disabled Attribute (For Form Elements)
Disables an input field.
12. The readonly Attribute (Non-Editable Fields)
Prevents users from editing the field, but allows selection.
Example Code: Using Various HTML Attributes
