ID Selector

The CSS ID selector is used to style a single, unique element on a webpage. IDs are unique within a page, meaning each element should have only one ID.

Syntax

#idname {
    property: value;
}

Example

#header {
    background-color: black;
    color: white;
    padding: 20px;
    text-align: center;
}
/* Styling a unique button with the ID "submit-btn" */
#submit-btn {
    background-color: green;
    color: white;
    font-size: 16px;
}

Explanation

  • #header applies styles only to the element with ID "header".
  • #submit-btn applies styles only to the element with ID "submit-btn".

Example in HTML

<h1 id="header">Welcome to My Website</h1>
<button id="submit-btn">Submit</button>
Differences: ID vs. Class

SelectorUsageExample
#idnameUnique for one element#header { color: red; }
.classnameReusable for multiple elements.button { color: blue; }
Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2025 Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz