Attributes in HTML

  • 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"
Attribute Name Description
bgcolor Background Color of the document
background Background Image of the document
align Align left, right, center
size Declare size of font
bottom margin Margin from bottom
top margin Margin from top
class Specifies a class name for an element
id Specifies a unique id for an element
style CSS attribute for tags(Specifies an inline style for an element)
title Specifies extra information about an element (displayed as a tool tip)

Bgcolor ( deleted in html5)

Used to give background color to body tag and table tag.

(How to create a Bgcolor)


<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>title</title>
</head>
<body bgcolor="#999000">
		// content 
</body>
</html>

(Browser View)

Background ( deleted in html5)

Used to give background image in html4.

(How to create a Background)


<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>title</title>
</head>
<body background="http://www.techaltum.com/images/TechAltumLogo.png">
		// content 
</body>
</html>		

(How the HTML code above looks in a browser)



Alignment ( deleted in html5)

Align Attribute is used to horizontally align text or tables.

(How to create a Alignment)


<h1 align="left">TEXT Aligned Left</h1>
<h1 align="center">TEXT Aligned Center</h1>
<h1 align="right">TEXT Aligned Right</h1>

(How the HTML code above looks in a browser)

TEXT Aligned Left

TEXT Aligned Center

TEXT Aligned Right

Size ( deleted in html5)

size Attribute is used define size to font tag and input tag.

(Font Tag)


	
<font size="2" > Font with size 2</font>
<font size="5" > Font with size 5</font>
<font size="7" > Font with size 7</font>
<input type="text" size="10" >
<input type="text" size="20" >

Class

Class attribute is used to define a group of elements having same css properties.

(How to create a Alignment)


<style>
.red{ color:red}
</style>
		
<p class="red" > Font with class red</p>
<p class="red" > Font with class red</p>
<p> Font without class red</p>

(How the HTML code above looks in a browser)

Font with class red

Font with class red

Font without class red

ID

Id attribute is used to call a unique element. On a single webpage, an id cannot be repeated. An element always have single ID.

(How to create a Alignment)


<style>
.red{ color:red}
#blue{ color:blue}
</style>
		
<p class="red" > Font with class red</p>
<p class="red" > Font with class red</p>
<p id="blue"> Font with id blue</p>

(How the HTML code above looks in a browser)

Font with class red

Font with class red

Font with id blue