[ANSWERED] Hiding CSS Comments - Link Doesn't Help

For technical support for all editions of CSS HTML Validator. Includes bug reports.
Post Reply
paulp575
Rank IV - Intermediate
Rank IV - Intermediate
Posts: 136
Joined: Tue Aug 09, 2005 1:20 pm
Location: Spokane WA
Contact:

[ANSWERED] Hiding CSS Comments - Link Doesn't Help

Post by paulp575 »

The message for hiding CSS comments in HTML does not lead to a useful page.

Here's the message:
Using a <!-- --> comment to hide CSS from obsolete browsers is not recommended. Visit https://developer.mozilla.org/en-US/doc ... ents#notes for more information.
That page doesn't show any examples of CSS within HTML.

Can you please update with a link to a page that shows not using <!-- and --> to hide CSS comments?

Thanks.
Last edited by paulp575 on Fri Apr 22, 2022 1:14 pm, edited 1 time in total.
paulp575
User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3649
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Hiding CSS Comments - Link Doesn't Help

Post by Albert Wiersch »

HI Paul, I do see that the link may not be very useful. I could not locate a better replacement link, however.

But all you have to do is remove the comment markers... so instead of something like this:

Code: Select all

<style>
<!--
 .classname { color: black; }
-->
</style>
You can use this:

Code: Select all

<style>
 .classname { color: black; }
</style>
As a little history note, webmasters used to do this so that old/obsolete browsers that didn't recognize the "style" element wouldn't render the actually CSS to the page as if it were text to display to the user. But for many years now any decent browser should recognize the "style" element and not render its contents as if it were text for the user to see. It's hard to imagine any browser compiled within the last 20+ years not recognizing the "style" element.

An interesting brief history/timeline of CSS:
https://www.w3.org/Style/CSS20/
paulp575
Rank IV - Intermediate
Rank IV - Intermediate
Posts: 136
Joined: Tue Aug 09, 2005 1:20 pm
Location: Spokane WA
Contact:

Re: Hiding CSS Comments - Link Doesn't Help

Post by paulp575 »

Appreciate the reply.
I knew I only had to remove the <!-- and -->, but was interested in anything else I should know.
Also - should I removed the <!-- and --> from around scripts? Seems like I saw that message when using HTML Validator.

Thanks.
paulp575
User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3649
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Hiding CSS Comments - Link Doesn't Help

Post by Albert Wiersch »

Hello,

Yes, I would also recommend not enclosing scripts in HTML comments. Same principle.

Unless some of your visitors are using 20+ year old browsers. :D
Post Reply