Attributes in HTML and HTML5


An HTML attribute is a piece of markup language used to adjust the behavior or display of an HTML element. There are several attributes in HTML5 that do not consist of name/value pairs but consists of just name. Such attributes are called Boolean attributes. Examples of some commonly used Boolean attributes are checked, disabled, readonly, required etc.

Principles of Attributes

  • 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.
Attribute Values Works for
accesskey User Defined Specifies a keyboard shortcut to access an element.
align right, left, center and justify Horizontally aligns tags
alt user defined Specifies a hint for which works is happens in the element.
background URL Places an background image behind an element
bgcolor numeric, hexidecimal, RGB values Places a background color behind an element
class user defined Classifies an element for use with Cascading Style Sheets.
contenteditable true, false Specifies if the user can edit the element's content or not.
contextmenu Menu id Specifies the context menu for an element.
data-XXXX User Defined Custom attributes. Authors of a HTML document can define their own attributes. Must start with "data-".
draggable true,false, auto Specifies whether or not a user is allowed to drag an element.
height Numeric Value Specifies the height of tables, images, or table cells.
hidden hidden Specifies whether element should be visible or not.
id User Defined Names an element for use with Cascading Style Sheets.
item List of elements Used to group elements.
itemprop List of items Used to group items.
spellcheck true, false Specifies if the element must have it's spelling or grammar checked.
style CSS Style sheet Specifies an inline style for an element.
subject User define id Specifies the element's corresponding item.
tabindex Tab number Specifies the tab order of an element.
title User Defined Pop-up title for your elements.
valign top, middle, bottom Vertically aligns tags within an HTML element.
width Numeric Value Specifies the width of tables, images, or table cells.