Id Selector
- In CSS id selector is used to apply a style to a specific HTML element which is having a unique ID.
- It is written by using the hash character (#), followed by the id of the element.
Key Points:
- Inside the curly braces {}, you can specify various CSS properties and values to style the selected element.
- While IDs are powerful for unique styling, they should be used sparingly to avoid unnecessary specificity and maintain a clean structure in your CSS.
- Prefer using classes for styling elements that are repeated or have similar styles, reserving IDs for unique elements.
Syntax:
#elementID {
/* CSS properties and values */
}
In this syntax:
- The '#' symbol denotes the id selector.
- 'elementID' should be substituted with the actual id attribute value of the HTML element you wish to target.
- Within the curly braces {}, you can define the CSS properties and values you intend to apply to the chosen element.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
#para1 { // # used for id Selector
text-align: center;
color: red;
}
</style>
</head>
<body>
<p id="para1">Quipoin.com</p> // here id is the idSelector
</body>
</html>
Output:
Quipoin.com