Turning Learners Into Developers
Codekilla
CODEKILLA
back to course
Lesson 05 / 965%· free preview
CSS Basics5/7

CSS Comments

`/* comment */` — annotate your styles for future-you and teammates.

Definition

CSS uses /* */ for comments — single-line or multi-line.

css
/* This is a comment */

/*
  Multi-line comment
  Useful for section headers
*/

h1 {
  color: orange;       /* main brand colour */
  font-size: 48px;     /* override Tailwind default */
}
Writing Clear CSS Comments
css
/* ─── Reset ─── */
* { margin: 0; padding: 0; box-sizing: border-box; }

/* ─── Typography ─── */
body { font-family: 'Inter', sans-serif; line-height: 1.6; }
h1, h2, h3 { font-weight: 700; }

/* ─── Layout ─── */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem;
}

/* ─── Buttons ─── */
.btn {
  /* TODO: extract to design tokens */
  background: orange;
  color: white;
  padding: 0.5rem 1rem;
}
When to Comment
  • Section headers — group related rules.
  • TODOs — reminders.
  • Why, not what/* fixes Safari flex bug */ beats /* set width */.
  • Magic numberspadding: 7.5px /* matches header height */.
Common Mistakes
  • // single-lineNOT valid in CSS (works in SCSS).
  • Nested /* */ — invalid; outer ends at first */.
  • Comments left in production — strip in build (Webpack, Parcel).
Interview Questions

Practice Exercises
  1. Section your file — Add /* === Reset === */ headers. Hint: 3-5 sections.
  2. TODO — Add /* TODO: extract colour to var */ to a hardcoded value. Hint: searchable.
  3. Why comment — Replace /* set padding 7.5px */ with /* matches header line-height */. Hint: explanation.

💡 Think Like a Programmer: Comments aren't documentation — they're notes to future-you. Make them meaningful.

AI-powered recap

Quick recap quiz?

We'll generate 5 MCQs from this lesson and check your understanding instantly. Takes ~30 seconds.

Ready to move on?
// example library
Want more hands-on snippets in CSS3?
Browse 1 runnable example · across 1 chapter · short, copy-paste-friendly · grouped by topic
Explore examples
// sharpen your skills
Put this into practice right now
LeetCode-style problems, graded difficulty, hints and expected outputs — learning beats passively reading every time.
Start Practicing
// feedback.matters()
Did this lesson help you?