Member-only story

CSS Selectors Unmasked: A Guide to Type, Class, and ID Selectors for Beginners

An introduction to CSS selector types

Max N
3 min readMay 29, 2023
Photo by Ferenc Almasi on Unsplash

Type Selectors: The One-Size-Fits-All Stylists of CSS

Type selectors are like the one-size-fits-all stylists of CSS. They target all elements of a specific type, applying the same style to each one. It’s like giving everyone at a party the same hat to wear — it might not be the perfect fit for everyone, but it sure does create a consistent look!

For example, let’s say you want to make all the headings on your web page a lovely shade of purple. You’d use a type selector like this:

h1 {
color: purple;
}

In this case, the h1 is the type selector, and it targets all the first-level heading elements on your web page. Now, all your h1 headings will be rocking that royal purple hue!

Class Selectors: The Custom Tailors of CSS

Class selectors are like the custom tailors of CSS. They target specific elements that have a certain class attribute, allowing you to apply unique styles to different groups of elements.

It’s like designing custom outfits for different members of a band — each one gets their own unique look, but…

--

--

Max N
Max N

Written by Max N

A writer that writes about JavaScript and Python to beginners. If you find my articles helpful, feel free to follow.

No responses yet