Basic Selectors

๐ŸŽจ CSS3+ ๐ŸŸข Chapter 3 of 49 ๐Ÿ“‚ Phase 02: Selectors ๐Ÿ“… 2026 Edition
๐Ÿ“Œ Covered in this chapter: Universal ยท Element ยท Class ยท ID ยท Grouping ยท Attribute ยท Case Sensitivity ยท Naming ยท Reusable Classes ยท Avoid Excessive IDs
Welcome to Chapter 3: Basic Selectors โ€” part of the CSS Complete Roadmap. This lesson covers all subtopics with clear explanations, code examples, and best practices used in professional web development.
1What Are CSS Selectors?

CSS selectors HTML element patterns ni match chesi styles apply chestayi. Correct selector choose cheyadam โ€” maintainable, scalable CSS foundation.

CSS โ€” All Basic Selectorsโ–ถ Try in Editor
* { box-sizing: border-box; }

p { color: #333; }

.card { padding: 20px; }

#main-title { font-size: 2rem; }

a[href^="https"] { color: #2563eb; }

h1, h2, h3 { font-family: 'Sora', sans-serif; }
2Universal Selector (*)

* โ€” page lo every element match avuthundi. CSS resets and global box-sizing ki common:

CSS
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
3Element (Type) Selector

Tag name tho match โ€” p, h1, button, div:

CSS
p { color: #333; line-height: 1.7; }
button { cursor: pointer; border: none; }
4Class Selector (.) โ€” Reusable Styles

Class selector most common and reusable. HTML lo class="card", CSS lo .card:

CSS + HTML
.card {
  padding: 20px;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

Naming conventions: kebab-case (.nav-link), BEM (.card__title--active), semantic names (.btn-primary not .blue-box).

5ID Selector (#) โ€” Use Sparingly

ID unique ga undali page lo okate โ€” high specificity valla override cheyadam kashtam:

CSS
#main-title {
  font-size: 2rem;
  color: #1e293b;
}

Best practice: Styling ki classes prefer cheyandi. IDs JavaScript hooks and anchor links ki reserve cheyandi. Excessive IDs avoid cheyandi.

6Grouping & Attribute Selectors

Grouping โ€” same styles multiple selectors ki:

CSS
h1, h2, h3 {
  font-weight: 700;
  color: #0f172a;
}

Attribute selectors:

CSS
input[type="email"] { border-color: #3b82f6; }
a[href^="https"] { font-weight: 600; }
img[alt=""] { outline: 2px dashed red; }

Case sensitivity: HTML class/ID names case-sensitive in quirks mode but standard mode lo case-sensitive. Always consistent casing use cheyandi.

OC
Written by Our Compiler Technical Editorial Team
Reviewed for accuracy ยท CSS Complete Roadmap ยท Last updated August 2026