-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
HTML5 Basics
HTML Introduction
HTML Editors
HTML Basic
HTML Elements
HTML Attributes
HTML Headings
HTML Paragraphs
HTML Styles
HTML Formatting
HTML Quotations
HTML Comments
HTML Styling and Design
HTML Links and Media
HTML Layout and Structure
HTML Tables
HTML Lists
HTML Block & Inline
HTML Div
HTML Classes
HTML Id
HTML Head
HTML Layout
HTML Responsive
HTML Computercode
HTML Semantics
HTML Forms
HTML Forms
HTML Form Attributes
HTML Form Elements
HTML Input Types
HTML Input Attributes
Input Form Attributes
HTML Graphics
HTML APIs
HTML Advanced Topics
id
in HTML?The id
attribute is used to assign a unique identifier to an HTML element.
It is commonly used to:
Apply unique styles via CSS
Select elements via JavaScript
Create internal page links (bookmarks)
<tag id="uniqueId">Content</tag>
Note:
The id
must be unique on a page.
IDs are case-sensitive.
id
<style>
#main-heading {
color: blue;
font-size: 24px;
}
</style>
<h1 id="main-heading">Welcome</h1>
id
You can use getElementById()
to access or manipulate elements.
<p id="demo">Original Text</p>
<button onclick="changeText()">Click Me</button>
<script>
function changeText() {
document.getElementById("demo").innerText = "Text Changed!";
}
</script>
id
You can create internal links using an anchor and an id
.
<a href="#about">Go to About Section</a>
...
<h2 id="about">About Us</h2>
<p>This is the about section.</p>
id
and class
Feature | id |
class |
---|---|---|
Uniqueness | Must be unique | Can be reused |
CSS Selector | #id |
.class |
JavaScript | getElementById() |
getElementsByClassName() |
Q1. Create a paragraph with an id
and style it using CSS.
Q2. Add a heading with id="title"
and change its color to red.
Q3. Use JavaScript to change the content of a <div>
with id="output"
.
Q4. Create a button that updates a paragraph with a specific id
.
Q5. Use id="contact"
and create a link that jumps to that section.
Q6. Add an input box with a unique id
and set its value using JavaScript.
Q7. Create a list where one item has a special style via id
.
Q8. Demonstrate an internal link navigation using id
.
Q9. Apply font-style: italic
to an element with a specific id
.
Q10. Create a section with id="faq"
and a link that jumps to it.
HTML5 Basics
HTML Introduction
HTML Editors
HTML Basic
HTML Elements
HTML Attributes
HTML Headings
HTML Paragraphs
HTML Styles
HTML Formatting
HTML Quotations
HTML Comments
HTML Styling and Design
HTML Links and Media
HTML Layout and Structure
HTML Tables
HTML Lists
HTML Block & Inline
HTML Div
HTML Classes
HTML Id
HTML Head
HTML Layout
HTML Responsive
HTML Computercode
HTML Semantics
HTML Forms
HTML Forms
HTML Form Attributes
HTML Form Elements
HTML Input Types
HTML Input Attributes
Input Form Attributes
HTML Graphics
HTML APIs
HTML Advanced Topics