DEV Community

Cover image for Comment a line in HTML
CoderLegion
CoderLegion

Posted on β€’ Edited on β€’ Originally published at kodblems.com

1 1

Comment a line in HTML

πŸŽ‰ Before you dive into this article...

πŸš€ Check out our vibrant new community at CoderLegion.com!

πŸ’‘ Share your knowledge, connect with like-minded developers, and grow together.

πŸ‘‰ Click here to join now!

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

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay