CSS Selectors 101: Targeting Elements with Precision

Published: (January 30, 2026 at 02:34 PM EST)
1 min read
Source: Dev.to

Source: Dev.to

Introduction

CSS selectors are patterns that allow you to choose which HTML elements you want to style. Without them you cannot apply colors, fonts, or layouts to your page.

Element Selector

Targets all elements of a specific type, like all paragraphs:

p {
  color: blue;
}

All paragraph text will appear in blue.

Class Selector

Use a . in front of the class name.

.highlight {
  color: red;
}

Test

Test

ID Selector

IDs are unique identifiers for a single, specific element. Each ID should appear only once per page.

#header {
  font-size: 30px;
}

## Heading

Group Selectors

Group selectors with commas to apply the same style to multiple elements.

h1, h2, h3 {
  font-family: arial;
}

Descendant Selectors

Target elements that are inside other elements.

article p {
  color: blue;
}

Selector Priority: The Basics

When multiple selectors target the same element, CSS decides which style to apply based on specificity:

ID Selector > Class Selector > Element Selector


What a color?
Back to Blog

Related posts

Read more »

Build a Survey Form

Project Overview Despite having written a couple of posts on DEV, I was still able to complete the HTML Tables and Forms quiz on freeCodeCamp yesterday. That l...

HTML (The Skeleton)

!Cover image for HTML The Skeletonhttps://media2.dev.to/dynamic/image/width=1000,height=420,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.a...