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 id must 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.

CodeCapsule

Sanjit Sinha — Web Developer | PHP • Laravel • CodeIgniter • MySQL • Bootstrap Founder, CodeCapsule — Student projects & practical coding guides. Email: info@codecapsule.in • Website: CodeCapsule.in

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *