Comments

Exercise

  1. In the "index.html" file, write the following code:
<!DOCTYPE html>
      <html lang="en">
      <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>My First Web Page</title>
      </head>
      <body>
      
      </body>
      </html>
      
  1. Save.
  2. If "Live Server" is not already running, right-click anywhere in the editor and select "Open with Live Server" from the context menu.
  3. Add the following code between the opening and closing body tags:
<!-- This is a comment and will not be displayed in the browser -->
      <h1>Lots of Comments!</h1>
      
  1. Save.
  2. In the browser, you should see the following:

  3. Exercise 5 Result
  4. Update the code and comment out the heading like this:
<!-- <h1>Lots of Comments!</h1> -->
      
  1. Save.
  2. The heading will stop showing on the browser.

Code Walkthrough and Explanation


<!-- This is a comment and will not be displayed in the browser -->

This is the way to add comments in HTML by putting text in between <!-- and -->. Comments in HTML are used to add annotations to the code that are not displayed in the final web pages. Comments are ignored by the web browser and are only intended to provide information or explanations to the person reading the code.


<!-- <h1>Lots of Comments!</h1> -->

Sometimes when you want to temporarily stop a piece of code from rendering, you can also comment it out. This is helpful for troubleshooting your code to find problems.

There are several reasons to use comments in HTML:

In summary, comments in HTML are a useful tool for making code more readable and understandable, improving collaboration, and simplifying the development process.


Experiment with the Code


Video and Code References


Questions? Subscribe and ask in the video comments:



GitHub and Other References