Written by Philip
|
< Previous
|
Next >
|
|---|
Comments in HTML code are important. HTML Commenting is very much recommended as if you come back to your HTML code in the future you will be able to tell what each part of your HTML Code is doing; The better commented it is, the easier it will be for you to pick up again.
HTML Comments are not displayed in the users web browser. Therefore the user is not able to view the comments, unless they view the page source.
It is also advisable to use comments when working in any development team, as then any member of your team will hopefully be able to see what HTML you’ve developed, and what each part of the HTML on the web page is displaying. Also if you’re on holiday it’s helpful too!
To place HTML Comments in your code all you have to do is place <!— Which is the opening tag, and --> which is the closing tag, around any piece of HTML to make it into a comment.
<html>
<body>
<p>I am not commented out, so I can be seen by everyone!</p>
<!--<p>I am a commented out piece of code, therefore the user will not be able to see me.</p>-->
</body>
</html>
Something to note is that you can even place comments around other tags to ‘comment out’ the tag. Ie. You can place it around an image to comment out the image from the page. This may help you when developing as you will not have to maintain two files ; one with the page, and one with HTML tags from that page that you may or may not want to take out!
Example of Commenting out an image:
<html>
<body>
<img src="/images/stories/tryit2.jpg" alt="Try It Image" />
<p>This image is NOT commented out, so it can be seen by everyone!</p>
<!--<img src="/images/stories/tryit2.jpg" alt="Try It Image" />-->
<p>This image is commented out, therefore the user will not be able to see it.</p>
</body>
</html>
| Related Articles |
| Firefox View Page Source |
| Google Chrome View Page Source |
| Internet Explorer View Page Source |
|
< Previous
|
Next >
|
|---|