
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
How do we add a comment in HTML code?
In this article we are going to learn about how do we add a comment in HTML code. Let’s dive into the article for getting better understanding on adding comment in HTML code.
To add comments to HTML code, use the comment tag (!— Comment—>). It is a good coding practice so that both the coder and the reader can benefit from assistance in understanding the code. It is helpful to comprehend the intricate code's steps. When codes are being debugged, the comment tag is useful.
It is a straightforward bit of code that web browsers wipe off (ignore), meaning they do not appear.
Understanding the purpose of a piece of code, particularly in complex source code, is helpful to both coders and readers.
Syntax
Following is the syntax for comment in HTML
<!-- Comments here -->
Let’s consider the following examples to get clear idea on how do we add a comment in HTML code.
Single-line Comment
Single line comment is given inside the (<!—comment --->) tag.
Let’s look into the following example
Example
In the following examples we are using the single line comment.
<!DOCTYPE html> <html> <body> <!--This is heading Tag, It wont be displayed by browser --> <h1>TutorialsPoint</h1> <!--This is paragraph tag,it won't be displayed by browser --> <p>The Best E-Way Learning</p> </body> </html>
When the script gets executed, it will generate an output displaying the text without comments on the webpage.
Multi-line Comment
The syntax (!- ->) can be used to specify several lines. In essence, it is the same as the syntax for single-line comments; the only difference is that the first half of the comment ("->") is appended when the intended comment line ends.
Example
Considering the following example, where we are using the multi line comment tag.
<!DOCTYPE html> <html> <body> <!-- This isheading tag --> <h1>MSD</h1> <!-- This is multi-linecomment tag --> <h2>The Best Finisher</h2> </body> </html>
On running the above script, it will generate the output consisting of the text used in the script on the webpage.
Using <comment> tag
An HTML "comment" tag once existed, but none of the current browsers support it.
Example
Look into the following example we are using the <comment> tag.
<!DOCTYPE html> <html> <body> <comment>Heading tag</comment> <h1>DUCATI</h1> <comment>Paragraph tag</comment> <h2>The Fastest Bike</h2> </body> </html>
When the script gets executed, it will generate an output displaying the text used in the code on the webpage along with the comments used by tag as modern browsers won’t support it.
- Related Articles
- How do we add a sample computer code in HTML?
- How do we add a definition term in HTML?
- How do we add a menu list in HTML?
- How do we add a table row in HTML?
- How do we add a noframe section in HTML?
- How do we add a noscript section in HTML?
- How do we add document title in HTML?
- How do we add glossary definitions in HTML?
- How do we add bold text in HTML?
- How do we add a push button to HTML?
- How do we add a single-line input field in HTML?
- How do we add the width in characters for in HTML?
- How to add jQuery code to HTML file?
- How do we display a script in HTML?
- How do we add the maximum number of characters allowed in an element in HTML?
