Home Snippets Projects Donate

Get Snippets For:

   Java    HTML/CSS JavaScript

HTML and CSS Comments

Code Description:

Comments are used to temporarily prevent code from executing which can aid in debugging or they can be used for creating messages that yourself and other programmers can view within your code file. HTML and CSS both use different comment styles. Unlike most languages such as Java, HTML and CSS do not have a specific syntax for single-line comments. HTML uses "<!-- -->" while CSS uses the more traditional style of "/* */". Both of these can be used on a single line or multiple lines.

HTML Comment Syntax:

<!-- Comment Text -->

CSS Comment Syntax:

/* Comment Text */

Runnable Comment Example Code:

<!DOCTYPE html>
<html>
    <head>
        <title>Comment Example</title>
	   
	<style>
	   
	.heading {
	   
	/* This is a CSS comment that is not executed */
	color: purple;
	  
	}
	   
        </style>
	   
    </head>
 
    <body>
        <!-- This is an HTML comment that is not executed -->
	<h1 class="heading">Example Heading</h1>
	<p>Paragraph Example Text...</p>
    </body>
</html>

How to Run This Code:

Simply paste this code into a plain text file with the ".html" extension and save it. You will then be able to open it in the web browser of your choice.

Output:

HTML and CSS Comments Output Image

Related Links:

Comment Types in Java