Why âConditional Commentsâ Are Bad, Repeat: Bad
Published on February 1, 2007 (⻠February 5, 2024), filed under Development (RSS feed for all categories).
This and many other posts are also available as a pretty, well-behaved ebook: On Web Development.
This post is not as clear as it could be (and the tone is odd). Please refer to more recent posts on Conditional Comments, most notably To Be Clear (on Conditional Comments and Resets).
âConditional Commentsâ (CC) are inadvisable to use. They contradict the goal of separating structure from presentation, and because of that they will hurt you one day.
But first things first. For those lucky developers who donât know what Conditional Comments are, please see Microsoftâs âspecificationâ or refer to the following code snippet. Itâs an HTML extract showing a comment that contains a link
to a specific IE style sheet.
<!--[if IE 5]>
<link rel="stylesheet" href="ie5.css" type="text/css">
<![endif]-->
Rarely is that the only style sheet included in a document; usually, CC users include their âregularâ style sheets and then one if not more style sheets to address Internet Explorer needs.
Whatâs Wrong With Conditional Comments?
Two things.
-
While Conditional Comments are syntactically valid, they are not standards-compliant: âInformation that appears between comments has no special meaning,â and comments âwill be ignored by the parser.â
(Interestingly, that is exactly where all other implementations except Microsoftâs Internet Explorer are correct: They just ignore comments.)
The standardization process was weak, at best. That is natural for proprietary solutions, and Conditional Comments are no exception. While you think they help you, they will eat you at some point, sinceâŠ
-
Conditional Comments guarantee your HTML to be changed, because they mix to-be-separated structure and presentation.
No matter how you use CC, it will be necessary to adjust the HTML of each and every document or template once you focus on other Internet Explorer versions. This happens even if youâre the most visionary master of web development and thereâs otherwise no need to update the structure of your documents. Remember that you strive for consistent separation of structure and formatting.
Normally, your next redesign would require you to update your style sheetsâeven better, your style sheet, singularâ, but now you entered the lottery and will not only need to maintain additional style sheets, no, youâre likely also forced to update all these IE comment queries.
Itâs easier and also more âpragmaticââif thatâs whatâs desiredâto use the naughtiest (yet valid) CSS hacks and filters and workarounds. At least they live in style sheets, at least they only force you to do work when it comes to one file type.
Tips
Set guardrails and taboos for your work, and these should include âno Conditional Comments.â Communicate that. Explain why they donât help. I know companies where work results are desired (and have already been promised to clients) that you cannot otherwise accomplish, but solve this problem at the root, ask your team members if these results are useful, and instead rely on graceful degradation.
⧠Apologies for this somewhat cluttered guerrilla post, but I wanted to make this point.
Update (February 2, 2007)
For clarification: When I talk about using âthe naughtiest CSS hacks,â I recommend them over Conditional Comments (my IE character escape filter post includes a few notes concerning the use of hacks). Use them scarcely, use them wisely, but donât forget that theyâre a different storyâCSS âhacksâ usually depend on parsing bugs, syntax errors, or missing support for certain spec ingredients, while Conditional Comments have been intentionally created to violate the HTML specification.
Generally, thereâs only one case where Conditional Comments might not become a problem: When youâre a one-man-show whoâs responsible for HTML and CSS maintenance. In other cases, you wonât only force yourself butâworseâteam members to update HTML templates and style sheets, and even work on a file level (removing ie5.css, renaming ie.css, creating ie8b.css). A quick âsearch and replaceâ wonât do when CC changes become necessary.
Donât get lured. Conditional Comments appear safe, they look valid, but thatâs an illusion, and theyâre bad.
About Me
Iâm Jens (long: Jens Oliver Meiert), and Iâm a frontend engineering leader and tech author/publisher. Iâve worked as a technical lead for companies like Google and as an engineering manager for companies like Miro, Iâm a contributor to several web standards, and I write and review books for OâReilly and Frontend Dogma.
I love trying things, not only in web development (and engineering management), but also in other areas like philosophy. Here on meiert.com I share some of my experiences and views. (Please be critical, interpret charitably, and give feedback.)
Comments (Closed)
-
On February 1, 2007, 22:06 CET, David said:
Right on! I hate that these even exist for the same reasons you just stated. We just did a complete re-design at my place of work, where weâve used conditional comments in the past, and I found it very annoying to have to make changes in more than one place. Maintenance nightmares should be avoided at all cost, so why would anyone consider this segregation in the first place?
-
On February 2, 2007, 1:04 CET, Jens Nedal said:
1. Here i find myself pretty much in the same boat. The fact that Conditional Comments (CCs from now on) are not standard compliant is a total minus to the whole procedure. This counts for âsomeâ of the CSS hacks out there as well.
Concerning that only some of the CSS hacks are not compliant puts them in favor for sure.
The fact that when IE browser versions change, some will not be supported is the disadvantage.Although CCs are not compliant, once they are set there is only need to look for changes in newer browsers and add new CSS if needed for that specific version. Everything else remains the same and one has not to worry about updating those very few lines of code saved in the CC specific files, ever. The main stylesheet that is in use should not ever need to be touched, otherwise something is wrong with your structure.
â
2. CSS rendering problems covered by CCs are box model, PNG24 rendering and min-height.
The maintenance is minimal, since it only covers a few select problems, just like CSS hacks do. Structure always remains the same and must not be dictated by IE or any other browser.
Should you need to change structure because of using CCs something is wrong with your structure, meaning you go back to the drawing board!
Otherwise i would have thrown the whole CC idea over board long ago.Personally i would not like to advocate either CCs or CSS hacks, since both have their drawbacks. All i can say is, i know CSS hacks, i grew up with CCs.
â
I donât think this about being a fan of either of the 2, but just about which tool suited the screw best first, before the other tool fell into my hand.
Your other article made me think about the whole thing since bringing up the compliance problem.Concerning the 1st comment in this article: The side factors of how to maintain CSS files and what structure you use is important, though as long as the logic is simple (meaning easy to understand for you and others), what structure you use will not matter. Both CCs and CSS hacks have simple logic.
Knowing how to employ CSS hacks and CCs shows us, that both are basically used for the same type of thing, with different appliance.
What both ways teach though is one thing. DONâT use ANY of them, unless you REALLY have to! Before considering using them, think twice. If you see you are gathering more than a few lines of code in CCs or CSS hacks, something is wrong with your structure and you should reconsider.
My conclusion? None yet. Compliance is important, but what will i do the next time i need to replace a hack and no hack is there to fill in? Maybe i need to learn more about CSS hacks? *goes reading some more*
-
On February 2, 2007, 8:06 CET, Matthias said:
Sorry, but I donât agree with most of you points when you are advising âto use the naughtiest CSS hacks and filters and workarounds that you findâ instead of Conditional Comments (CC).
1. CCs are syntactically valid, they are not standards compliant.
Sure, but how is this an argument for using hacks? Are hacks standards compliant? Even if you say they are (this is question of interpretation what âstandard complianceâ exactly means), they are definitely und unquestionable not valid. What is more important, fulfiling (questionable) the by-letter meaning of a specification document, or prevent causing parsing errors?2. CCs guarantee your HTML to be changed.
No. Why should they? If I give an element a 1% height in a conditional stylesheet to force IE into the âhasLayout = yesâ mode, how does this change my HTML?I took this out of your point 2:
3. Youâre most likely forced to update your clever IE comment queries when thereâs any highly critical security update containing support for âa few more selectorsâ.Is this an arggument against CCs? No, of course not: exactly the same will happen to your hacks, and even more likely: What if the bug that is causing your hack to work is fixed, but the bug the hack should prevent is not, or vice versa? THIS is a much bigger âlotteryâ. In contrast to hacks, CCs can and should be aimed at certain browser versions, so your CC-workaround for IE6 wil never bother IE7. Your hack will.
There is another argument for preferring CCs over hacks: Your CCs will never cause a problem in any Browser that they are not aimed at - can you state the same with a clear conciense about your ânaughty hacksâ? Definitely not.
-
On February 2, 2007, 11:10 CET, Jens Oliver Meiert said:
Thanks for all your comments so far. They prompted me to update the post.
Matthias, please see the update. Regarding 1. and compliance, compliance is defined by the respective specification; and regarding 2., Conditional Comments refer to HTML, as you cannot use them without changing HTML.
-
On February 2, 2007, 12:05 CET, Jens Nedal said:
This is kind of turning into a discussion about work structure ethics, which might be part of the whole approach too, but seriously this cannot be considered as an argument against CCs or for CSS hacks at all.
You might(!) as well argue, that finding CSS hacks in one file will take more time, since you will have to search for the right place in the code. With CCs you just choose the right file, change a few short lines and thats it and donât have to worry about the hundred lines of code in the main file.
Both arguments are unfounded since they only reflect the work ethics of an individual or a team, and bascially you do the same thing. You search/replace. If someoneâs editing skills are not up to doing a fast search/replace in 1 or more files, than one should better reconsider beiing an application developer for anything.
A team has to establish their working ground and all team members have to adhere to that structure, be that using CCs, CSS hacks or whatever other structure.
Should the case arise, that a developer has not touched unto a project yet, it is his responsibility to look and see where all information is gathered and what structure is used.
I agree with your argument to keep things simple, but both approaches are simple.
In a CC scenario there will be a couple more files in a directory which are clearly named. If that is not good for the team, or they canât agree on that structure, then please go forth and use a different one that might include the use of CSS hacks.
Your argument to favor hacks before CCs is to itchy for me. I say, favor none and if you have no choice agree on a procedure with your team and thats it.
Just emphasizing that CCs are âbadâ is like trying to emphasize an argument that apart from the compliance part(!) lacks a ground to support it totally.
Both are on the same boat that can loose its balance anytime when browser vendors upgrade to more compliant CSS rendering. Both are using techniques that can be non-compliant.
About changing HTML: Yes the header is changed obviously, to contain the CCs. Otherwise the structure remains the same.
Your comment about âillusionâ also goes in the direction of using âbadâ. Emphasizing arguments with no ground attached.
Compliance is something that certainly makes me think though. Again i would advocate neither CCs nor CSS hacks!
-
On February 2, 2007, 12:33 CET, Jens Oliver Meiert said:
Jens, I donât want to repeat too much.
The entire topic is about standards compliance (which makes CC a taboo), maintainability (where in most cases CC will be counterproductive), and, ultimately, the âvision of CSS.â
Concerning hacks and maintainability: I just added âyet validâ when it comes hacks, thatâs what I left aside before. Itâs also important to note that itâs in every developerâs responsibility to comment workarounds anyway, to make sure they can easily be removed, modified, or whatever later. (For example, denote an IE-specific declaration with
/* IE */
; the more specific the UA is named, the better.)It will become difficult to argue about the CC problem when we drift towards web development âphilosophy,â expertise, and âsecondary virtuesâ like work organization, structure, and style.
-
On February 2, 2007, 16:38 CET, David said:
Jens Nedal, I strongly disagree with your assumption that all CC work around consist of just âchange a few short lines and thats itâ. At my job our CC style sheets are several hundred lines of CSS. That is beside the point as well. You should always, always, always avoid creating maintenance.
-
On February 2, 2007, 18:08 CET, Jens Nedal said:
Okay, sofar so good. I agree on compliance.
David: If your CCs have more than 100 lines of code, then the whole setup of your structure is wrong. If i were to have more than 10 lines of code in the CC files that we use i would immediately revert to CSS hacks and forget the whole ordeal. Any use of either methods that require you to change more than a few small lines are useless! With the experience you have with CCs i would react no differently.
I think the discussion is on a stalement here and all have made there points. Interesting to read what others think about this and how others work with CSS. Between i have been thinking about getting a copy of your book Jens.
kind regards, Jens
-
On February 5, 2007, 16:26 CET, Nathan Rutman said:
Of course, this largely ignores the most prolific uses for Conditional Comments: targeting old versions of IE that will not easily conform to CSS basics (box models, etc.). With IE7, I find it fairly easy to get my pages to work well between IE7 and other browsers. The problem is with IE5.5-6. There, Conditional Comments donât hold promise for future problems since the parsing rules for IE5.5 or IE6 wonât change. Feed fixed measurements to those browsers, and youâre set!
-
On February 5, 2007, 16:51 CET, Richard Rutter said:
Disregarding workflow for a moment, it would seem to me that I would disagree that CSS hacks are a conditional comments a more reliable way to get around bugs in IE/Win than CSS hacks. CSS hacks inherently rely on a bug to fix a bug, whereas CC rely on a feature to fix a bug.
In terms of reliable use among teams, it is of course advisable to avoid CC or CSS hacks wherever possible, however as we all know life isnât that simple. So where IE-specific workarounds are needed, our workflow is to put those rule in a separate style sheet called via CC and - most importantly - to document the normal style sheet where rules are being overwritten (as is normally the case).
-
On February 5, 2007, 17:43 CET, patrick h. lauke said:
as i always said, conditional comments are browser-specific, proprietary markup masquerading as a harmless comment. the fact that they validate is irrelevantâŠtheyâre just as wrong as adding proprietary *anything* (attributes, elements, etc) to code.
i also donât quite follow the rationale some CC fans peddle: âif a new version comes out, youâll have to find another hackâŠnot so with CCsâ. actually, if a new version comes out, iâd rather wait a few days until a hack surfaces and then change my CSS accordingly, rather than having to futz about with every single piece of HTML. and again, as i said at the time of the â* html is evilâ debate on chris wilsonâs blog: IE developers should stop trying to fix the bugs that enable the hacks, but the actual bugs that force developers to use hacks in the first placeâŠ
-
On February 5, 2007, 17:50 CET, Montoya said:
I have my own reason for avoiding conditional comments which I recently posted on my blog: Why I avoid using conditional comments. Itâs nice to find someone who thinks alike đ
-
On February 5, 2007, 17:53 CET, Barney said:
Iâm glad this view is becoming more widespread. Itâs only recently that people are dropping the long-standing myth that anything other than CCs is intrinsically invalid.
To those who still maintain the latter point of view: CCs only pass automated validation because you are hiding functional markup from the validator in the guise of comments. It is a hypocritical duplicity to boycott invalid CSS while using trickery in HTML, where standardisation is absolutely vital (arguably it is vital to have invalid CSS in order maintain a standard experience accross browsers).
-
On February 5, 2007, 23:35 CET, Anson said:
Totally disagree.
CCâs are much more maintainable in that you centralize your design workarounds in a single file (or potentially a few files if you have highly specific CCs). Relying on bugs in a browserâs rendering engine (i.e. CSS hacks) is a bad, bad practice. As is scattering hacks throughout all your CSS files. Very hard to maintain this.
As others have commented, you have know way of knowing when the bug youâre exploiting for your CSS hack will be patched and how other browsers will deal with it in the future.
Conditional comments are by far the lesser of two evils. Particularly since you can directly target versions of IE and throw these away when IE eventually makes it to standards compliance.
-
On February 6, 2007, 0:35 CET, Jens Oliver Meiert said:
Anson; no. CC collide with everything we strive for, and they are a sleeper maintenance problem. Other than that, all major points should be covered by this thread.
-
On February 6, 2007, 0:41 CET, jonnny_noog said:
I also have to disagree with the main thrust of your post. I am a web developer who generally tries very hard to make sure that the sites I work on do validate and are standards compliant, and yes, it does irk me somewhat to know that CCâs go against the HTML specification⊠But not enough to stop using them.
To me, CSS hacks are more messy, thatâs just my subjective opinion. Iâm not going to rehash all the points for and against that we all already know, but I will point out that even the smallest sites that I build these days make use of includes of some kind, specifically to make it easy on my self when I do have to go in and change a line in the head tag or whatever.
I also have found (as another poster noted, I think) that IE7 tends to be pretty good in my experience so far, I am mainly interested in targeting IE5/5.5/6 with CCâs, and as much as I am no big fan of M$, I do think that if IE7 is any indication, they will move towards a more standards compliant browser with each new release.
I understand the argument for full separation of structure and presentation and how CCâs violate this principle⊠But try explaining this forward thinking principle to a computer illiterate client at 6:45pm on a Friday when their website doesnât look like they think it should in IE and see how much they care.
-
On February 6, 2007, 5:07 CET, Ben Buchanan said:
CCs annoy me because they destroy one of the key advantages of CSS: being able to maintain a whole site by changing the stylesheets. The CC way means you have to go back to the bad old days and edit everything you have, just for one browser.
If they were going to make up a non-standard conditional hack (CCs being a hack dressed up as legitimate code, nothing more), they should at least have done it in the CSS.
-
On February 6, 2007, 11:20 CET, Gerry Quach said:
We only recently started using conditional comments in our sites. Up until then we were using a large variety of CSS hacks.
Iâm now convinced that CSS hacks are not the way to go, and CCs are a necessary evil. CCs are to be avoided where possible, but if not, they provide a consistent and reliable way to fix IE/Win rendering bugs.
Most importantly, I can be confident that CCs will continue to work correctly with all future versions of IE, whereas with CSS hacks this cannot be guaranteed. This is perhaps the most critical advantage of CCs.
Sadly, even IE7 has shown itself to require the occasional CC, in order to fix problems it has with the Son of Suckerfish CSS dropdown menus.
In the future, once IE5/Win and its ilk have dropped into obscurity forever, I can simply take out the CCs from my markup and discard the IE-specific stylesheets, and Iâm done.
-
On February 6, 2007, 16:56 CET, Anthony Cartmell said:
While âConditional Commentsâ are syntactically valid, they are not standards compliant
Yes they are standards compliant. What isnât standards compliant is the way IE uses them. As you point out yourself, all other browsers treat them as perfectly valid and standards-compliant HTML.
I canât believe you prefer to have a single style sheet littered with hacks (that rely on bugs to work!) over a set of style sheets, one for standards-compliant browsers, plus a set of minimal ones, included by conditional comments, adding in overrides for specific IE versions.
With conditional comments, I may have to add another line to my HTML page-top file when a new IE is released, although future CSS fixes will probably mean that I wonât.
With CSS hacks, you have to test every hacked style to see both whether the bug still exists in the new IE and also whether the new IE still needs the style fix. And youâll need to do that every time a new IE is released (and that includes updates!).
CCs only pass automated validation because you are hiding functional markup from the validator in the guise of comments. It is a hypocritical duplicity to boycott invalid CSS while using trickery in HTML, where standardisation is absolutely vital
The stuff in conditional comments is not functional markup, itâs a comment. The fact that IE reads the contents of that comment, allowing you to fix problems with IE, makes no difference to the validity of the HTML.
âInformation that appears between comments has no special meaningâ, and comments âwill be ignored by the parserâ
Exactly. The standards do not say âinformation that appears between comments must have no special meaning, and may not be used by the parserâ, which is I think what the original article tries to suggest.
-
On February 6, 2007, 20:19 CET, pauldwaite said:
While âConditional Commentsâ⊠are not standards compliant
Iâm going to venture a distinction here: Internet Explorerâs recognition of conditional comments as having special meaning is not standards compliant.
As such, I donât see the difference (in purely standards-compliance terms) between conditional comments and CSS hacks. With CSS hacks, youâre taking a non-standards-compliant CSS behaviour, and using it to tackle another non-standards-compliant CSS behaviour.
âConditional Commentsâ guarantee your HTML to be changed
Very true. However, I think youâve overstated a couple of the negative consequences.
youâre most likely forced to update your clever IE comment queries when thereâs any highly critical security update containing support for âa few more selectorsâ.
Internet Explorer has had one update to its rendering engine in 5 years. While weâre all expecting further updates to arrive more quickly, the conduct of the IE team thus far suggests that weâll have a fair bit of warning when they do. Aside from that, the IE team seem to be making great strides towards standards compliance in CSS. As such, it may be that IE 7.5 or 8 has few enough bugs not to require any more special measures. By the time they come along, IE 5 may also be rare enough to drop IE 5-specific stylesheets, thus meaning the number of stylesheets to maintain stays the same.
And, as you say, the changes necessary to include another stylesheet via conditional comments may be nothing more than changing one line in one template file (this would be the situation, for example, for my employerâs ASP.NET web site).
As far as ârenaming ie.cssâ goes, conditional comments are designed to target specfic versions of IE. If youâve got a stylesheet called âie.cssâ, youâre not using conditional comments very well.
Iâm very glad youâve sparked a debate over this. I can certainly understand that some developers may prefer to keep all their CSS inside one stylesheet (or as few stylesheets as possible). I personally prefer to write my stylesheets as if all browsers had a decent level of standards support, and keep the IE-specific rules in their own stylesheets, so that I know exactly how much extra work it is supporting them.
I think this is somewhere where reasonable developers can disagree.
-
On February 6, 2007, 21:35 CET, George said:
Agreed you should try and avoid CCs and hacks if you can but it is a fact of life you will need to use one technique at some point.
For me CCs are far better. Look at the pain that IE7 caused to many who had been hacking away in their main stylesheet.
I agree that neither approach is perfect but CCs are the lesser of two evils for me.
-
On February 6, 2007, 21:59 CET, Darren Wood said:
Maybe Iâm doing it wrong, but my ‘iehacks.cssâ stylesheet (thatâs called from a CC) only has - at most - 10 lines. This is WAY easier than maintaining nastly CSS hacks sprinkled throughout the default.css fileâŠ
Each to their own, I say. We (me the other developers who work on my code) find CCâs the only way forward in terms of getting sites to render semi-correctly in IE. And easy to maintain.
-
On February 7, 2007, 0:20 CET, Paul W said:
Conditional Comments have been intentionally created to violate the HTML specification
I believe they were created to solve a problem Microsoft had (due to bugs in itâs browser).
Information that appears between comments has no special meaning
This is written in the context of explaining SGML and gives the example of character references not being interpreted. After that it says:
Note that comments are markup.
It doesnât say browsers MUST NOT do anything with that markup. BTW, another specification that exploits this ambiguity is Trackback, which I understand to be quite popular, however ugly it might be.
(Your other quote is from the HTML 3 spec. It is out of date. Again, it is general guidance on HTMLâs relationship with SGML and there is no MUST IGNORE type language.)
Saying CCs are not standards compliant is, I think, reading a lot more into these quotes than they explicitly state.
CCs are good because they are future proof. No other browser is going to implement this quirky syntax. They will only ever affect the IE versions you choose to target.
With CSS hacks, no-one can say how they will be interpreted by future browsers.
As to changing your HTML, most (modern?) sites are template driven. Iâve been writing mark-up 6 or 7 years and Iâve never come across a site with more than one header template.
A quick anecdote to illustrate: Iâm currently working on a redesign for an international recruitment site. The IE target was version 6 and above. Once the CSS was done itâs checked in and the website goes through rigorous QA testing on all target browsers. This costs time and money.
Picture my bossâs embarassment when he presents this in the boardroom and it turns out the laptop they have is running IE5. The board is not happy - I have to get this working in IE5. Now if I did that with CSS hacks the whole QA process would have to be repeated for all target browsers, to make sure none of the hacks upset anything.
As it was (and as I prefer to), I used conditional comments. The developer had to include one line in the header template to include a CSS file that contained about 10 lines and the QA testing had to be repeated for one browser.
(Aside: I think some people are under the impression using CCs means you have to maintain a complete duplicate of your default stylesheet. This is not the case; the styles you include via CCs only need to contain the ‘correctionsâ for IE browsers.)
The developer was happy because it was clear what this one line did, he knew it wouldnât affect other browsers, no additional documentation had to be written (as CCs are pretty much self documenting, unlike the voodoo of CSS hacks which I didnât have a spare 2 hours to explain to him) and it wouldnât break the validity of the site.
The boss was happy because the board was happy he didnât have to spend more time and money repeating a process on an already late and over budget project.
To labour the point, CCs do not invalidate your HTML, are easy to maintain, self-documenting, future proof and may even save some time and money đ Can you say that about CSS hacks?
Sorry for the long comment, but I really felt a practical example was needed to illustrate exactly why CCs are safer than relying on parser bugs.
-
On February 7, 2007, 19:23 CET, Mani Sheriar said:
I have to respectfully disagree with the author, although I value his thoughts and appreciate the debate they have sparked.
I only relatively recently began using conditional comments to feed separate style sheets to both ie6 and ie7. Before that I did exactly what this author recommends ⊠relying on valid âhacksâ throughout my one stylesheet (I was a BIG fan of using the !important declaration to feed certain values to the âgoodâ browsers and then override them for ie). This method simply became a total nightmare to maintain. I cannot emphasize this enough. It was completely unmanageable. Even so, I clung to my view that it was better than CCs to the very end!
When I finally âgave upâ and began using CCs I was amazed at how much easier everything was. I wonât go into details, as so many here have already done so (I think comment 26 described it best), but truly, it simplified my coding life immensely.
I have a hard time even beginning to grasp how doing things the way I used to do them could present less of a maintenance headache. However, each to her own.
Thanks for the article.
-
On February 7, 2007, 19:41 CET, Jens Oliver Meiert said:
Mani, I can relate when youâre talking about maintainability problems due to more or less heavy use of
!important
declarationsâyouâre then adding a new dimension which can even make âregularâ style sheets challenging to maintain.I⊠enjoy the discussion. Only a few contributors seem to accept CC as a taboo, only a few seem to have (âvalid,â once again) CSS filters under control (provocative, right). And most of youâre quite optimistic about the future with CC.
-
On February 8, 2007, 14:27 CET, pauldwaite said:
> âI guess we need to talk more about web development goals and philosophy here, garnished with more examples. Sounds good, right?â
Always good đ
-
On February 9, 2007, 14:29 CET, Jon Christopher said:
Iâm really glad that this article sparked a conversation filled with intelligent remarks and opinions.
Respectfully, I too will disagree with the author as well as the other developers who support CSS hacks over CC. First and foremost, if your CC style sheets are 100 lines long, you have some issues that root with your original style sheet, not IE.
I donât want to regurgitate what others have said, but standards compliant browsers treat Conditional Comments as comments and truly ignore themâintended purpose. While including a Conditional Comment does change your HTML, I donât feel itâs doing much different than including your external style sheet.
The most common reaction I read about Conditional Comments is that theyâre bad because theyâre proprietary. While thatâs a valid point, theyâre proprietary in a way that doesnât interfere with more advanced products. Theyâre proprietary in that theyâre a crutch for an inferior product, and the developer of that product knows it. All of the troubles you have with Conditional Comments (maintenance, etc.) are exactly the same problems youâll have with hacks in that youâre still doing the same ‘workâ, just in a different way. With Conditional Comments, however, youâre able to know exactly what to edit. Theoretically, providing conditional comments should decrease the time needed for maintenance in that youâre able to target specific versions of IE and there are no overlapping hacks to deal with.
Again, the major issue that struck me was that some CC style sheets are ~100 lines long. That is missing the point of Conditional Comments. These style sheets should be quite small in nature (throwing out a number, mine are usually about 4-10) and easy to maintain. Weâll always have to test in each browser, and there will be times where there are single browser issues that need attention.
I think the true issue for me is the scope of hacks versus the scope of Conditional Comments. Hacks do what they do because every browser processes them, and the ‘goodâ browsers render as expected, and youâre taking advantage of the many shortcomings of an inferior product in other cases. The latter is, in my opinion, an extremely unstable method to work in, and in essence harms the longevity of your styles and site as a whole.
As far as standards compliance, Iâm not sure why people feel Conditional Comments are not compliant. IE isnât standards compliant, and itâs the only browser which does a thing with Conditional Comments. I fail to see how this one instance of IE not being standards compliant is having an affect on the general perception of leaving CSS hacks in the past. Just because hacks are valid doesnât give anybody the green light to use them, the same goes for (X)HTML. A document can be constructed with completely valid markup, but if the markup doesnât make any sense, the document has lost much of itâs worth. Personally I feel the same idea is pushed upon style sheets.
I look forward to keeping up with this conversation, thanks to the author and all of the intelligent people who took the time to post their thoughts.
-
On February 11, 2007, 13:33 CET, Jordan Clark said:
Although I do agree with you in principle, I think that if you have to use hacks, CCs are useful for isolating the workarounds.
Users of ‘goodâ browsers get a faster download, and when older versions of IE (hopefully!) die out you can delete the hacks in one fowl swoop.
I currently use a CC on my personal web site, but I am hoping to phase it out soon. -
On February 13, 2007, 0:46 CET, Colin Lieberman said:
I have to agree with Matthias and John CristopherâJens, I think you are mistaken.
Conditional comments are almost a god-send: the manufacturer of the most problematic browser gave us a way to specifically target versions of that browser, with no fear of bungging anything up for other browsers. This is great.
CSS hacks are exactly that, hacks. We donât know how reliable theyâll be in future versions or in browsers we never think about.
Conditional Comments let us cut right to the problem - if this is IE with a version less than 7, do such-and-such.
As to your other criticism - in what way are they not standards compliant? If the standard says âignore all the jazz in commentsâ, and all the browsers except IE do this, then itâs a win-win situation.
The correct criticism should be âIE does not parse comments correctly.â Thatâs IEâs problem, not ours. If they fix it in IE8, the guess what, it will ignore conditional comments, which is exactly what weâd want to happen anyway.
As for making life difficult for a development team, I can assure you just the opposite is the case. I work in 3-man development team. Good source control (which should be part of any serious development effort) makes updating code among the team a no-brainer. As for conditional comments specifically, Iâd rather explain to a new team member âall the IE7 stuff is in ie7_main.css, and IE7 pulls that in via a conditional commentâ than âthat * html hack is supposed to get IE 6 and belowâ.
Maybe I donât fully understand your arguments, because I just donât see what damage conditional comments do.
-
On February 21, 2007, 12:34 CET, Destry Wion said:
Jens,
First, I can appreciate this kind of discussion, glad to finally see it (though I think itâs about 8 years too late). I am in the camp where I see hacks or CCs alike being something to avoid whenever possible.
However, I personally would go with a CC over a classic hack anytime to isolate a few lines of CSS to make something work in an old version of IE; doing so with the happiness of knowing that in the near future I drop both the CC and the associated file in 30 seconds of work. Not too tough.
You seem to have an agenda against CCs beyond just discussing their utility or not, like they are a cancer in the markup that can only be bad. Contrarily, they might be considered more a sterilized nano-robot in that same body, having a specific task to do. When the task is finished, the robot is removed and the body is right as rain. Nothing wrong with that.
There are no rules, only ârecommendationsâ from the W3C. If the W3C said donât use CCs, that might hold more weight in the grand scheme of thingsâŠbut they donât. Truth is, CCs, however you want to paint them, are a viable way to treat a viable problem without interfering with oneâs aims at improving compliance everywhere else.
Peter Paul Koch suggests CCs are one of the only three safe (sure to work unfailingly over time) hacks to count on. I tend to agree there.
Also, CCs are handy for flexy-widths, which in turn are a great way to deal with horizontal scrolling issues without fixed widths of 750px or long lines of text in 17″+ monitors. This is mostly what I use them for, as do other folks like Roger Johansson, a true standards evangelist.
In any case, they shouldnât be necessary for very long, by indication of IE7âs fast adoption rate and the already anticipated next release of IE. In that light the entire issue is rather pointless because 5, 5.5, and maybe even 6 will be toast when the next IE comes out (I know, I know, but thatâs another issue people). Folks can then drop their CCs for those browsers, and with any luck, wonât be needed anymore. đ
Itâs a time thing, man. If we take sensible steps to deal with problems in potentially low-maintenance ways without really bucking the long-term goal (full compliance) then thereâs no need to grab pitchforks and torches.
My two cents, respectfully.
-
On March 8, 2007, 9:44 CET, Craig said:
Itâs great to find people who have the same opinion as me! Conditional comments are just another way of browser sniffing. Iâd hoped the industry had abandoned that 5/6 years ago.
Itâs far better to have one stylesheet that works in all browsers. End of story!
-
On March 15, 2007, 21:56 CET, Dennis said:
I respectfully disagree with your article. Iâd tend to say âusing IE is bad, repeat: badâ. The IE browser itself is the reason we developers must use Conditional Comments in the first place since it doesnât adhere to standards as Microsoft makes up its own rules.
-
On April 3, 2007, 22:00 CEST, Dan said:
I rather like the CCs. I was going nuts trying to get a site done for my church, and was not surprised when it rendered poorly in IE6 but looked fab in FF2. The CSS and HTML (strict dtd) validated. This SHOULD be the point when the developer can say the project is completeâŠbut alas IE was mocking me and putting my floating divs where it thought they looked better in the overall design.
A quick CC and some minimal css on my ie6 stylesheet put it back in its proper place. I agree with jonnny_noog and his 6:45 pm commentâŠtoo true.
-
On April 4, 2007, 3:09 CEST, Dan said:
I actually disagree with this quite a bit. I think theyâre a much more elegant way to take care of things. Itâs only a little extra markup in the head (which probably shouldnât be considered such a harsh violation of the structure/presentation rule). Most of the hacks are pretty ugly and cumbersome, and they always leave me a little nervous that theyâll be misinterpreted by a particular browser. And finally, I mean, 80% of the hacks are for IE in the first place! Furthermore, as MS releases newer versions the hacks are being ignored and layouts are breaking. Itâs a nightmare to keep up with it. I say use conditional comments. Actually, if youâre familiar with Facebook⊠Their site is rock solid, XHTML strict, amaaazing work⊠They use conditionals which I thought was pretty coolâŠ..
-
On April 16, 2007, 9:07 CEST, Nils said:
Now you got me courious. What are all those people with those long iehack.css putting in there? Mine usually arenât longer than about 10 lines.
Are you adapting size information? IE does render em a little differently. I really would like to now, as most people commenting here do seem to know what thea are doing.
Anyway, I think we all can aggree on IE being the real problem here đ
-
On April 16, 2007, 20:06 CEST, Elijah said:
CCâs are a way of exploiting a feature rather than a flaw. CSS hacks are exploiting flaws. They will break as technology evolves. No question about it.
CCâs are a feature, and as such, are more âvalidâ than CSS hacks in the fantasy-land of abstraction so many web developers live in.
The arguments about CCâs not being âstandards compliantâ sound like lawyerâs arguments to me. What does it really matter? No meaning? What about a comment I write to myself? It has meaning. Why have comments at all if they are meaningless?
And one last question: what in the world⊠in all the universe (aside from interpretations of spec verbiage) is the harm in having a comment that means something? Youâd think the W3c was a religious organization the way people behave about this stuff.
-
On September 2, 2007, 15:14 CEST, René said:
Hm, i agree in parts with you Jens.
If possible iâll avoid the usage of CCs but sometimes, working on projects for some agencies with their own creative artists, it becomes a problem, that other browsers didnât have a same solution like Microsoft with CCs.What if a style definition works well in FF but only in Windows. If you visit the site with a Mac it becomes a terrible desaster because of one damn pixel. Wouldnât be great if we could say â if FF mac, do this, else do anything what iâve defined before? Same thing⊠iâve found a damn bug between FF 1.0.4 and the latest Version. The old one didnât renders some things like the new one and we donât have any possibilities to handle that.
And no, there is no problem in my styles or my markup.
Another prob⊠safari⊠because of the different behaviour, e.g. os-dependent rendering of buttons, textareas and input fields iâve to find a solution only to fix this only browser. The hacks iâve used where valid as the w3c validator said. But they kill Firefoxâ debugger.
Wouldnât it be great if we could present all users the same layout?
For me CCs are only a solution to keep older browsers as long users using them. I hate those badges⊠âsorry, your are using Browser X but we only support Browser Yâ.
If the w3c would recommend conditional comments no one would ask about the usageâŠ
Thanks,
René -
On October 19, 2007, 1:29 CEST, Patrick Garies said:
While âConditional Commentsâ are syntactically valid, they are not standards compliant: Information that appears between comments has no special meaning, and comments will be ignored by the parser (old, but sufficient reference).
Conditional comments are not a compliance issue for the author; the compliance issue lies with the user agent (i.e., Internet Explorer). Consider them a convenient exploit (i.e.., âhackâ).
As long as a document works properly and is compliant in a standardsâcompliant browser when the CCs are removed, I donât see what makes them any more wrong than use of CSS exploits since CSS exploits also exploit lack of user agent compliance.
CCs can also mean a better experience for the user since, when you externalize all of that proprietary stuff, standardsâcompliant browsers donât have to download and read it. You can also do this in reverse with soâcalled âdownâlevel revealedâ CCs to speed things up for Internet Explorer users. This means that pages load faster, particularly for dialâup users, the server has less strain placed upon it, and scripts can be executed with less overhead.
Issue 2:
Conditional comments only hurt maintainability if youâre using
[if IE]
with no references to version numbers. Unless Microsoft applies a nonâsecurity patch that affects coding language support without changing the version number, I donât think that this will be much of an issue.Itâs true that you would probably have to add more CCs in the future, but at that point, you can decide to take the trouble (at which point youâve decided that the trouble is worth your time) or you can decide to move to CSS exploits if adding more CCs is too much trouble.
-
On November 20, 2007, 23:59 CET, Richard Jones said:
I have to say that I find CC very useful and a good method to aid learning how different versions of IE work (or fail).
I like to keep as perfect a stylesheet as possible. Well ordered and well commented. I would hate to have to go back to two years ago and to start littering my stylesheets with hacks for the abomination that is IE6 (and lower).
So using one CC I make one IE stylesheet that is pointed at all IEs which contain any hacks required. Usually only a couple for IE7 and the rest are generally just ‘height: 1%;â hasLayout fixes for the others. I then know that everything in the main stylesheet is perfect for proper browsers.
When a new IE version comes out and Iâm testing and therefore learning about this version, I have already separated/hidden all the ugly hacks from this version. I can then see what this version fails to render properly and fix, either by adding new hacks to the IE stylesheet, or (hopefully not) adding another CC just for that version.
This seems to work perfectly for me and maintenance is minimal. If I do have to fix the CC in the HTML, I only have to do it once as I always use server-side includes.
But if there was a way to not use CCs whilst still achieving the above, Iâd use that in a second. The CC in the head is just another reminder of one of the banes of my life.
-
On December 5, 2007, 1:07 CET, minimal design said:
I think you misunderstand the use of conditional comments. You donât need to âmaintainâ them separately from your main css files. You should use them to load CSS files AFTER the main CSS. That way, you just address the few IE specific caveats like box model, PNG transparency, etc⊠Itâs pretty much the equivalent of keeping all your hacks grouped and isolated from your clean Standards compliant css code. In my personal experience, this makes it a lot easier to read CSS files and therefor a lot faster to update/modify.
And adding an extra call to an external CSS file doesnât mean youâre changing the structure of your HTML document. When talking about separation of presentation and structure/content, people refer to whatâs inside the body, not in the header.
Your claim that the IE specific CSS file will need to be updated when IE will âsupport for a few more selectorsâ makes no sense for 2 reasons: #1 everyone knows how often IE CSS support is updated⊠#2 youâd have to update your hacks just the same way if that were to happen. Only, with conditional comments, youâd find the lines to edit much faster than looking for hacks intermingled in your general CSS⊠AND you can target specific IE versions much more easily than with hacks.
I donât know what you mean by the âstandardization process was weakâ since those conditional comments are by definition not standard⊠thereâs useful only for IE and work very reliably in IEâŠ
Lastly, setting âtaboosâ makes no business sense when you work for real clients with real money. And *promising* that following your advice will make me âhappy one dayâ is both patronizing and devoid of any practical justification.
-
On December 9, 2007, 18:40 CET, Callum said:
I really am confused at how you can consider CCs a maintenance problem. Here is the big problem with hacks: when you write a hack for one browser, you might adversely affect another.
I always have three stylesheets: one âmain.cssâ for all browsers, then an extra one each for IE6 and IE7âjust a few lines to address specific problems in these browsers. Like this:
<link rel="stylesheet" type="text/css" href="main.css" />
<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="ie6.css" />
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="ie7.css" />
<![endif]-->
Itâs great; if I spot something not working properly in IE6, I just make a change to the IE6 stylesheet. I know that the changes I make will only affect IE6âthey definitely wonât harm IE7, Firefox, or any other browser. If I tried to do it with a hack, I would have to test in every browser to ensure that the hack hasnât caused problems. (I used to do this, and I sometimes ended up creating a hack for another browser to address the problem that the first hack caused⊠crazy.)
Even worse, hacks might even cause problems for browsers that havenât even been released yet! What happens if a new version of a browser comes out, and it chokes on a CSS hack? Using hacks means that, to be absolutely safe, I have to revisit every website Iâve ever made whenever a new browser version is released.
Also, how can you say that CCs are not standards compliant? They are. They are comments, and comments are fine. The fact that IE reads these comments and acts on them means that IE is not standards compliant. It doesnât mean my code is not standards compliant.
And what about this:
âSurely depending on the way you use CC, it will be necessary to adjust the HTML of each and every document or template once you focus on other Internet Explorer versionsâ
Why?
You also said âstick to graceful degradationâ. How do CCs impact upon graceful degradation?
Iâm sorry, but I think this post is very wrong, and I think you should consider revising your bizarre view that âConditional Comments appear safe, they apparently validate, but thatâs an illusion, and theyâre bad.â No, itâs not an illusion: they are safe (they are guaranteed to only affect one browser, unlike hacks); and they do validate (no âapparentlyâ about it).
Hacks are bad. Hacks are not standards compliant. Hacks are difficult to keep track of.
Conditional comments are completely harmless and very convenient. Please consider admitting you were wrong.
-
On December 16, 2007, 9:16 CET, Wes said:
This discussion smacks of the tables vs. CSS debates of yore. Donât bat for the wrong team this go around Jens.
Internet Explorer is in need of correctional CSS. You seem to have realized this. Youâre exasperation over this simple solution is therefore baffling.
Hacks are so named for a reason. As you yourself put it:
CSS âhacksâ usually depend on parsing bugs, syntax errors, or just missing support for certain spec ingredientsâŠ
Has it occurred to you that browser manufacturers have, and will continue to, correct bugs in their software?
The underscore or slash hacks, for instance, are liable to be patched. Iâd like to hear you explain the merits of hacks vs. conditional comments to an angry customer on that occassion. Or perhaps your customers are the sort that donât care about their websites.
So far as them being unmaintainable, your argument is poor at best. When IE8 comes out it will (hopefully) have better CSS support than ever. Since my sites have no IE8 specific sheet, it will be served the same valid, well-tested CSS the other blokes get. In all likelihood everything will continue working without a single change. If theyâve corrected any of the infamous parser bugs you rely on, however, youâre stuck updating every stylesheet you put your dirty hands on.
On the off-chance I need to introduce a new IE stylesheet, a global find/replace for </head> should do the job in a wink.
Some of us have work to do. Some of us donât have time to change hundreds of stylesheets after inconsequential browser patches. Some of us have customers who donât tolerate sloppy hacks, invalid CSS, or broken websites.
To be frank: your own inability to create an understandable and maintainable stylesheet hierarchy with conditional comments is a poor argument against them. Used correctly they are a tool to keep your standards-compliant CSS (and developers) neatly seperated from ugly hacks.
-
On December 16, 2007, 9:28 CET, Wes said:
Also, of great importance:
The behaviour of conditional comments is understandable and intuitive to another developer. If IE 5, do this. Not so for hacks. Whatâs this !@#$%^&*()_-+=/?.,|[]{;:_background: red; rule do? Why, it makes the background red in IE only! No really—it does. Somehow this is easier to document and maintain in a collaborative setting?
-
On December 16, 2007, 12:31 CET, Jens Oliver Meiert said:
your own inability to create an understandable and maintainable stylesheet hierarchy with conditional comments is a poor argument against them. Used correctly they are a tool to keep your standards-compliant CSS (and developers) neatly seperated from ugly hacks.
That I recommend hacks over CC does not mean that I recommend hacks.
-
On December 17, 2007, 20:30 CET, Joe R said:
I think your logic is lacking. I see no problem with developing a main stylesheet that works in all browsers, and any minor defects that you canât correct for IE within that main stylesheet you can just add to a small secondary stylesheet put inside a CC. That way you donât have 2 20k css files, you have 1 20k and 1 >1k css file. And your css files WILL validate!
-
On December 28, 2007, 1:05 CET, Dieter said:
The necessity of âConditional Commentsâ is the result of bugs from the IE.
My point of view: CC are better than using bugs to solve bugs from the IE.
The best is: Both are from Microsoft and you can use CC to blame Microsoft like I do. You can use CC not only to hide CSS. You can also use them to hide HTML for other browsers than IE. For example: Only if you visit my website dieter-welzel.de with an IE you will see my commendation to change the browser.
I think everybody should also use CC in this way. đ
-
On March 5, 2008, 1:27 CET, Brian said:
Conditional comments are guaranteed to continue working in the future the same way they work now. They are safe for this reason.
Hacks, on the other hand, have no such guarantee (or even a mild expectation); their future behaviour is completely undefined. That hack you use today WILL break (and unpredictably so) in some future browser. They are UNSAFE for this reason.
This simple and unavoidable fact completely trumps idealistic notions about absolute standards compliance.
Jens wrote: âdepending on the way you use CC, it will be necessary to adjust the HTML of each and every documentâ.
First, why would this be NECESSARY? CCs target existing browsers (ie, that will not change), so CCs can be safely left in place indefinitely with no ill effects regardless of what browsers come out in the future. The same cannot be said for hacks.
Second, even if you DID need to âadjust the HTML of each and every documentâ, so what? The same problem exists when you have to update the copyright year, or add a menu item, or update ANY common site element. This is just part of a web developerâs job, and why sites are generally built using templates or includes, so you just make your change in a single spot.
In my designs, I strive for a single stylesheet, using techniques that work the same in all browsers, and am successful on about 80-90% of my sites. The rest of the time I am able to use CCs to cleanly target specific IE bugs (generally IE6) with only a handful of additional rules. This is very easy to maintain.
People who have âhundreds of linesâ in conditional sheets are obviously going to have maintenance issues; my advice to such people would be to focus on your global stylesheet more, getting it as close as possible in all browsers before adding any needed conditional tweaks.
-
On March 5, 2008, 11:05 CET, Jens Oliver Meiert said:
This discussion has been quite interesting, passionate for sure, but there have been no new arguments for a while now, and so I close it. You may want to check out the equally⊠provoking âfive questions for CC usersâ follow-up until I write something more⊠non-controversial.
Read More
Maybe of interest to you, too:
- Next: Word Division: On âword-break,â Soft Hyphens, and Zero-Width Spaces
- Previous: QA: On Errors, and Why Paying for Errors Pays Off
- More under Development
- More from 2007
- Most popular posts
Looking for a way to comment? Comments have been disabled, unfortunately.
Get a good look at web development? Try WebGlossary.infoâand The Web Development Glossary 3K. With explanations and definitions for thousands of terms of web development, web design, and related fields, building on Wikipedia as well as MDN Web Docs. Available at Apple Books, Kobo, Google Play Books, and Leanpub.