HTML Attributes
Attributes provide additional information about HTML elements.
HTML Attributes
- HTML elements can have attributes
- Attributes add additional information to elements
- Attributes are usually specified in the opening tag
- Attributes always come in name/value pairs, like: name="value"
Attribute Example
HTML links are defined by the <a>
tag. The link address is specified in the href attribute:
Example
<a href="http://www.tutorialpro.org">This is a link</a>
HTML Attribute Values
Attribute values should always be enclosed in quotes.
Double quotes are most common, but single quotes are also acceptable.
Tip: In some cases, such as when the attribute value itself contains double quotes, you must use single quotes, for example:
name='John "ShotGun" Nelson'
HTML Tip: Use Lowercase Attributes
Attributes and attribute values are not case-sensitive.
However, the World Wide Web Consortium recommends lowercase attributes/attribute values in their HTML 4 recommendation.
Newer versions of (X)HTML require the use of lowercase attributes.
HTML Attribute Reference
View the complete list of HTML attributes: HTML Tag Reference.
The following attributes are applicable to most HTML elements:
Attribute | Description |
---|---|
class | Defines one or more classnames for an HTML element (classnames are referenced from style sheets) |
id | Defines a unique id for an element |
style | Specifies an inline style for an element |
title | Describes additional information about an element (displayed as a tool tip) |
For more standard attribute descriptions: HTML Standard Attribute Reference.