Advertisement
Google Ad Slot: content-top
CSS Syntax
CSS syntax consists of a set of rules that are applied to HTML elements. Each rule has two main parts: selectors and declarations.
Syntax:
selector { Property: value; }
Components of CSS Syntax:
- Selector: Targets the HTML element(s) to be styled. Examples include elements (
h1,p), classes (.classname), and IDs (#idname). - Declaration Block: Contains one or more declarations inside curly braces
{}. Each declaration consists of:
- Property: The aspect of the element to be styled (e.g.,
color,font-size). - Value: The value applied to the property (e.g.,
blue,16px).
Example
/* Styling an h1 element */
h1 {
color: blue; /* Property: color, Value: blue */
font-size: 24px; /* Property: font-size, Value: 24px */
}
/* Styling a class (.container) */
.container {
width: 200px; /* Property: width, Value: 200px */
}
/* Styling an ID (#header) */
#header {
background-color: gray; /* Property: background-color, Value: gray */
padding: 10px; /* Property: padding, Value: 10px */
}