HTML Attributes
HTML Attributes
Attributes provide additional information about HTML elements.
HTML Attributes:
- HTML elements can have attributes.
- Attributes add extra information to elements.
- Attributes are generally described in the opening tag.
- Attributes always appear in name/value pairs, like name="value".
Example of Attributes:
HTML links are defined by the <a> tag. The link's address is specified in the href attribute:
Example:
<a href="http://www.webcode101.com">This is a link</a>
Quoting Attribute Values:
Attribute values should always be enclosed in quotes. Double quotes are most common, but single quotes are also acceptable.
Tip: In cases where the attribute value itself contains double quotes, single quotes must be used, e.g., name='John "ShotGun" Nelson'.
HTML Tip: Use Lowercase Attributes:
Attributes and attribute values are case-insensitive. However, the World Wide Web Consortium (W3C) recommends using lowercase for attributes/values in HTML4, and lowercase is required in newer (X)HTML versions.
HTML Attribute Reference:
For a complete list of HTML attributes, refer to the HTML Tags Reference Manual.
Here are some attributes applicable to most HTML elements:
Attribute | Description |
---|---|
class | Defines one or more class names for the HTML element (class names are used in stylesheets). |
id | Defines a unique id for the element. |
style | Specifies inline styles for the element. |
title | Provides additional information about the element (displayed as a tooltip). |