Course Content
HTML Introduction
0/1
HTML Editors
0/1
HTML Basic Tags
0/1
HTML Elements
0/1
HTML Attributes
0/1
HTML Headings
0/1
HTML Paragraph
0/1
HTML Text Formatting
0/1
HTML Meta Tags
0/1
HTML Quotations
0/1
HTML Comments
0/1
HTML Images
0/1
HTML Background
0/1
HTML Colors
0/1
HTML Lists
0/1
HTML Tables
0/1
HTML Forms
0/1
HTML Spell Check
0/1
HTML Media
0/1
HTML Marquees
0/1
HTML CSS
0/1
HTML Links
0/1
HTML Block & Inline
0/1
HTML Classes
0/1
HTML Id
0/1
HTML I frames
0/1
HTML Java script
0/1
HTML File paths
0/1
HTML Layout
0/1
HTML Responsive
0/1
HTML Computer Code
0/1
HTML Tutorial
About Lesson

HTML Id

In this tutorial, we will learn about id in HTML with the help of examples.


Id

TheĀ idĀ attribute is used to specify a unique id for an element in an HTML document.
It is used by CSS and JavaScript to perform certain tasks for a unique element.
We cannot use more than one element with the same id in an HTML document.
The value of theĀ idĀ attribute must be unique within the HTML document.


Using Id Attribute

An Id name can be defined within theĀ <style>Ā element, or in the external CSS file.
The id name isĀ case sensitive.
To create a id, write a hashĀ #Ā character followed by a id name.

Syntax :

#idName

Example :

<!DOCTYPE html>
<html>
Ā Ā <head>
Ā Ā Ā Ā <title>HTML Id</title>
Ā Ā Ā Ā <style>
Ā Ā Ā Ā Ā Ā #cricket {
Ā Ā Ā Ā Ā Ā Ā Ā color : blue;
Ā Ā Ā Ā Ā Ā }
Ā Ā Ā Ā Ā Ā #football {
Ā Ā Ā Ā Ā Ā Ā Ā color : green;
Ā Ā Ā Ā Ā Ā }
Ā Ā Ā Ā </style>
Ā Ā </head>
Ā Ā <body>
Ā Ā Ā Ā <p id = "cricket">This is a paragraph with cricket id.</p>
Ā Ā Ā Ā <p id = "football">This is a paragraph with football id.</p>
Ā Ā </body>
</html>

Output

This is a paragraph with cricket id.

This is a paragraph with football id.

error: Content is protected !!