How do I comment my HTML, CSS, JavaScript, and PHP code?

When you are designing your website, there are many instances that require you to comment out code in your website. Commenting code is good for diagnosing website problems, hiding code instead of deleting the code, placing notes in a file to explain what was done, and many more reasons. This article will explain the basics of commenting code in your website files.

HTML Comments

HTML comments are specifically designed to comment out code when you are in an HTML coded document. Below is the syntax for HTML comments.

HTML comment

<!-- <code to be commented out>  -->

Example of an HTML comment

An Example of a usage of this is shown in the following code.

<html><head>
<title>Document</title> 
</head><body>
<!-- This is a comment -->
<p>A paragraph in your site</p>
<!-- This is code commented out <h1>Commented Title</h1> <p>A paragraph that is commented out.</p> -->
</body></html>

CSS, JavaScript, and PHP Comments

CSS comments are done in the CSS .css stylesheet or in the Internal Style sheet. JavaScript comments can be placed inside HTML documents or in a .js file where JavaScript is ran. PHP code will be in .php files between <?php and ?> code. The following code shows the syntax for commenting out CSS, JavaScript, and PHP code.

Single Line comment

// <code to be commented out>

Multiple Line comment

/* <code to be commented out> <Other code to be commented out> <Some more code to be commented out> */

Example of PHP comment

An Example of a usage of this is shown in the following code. Below is showing PHP code; however, you use the same process to comment JavaScript and CSS.

<html><body> 
<?php   
// This is a comment on one line 
echo '<p>HTML code echoed by PHP.</p>'; /* This is code commented out echo '<h1>An HTML Title from PHP</h1>'; echo '<p>HTML code echoed by PHP.</p>'; */ ?> 
</body></html>

33 thoughts on “How do I comment my HTML, CSS, JavaScript, and PHP code?

  1. I’ve been told that in order to find the code of my faulty website the new dev needs to get it from the server. I would like to kmow whehter this is a fact and whether is a difficult task. Thanks

    1. This depends on the effects of the malware on your website. Server access is one of many options. You could give them a full server backup. If you believe it’s only affected a website, you could share FTP access or a website backup of that website only. I recommend first contacting our Live Support as there are more options depending on your hosting plan.

    1. Thanks for your feedback. Be sure to click the Yes button next to: “Did you find this article helpful?” This helps others in the community quickly locate the most helpful articles!

  2. Thank for information about HTML. It is realy useful for me. HTML coding is helpful in giving some idea.

  3. Awesome!! Just used this to edit some JS.

     

    I had never thought of this until now. Much better solution than deleting code. 

  4. I’ve been told that in order to find the code of my faulty website the new dev needs to get it from the server.  I would like to kmow whehter this is a fact and whether is a difficult task.  Thanks

    1. Hello Lavinia,

      As this question does not relate to the article topic, it has been moved and created as a new question. To maintain topic relevance please only comment on related articles. You can always ask a new question if you cannot find your answer in our article lists.

      Kindest Regards,
      Scott M

Was this article helpful? Join the conversation!