Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML Attributes

HTML Attributes


Attributes provide additional information about HTML elements.

Attributes typically appear in the opening tag of an HTML element and define the element's behavior, style, content, or other characteristics.

Attributes are always written inside the tag in the form name="value",name is the name of the attribute,value is the value of the attribute.


HTML Attributes


Attribute examples

HTML links are defined by the tag. The link's address is specified in the href property:

Example

<

a

href

=

"

http://www.runoob.com

"

This is a link

a

Try it »


HTML attributes commonly use quoted attribute values

Attribute values should always be enclosed in quotes.

Double quotes are the most commonly used, but single quotes work just as well.

Using double quotes:



Link

Using single quotes:



Link

Attribute values containing quotes:

Link

RemarkTip: In some rare cases, such as when the attribute value itself contains double quotes, you must use single quotes, for example:

name='John "ShotGun" Nelson'

or:

Link


HTML Tip: Use lowercase attributes

Attribute and attribute value names are case-insensitive.

However, the World Wide Web Consortium recommends lowercase attributes/attribute values in its HTML 4 recommendation.

Newer versions of (X)HTML require lowercase attributes.


HTML Attribute Reference Manual

View the complete list of HTML attributes: HTML Tag Reference Manual。

The following lists attributes applicable to most HTML elements:

Attribute name Applicable elements Description
id all elements Specifies a unique identifier for the element.
class all elements Specifies one or more class names for the element, used for CSS or JavaScript selection.
style all elements Applies CSS styles directly to the element.
title all elements Provides extra hint information about the element, usually displayed on mouse hover.
data-* all elements Used to store custom data, usually accessed via JavaScript.
href , Specifies the target URL of a link.
src ,