DEV Community

Cover image for CSS Selectors 101: The Foundation of Styling
Janmejai Singh
Janmejai Singh

Posted on

CSS Selectors 101: The Foundation of Styling

CSS selectors decide what gets styled.

Types You Must Know

  • Element → Targets all tags (p)
  • Class → Reusable group (.card)
  • ID → One unique element (#header)
  • Group → Multiple selectors at once
  • Descendant → Context-based styling

Priority (Simple Rule)

Element < Class < ID

Pro Tip

Use classes for styling, IDs sparingly.

If CSS feels hard, selectors are usually the reason.

Top comments (0)