HTML Comments and Whitespace
What Is It?
A comment is a note in your code. The browser does not show it as page text.
What the Tags Mean
<!-- ... -->: a comment.br: starts a new line.pre: keeps spaces and line breaks.
Example 1
Save each example as index.html and open it in your browser. Each code block is a complete page.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML Comments and Whitespace</title>
</head>
<body>
<!-- This heading introduces the page. -->
<h1>My notes</h1>
</body>
</html>Browser preview
What you see: Only My notes is visible.
Example 2: Another Use
Use pre when spaces and line breaks are part of the content.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML Comments and Whitespace</title>
</head>
<body>
<pre>Monday Read
Tuesday Practise</pre>
</body>
</html>Browser preview
Simple Tip
Pressing Enter in the HTML source usually does not create a visible line break. Use paragraphs or br when needed.
Try It Yourself
Add a comment above a paragraph. Confirm that it is not visible on the page.