AI Summarize
Tutorials /HTML /Doctype & Comments

Doctype & Comments

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.
💡 Why Doctype is Important?
  • 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 -->.
💡 Key Points About HTML Comments
  • 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!
  -->
  
⚠️ Anyone can view your comments by checking the page source. Never put sensitive data like passwords or API keys inside comments!

The Coding Journey provides high-quality, beginner-friendly, and advanced web development tutorials. Learn React, Next.js, JavaScript, Tailwind CSS, and more with hands-on projects. Build faster, code smarter, and level up your skills! 🚀

© 2025 All Rights Reserved | The coding journey