[html] How to make HTML code inactive with comments

I have some HTML code on a page that I don't want to erase, but make inactive for the short term. How can I make the browser ignore parts of the page in the same way the // works in some programming languages?

This question is related to html xhtml

The answer is


HTML Comments:

<!-- <div> This div will not show </div> -->

See Reference

CSS Comments:

/* This style will not apply */

See Reference

JavaScript Comments:

// This single line JavaScript code will not execute

OR

/*
   The whole block of JavaScript code will not execute
*/

See Reference


Reason of comments:

  1. Comment out elements temporarily rather than removing them, especially if they've been left unfinished.
  2. Write notes or reminders to yourself inside your actual HTML documents.
  3. Create notes for other scripting languages like JavaScript which requires them

HTML Comments

<!-- Everything is invisible  -->

To comment block with nested comments: substitute inner (block) comments from "--" to "++"

<!-- *********************************************************************
     * IMPORTANT: To uncomment section
     *            sub inner comments "++" -> "--" & remove this comment
     *********************************************************************
<head>
   <title>My document's title</title> <++! My document's title ++>
   <link rel=stylesheet href="mydoc.css" type="text/css">
</head>

<body>
<++! My document's important HTML stuff ++>
...
...
...
</body>

*********************************************************************
* IMPORTANT: To uncomment section
*            sub inner comments "++" -> "--" & remove this comment
*********************************************************************
-->

Thus, the outer most comment ignores all "invalid" inner (block) comments.


Just create a multi-line comment around it. When you want it back, just erase the comment tags.

For example, <!-- Stuff to comment out or make inactive -->


Use:

<!-- This is a comment for an HTML page and it will not display in the browser -->

For more information, I think 3 On SGML and HTML may help you.


If you are using Eclipse then the keyboard shortcut is Ctrl + Shift + / to add a group of code. To make a comment line or select the code, right click -> Source -> Add Block Comment.

To remove the block comment, Ctrl + Shift + \ or right click -> Source -> Remove Block comment.