Hit enter after type your search item

HTML comments: How to write with live demos

How can I write comments in HTML?

The comment is the way to write some instructions, information, purpose etc. for the complete or a block or even a line of code in a program. For example, writing the name of the coder, the date when started coding, last updates, and purpose of using a particular block.

The text information written inside the comment does not execute. That may help the developer who is writing the program to understand the context or purpose of the code or a line of code in future.

Similarly, the comments are helpful for other developers as well that help them understand the code easily.

Different programming languages provide different ways, for example, in PHP you may write comment by using a double slash:

// Write comment here

The HTML comments can be written in single or multiple lines as shown below:

<!—Information / purpose of code here –>

For multi-line comments just enclose it after the comment as follows:

A demo of single line HTML comment

In this example, the single line comments are written. A simple div element is created with a few CSS properties. You can see the comments enclosed in the demo page or code below:

html comments

See online demo and code

The code with comments:


You can see, the comments are not executed or displayed as you run the demo page.

A demo of using multi-line comments

In many situations, you may need writing the bigger descriptions in comments that require multiple lines. For that simply start the comments directive (<!–), write the comments in multiple lines and close just like in above demo:

html comments multi lines

See online demo and code

The code for writing multi-line comments:

Also see:
This div height required for enabling the sticky sidebar