Back to Lessons

CSS Fundamentals Selectors

April 5, 2026

CSS Basics and Selectors

CSS (Cascading Style Sheets) controls presentation of HTML elements.

CSS Syntax

selector {
  property: value;
  font-size: 16px;
  color: #333;
}

Selector Types

Element: p { color: blue; }
Class: .highlight { background: yellow; }
ID: #main { width: 100%; }
Universal: * { margin: 0; }
Attribute: input[type="text"] { border: 1px solid; }
Descendant: ul li { list-style: none; }
Child: ul > li { padding: 10px; }
Pseudo-class: a:hover { color: red; }

Specificity Rules

  • Inline > ID > Class > Element
  • Weights: 1000/100/10/1
  • Last declaration wins