CSS SYNTAX /// SELECTORS /// PROPERTIES /// VALUES /// RULES /// CSS SYNTAX /// SELECTORS /// PROPERTIES /// VALUES /// RULES ///

CSS Syntax

Learn the grammar of design. Master selectors, properties, values, and write clean, bug-free CSS rulesets.

styles.css
1 / 12
12345
🎨

Tutor:Welcome to CSS! CSS stands for Cascading Style Sheets. It's the language we use to style an HTML document.


Skill Matrix

UNLOCK NODES BY MASTERING SYNTAX.

Concept: Selectors

Selectors target HTML elements. They can be tags (p), classes (.btn), or IDs (#hero).

System Check

Which selector targets ALL <div> tags on the page?


Community Holo-Net

Share Your Styles

ACTIVE

Struggling with a weird syntax error? Share your snippet and get feedback from peers!

CSS Anatomy: The Core Syntax

Author

Pascual Vila

Frontend Instructor // Code Syllabus

Mastering CSS begins with understanding its structure. The syntax is the set of rules that tells the browser exactly what you want it to do with your HTML elements. It's a simple, yet incredibly powerful language grammar.

The Rule Structure

Every piece of styling you write in CSS is part of a Ruleset (or Rule). A ruleset consists of two primary components: the Selector and the Declaration Block.

The Selector

The selector points to the HTML element you want to style. It "selects" the targets.

  • Type Selectors: Target elements by their HTML tag name (e.g., p, h1, div).
  • Class Selectors: Target elements with a specific class attribute. Always start with a period (e.g., .button).
  • ID Selectors: Target a single, unique element on the page. Always start with a hash (e.g., #header).

Declarations (Properties & Values)

Inside the curly braces { } lives the declaration block. Here, you write one or more declarations. Each declaration specifies a property you want to change, and the value you want to give it.

color: blue;
↑ Property   ↑ Value

Punctuation is critical: The property and value are separated by a colon (:). Each declaration MUST end with a semicolon (;). Forgetting the semicolon is the #1 cause of broken CSS layouts for beginners!

❓ Frequently Asked Questions (Syntax)

What happens if I forget the semicolon (;) at the end of a declaration?

If you forget the semicolon and have more declarations below, the browser won't know where one rule ends and the next begins. This will break both the current line and the next one. Always use the semicolon!

Why use classes (.) instead of IDs (#)?

Classes are designed to be reusable. You can apply .btn to fifty different buttons on your page.IDs must be unique (only one #navbar per page). Plus, classes keep your CSS cleaner and more modular.

Is CSS case-sensitive?

In general, CSS property names and values (like color or blue) are not case-sensitive. HOWEVER, Class and ID names that link your HTML to your CSS are case-sensitive. (.MyClass is not the same as .myclass).

Syntax Glossary

Ruleset
The complete block of CSS code containing the selector and the declaration block.
snippet.css
Selector
The part of the rule that specifies which HTML elements will receive the styling.
snippet.css
Declaration Block
The section enclosed in curly braces { } containing one or more declarations.
snippet.css
Declaration
A single rule consisting of a property and a value, ending in a semicolon.
snippet.css
Property
The specific stylistic feature of the HTML element you are modifying.
snippet.css
Value
The exact setting or magnitude given to a property.
snippet.css