< Html Tutorial

Html attributes

← Previous Next →

An attribute is used to define the characteristics of an HTML element and is placed inside the element's opening tag.

Attributes come in name/value pairs like: name="value"
It is used to add more information with a tag. Such additional information is called an attribute.

The lang Attribute

The document language can be declared in the tag. The language is declared in the lang attribute. Declaring a language is important for accessibility applications (screen readers) and search engines:

<!DOCTYPE html>
<html lang="en-US"> 
  <h1>My First Heading</h1> 
  <p>My first paragraph.</p> 

The first two letters specify the language (en). If there is a dialect, use two more letters (US).

The title Attribute

HTML paragraphs are defined with the tag. In this example, the element has a title attribute. The value of the attribute is "breakinterview":


<p title="breakinterview"> 
   BreakInterview.com is a programmer's site. 
   It provides tutorials and tests.

The href Attribute

HTML links are defined with the tag. The link address is specified in the href attribute:


<a href="http://www.breakinterview.com">This is a link</a>

Size Attributes

HTML images are defined with the tag. The filename of the source (src), and the size of the image (width and height) are all provided as attributes:


<img src="breakinterview_cover.jpg" width="300" height="142">

The image size is specified in pixels: width="300" means 142 screen pixels wide.

The alt Attribute

The alt attribute specifies an alternative text to be used, when an HTML element cannot be displayed. The value of the attribute can be read by "screen readers". This way, someone "listening" to the webpage, i.e. a blind person, can "hear" the element.


<img src="breakinterview_cover.jpg" alt="breakinterview.com" width="300" height="142">
← Previous Next →