HTML Attributes

attributes that provide additional information for HTML elements.

HTML Attributes

HTML tags can haveAttribute. Attributes provide information about theMore Information.

Attributes always appear in the form of name/value pairs, for example:name="value".

Attributes are always within the HTML element'sStart Tagstipulated.

Attribute Examples

HTML links are defined with the <a> tag. The link address is specified in the href attribute:

<a href="http://www.codew3c.com">This is a link</a>

Try It Yourself

More HTML Attribute Examples

Attribute Example 1:

<h1> Defines the start of a heading.

<h1 align="center"> Additional information about the alignment style.

Try It Yourself: Centering a Title

Attribute Example 2:

<body> Defines the main content of an HTML document.

<body bgcolor="yellow"> Additional information about the background color.

Try It Yourself: Background Color

Attribute Example 3:

<table> Defines an HTML table. (You will learn more about HTML tables in later chapters)

<table border="1"> Contains additional information about table borders.

HTML Tip: Use lowercase attributes

Case sensitivity of attributes and attribute valuesInsensitive.

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

However, the new version of (X)HTML requires the use of lowercase attributes.

Always quote attribute values

Attribute values should always be enclosed in quotes. Double quotes are the most commonly used, but using single quotes is also fine.

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

name='Bill \

HTML Attribute Reference Manual

Our complete HTML reference manual provides a complete list of valid attributes that can be used by each HTML element:

Complete HTML Reference Manual

The following lists the attributes applicable to most HTML elements:

Attribute Value Description
class classname Class name (classname) for the specified element
id id Unique id for the specified element
style style_definition Inline style for the specified element
title text Additional information about the specified element (which can be displayed in a tooltip)

For more information about standard attributes, please visit:

HTML Standard Attributes Reference Manual