In most code editors, there are two shortcuts for two different types of comments: line and block. Here at CodePen, we do both too.

Line Comments

Line comments are your standard ctrl + / on Windows/Linux or cmnd + / on OSX. In languages where there are more than one type of comment, like JavaScript and most preprocessors, line comments only comment out a single line. In languages where there is only one type of comment, like vanilla CSS and HTML, line comments will behave similarly to block comments (/* */ and <!-- -->).

Unless there is no true line comment (vanilla HTML and CSS), the line comment shortcut will comment out the entire line your cursor is in (even if you haven't selected the whole line):

When you have many lines selected, the line comment shortcut will comment out each line with a line comment:

Block Comments

To make a block comment, add the shift key to the same keyboard shortcut as line comments: shift + ctrl + / on Windows/Linux or shift + cmnd + / on OSX.

The biggest difference with block comments is that they are very selection-sensitive. If nothing is selected, the block comment shortcut typically injects an empty block comment at the cursor position. If you have a selection, it will only wrap the selection:

In most preproscessors, line comments are hidden from compiled output, but block comments will be compiled into valid comment markup. For example, in SCSS:

// this line comment will not compile into a CSS comment
.thing {
 /* but this block comment will */
 color: #FFBB00;

Compiles to:

.thing {
  /* but this block comment will */
  color: #FFBB00;

Whitespace-Sensitive Block Comments

For some HTML preprocessors (Jade, Slim, and Haml), block comments do not have a closing comment flag. Instead, they use an open flag and then indentation.

Whitespace Block Comments in Haml

Whitespace Block Comments in Slim

Whitespace Block Comments in Jade

Comment Flag List

Here is a list of all of our editor languages and their corresponding comment flags:

Flavor Line Block Open Block Close Whitespace?
HTML <!-- -->
Markdown <!-- -->
Slim / /! true
Jade //- // true
Haml -# / true
CSS /* */
PostCSS /* */
Sass // /* */
SCSS // /* */
LESS // /* */
Stylus // /* */
JavaScript // /* */
CoffeeScript # ### ###
TypeScript // /* */
LiveScript # /* */