Speedwalking through CSS Selectors

Amlan Kumar Nandy
3 min readSep 11, 2022

--

CSS Selectors are utilities provided that allow the developer to target HTML elements and apply a style to them specifically. Here are a few common ones everyone should be aware of.

Universal Selector ( * )

As simple as it sounds. Used to target EVERY element in the HTML. Useful to set up a theme/global style.

Universal Selector

Class Selector ( .a )

The most obvious one that everyone knows. Selects all elements with class name a (we can also call them a elements).

Class Selector

ID Selector ( #i )

Also something everyone knows but rarely uses. Used to target a single element usually. Selects the element whose id is i.

ID Selector

Multiclass Selector ( .a.b )

Selects all the elements that have both a and b class names.

Multiclass Selector

Child Combinator ( a > b )

Selects all b elements that are directly present (immediate children) inside a elements.

Child Combinator

Descendant Combinator ( a b )

Selects all b elements that are anywhere inside a elements, not just direct children.

Descendant Combinator

Adjacent Sibling Combinator ( a + b )

Used to select all b elements that are immediately next to a elements on the same level.

Adjacent Sibling Combinator

General Sibling Combinator ( a ~ b )

Selects all b elements that occur anywhere after a elements, no matter the level or position.

General Sibling Combinator

Tag + Class Selector ( t.a )

Select all the elements that have tag t and class a.

Tag + Class Selector

Attribute Selector ( a[x=y] )

Select all a elements that have the x attribute set to y.

Attribute Selector

That’s all for today. On the never-ending journey of struggling with CSS, hope this lessens the hassle a little bit.

--

--

Amlan Kumar Nandy

Software Engineer at Clumio, a SaaS-based startup focusing on Data Security for the Cloud. Love exploring new tech and collaborating with passionate people! :)