Mastering the Language: Understanding CSS Syntax

Understand the grammar of styling. Learn how selectors, properties, and values form the foundation of every stylesheet.

The Rule: Selector & Declaration Block

A CSS rule is the basic building block. It starts with a selector (like h1) to target an HTML element, followed by a declaration block enclosed in curly braces { ... }.

Declarations: Properties & Values

Inside the declaration block, you have one or more declarations. Each consists of a property (e.g., color) and a value (e.g., blue), separated by a colon :. Every declaration must end with a semicolon ; to separate it from the next one.

Comments: Explaining Your Code

You can add comments to your CSS to explain your code. Comments start with /* and end with */. Anything between these markers will be ignored by the browser. They are great for organization and notes.

Practice Zone


Interactive Test 1: Drag & Drop

Arrange the code blocks to form a complete CSS rule that sets the color of `h1` elements to blue.

Arrastra en el orden correspondiente.


Arrastra las opciones:

h1
{
color
blue
}

Completa el código:

h1______
{______
color______:
blue______;
}______
Unlock with Premium

Interactive Test 2: Fill in the Blanks

Complete the CSS rule to change the background color of the body to `orange`.

Rellena los huecos en cada casilla.

body {
  background-: ;
}
Unlock with Premium

Practice Example: Code Editor

In the editor, write a simple CSS rule to set the font size of all `p` elements to `18px`.

Enunciado:

This simple rule selects all paragraph tags and applies a font size of 18 pixels.

* Escribe el código a continuación. Los caracteres correctos se mostrarán en verde y los incorrectos en rojo.

p { font-size: 18px; }
Unlock with Premium

Knowledge Check

What punctuation mark separates a CSS property from its value?


Unlock with Premium