CSS Syntax
- CSS syntax defines how CSS rules are written
- It includes selector, property, and value
- CSS rules tell browser how to style HTML elements
- Each rule is written inside curly braces { }
What is CSS Syntax?
CSS syntax is a simple rule system used to style HTML elements. It tells the browser which element to style and how it should look. Every CSS rule has two main parts: selector and declaration block.
CSS Syntax Example
Example
h1 {
color: blue;
font-size: 28px;
}
Example Explained
h1
This is the selector. It selects all <h1> elements in HTML.
color
This is a property that changes the text color.
blue
This is the value that sets the color to blue.
{ }
Curly braces contain all CSS rules for a selector.
CSS Syntax Structure
selector
{ property: value; }
Selects HTML element
Defines style rules
💡 Note: Each CSS rule must end with a semicolon (;) inside the declaration block.
Real Life Example
Think of selector as a name (like "student"), property as action (like "wear"), and value as object (like "blue shirt").
So CSS tells: which element to style and how it should look.