how to write comment in correct way - html

How to write comments in an (x)HTML file? just using <!-- comment -->?
Is it correct also?: <!-"-" comment "-"->?
Any other methods to put a comment in code? (because some editors filter <!-- --> comments).

This is the correct and only way for HTML and XML:
<!-- comment -->
Your other example is not valid.

The only valid type of (x)HTML comment is <!-- -->.

Related

what is the tag for html comment?

what is the tag to insert a comment in html?
<!--comment--> or <!comment!>
Both the above tags are performing the task of a comment(that it is not executed in to the output)but what is the correct tag to insert a comment in html?
Universally, <!-- comment --> is being used.
Browser converts <!comment!> tag to <!--comment!-->, but other than that, i do not know what is so special about <!comment!> tag.
You can also use <comment> tag for comments.
<!-- Comments Added Here -->
You can use the above format to add the comments inside the HTML pages
<!-- comment -->
is the proper syntax. You can check W3Schools documentation for reference
W3C Comments
The "!" syntax is reserved for declarations such as "<!DOCTYPE..." and not for comments.
see: What is the correct way to declare an HTML5 Doctype.
You can use like : <!-- Comment -->
Its like this <!-- comment -->
Check out this link for further explanation

HTML comment missing symmetry

In HTML we usually do comments alike:
<!-- Comment here -->
Why is the comment not symmetrical as in:
<!-- Comment here --!>
I'm looking for the historical answer.
Please look into HTML 2.0 RFC
here's and interesting part:
To include comments in an HTML document, use a comment declaration. A
comment declaration consists of <!' followed by zero or more comments followed by >'. Each comment starts with --' and includes all text up to and including the next occurrence of --'. In a
comment declaration, white space is allowed after each comment, but
not before the first comment. The entire comment declaration is
ignored.
NOTE - Some historical HTML implementations incorrectly consider
any `>' character to be the termination of a comment.
For example:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HEAD>
<TITLE>HTML Comment Example</TITLE>
<!-- Id: html-sgml.sgm,v 1.5 1995/05/26 21:29:50 connolly Exp -->
<!-- another -- -- comment -->
<!>
</HEAD>
<BODY>
<p> <!- not a comment, just regular old data characters ->
Simply put, it's because it's derived from SGML where that used to be the standard
From sitepoint:
The HTML comment looks like this: . It’s derived from SGML, which starts with an <! and ends with an >
This page has quite some information about the history of HTML and SGML

Comments: How to comment -- or -->

How shall I properly write --> or --> within a comment?
I am maintaining a large html-file with many tiny entries of program code. Say:
a --> b.
which I encode in HTML as -->:
a --> b.
However, from time to time, I change an entry and want to comment out the old entry. (Yes, I do have version control in addition to that.) But when I then write
<!-- a --> b -->
the validator barfs. Indicating that I "forgot" a closing >.
Is this actually an error or just some overcautious warning?
Are there established ways how to "escape" within comments?
You could use a CDATA block to tell the parser to ignore the comment.
<![CDATA[ a --> b ]]>
It's not quite as nice looking as a comment, but it should pass a validator.

JSP comment is called hide comment whereas html comment is called output comment

I'm preparing for an interview so while reading some questions I found that the "JSP comment is called hide comment whereas html comment is called output comment". And the answer says that if we try to view source in JSP, the comments will not be shown whereas in HTML, it will be shown.
But I'm able to see the comment in the view source section.
Can anybody clear this doubt?
Thanks in advance.
There are two types of comments are allowed in the JSP. These are hidden and output comments. A hidden comments does not appear in the generated output in the html, while output comments appear in the generated output.
Example of hidden comment:
<%-- This is hidden comment --%>
Example of output comment:
<!-- This is output comment -->
Well, technically if you use a typical JSP comments , like
<%-- This is a comment --%>
, and do a veiw source , you wont see it on the client side , if you however do an HTML style comment
<!-- This is a comment -->
, you can see view source and see that on the client side . needless to say , you can comment like the normal java style too , inside the jsp tags . hope it helps .
Html comments don't prevent jsp from evaluating values
<!-- <%! int x = 0; %> -->
This line will declare x variable.

HTML Comments Clarification

Can I use /* */ comment tags in html .
If not why because they are common for comments ?
No you cannot. You can use <!-- -->
As to the second part of the question, I can't really help you there :)
EDIT - Just realized that /* */ wouldn't be tags at all, which would make sense as to why you can't use them,
No, you can't, because the specification says so:
HTML comments have the following syntax:
<!-- this is a comment --> <!-- and so is this one,
which occupies more than one line -->
White space is not permitted between the markup declaration open
delimiter(""). A common error is to include a
string of hyphens ("---") within a comment. Authors should avoid
putting two or more adjacent hyphens inside comments.
Information that appears between comments has no special meaning
(e.g., character references are not interpreted as such).
Note that comments are markup.
That last line tells you why you can't use /* */ - because HTML comments are markup too, just like any other tag, and those "universal comments" would not be tags.
You need to use:
<!-- A Comment -->
in HTMl as far as I'm aware.
/*
*/
is not universal, although it is common for block comments