Home 〉 HTML Tutorials 〉 Add Comment Tag in HTML to Comment Out Code Line
Add Comment Tag in HTML to Comment Out Code Line !
Do you know what is an HTML comment, and why should you use it? HTML comments are a simple yet powerful way to add remarks in your code without affecting how the webpage looks. They're mainly used to explain lines of code, leave helpful notes, or temporarily hide parts of your page like a box, form, or section. Comments help you stay organized, especially when working on larger websites or blog pages. With a clean and easy-to-understand syntax (`<!-- comment -->`), adding comments is a smart habit for both beginners and professionals. From marking sections to noting down changes, comments make editing and debugging your HTML code much smoother. If you're ready to level up your coding workflow, here is a detailed blog post on 'HTML comment'.
An HTML comment is a simple way to leave a remark in your code without showing it on the website. It helps you organize, explain, and debug your HTML code easily. Comments are ignored by browsers, so they don't appear on your webpage.
Using comments is a good practice when building any free or professional website.
Here's the basic syntax to add a comment tag in HTML:
html syntax 📄
<!-- This is a comment -->
Everything between <!-- and --> are called a comment in html.
<!DOCTYPE html>
<html>
<body>
<!-- This is a comment -->
<p>This is Paragraph</p>
</body>
</html>
output 📌
This is Paragraph
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Everything between <!-- and --> is treated as a comment.
<!DOCTYPE html>
<html>
<body>
<!-- This line adds the heading -->
<h1>Welcome to My Blog</h1>
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<!-- <div class="box">
<p>This content is hidden for now.</p>
</div> -->
<div class="box1">
<p>This content is visible.</p>
</div>
</body>
</html>
output 📌
This content is visible.
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<form>
<!-- Remember to add validation attributes -->
<input type="text" name="name" required>
</form>
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<head>
<style>
/* CSS comment */
/* This selection adds background color */
.highlight {
background-color: yellow;
padding: 30px;
}
</style>
</head>
<body>
<p class="highlight">This paragraph is highlighted</p>
</body>
</html>
output 📌
This paragraph is highlighted
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<!-- Header Section -->
<header>
<h2>My Website</h2>
</header>
<!-- Main Content Section -->
<section>
<p>This is a simple content section.</p>
</section>
</body>
</html>
output 📌
This is a simple content section.
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
In the above Example
Adding HTML comment tags is a free and simple way to improve your coding process. Whether you want to leave notes, hide a form or box, or mark a section, using comments helps make your HTML page more organized and easier to understand.
When used correctly, comments make maintaining and updating your website easier. They also help other developers who may work on your blog or project later.
Now that you know how to use the comment tag in HTML.!