CSS | #id Selector
The #id selector is used to set the style of given id. The id attribute is the unique identifier in HTML document. The id selector is used with # character.
Syntax:
#id {
// CSS property
}
Example:
<!DOCTYPE html> <html> <head> <title>#id selector</title> <!-- CSS property using id attribute --> <style> #gfg1 { color:green; text-align:center; } #gfg2 { text-align:center; } </style> </head> <body> <!-- id attribute declare here --> <h1 id = "gfg1">GeeksforGeeks</h1> <h2 id = "gfg2">#id selector</h2> </body> </html> |
chevron_right
filter_none
Output:

Supported Browsers: The browser supported by id selector are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Safari
- Opera
Recommended Posts:
- CSS | ::before selector
- CSS | ::after Selector
- CSS | * Selector
- CSS | :not Selector
- CSS | Class Selector
- CSS | ::first-letter Selector
- CSS | ::first-line Selector
- CSS | [attribute$=value] Selector
- CSS | :nth-last-child() Selector
- CSS | :nth-child() Selector
- CSS | :indeterminate Selector
- CSS | optional Selector
- CSS | :target Selector
- CSS | :first-of-type Selector
- CSS | :default Selector
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




