Id selector
CSS Id selector
- The id selector uses the id attribute of an HTML element to select a specific element.
- The id of an element is unique within a page, so the id selector is used to select one unique element!
- To select an element with a specific id, write a hash (#) character, followed by the id of the element.
- Must begin with a letter A-Z or a-z
- Id name cannot start with a number
- Must not contain any space characters
- Can be followed by: letters(A-Za-z), digits(0-9), hyphens("-"), and underscores("_")
- In HTML, all values are case-insensitive
Syntax:
#IdName{
property : value;
}
For example:
<html>
<head>
<style>
#para1 {
text-align: center;
color: blue;
}
</style>
</head>
<body>
<p id="para1">Hello Javatpoint.com</p>
<p>This paragraph will not be affected.</p>
</body>
</html>