Friday, 9 December 2016
Home »
» HTML Attributes
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:
defines an HTML table. (You will learn more about HTML tables later)
The border attribute defines a border type for the
element.
Attributes Example 2:
defines an anchor (an HTML link). (You will learn more about HTML links later)
The href attribute provides the link address for the element.
Attributes Example 3:
defines the body of an HTML document.
The bgcolor attribute defines the background color for the 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:
0 comments:
Post a Comment