- HTML Tutorial
- HTML - Home
- HTML - Introduction
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Headings
- HTML - Paragraphs
- HTML - Fonts
- HTML - Blocks
- HTML - Style Sheet
- HTML - Formatting
- HTML - Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - Comments
HTML Comments are used to comment in HTML codes, so the developer can understand the purpose of that code section and it is helpfull for debugging also. If we are facing some issue becouse of any particular element we cah check it by commenting out that element.
What are HTML Comments?
HTML comment tag is used to create a comment. A comment in HTML is like a note for yourself and others. Comments are completely ignored by web browsers, so they don't affect how your page looks or works. There are two types of comment in HTML.
- Single Line Comment: The single-line comment is given inside the <!-- ... -->.
- Multi Line Comment: Same as single-line comment but if we add multiple lines in the comment we will have multi-line comments.
Why to use HTML Comments?
Comments help you and others to understand the code and increases code readability. HTML comments are placed in between <!-- ... --> tags. So, any content placed with-in <!-- ... --> tags will be treated as comment and will be completely ignored by the browser.
Try to click the icon run button to run the following HTML code to see the output.
Examples of HTML Comments
In the bellow examples we will witness single and multiline both types of comments.
HTML Single Line Comment
Here in this example we will use single line comment for each element used in the body tag.
<!DOCTYPE html> <html> <head> <title>Online HTML Editor</title> </head> <body> <!-- This is a single Comment--> <h1>Tutorialspoint</h1> <!-- This is a single line Commnet --> <p>Simply Easy Learning</p> </body> </html>
HTML Multi Line Comment
Here in this example we will use multi line comment for each element used in the body tag.
<!DOCTYPE html> <html> <head> <title>Online HTML Editor</title> </head> <body> <!-- This is a multiline Comment Heading Section --> <h1>Tutorialspoint</h1> <!-- This is a multiline line Commnet paragrapgh Scetion --> <p>Simply Easy Learning</p> </body> </html>
Note: We can not use the above approach of commenting on internal CSS and JavaScript section. In the <style> and <script> tag we have to use CSS and JavaScript comment syntax.
Hide Content using HTML Comment
This is required when we will work on debugging HTML code, this will help us to not to render specific html element.
<!DOCTYPE html> <html> <head> <title>Hiding p Element</title> </head> <body> <h1>Tutorialspoint</h1> <!-- <p>Simply Easy Learning</p> --> </body> </html>
Valid vs Invalid Comments
Comments in HTML have a single that you need to follow. You need make sure that there are no spaces in the start or end of comment string.
<!DOCTYPE html> <html> <head> <title>Valid & Invalid Comment</title> </head> <body> <!-- This is valid comment --> < !-- This is not a valid comment --> < !-- This is not a valid comment -- > </body> </html>
Conditional Comments
Conditional comments are a feature specific to Internet Explorer (IE) on Windows but they are ignored by other browsers. They are supported from Explorer 5 onwards, and you can use them to give conditional instructions to different versions of IE.
<!DOCTYPE html> <html> <head> <title>Conditional Comments</title> <!--[if IE 6]> Special instructions for IE 6 here <![endif]--> </head> <body> <p>Document content goes here.....</p> </body> </html>