HTML Attributes
HTML attributes provide additional information about HTML elements. They are always specified in the opening tag of an element and usually come in name-value pairs. Here's a breakdown of HTML attributes with examples:
Basic Structure
Attributes are written as a name-value pair in the form:
name="value"
Examples
-
href Attribute (Used in <a> tag)
-
src Attribute (Used in <img> tag)
-
alt Attribute (Used in <img> tag)
-
class Attribute
-
id Attribute
-
style Attribute
-
type Attribute (Used in <input> tag)
-
placeholder Attribute (Used in <input> tag)
Notes
- Attribute names are case-insensitive, but values are usually case-sensitive.
- Some attributes can be used without a value, in which case the presence of the attribute itself is sufficient to activate its effect (e.g.,
checked in checkboxes).
Each HTML element has its own set of attributes that can be used to control its behavior and appearance.