HTML id Attribute
HTML id Attribute
The id attribute is used to give an unique identifier to an HTML element.
Unlike class, an id must be unique within a page. It is often used for:
-
Styling a specific element with CSS
-
Accessing an element in JavaScript
-
Creating anchor links within the page
Syntax
Example Code
Output Preview
-
First paragraph → Blue, bold, larger font
-
Second paragraph → Normal styling
Key Points
-
Each
idmust be unique on the page. -
Can be used to link to a section:
-
Can be accessed in JavaScript:
The id attribute is essential for targeted styling, linking, and scripting in HTML.
