Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Pseudo‑Classes & Pseudo‑Elements | CSS Course lesson | BraveProgrammer
  1. Courses
  2. /
  3. CSS Course

Lesson 19 of 50

·css

Pseudo‑Classes & Pseudo‑Elements

12 mins

Course progress38%

What you'll learn

Keep these ideas in mind as you work through the lesson.

3 points
  • `:nth-child(odd/even)` and `:nth-of-type()` are powerful for pattern‑based styling.
  • `::before`/`::after` require `content` (even empty string) to render.
  • `:has()` (relational selector) is a CSS 4 feature, currently supported in Safari and Chrome 105+.

Pseudo‑classes (:hover, :focus, :nth-child, :not, :has) target states or structure of an element.

Pseudo‑elements (::before, ::after, ::first-line, ::first-letter) create virtual child elements.


Example: Fancy button with ::after

.btn {
  position:relative; padding:0.8rem 1.5rem; overflow:hidden;
}
.btn::after {
  content:""; position:absolute; inset:0; background:linear-gradient(45deg,var(--c1),var(--c2));
  transform:scaleX(0); transform-origin:left; transition:transform .3s;
}
.btn:hover::after { transform:scaleX(1); }
Make it stickPractice what you've learned1 quiz · 6 practical tests · Optional activities from CSS CourseBrowse activities
Previous lessonCSS Blend ModesContinue to lesson 20TransitionsBack to CSS Course curriculum