Attributes

Attributes in HTML are special words used inside the opening tag of HTML element to control the element's behaviour it's looks and layout. Using attribute we can modify a tag and its contents in different forms. An attribute has value OR property name. Different types of tags/elements may have different types of attributes.

Points to remember for attributes

  • HTML attributes are special words which provide additional information about the elements or attributes are the modifier of the HTML element.
  • Each element or tag can have attributes, which defines the behaviour of that element.
  • Attributes should always be applied with start tag.
  • The Attribute should always be applied with its name and value pair.
  • The Attributes name and values are case sensitive, and it is recommended by W3C that it should be written in Lowercase only.
  • You can add multiple attributes in one HTML element, but need to give space between two attributes.

Common Attributes

Some attributes in HTML are common for all tags OR elements these are:
  • Id
  • Title
  • Class
  • Style

ID Attribute

This attribute is used to provide a unique identification for same kind OR different types of elements.While we provide different ids to various elements in that case they can be uniquely accessed.

Title Attribute

The title attribute is used to explain an element on hovering the mouse over it. The behavior differs with various elements but generally the value is displayed while loading or hovering mouse pointer over it.

Class Attribute

The class attribute is used to associate an element with a style sheet, and specifies the class of element. While we give a space separated value to the class attribute it represents a different class name to that element.

Style Attribute

This attribute is used to provide various CSS (Cascading Style Sheets) effects to the HTML elements such as increasing font-size, changing font-family, coloring etc.

Example:-

<!DOCTYPE html>
<html>
<head>
<title>Learning HTML attributes</title>
</head>
<body>
<p id="unique">I am a unique identifier of this tag</p>
    <h3 title="learning HTML attributes">I am a title of this element point your mouse here.</h3>
   <p class="identifier">I am a unique identifier of this tag by className.</p>
    <h2 style="color:#8CCEF9;font-size:22px;">Hello Myragroup Tutorial.</h2>

   </body>
	
</html>
Learning HTML Attributes

I am a unique identifier of this tag

I am a title of this element point your mouse here.

I am a unique identifier of this tag by className.

Hello Myragroup Tutorial.



List of General Attributes

  • Height
  • Width
  • Align
  • Valign
  • ID
  • Class
  • Title
  • Bgcolor
  • Background
  • Lang
  • Dir
  • Href
  • Style
  • src
  • direction
  • behavior
  • start
  • stop
  • contenteditable
  • oncontextmenu
  • alink
  • vlink
  • link
  • media
  • type
  • language
  • hspace
  • vspace and more