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>
        <title>Comment Example</title>
	.heading {
	/* This is a CSS comment that is not executed */
	color: purple;
        <!-- This is an HTML comment that is not executed -->
	<h1 class="heading">Example Heading</h1>
	<p>Paragraph Example Text...</p>

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.


HTML and CSS Comments Output Image

Related Links:

Comment Types in Java