CSS ID SELECTOR
CSS id selector is used to select an element using the id attribute.
An id is used for many purposes like
- selecting element using javascript for various purposes
- creating page link
- Adding CSS property to the element
Here in this section we will mainly focus on CSS implementation of id.
CSS Id
Same as CSS class we can use CSS id to add style to the element it is defined to. From CSS point of view there is no difference between class and id.
Unlike CSS class id can't be used more than once in any webpage.
An id is defined by id_name preceded by a hash symbol ("#") .
#id_name { property: value; }
Example
Adding Id to an element
An id is added to an element by using the id attribute. As shown below
Example
Example
Output:
This paragraph is added with id1.