Saturday, July 2, 2011

HTML Attribute

HTML Attributes

HTML tags can contain one or more attributes. Attributes are added to a tag to provide the browser with more information about how the tag should appear or behave. Attributes consist of a name and a value separated by an equals (=) sign.

* HTML elements can have attributes
* Attributes provide additional information about an element
* Attributes are always specified in the start tag
* Attributes come in name/value pairs like: name="value"

Example

Consider this example:


<*body style="background-color:orange">

PLEASE Remove Firstly All Asterics *

OK, we've already seen the body tag in previous lessons, but this time we can see that something extra has been added to the tag - an attribute. This particular attribute statement, *style="background-color:orange", tells the browser to style the body element with a background color of orange.

The browser knows to make the background color orange because we are using standard HTML tags and attributes (along with standard Cascading Style Sheets code) for setting the color.

Another Example

Here's another example of adding an attribute to an HTML tag. In this example, we use the <*a> tag to create a hyperlink to the Quackit website.


<*a href="http://dkdashinghtml1.blogspot.com/<*/a>

PLEASE Remove Firstly All Asterics *

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.

Tip: In some rare situations, 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.

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

HTML Attributes Reference

Below is a list of some attributes that are standard for most HTML elements:


Attribute----Value----Description
class----classname----Specifies a classname for an element
id----id----Specifies a unique id for an element
style----style_definition----Specifies an inline style for an element
title----tooltip_text----Specifies extra information about an element (displayed as a tool tip)

PLEASE Remove Firstly All Asterics *

THANK YOU