HTML Attributes

From http://www.w3schools.com (Copyright Refsnes Data)

# HTML Attributes

Attributes provide additional information about HTML elements.

## HTML Attributes

- HTML elements can have attributes
- Attributes provide additional information about the element
- Attributes are always specified in the start tag

## Attribute Syntax

Attributes always come in name/value pairs like this: name="value".

Examples

border="1"

href="http://www.w3scchools.com"

bgcolor="yellow"

## Attributes Example 1:

<table> defines an HTML table. (You will learn more about HTML tables later)

<table border="1">

The border attribute defines a border type for the <table> element.

## Attributes Example 2:

<a> defines an anchor (an HTML link). (You will learn more about HTML links later)

<a href="http://www.w3schools.com">

The href attribute provides the link address for the <a> element.

## Attributes Example 3:

<body> defines the body of an HTML document.

<body bgcolor="yellow">

The bgcolor attribute defines the background color for the <body> element.

Note: bgcolor is a "dying" attribute, use styles instead (next chapter).

## Always Quote Attribute Values

Attribute values should always be enclosed in quotes. Double style quotes are the most common, but single style quotes are also allowed.

In some rare situations, like when the attribute value itself contains quotes, it is necessary to use single quotes:

name='John "ShotGun" Nelson'

## HTML Tip - Use Lowercase Attributes

Attribute names and attribute values are case-insensitive.

However, the World Wide Web Consortium (W3C) recommends lowercase attributes/attribute values in their HTML 4 recommendation

Newer versions of (X)HTML will demand lowercase attributes.

## HTML Attributes Reference

A full list of attributes for each HTML element is listed in our:

Complete HTML Reference

Below is a list of some attributes that are standard for all HTML elements (with a few exceptions):

Attribute | Value | Description
--- | --- | ---
class | class_rule or style_rule | The class of the element
id | id_name | A unique id for the element
style | style_definition | An inline style definition
title | tooltip_text | A text to display in a tool tip

For more information about standard attributes:

HTML Standard Attributes Reference

From http://www.w3schools.com (Copyright Refsnes Data)