CSS Selectors: Mastering the Art of Targeting

Athena Ozanich
2 min readDec 19, 2024

Become a CSS Sharpshooter and Style with Precision

Welcome back, CSS cadets! In our last mission, we learned the basics of CSS and how to add style to our webpages. Now, it’s time to become CSS sharpshooters and master the art of targeting specific elements with CSS selectors.

Think of selectors as your crosshairs. They allow you to pinpoint exactly which HTML elements you want to style. This precision is essential for creating complex and visually appealing websites.

Types of Selectors

CSS offers a variety of selectors to help you hit your styling targets:

Element Selectors: The simplest type, these target HTML elements by their tag name.

  • p { color: blue; }

This will make all paragraphs on your page blue.

Class Selectors: Target elements with a specific class attribute.

  • .highlight { background-color: yellow; }

This will highlight any element with the class “highlight.”

ID Selectors: Target a single, unique element with a specific ID attribute.

  • #main-heading { font-size: 36px; }

This will style the element with the ID “main-heading.”

Attribute Selectors: Target elements based on their attributes and values.

  • a[href="https://www.example.com"] { font-weight: bold; }

--

--

Athena Ozanich
Athena Ozanich

Written by Athena Ozanich

Front-End Developer by day, UI/UX designer by night! I’m an enigma with a desire to learn and teach others. Tech, Art, Philosophy and more

No responses yet