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.

Basic Selectors | CSS Basics to Advanced lesson | BraveProgrammer
  1. Courses
  2. /
  3. CSS Basics to Advanced

Lesson 3 of 50

·css

Basic Selectors

10 mins

Course progress6%

What you'll learn

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

3 points
  • Selectors are the bridge between HTML and CSS.
  • Class selectors (`.myClass`) are the most common way to style groups.
  • IDs (`#myId`) are unique and have higher specificity.

Selectors are the language‑level address of CSS. Mastering them early gives you a mental model that works across Flexbox, Grid, Animations, and Component Libraries.

SelectorExampleWhat it Matches
** { box-sizing:border-box; }Every element on the page.
pp { line-height:1.6; }All <p> elements.
.class.btn { padding:0.5rem; }Elements with class="btn".
#id#logo { width:120px; }The element whose id equals logo.
element, element2h1, h2 { margin:0; }Group of selectors (comma‑separated).
element > childul > li { list-style:none; }Direct children only.
element + siblingh2 + p { margin-top:0; }The adjacent sibling that follows.
element ~ siblingh2 ~ p { color:#555; }Any sibling that follows.

Example – Styling a Button Set

/* Group selector – same rules on two different tags */
button, .button {
  background:#0066cc;
  color:#fff;
  border:none;
  padding:0.6rem 1.2rem;
  cursor:pointer;
}

Real‑World Recommendation

Avoid deep descendant selectors such as header nav ul li a. They raise specificity and make future refactoring painful. Prefer a single‑class approach (.nav-link).

Make it stickPractice what you've learned1 quiz · 6 practical tests · Optional activities from CSS Basics to AdvancedBrowse activities
Previous lessonAdding CSS to a PageContinue to lesson 4The Cascade & SpecificityBack to CSS Basics to Advanced curriculum