Introduction to HTML : Attributes

Attributes

HTML attributes are name-value pairs that provide additional information about HTML elements. They are always specified in the start tag and, values are always quoted. Let's now see some example of common attributes:

The id attribute

The id attribute uniquely identifies an element within an HTML document. So elements of the same tag name can be differentited with the id attribute. The example below shows how you can defferentiate between two or more span elements

<span id="first-span">This is the first span</span>
<span id="second-span">This is the first span</span>

The class attribute

The class attribute groups a number of elements into one class so certain behaviours can be associated with all the elements in the group.

<span class="span-group">This is a span</span> 
<span class="span-group">This is another span</span>

The href attribute

The href attribute specifies the url or link address of a link element.

Example:

<a href="https://teachsomebody.com">This is the homepage of TeachSomebody</a>

This will result in this:

This is the homepage of TeachSomebody 

The style attribute

The style attribute specifies Cascading Styles pertaining to an HTML element.

Example:

<p style="color: red">This text will be red</p>

This will make the color of the paragraph red.

This text will be red


course logo
Introduction to HTML
Number of sections:
11
Content length:
Delivery formats: