Understanding CSS Comments and Formatting


Writing CSS is not only about making styles work.

It is also about making your code easy to read and understand.

Why Clean CSS Matters

Clean CSS helps:

  1. You understand your own code later
  2. Other developers work with you
  3. Reduce mistakes and confusion

What Are CSS Comments

Comments are notes written inside CSS.

They are ignored by the browser and only for humans to read.

You can write comments to explain what your styles do.

Where to Use Comments

Use comments to:

  1. Describe sections of your stylesheet
  2. Explain complex styles
  3. Leave notes for teammates

This makes your CSS easier to navigate.

Why Formatting Matters

Formatting means how your code is spaced and aligned.

Good formatting makes CSS readable at a glance.

Bad Formatting Example

Hard-to-read CSS causes mistakes.

This code works, but it is hard to read.

This version is clean and professional.

Best Practices for Formatting

  1. Use one rule per line
  2. Indent properties properly
  3. Leave space between sections

Why This Matters for Jobs

Companies expect developers to write clean code.

Readable CSS shows professionalism and experience.

Practice Task

Take a small CSS file and:

  • Add comments for each section
  • Format it to be clean and readable

What You Will Learn Next

In the next lesson, you will learn common CSS properties used by beginners.