HTML comments

HTML comments are used to add notes or explanations within the HTML code, which are not displayed in the web browser. They are useful for documenting the code, explaining the structure, or temporarily disabling parts of the code. HTML comments are enclosed within <!– and –> tags.

Here is an example of an HTML comment:


<!-- This is a comment -->
<p>This is a paragraph.</p>
<!-- <p>This paragraph is commented out and will not be displayed.</p> -->

In this example, the first line is a comment that won’t be displayed on the web page, and the second comment surrounds a paragraph tag, making the browser ignore it. Comments can be very useful for developers to leave notes or explanations about the code.

HTML comments – Interview Questions

Q 1: What are HTML comments?
Ans: Comments are notes ignored by browsers.
Q 2: Syntax of HTML comment?
Ans: .
Q 3: Are comments visible on the page?
Ans: No.
Q 4: Why use comments?
Ans: For code readability and debugging.
Q 5: Can comments span multiple lines?
Ans: Yes.

HTML comments – Objective Questions (MCQs)

Q1. How do you write a comment in HTML?






Q2. Do HTML comments appear in the browser page?






Q3. Can HTML comments span multiple lines?






Q4. Are HTML comments visible in the page source code?






Q5. Which of the following is correct for an HTML comment?






Related HTML Elements Topics