W3Newbie
  • HTML Tutorial
  • CSS Tutorial
  • Web Dev
    • VS Code Tutorial
    • Command Line Tutorial
    • Git Tutorial
    • Github Tutorial
    • Sass Tutorial
  • Courses
  • Resources
  • Tutorials
  • Click to open the search input field Click to open the search input field Search
  • Menu Menu

CSS Comments

CSS comments serve as notes or explanations for developers within in our stylesheets that don’t affect our HTML webpage. They are used to clarify code, provide documentation, leave reminders, and temporarily disable specific style rules without removing them entirely.

How to create CSS comments:

  • Enclose the comment text within the /* */ comment delimiters.
  • Everything within these delimiters is ignored by the browser and won’t affect the visual rendering of the page.
  • Comments can appear within CSS rules or blocks, but not within property values.
  • Comments often appear with dashes “-” or equals signs “=” to make them easier to find in stylesheets.
  • Unlike HTML comments, in CSS they aren’t seen in browser developer tools.
  • Comment’s can’t be added styling inline, i.e. inside of HTML elements.

Comment Examples:

CSS:

/* This is a single-line comment. */

/* This is a
   multi-line comment
   spanning multiple lines. */

p {
  color: red; /* This comment is within a declaration block. */
}

/*==========
Emphasized comment with equals signs.
==========*/

Common uses of CSS comments:

  • Explanation: Providing context for specific CSS styles or noting changes.
  • Organization: Separating CSS document sections of styles for better readability.
  • Disabling code: Temporarily removing styles for testing or debugging.
  • Collaboration: Leaving notes for other developers working on the CSS.
  • Version control: Tracking changes and identifying different versions of the CSS.

Best practices

  • Use for clarity, thus not stating the obvious.
  • Explain complex logic or non-standard approaches.
  • Keep comments concise and to the point.
  • Update comments when code changes to maintain accuracy.
  • Use a consistent commenting style throughout your stylesheets.

Additional tips:

  • Consider using a commenting framework or template for consistency.
  • Use clear and descriptive language in your comments.
  • Avoid excessive commenting that clutters the code.
  • Proofread your comments for typos and grammar errors.

Avoid the temptation of over-commenting, redundant remarks, and messages others wouldn’t understand. Lastly, remember to use comments to build well-organized stylesheets with focused explanations.

< Previous
Next Lesson >
  • CSS Tutorial
  • CSS Introduction
  • CSS Syntax
  • CSS Style Sheets
  • CSS Comments
  • CSS Fonts
  • CSS Sizing
  • CSS Colors
  • CSS Backgrounds
  • CSS Borders
  • CSS Outlines
  • CSS Margin
  • CSS Padding
  • CSS Box Model
  • CSS Floats
  • CSS Alignment
  • CSS Positioning
  • CSS Overflow
  • CSS Z-Index
  • CSS Opacity
  • CSS Pseudo-Classes
  • CSS Pseudo-Elements
  • CSS Buttons
  • CSS Icons
  • CSS Media Queries
  • CSS Responsive Web Design
  • CSS Navigations
  • CSS Animations
  • CSS Flexbox
  • CSS Grid
  • CSS Responsive Typography
  • CSS Mobile-First Responsive
  • CSS Fluid Layouts
  • CSS Variables

The Newbie Template Bundle

The 12 Website Bundle Pack

Subscribe on YouTube

Web Development Courses

The HTML Email Mastery Course - Build Responsive HTML Email Templates.

Latest Tutorial Posts

  • The HTML Email Mastery Course - Build Responsive HTML Email Templates.w3newbie.com
    HTML Email Mastery Course CouponOctober 12, 2020 - 8:10 pm
  • Create A 5 Page Website With PHP Includes, HTML5, CSS3 & Bootstrap 4w3newbie.com
    Create A 5 Page Website With PHP Includes, HTML5, CSS3 & Bootstrap 4April 22, 2019 - 1:48 pm
© w3newbie.com, 2026. Terms of Use. Privacy Policy.
Scroll to top Scroll to top Scroll to top