Courses Job Ready Fresher Training AI for Class 7 to 12 Corporate Training Placements Tutorials
Free Learning Resources

IT Tutorials & Interview Prep

Free guides, interview Q&As, and job responsibility breakdowns — curated by industry veterans to help you crack MNC interviews

109+
Tutorial Articles
9
Topic Categories
100%
Free to Read
← Back to CSS

Syntax of CSS

CSS Last Updated: Oct 06, 2025

Syntax of CSS

CSS follows a rule-based structure. Each rule consists of a selector and a declaration block. Each CSS rule comprises a selector and a declaration block, where selectors identify the HTML elements to style, and declaration blocks define the properties and their corresponding values.

General Syntax of CSS

Key Elements of CSS Syntax

  • Selector: Specifies the HTML element(s) to target (e.g., h2, .class-name, #id-name).
  • Declaration Block: Enclosed within curly braces {} and contains one or more property-value pairs.
  • Property: Defines the style attribute to modify (e.g., color, background-color).
  • Value: Sets the specific style for the property (e.g., blue, 5px).
  • Semicolon (;): A critical component, required at the end of each property-value pair to separate multiple declarations within a block.

Example: Single Property Declaration

cwh tutorial image

Within the declaration block, there can be multiple pairs of properties and values.

Example: Multiple Property Declarations

Here, button is the selector, and there are multiple pairs of properties and values. Each pair is separated by a semicolon ;.

Best Practices

  • Always include a semicolon (;) after each property-value pair, even if it’s the last declaration in the block, to maintain consistency and avoid errors when adding new styles.
  • Use clear and descriptive property names and values to enhance code readability and maintainability.
Want to practice these scenarios in a real IT environment? Our 45-Day Internship Program gives you hands-on experience with Active Directory, Ticketing Tools, and Networking.
Join the Internship →