DEV Community 👩‍💻👨‍💻


Posted on

Comments in CSS HTML & CSS Comments

Writing lots of lines of code and you're worried you might not understand your code next week?

Want to make your project understandable to other programmers?

Comments are the way to go about it. A comment is a programmer-readable explanation or annotation in the source code of a computer program.

Comments are added to make the source code easier for humans to understand and are generally ignored by compilers and interpreters.

Comments are started with a language-specific symbol


<!--This is a comment -->
Enter fullscreen mode Exit fullscreen mode


/* This is a comment */
Enter fullscreen mode Exit fullscreen mode


//This is a comment
Enter fullscreen mode Exit fullscreen mode

When to use comments

"A handy rule of thumb is: a comment should only be added to answer a question that the code can't. If you aren't confused by what a piece of code is doing, but rather why it's doing it at that moment, then a comment should be added." - Mark Cronin

Comments can be placed wherever white space is allowed within a style sheet. They can be used on a single line, or traverse multiple lines. This allows commenting inside a block of code and between a group of codes. What matters is making your code glanceable.

/* A one-line comment */

A comment
which stretches
over several
Enter fullscreen mode Exit fullscreen mode


The /* */ comment syntax is used for both single and multiline comments. There is no other way to specify comments in external style sheets.

Top comments (4)

joelbonetr profile image

Javascript also supports multiline comments with same syntax:


and it can be used to comment a part of a line like this:

doSomething(  foo,  /* foo 2 */ );

inqalan profile image

Are you all up for A Simple Guide To Write A Perfect Essay? If yes, then i would like you to try out this site as it has everyting that you look for. I hope this will be used by this and other similar sources given there sooner this time.

funnyvi45821188 profile image
funny video

Hi, guys, I am here to tell you a website where you can continue your study check this website this is the best website where you can study online

Update Your DEV Experience Level:


Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. 🛠