A+ A-

The Core Attributes of an HTML Document

Core Attributes:


 The four core attributes that can be used on the majority of HTML elements (although not all) are:


  1. Id 
  2. Title
  3. Class
  4. Style


 

The Id Attribute:


The id attribute of an HTML tag can be used to uniquely identify any element within an HTML page. There are two primary reasons that you might want to use an id attribute on an element:


  • If an element carries an id attribute as a unique identifier, it is possible to identify just that element and its content.   
  • If you have two elements of the same name within a Web page (or style sheet), you can use the id attribute to distinguish between elements that have the same name.

 Example :



<p id="html">This para explains what is HTML</p>
<p id="css">This para explains what is Cascading Style Sheet</p>



 

The title Attribute:


The title attribute gives a suggested title for the element. They syntax for the title attribute is similar as explained for id attribute:
The behavior of this attribute will depend upon the element that carries it, although it is often displayed as a tooltip when cursor comes over the element or while the element is loading.

Example :



<!DOCTYPE html>
<html>
<head>
<title>The title Attribute Example</title>
</head>
<body>
<h3 title="Hello HTML!">Titled Heading Tag Example</h3>
</body>
</html>


This will produce the following result:


Titled Heading Tag Example



 

The class Attribute:


The class attribute is used to associate an element with a style sheet, and specifies the class of element. The value of the attribute may also be a space-separated list of class names. For example:



class="className1 className2 className3"



 

The style Attribute:


The style attribute allows you to specify Cascading Style Sheet (CSS) rules within the element.



<!DOCTYPE html>
<html>
<head>
<title>The style Attribute</title>
</head>
<body>
<p style="font-family:arial; color:#FF0000;">The style attribute allows...</p>
</body>
</html>


This will produce the following result:


The style attribute allows...