Advertisement

Google Ad Slot: content-top

CSS Syntax

~1 min read · CSS
On this page

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:

  1. Selector: Targets the HTML element(s) to be styled. Examples include elements (h1, p), classes (.classname), and IDs (#idname).
  2. 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 */ }
Try it yourself