Understanding CSS Syntax
A CSS rule consists of a selector and a declaration block.
The selector points to the HTML element you want to style. The declaration block contains one or more declarations separated by semicolons.
/* Selector and Declaration Block */
h1 {
color: blue; /* property: value */
font-size: 24px; /* property: value */
}
/* Multiple Selectors */
h1, h2, h3 {
color: navy;
font-family: Arial;
}
- Selector - Points to HTML element
- Declaration Block - Contains styling rules
- Property - What to style (color, font-size, etc.)
- Value - How to style it (blue, 24px, etc.)
Try CSS Syntax
<h1>Main Heading</h1>
<h2>Subheading</h2>
<p>This is a paragraph with custom styling.</p>
Note: Each declaration includes a CSS property name and value, separated by a colon.