HTML · Chapter 5 of 45
HTML Attributes
Attributes provide extra information about an element and are always specified in the start tag, usually as name="value" pairs.
Common attributes include href (link target), src (resource path), alt (image description), and style (inline CSS). Attribute values should always be quoted.
Syntax
<tagname attribute="value">content</tagname>Syntax rules
Attributes go inside the opening tag: <tag attribute="value">. Multiple attributes are separated by spaces.
Global attributes
Some attributes like id, class, style, and title can be used on almost any HTML element, regardless of tag type.
Example 1 (html)
<a href="https://example.com">Visit Example</a>Output
Visit Example (link)The href attribute defines the link's destination.
Example 2 (html)
<img src="logo.png" alt="Company Logo" width="100">Output
(renders image at 100px wide)Multiple attributes describe the image source, fallback text, and size.
Key points
- Attributes appear in the opening tag only.
- Always use quotes around attribute values.
- href, src, and alt are among the most common attributes.
- Global attributes like id and class work on nearly all elements.
💡 Note: Attribute names are case-insensitive, but lowercase is the recommended convention.
