HTML Standard Attributes

HTML tags can have attributes. The special attributes for each tag are listed under each tag description. The attributes listed here are the core and language attributes that are standard for all tags (with a few exceptions).

Core Attributes

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

  • id
  • title
  • class
  • style

id attribute

The id attribute can be used to uniquely identify any element within a page ( or style sheet ). 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.

Note that there are some special rules for the value of the id attribute, it must:

  • Begin with a letter (A.Z or a.z) and can then be followed by any number of letters, digits (0.9), hyphens, underscores, colons, and periods.

  • Remain unique within that document; no two attributes may have the same value within that HTML document.

<p id="style1">This paragraph explains what is HTML</p>

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 or while the element is loading.

<h6 title="tooltip text">please hover mouse on this text</h6>

The class Attribute

The class attribute is used to associate an element with a style sheet, and specifies the class of element. You learn more about the use of the class attribute when you will learn Casecading Style Sheet (CSS). So for now you can avoid it. Following file is style.css


HTMl file index.html

<title>css class </title>
<link rel="stylesheet" type="text/css" href="style.css">
<p class="firstName" >random text</p>

The lang Attribute

The lang attribute allows you to indicate the main language used in a document, but this attribute was kept in HTML only for backwards compatibility with earlier versions of HTML. This attribute has been replaced by the xml:lang attribute in new XHTML documents.

When included within the tag, the lang attribute specifies the language you’ve generally used within the document. When used within other tags, the lang attribute specifies the language you used within that tag’s content. Ideally, the browser will use lang to better render the text for the user.

<html lang=en>
<title>English Language</title>
This page is using English Language