What are CSS Selectors? and it's Types:

What are CSS Selectors? and it's Types:

CSS Selector: CSS Selector is used to select and target specific HTML elements which we want to style. There are different types of selectors in CSS, including:

  1. Universal Selector: In CSS, the universal selector is denoted by an asterisk (*) and it targets all elements on a page.

  2. Element Selector: In CSS, an element selector is used to select and target all instances of a specific HTML element on a web page. It is denoted by the name of the HTML element.

  3. Class selector: In CSS, a class selector is used to target and select HTML elements based on their class attribute. It is denoted by (' . ') the name of the class.

    Class selectors can be used multiple times in a single HTML document, allowing us to apply the same styles to different elements with the same class attribute.

    We can also use multiple class selectors in a single CSS rule to target elements that have multiple classes applied to them.

  4. Id Selector: In CSS, an ID selector is used to select and target HTML elements based on their unique ID attribute. It is denoted by a hash (#) with the ID name.

    ID selectors are unique in that they should only be used once in a single HTML document. This is because the ID attribute is intended to uniquely identify a single element on a web page.

    Note: ID selectors have a higher specificity than class or element selectors, which means that styles applied to an element through an ID selector will take precedence over styles applied through other selectors.

  5. Selector List: In CSS, a selector list is a series of selectors separated by commas that are used to target specific elements on a web page. The styles defined in the CSS rule will be applied to any element that matches any of the selectors in the list.

    Note: Apart from that there are more selectors like 'Descendent Selector', 'Child Selector', 'Adjacent Sibling Selector', 'General Sibling Selector', 'Attribute Selector', 'Pseudo Selector' etc. But, we mainly use the above-given selectors.