HTML Attributes

Core attributes

Core attributes may also be applied across almost the entire range of HTML elements.

Core attributes are
  • id
  • title
  • class
  • style
  • lang
  • dir
id
  • The id attribute of an HTML element provides a unique identifier for an element within the document.
  • The value of id attribute must be absolutely unique.
  • The id attribute value must begin with an alphabet and followed by any combination of digit, hyphens (-), underscores (_), colons (:), and periods (.).
  • The id value is case sensitive.
Syntax:
<element id=“value”>

Example:
<div id=“mnu”>

title
  • The title attribute specifies extra information about an element.
  • The information is displayed in a tooltip when the mouse pointer is placed over the element.
Syntax:
<element title=“text”>

Example:
<h1 title=“about JavaScript”>JavaScript</h1>

class
  • The class attribute is used to specify the class of element.
  • This attribute is used to associate an element with a style sheet.
  • One or more class names can be specified for an element.
Syntax:
<element class="classname">

Example:
<div class="applycolor">Welcome to CareerRide Info</div>

style
  • The style attribute specifies an inline style for the element.
  • This attribute provides the facility to specify Cascading Style Sheet (CSS) rules within the element.
Example:
<p style="font-family:arial; color:#800080; text-align:center">CareerRide Info</p>

lang
  • The lang attribute specifies the language of the element’s content along with the language of any attribute content.
  • This attribute is used to identify the language of the content on a web page.
  • The  language of the document is declared in the <html> tag.
Syntax:
<element lang=“language_code”>

Example:
<html lang="en">

dir
  • The dir attribute specifies the reading direction for text as left to right or right to left.
  • The dir attribute tells the browser the direction in which the displayed text is intended to be read.
The dir attribute can take one of the following two values.

ValueMeaning
ltrLeft to right direction
rtlRight to left direction

Syntax:
<element dir="ltr">

Example:
<p dir="rtl"> content </p>