Skip to main content
⚡ OpenDevDocs
CSS
frontendcssGuideBeginner

CSS Syntax and Selectors Overview

Understanding CSS rulesets: selectors, declarations, properties, values, and how browsers parse stylesheets.

Verified: 2026-09-30
Platforms:
web
#css#styling#syntax#web#frontend

CSS Syntax and Selectors Overview

CSS (Cascading Style Sheets) describes how HTML elements are formatted, styled, laid out, and animated on screens, paper, or other media.


1. Anatomy of a CSS Rule

A CSS stylesheet consists of one or more rulesets:

/* Selector */
.button-primary {
  /* Declaration */
  background-color: #0284c7; /* Property: Value; */
  color: #ffffff;
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
}
  • Selector: Points to the HTML element(s) you want to style.
  • Declaration Block: Enclosed in curly braces {}.
  • Property: The style attribute you want to change (e.g. color, font-size).
  • Value: The specific setting assigned to the property (must end with a semicolon ;).

2. Including CSS in HTML

<link rel="stylesheet" href="/styles.css" />

2. Internal <style> Block (For critical path styles)

<style>
  body { margin: 0; font-family: sans-serif; }
</style>

3. Inline Styles (Avoid for maintainability)

<p style="color: red;">Alert message</p>

On this page