Attributes have a pair of a name and a value.The Attributes for an element are defined inside the start tag of the element.
Attribute is a property of the HTML elements that provide additional information about HTML elements on web page. Moreover, attributes are another important part of HTML markup. Along with this, it is used to define the characteristics of an element and is placed inside the element's opening tag.
Parts of Attributes
All attributes always have following two parts.
1. Name.
It defines the name of the attributes in HTML elements and the attribute tells the browser how action can be performed with elements.
Attribute names must consist of one or more characters without Unicode space characters like Null, Quotation Mark ( “ ), Apostrophe ( ' ), Greater-Then Sign (>), Solidus ( / ) , Equals sign( = ) and also any characters that are not defined by Unicode.
In the HTML syntax, attribute names written with any mix of lower and uppercase letters that are an ASCII case-insensitive match for the attribute’s name.
2. Value
Attribute values are a consist of text and characters. The
Value is what action you want to perform by elements. For example if you want to add bgcolor attribute to <body>. You can tell the browser that the background color of your page should be
blue, like this:
< body bgcolor="blue" > .... </body > and < img src=”images/myImageName.jpg” width=”100px” height =”100px” /> .
Attributes Syntex
<tagName attributeName=”Value” > . . .</tagName>
AND
<tagName attributeName=”Value” />
Note:
The syntes for Paired and Unpaired tag are given above .
Defined HTML Attributes
There are the four way to define HTML Attributes.
Empty Attribute Syntax
Write Just the attribute name.The value will be implicitly the empty string.
In the following example, the disabled attribute has a implicitly empty attribute value.
Example 1
<input disabled>
Note:
If an attribute using the empty attribute syntax is to be followed by another attribute, then there must be a space character separating the two.
Unquoted attribute value syntax
The attribute name come with single equal sign character, zero or more space characters, and with any attribute value, which provides additional requirements to the html element.
In Unquoted attribute value syntax the attribute value must not be the empty string and must not contain any Unicode characters like literal space characters, any QUOTATION MARK characters ("), APOSTROPHE characters ('), EQUALS SIGN characters (=), LESS-THAN SIGN characters (<), GREATER-THAN SIGN characters (>), or GRAVE ACCENT characters (`).
In the following example, the value attribute is used with the unquoted attribute value syntax:
Example 2
<input value=yes>
Note:
If an attribute using the unquoted attribute syntax is to be followed by another attribute , then there must be a space character separating the two.
Single-quoted attribute value syntax (' ')
The attribute name come with a single equal sign character, zero or more space characters, a single APOSTROPHE character (') and with attribute value, which provides additional requirements to the html element.
Single-quoted attribute value syntax, the attribute value must not contain any literal APOSTROPHE characters ('), and a second single APOSTROPHE character (').
In the following example, the type attribute has the single-quoted attribute value syntax
Example 3
<input type='text'>
<input type=' '>
<a href='http://www.htmlreaders.com/' title='single "equal sign" character'></a>
Note:
If the HTML element, attribute using the single-quoted attributes syntax by using another attribute, then you must be use space between them to keep separate. like <input type='Text' value='123'>
Double-quoted attribute value syntax (" ")
The attribute name come with a single EQUALS SIGN character, zero or more space characters, single QUOTATION MARK character (") Unicode characters and with attribute value, which provides additional requirements to the html element.
Double-quoted attribute value syntax, the attribute value must not contain any literal QUOTATION MARK characters ("), and a second single QUOTATION MARK character (") Unicodes.
In the following example, the type attribute has the single-quoted attribute value syntax
Example 4
<input type="text">
<input type=" ">
<input name="be text">
<a href="http://www.htmlreaders.com/" title="single 'equal sign' character"></a>
Note:
If the HTML element, attribute using the double-quoted attribute syntax by using another attribute, then you must be using the space character between them to keep separate. like <input type="Text" value="123">
W3c Org Recommendetion
Does not allow two or more attributes with name in the same start tag.
Attributes are always specified in the start tag.
All attributes are ASCII case-insensitive with uppercase or lowercase, like Title or TITLE match for each other.
You should use lowercase attributes in HTML.