DEV Community

loading...

Comments in CSS HTML & CSS Comments

marvelnwachukwu profile image MornsCanCode ・1 min read

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

HTML5

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

CSS

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

JavaScript

//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
lines
*/
Enter fullscreen mode Exit fullscreen mode

Note

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

Discussion (4)

pic
Editor guide
Collapse
joelbonetr profile image
JoelBonetR

Javascript also supports multiline comments with same syntax:


/*
javascript
multiline
comment
*/

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


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

Collapse
inqalan profile image
inqalab

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 australianwritings.com/ this and other similar sources given there sooner this time.

Collapse
funnyvi45821188 profile image
funny video

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

Collapse
qadir_bhai profile image
Abdul Qadir

Hey, this page is relevant to the search query! The user has found the information they were looking for!”
Dofollow Niche blog comments