Comment a line in HTML

coderlegi0n

CoderLegion

Posted on March 12, 2022

Comment a line in HTML

However the syntax was developed by Microsoft to allow the inclusion of conditional code, HTML or CSS. This is what Microsoft calls "Conditional Comments".

And it gets more complicated. They are only recognized by Internet Explorer, since version 5, but since they are used to adapt the code according to the version of Internet Explorer, the fact that they are ignored by other browsers is irrelevant.

Conditional code
By placing code in a conditional comment, it is made accessible or not to the browser rendering engine depending on the condition.

There are two types of conditional comments, those whose content is ignored by browsers that do not interpret the conditional expression, and those whose content on the contrary will always be taken into account.

Comment whose content should be ignored by other browsers
For Internet Explorer, whether the content is taken into account depends on whether the condition is satisfied.

<! - [if expression ]>
HTML

<! [endif] ->
What other browsers see:

<! - [if expression ]>
HTML
<! [endif] ->
Anything between the opening and closing tags is a comment and should be ignored.

Comment whose content must be taken into account by other browsers
In the case of Internet Explorer, the content will be taken into account only if the condition of the expression is met.

<! [if expression ]>
HTML

<! [endif]>
What other browsers see:

<! [if expression ]>

HTML

<! [endif]>

The opening and closing tags are not part of the HTML standard, they are ignored and therefore the content is taken into account.

HTML, JavaScript, CSS
The content can be any HTML code. It can be CSS code introduced by the

💖 💪 🙅 🚩
coderlegi0n
CoderLegion

Posted on March 12, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related