HTML comments
1. HTML comments stop the HTML code written within it, form being processed while displaying an HTML document in the browser.
2. HTML comments start with "<!--" and end with "-->".
3. HTML comments can be placed anywhere in an HTML document. But our suggestions is , do not place it before DOCTYPE.
4. HTML comment can not be nested, i.e. a comment can not hold another comment within it.
Pictorial presentation of HTML comment
HTML page with some HTML comment
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>An example with HTML elements</title>
</head>
<body>
<h1>HTML tutorials - w3resource.com</h1>
<p>HTML Elements are key components of an HTML document</p>
<p><a href="/html/HTML-tutorials.php">Start learning HTML</a></p>
<!--<img src="html-comment.gif" alt="HTMLcomment" />-->
<h3>Write to us</h3>
<form name="demo" action="">
Name: <input type="text"><br><br>
email:
<input type="text"><br><br>
Remarks:<br>
<textarea rows="10" cols="4">
</textarea><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Result
HTML tutorials - w3resource.com
HTML Elements are key components of an HTML document
Start learning HTMLWrite to us
If you view this HTML comment example in a separate browser window, you will find that the commented code is not being displayed.
Conditional comments
Description of Conditional comments
1. Conditional comments are conditional statements to hide or provide HTML source code from Internet Explorer.
2. There are two types of conditional comments - downlevel-hidden - which is used to hide HTML source and downlevel-revealed which is used to reveal HTML source code in Internet Explorer.
Syntax of Conditional comments
Type | Syntax |
---|---|
downlevel-hidden | <!--[if expression]> HTML Code<![endif]--> |
downlevel-revealed | <![if expression]> HTML Code <![endif]> |
Operators used in conditional comments
Operators | Description |
---|---|
! | NOT operator |
lt | Less than |
lte | Less than equal to |
gt | Greater than |
gte | Greater than equal to |
( ) | Subexpression, i.e to construct a condition within a condition |
& | AND operator |
| | OR operator |
Example of conditional comment (downlevel hidden)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example of conditional comment (downlevel hidden)</title>
</head>
<body>
<h1>We are learning conditional comment</h1>
<!--[if lte IE 8]>
<link href="ie8only.css" rel="stylesheet">
<![endif]-->
</body>
</html>
View the example of conditional comment (downlevel hidden) in browser.
Example of conditional comment (downlevel revealed)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example of conditional comment (downlevel revealed)</title>
</head>
<body>
<h1>We are learning conditional comment</h1>
<![if !IE]>
<p>You can see this if your borwser is not IE </p>
<![endif]>
</body>
</html>
View the example of conditional comment (downlevel revealed) in browser.
Previous: HTML width attribute
Next:
DOCTYPE HTML 4.01 tutorial
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/html/HTML-comments.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics