CSS id selector is used to select the HTML element using the ID attribute to apply a style to it. This id element is distinctive always inside the page, and hence it is preferred for selecting a distinct, unique HTML element. When you want to apply the style to only one HTML tag at a time on a page, then you can use the ID selector.
Id selector can be implemented by writing it with the hash (#) character, trailing with your desired element's id.
Syntax:
#id_name{
/* declarations */
}
Here is an example of an Id selector implemented on a particular div tag:
CSS Id Selector Example
Example:
<!DOCTYPE html>
<html>
<head>
<style>
#mainframe {margin: auto, max-width: 1200px}
</style>
</head>
<body>
<!-- On this element, the ID selector class will be applied. -->
<div id="mainframe">
<!-- This is the main container of page. -->
<p>This paragraph is not assigned with id selector and hence no affect on it.</p>
</div>
</body>
</html>