HTML Attributes
HTML Attributes
We have seen few HTML tags and their usage like heading tags <h1>, <h2>, paragraph tag <p> and other tags. We used them so far in their simplest form, but most of the HTML tags can also have attributes, which are extra bits of information.
An attribute is used to define the characteristics of an HTML element and is placed inside the element's opening tag. All attributes are made up of two parts − a name and a value
Attribute names and attribute values are case-insensitive.
n The name is the property you want to set. For example, the paragraph <p> element in the example carries an attribute whose name is align, which you can use to indicate the alignment of paragraph on the page.
n The value is what you want the value of the property to be set and always put within quotations. The below example shows three possible values of align attribute: left, center and right.
Example
<!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>
Here's a table of some other attributes that are readily usable with many of the HTML tags.
Attribute
|
Options
|
Function
|
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.
|
class
|
User Defined
|
Classifies 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.
|
title
|
User Defined
|
"Pop-up" title of the elements.
|
Comments
Post a Comment