
CSS Syntax
CSS syntax consists of a set of rules that define how to apply styles to HTML elements. These rules are made up of selectors, properties, and values.
1. Selectors: Selectors are used to target HTML elements to which styles should be applied. There are several types of selectors, including element selectors, class selectors, ID selectors, attribute selectors, and pseudo-classes.
h1 {
color: blue;
}The selector is the h1 element, and the style rule is to set the color property to blue.
2. Properties: Properties define the specific visual characteristics of an HTML element that should be styled. There are many CSS properties that can be used, including font-size, color, background-color, margin, padding, and border.
h1 {
color: blue;
font-size: 24px;
}Two properties, color and font-size, are defined for the h1 element.
3. Values: Values define the specific setting for a CSS property. For example, if the color property is set to blue, the value of the property is “blue”.
h1 {
color: blue;
font-size: 24px;
}The value for the color property is “blue”, and the value for the font-size property is “24px”.
CSS rules are enclosed in curly braces {} and each property-value pair is separated by a colon :. Multiple CSS rules can be combined into a block using a comma ,.
Example:
h1, h2, h3 {
color: blue;
font-size: 24px;
}The CSS rule applies to all h1, h2, and h3 elements on the web page, setting their color to blue and font-size to 24px.
In summary, CSS syntax consists of selectors, properties, and values, which are combined to create CSS rules that define how to apply styles to HTML elements.