In programming or coding, comments provide readability, understandability, clarifications, helpful notes, and so on. It is a good practice to add comments in your code. While writing HTML, you can also add comments.
<!-- [comment] -->
HTML comments begin with the <!--
tag and are closed with the -->
tag.
Note: The opening tag has an exclamation mark, but the closing tag does not.
Just like in other languages, comments can be single-line or multi-line. In HTML, we use the same syntax for both.
<!-- This is a single line comment --><!-- This is amulti-line commentin HTML-->
Let’s demonstrate the use of a comment in HTML in the following code by making sure that only one p
element is displayed on the browser.
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>HTML Comment</title></head><body><p>This paragraph should display</p><!-- Hey browser don't display this<p>This paragraph should not display yet</p>--></body></html>
Thanks for reading!