HTML Comments

HTML Tutorial

What is an HTML Comment?

HTML comments are used to add notes or explanations inside HTML code.
They are not displayed in the browser and are meant only for developers.

Syntax of HTML Comment

<!-- This is a comment -->

Single-Line Comment

<!-- This is a single-line comment -->
<p>Hello World</p>

The comment will not appear on the web page.

Multi-Line Comment

Useful for documenting large sections of code.

Commenting Out HTML Code

You can disable code temporarily using comments.

<!-- <p>This paragraph is hidden</p> -->

The paragraph will not be rendered.

Comments Inside Hypertext Markup Language Structure

Important Rules

  • Comments start with <!-- and end with -->

  • Do not nest comments

  • Avoid using comments for sensitive information

  • Comments are visible in View Page Source

HTML Comments vs CSS & JavaScript Comments

HTML

<!-- HTML comment -->

CSS

/* CSS comment */

JavaScript

// Single-line
/* Multi-line */

Common Uses of HTML Comments

  • Explaining code

  • Temporarily disabling elements

  • Marking sections (header, footer, main content)

  • Team collaboration

Interview One-Liners

  • They are not rendered in the browser

  • Used only for documentation

  • Syntax uses <!-- -->

  • Visible in page source

Final Summary

  • It helps developers understand code

  • They do not affect page output

  • Useful for debugging and documentation

  • Should not contain sensitive data

You may also like...