HTML Tutorial

INTRODUCTION

Edit Template

HTML Tutorial

INTRODUCTION

Edit Template

HTML Comments

In HTML, comments are like digital sticky notes you place inside your code. They help you or other developers understand what certain parts of the code do, without affecting how the web page looks or behaves. Browsers completely ignore comments – they won’t show up on your website.

Why Use HTML Comments?

HTML comments are valuable for:

  • Making your code more readable and
  • Leaving reminders or explanations for yourself or others.
  • Temporarily disabling parts of your code for testing without deleting them.
  • Adding documentation within your HTML file.

Key Facts About HTML Comments

  • Visibility: Not visible in the browser (for developers only).
  • Syntax: Comments begin with <!-- and end -->.
  • Shortcut Key: use Ctrl + / to quickly comment/ uncomment lines.
  • Comment Types: Supports both single-line and multi-line

Syntax of an HTML Comment

				
					<!-- This is a comment -->

				
			

Everything inside <!-- and --> will be ignored by the browser.

Types of Comments in HTML

HTML allows two common types of comments:

1. Single-line Comments

Used for quick notes or short explanations. These are written on a single line.

				
					<!-- This is a single-line comment -->

				
			

Use Case: Briefly explain what a line or element of HTML is doing.

2. Multi-line Comments

These span across several lines and are useful for:

  • Adding detailed notes
  • Temporarily disabling sections of code
  • Explaining complex layouts or logic
				
					<!-- 
  This is a multi-line comment.
  It can stretch over several lines.
  Useful for longer explanations.
-->

				
			

Real Use example

				
					<!-- Header Section Starts -->
<h1>Welcome to LearnWithArshyan</h1>
<!-- Header Section Ends -->

<!-- 
  The below section is for featured courses.
  Do not remove this section unless updating layout.
-->
<div class="courses">
  <!-- Course Cards Go Here -->
</div>

				
			

Output

No output will be shown for comments. They are only visible in the source code and help with internal documentation.

Summary

  • HTML comments are ignored by browsers.
  • Use <!-- comment content --> for creating comments.
  • Ideal for writing notes, explanations, or temporarily disabling parts of code.
  • Improve your coding habits by regularly using comments for clarity and structure.
Scroll to Top