HTML comments are sections of text inside HTML documents that are ignored by the browser and do not therefore not displayed on the website. They are used to make the code more understandable for developers, to leave comments and to temporarily deactivate certain passages of the code.
Web Hosting
State-of-the-art web hosting at the best price
- 3x faster, 60% savings
- High availability >99.99%
- Only at IONOS: up to 500 GB included
An HTML comment is a special markup that allows programmers to leave some sort of note in code. These notes are not taken into account by web browsers and are therefore invisible to end users. To create a comment in HTML, we use the syntax . Below is a simple example that shows how to insert a comment into an HTML document:
In the example above, the first comment and the one around the HTML paragraph are ignored by the browser, so only the text inside the HTML title is displayed.
Note that in HTML, there is no no specific syntax for multiline comments. However, you can simply use several lines in a single comment. This is particularly useful when explanations or longer notes are needed. Multi-line comments start and end like single-line comments, the text in between can be as many lines as necessary.
Note
Comments are one of the first things you'll encounter when learning HTML. To learn about other things to consider when you want to program websites in HTML, check out our great introductory HTML tutorial.
HTML comments are an essential tool in web development. They have several important functions:
- Document: comments help document code so that other developers or your future self can more easily understand the purpose and operation of certain sections of code.
- Disable code: programmers can temporarily disable parts of code or HTML tags without having to remove them. This is especially useful when troubleshooting, debugging, or experimenting.
- Be organized: Large HTML documents can be structured and organized through the use of HTML comments. This makes code easier to navigate and edit.
- Annotate: developers can, if necessary, leave personal notes in the code.
When using an HTML comment, programmers need to consider a few things. Especially, no nested comments is not possible. This means that a comment cannot be placed inside another comment. This would result in an error. The following example illustrates this point:
When writing comments, it is also important to follow certain best practices. First, comments must be clear and concise in order to improve the readability of the code; Long comments can indeed make the code confusing. Superfluous comments should be avoided. Plus, in the best case, the code is self-explanatory. Comments are a useful addition, but do not replace a clean programming style.
Domain name
Your domain in one click
- 1 Wildcard SSL certificate per contract
- Included Domain Connect feature for simplified DNS setup

