Before starting any HTML document, it’s important to declare a
<!DOCTYPE>
.
This tells the browser which version of HTML the page is written in.
<!DOCTYPE html>
<html lang="en">
<head>
<title>My First Page</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
Always write <!DOCTYPE html>
at the very top of your HTML page.
- It tells the browser the document type is HTML5.
- Ensures consistent rendering across browsers.
- Prevents older “quirks mode.”
HTML Comments
Comments in HTML are like notes you leave in your code. They help developers understand the code, but don’t show up on the webpage. The browser simply skips over them.
HTML comments start with<!--
and end with-->
.
- Browsers ignore comments completely.
- They make code easier to read and maintain.
- Shortcut: Ctrl + / in most editors.
- Support single-line and multi-line comments.
- Can be used to temporarily disable code.
Types of Comments
1. Single-line Comments
Best for short notes or quick explanations.
<!-- This is a single-line comment -->
<p>Hello World!</p>
2. Multi-line Comments
Used for detailed explanations or for disabling blocks of code during testing.
<!--
This is a multi-line comment.
It spans multiple lines.
Helpful when you need detailed notes
or want to hide code temporarily!
-->