How to comment in HTML, CSS and JavaScript

Adding comments to your code is a helpful way to include notes that explain to you or others what the code does. Code or other text that is commented out is ignored by the browser.

Read on to see how to create comments in HTML, CSS and JavaScript code!

How to write comments in HTML

Single line HTML comments

To comment out a single line of HTML, place the text or code you are commenting between comment tags: <!-- -->.

Here’s how this looks in the code:

<!-- The text in here will be invisible on the website -->
<div class="content">
  Here's some regular HTML content!
</div>

When you load the website, the HTML comment won’t show up on the page itself:

Website showing text content but not the HTML comment

But if you inspect the website code in your browser, you will still be able to see the HTML comment text:

Code inspector in the browser showing the comment

Multiline HTML comments

To create a multiline or block HTML comment, you still use the comment (<!-- -->) tags, but you can have more than one line in your comment. As long as you contain the comment text between the tags, it will be included in the comment.

Here’s an example of a multiline HTML comment:

<!-- 
  The text in here will be invisible on the website!
  Here's another line of the comment.
  You can have as many lines as you want! 馃榿
-->
<div class="content">
  And here's that regular HTML content again.
</div>

Here’s how it will look on the website:

Website text without HTML comment showing

And you can see the whole HTML comment in the inspector:

Browser inspector showing the multiline HTML comment

How to write comments in CSS

Single line CSS comments

To make a single line CSS comment, put the comment text or code between /* */tags.

Here’s an example:

/* This text will be ignored by the browser! */
.description {
  font-size: 1rem;
  line-height: 1.25rem;
  color: #202020;
}

Multiline CSS comments

To write multiline or block CSS comments, you can use the same /* */ tags, and put the comment content on multiple lines.

Here’s what a multiline CSS comment would look like:

/* 
  This text will be ignored by the browser! 
  And this will also be included in the comment!
  One last line of comment for good measure 馃榿
*/
.description {
  font-size: 1rem;
  line-height: 1.25rem;
  color: #202020;
}

How to write comments in JavaScript

Single line JavaScript comments

To create a single line comment in JavaScript, begin the line with two forward slashes (//).

Here’s an example of that:

// This text is a comment and will be ignored!

You can also add a single line comment on the same line as some code. As long as the comment is the last content on that line, it will work.

Here’s what that would look like:

console.log('Test code here!'); // This is a console log message

Multiline JavaScript comments

If you want to create a multiline or block comment in JavaScript, enclose the comment text between /* */ tags. (This is the same method as in CSS.)

Here’s what that will look like:

/* 
  Function: doSomeAwesomeThing()
  This does something awesome, but I don't know what! 
*/

function doSomeAwesomeThing(){
  console.log('Run awesome function');
}

In closing

Adding comments to your code in HTML, CSS, and JavaScript will help other people to understand what your code is about.

It’s also helpful when you’re working on a project in development and need to temporarily comment out some code while testing. But just make sure to not leave comments in production code!

Enjoyed this post?
Tweet me about it! 馃榾
Want to learn how to build a website?

I'm making a course that will teach you how to build a real-world responsive website from a Figma design!

Learn more
Want to learn web development?

Sign up to get emails about new posts and other info. Unsubscribe anytime.

Learn more at our Privacy Policy.

Affiliate Disclaimer

I participate in various affiliate programs and my content contains affiliate links. If you purchase through those links, I may receive a commission from the seller, at no cost to yourself. It's one way you can support this site!

As an Amazon Associate I earn from qualifying purchases. I only recommend products that I personally know and believe are helpful to my readers.

Twitter icon Facebook icon

哆哆女性网属猪张姓宝宝起名大全园林公司起名言情小说名字怎么起绿化公司注册起名字给学校起个名子故事起名田渊正浩中式餐饮加盟快乐的除夕夜囫囵吞枣的意思过犹不及什么意思十月宝宝出生起名安全生产奖惩制度棉花糖歌词大将军司马懿之军师联盟免费取名起名软件浮生六记南康谢画屏以润字起名公司的名字神话故事100篇2020感动中国十大人物事迹及颁奖词王和王怎么起名子youporn官网羊肉店起名冬之蝉ova7月13日smskbrang开头的成语孙氏男性起名代号13钗淀粉肠小王子日销售额涨超10倍罗斯否认插足凯特王妃婚姻不负春光新的一天从800个哈欠开始有个姐真把千机伞做出来了国产伟哥去年销售近13亿充个话费竟沦为间接洗钱工具重庆警方辟谣“男子杀人焚尸”男子给前妻转账 现任妻子起诉要回春分繁花正当时呼北高速交通事故已致14人死亡杨洋拄拐现身医院月嫂回应掌掴婴儿是在赶虫子男孩疑遭霸凌 家长讨说法被踢出群因自嘲式简历走红的教授更新简介网友建议重庆地铁不准乘客携带菜筐清明节放假3天调休1天郑州一火锅店爆改成麻辣烫店19岁小伙救下5人后溺亡 多方发声两大学生合买彩票中奖一人不认账张家界的山上“长”满了韩国人?单亲妈妈陷入热恋 14岁儿子报警#春分立蛋大挑战#青海通报栏杆断裂小学生跌落住进ICU代拍被何赛飞拿着魔杖追着打315晚会后胖东来又人满为患了当地回应沈阳致3死车祸车主疑毒驾武汉大学樱花即将进入盛花期张立群任西安交通大学校长为江西彩礼“减负”的“试婚人”网友洛杉矶偶遇贾玲倪萍分享减重40斤方法男孩8年未见母亲被告知被遗忘小米汽车超级工厂正式揭幕周杰伦一审败诉网易特朗普谈“凯特王妃P图照”考生莫言也上北大硕士复试名单了妈妈回应孩子在校撞护栏坠楼恒大被罚41.75亿到底怎么缴男子持台球杆殴打2名女店员被抓校方回应护栏损坏小学生课间坠楼外国人感慨凌晨的中国很安全火箭最近9战8胜1负王树国3次鞠躬告别西交大师生房客欠租失踪 房东直发愁萧美琴窜访捷克 外交部回应山西省委原副书记商黎光被逮捕阿根廷将发行1万与2万面值的纸币英国王室又一合照被质疑P图男子被猫抓伤后确诊“猫抓病”

哆哆女性网 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化