CSS Tutorial

Coming Tutorials

>Home>CSS Tutorial>CSS Selectors

CSS Tutorial

Coming Tutorials



CSS Selector | How It Used

CSS selector is an expression following the CSS rules and used to select the HTML element we want to style. And CSS selector syntax means how we write or use those selectors in the CSS editor.


* { css declaration } Select all the elements.
p { css declaration } Element selector, Selects all paragraphs.
. { css declaration } Class selector, Selects all the elements with the given class name.
# { css declaration } Id selector, Selects all(in case of duplicate id) element with an id.


Difference between an ID selector and the Class selector

• An ID Selector finds and modifies the style to only a single element whereas a class selector may apply to any no. of HTML elements.

• The id is for selecting specific element so it has more priority than class selector.

• Id should be prefixed with '#' where as class should be prefixed as '.'

• Note: Id should be unique in a web page but if duplicated then style will apply to all the elements with the same id.

Share the article to help your friends