We have studied tags in previous chapters, likewise html elements can also have attributes which are extra bits of information. Tags comes in simpler way like <p>, <h1>, <title>.
An attribute is used to define the characteristics of an HTML element and is always placed inside the opening tag containing two parts a name and a value.
• The name is the property you want to set.
• The value is what you want the value of property to be set and it should be always put within qoutations.
HTML example for Attribute:
<!DOCTYPE html> <html> <head> <title> Align Attribute Example </title> </head> </body> <p align= “left”> This is left aligned </p> <p align= “center”> This is center aligned </p> <p align= “right”> This is right aligned </p> </body> </html>
Description for HTML example:
In the above example the paragraph <p> element carries an attribute whose name is align, which is used to indicate the alignment of paragraph on the page.
For the value in above example shows three possible values of align attribute i.e. left, center and right.
Attribute names and Attribute values are case sensitive. However, we at Tutsfinder recommend lowercase attribute names.
Some main Attributes of HTML
HTML Title Attribute
The title attribute is used as text tooltip in most of the browsers. It display its text when user move the cursor over a link or any text. You can use it with any text or link to show the description about that link or text.Example:
<p title= “I’m a toottip”> This is a Paragraph. </p>
HTML Style Attribute
The style attribute allows you to specify Cascading Style Sheet (CSS) rule within the element.Example:
<p style= “color:orange> This is a Paragraph. </p>
HTML alt Attribute
The alt attribute specifies and alternative text to be used, if an image cannot be displayed.
The value of the alt attribute can be read by screen readers.Example:
<img src =“img_scenery.jpg” alt=”House with a lobby”>
HTML class Attribute
The class attribute is used to associate an element with a style sheet, and specifies the class of element, it is basically used In CSS.Example:
Class= “className1 className2 className3”
Below table consisting of some other attributes that are commonly used.
|align||right, left, center||Horizontally aligns tags|
|valign||top, middle, bottom||Vertically aligns tags within an HTML element.|
|bgcolor||numeric, hexidecimal, RGB values||Places a background color behind an element|
|background||URL||Places a background image behind an element|
|id||User Defined||Names an element for use with Cascading Style Sheets.|
|width||Numeric Value||Specifies the width of tables, images, or table cells.|
|height||Numeric Value||Specifies the height of tables, images, or table cells.|