Use CSS Grid like a pro
Learn CSS Grid with live examples and images.
Check it outA comment tells browsers to ignore a piece of code.
Developers typically use comments for notes, debugging, and code deactivation.
Let’s see how commenting works in HTML, CSS, and JavaScript.
We use a <!-- -->
pattern to create an HTML comment. Here is the syntax:
<!-- Your text -->
Here’s an example:
<!-- <p>This paragraph is a comment</p> -->
<p>This is not a comment</p>
You can also comment out multiple lines like so:
<!--<p>This paragraph is a comment</p><p>This is another paragraph comment</p><p>And another paragraph comment</p>-->
<p>This is not a comment</p><p>This is also not a comment</p>
We use a /* */
pattern to create a CSS comment. Here is the syntax:
/* Your text */
Here’s an example:
/* This is a one-line CSS comment */
/*This is a multi-lineCSS comment becauseit spans multiple lines*/
/* We commented the paragraph ruleset below *//* p { color: red; font-size: 1.2rem; } */
/* Below is an uncommented ruleset */div { background-color: green; border-radius: 5px;}
There are two patterns for commenting in JavaScript.
//
(Two slashes)/* */
(Two slashes and asterisks)We use the /* */
pattern to comment out one or multi-lines. But //
works for only single line commenting.
Here’s an example:
// This is a one-line JavaScript comment
/* This is another one-line JavaScript comment */
/*This is a multi-lineJavaScript commentbecause it spansmultiple lines*/
/* We commented the function statement below *//*function sayHello() { console.log('Hello there!!!')}*/
/* Below is an uncommented JavaScript statement */function sayHi() { console.log("Hi there!!!");}
The keyboard shortcut to add comments in HTML, CSS, and JavaScript is: