CSS Syntax
A CSS rule set consists of a selector and a declaration block.
CSS Syntax
A CSS rule set consists of a selector and a declaration block:
selector {
property: value;
}
The selector points to the HTML element you want to style.
The declaration block contains one or more declarations separated by semicolons.
Each declaration includes a CSS property name and a value, separated by a colon.
Example 1: Basic Syntax
In this example, p is the selector, and the declaration block contains two declarations.
Hello World!
Example 2: Multiple Declarations
You can have as many declarations as you want in a block.
This text has multiple styles.
Example 3: Formatting Code
It is good practice to put each declaration on a new line for readability.
body {
background-color: lightblue;
color: black;
font-family: Arial;
}
Example 4: Using Comments
Comments are used to explain the code, and may help when you edit the source code at a later date. Comments are ignored by browsers.
p {
color: red; /* This is a single-line comment */
text-align: center;
}
/* This is a
multi-line comment */