본문으로 건너뛰기

Comment (Comment)

Comment (Comment)

HTML comments are used to write notes or explanations that are not displayed on the web page. They are useful for developers or web designers to add explanations to specific parts of the code, much like making notes in the margins of a book or sticking notes on important sections.


Basic Structure

HTML comments start with <!-- and end with -->. Any content between these will not be displayed on the web page.

<!-- This is a comment and will not be displayed on the web page. -->
<p>This sentence will be displayed on the web page.</p>

Examples of Using Comments

  1. Code Explanation: You can add explanations to complex code or parts that might need to be modified later.

  2. Code Deactivation: If you want to temporarily deactivate a certain part of the code, you can wrap it in comments. This prevents that part of the code from being displayed on the web page.

<!-- The image below is temporarily deactivated.
<img src="example.jpg" alt="Example Image">
-->
  1. Separation: Comments can also be used to distinguish different sections of a web page.

For instance, comments can delineate and mark major sections of a website like:

  • Header: The top of the web page, displaying the logo, main menu (navigation), search bar, etc.

  • Main: Displays the core content of the website.

  • Footer: The bottom of the web page displaying site information (social media, copyright notice, etc.)

Using comments to separate sections
<!-- Header Start -->
<header>...</header>
<!-- Header End -->

<!-- Main Content Start -->
<main>...</main>
<!-- Main Content End -->

<!-- Footer Start -->
<footer>...</footer>
<!-- Footer End -->

HTML comments enhance the readability of the code and facilitate collaboration with other developers. They allow for easy communication about why certain parts of the code were written that way or what changes may be necessary.