條件式註解是 IE 獨有的機制,能讓某段內容只被特定版本的 IE 讀取,其他瀏覽器則視之為普通註解而忽略。寫法以 <!--[if 條件]> 開始、<![endif]--> 結束。
<!--[if !IE]><!--> 除 IE 外都可識別 <!--<![endif]-->
<!--[if IE]> 所有的 IE 可識別 <![endif]-->
<!--[if IE 5.0]> 只有 IE5.0 可識別 <![endif]-->
<!--[if IE 5]> IE5.0 與 IE5.5 可識別 <![endif]-->
<!--[if gt IE 5.0]> IE5.0 以上可識別 <![endif]-->
<!--[if lt IE 6]> IE6 以下可識別 <![endif]-->
<!--[if IE 6]> this is ie6 <![endif]-->
<!--[if gt IE 6]> IE6 以上可識別 <![endif]-->
<!--[if lt IE 7]> IE7 以下可識別 <![endif]-->
<!--[if IE 7]> this is ie7 <![endif]-->
<!--[if gt IE 7]> IE7 以上可識別 <![endif]-->
<!--[if lt IE 8]> IE8 以下可識別 <![endif]-->
<!--[if IE 8]> this is ie8 <![endif]-->
<!--[if gt IE 8]> IE8 以上可識別 <![endif]-->
<!--[if lt IE 9]> IE9 以下可識別 <![endif]-->
<!--[if IE 9]> this is ie9 <![endif]-->
IE:指定版本(含)以上。lt:less than,小於。gt:greater than,大於。!:not,排除。5.0 或 5,前者只比對該完整版本,後者會涵蓋同主版本的各個小版本(如 5 涵蓋 5.0 與 5.5)。實務上最常見的是替 IE 單獨掛一份樣式表,讓主樣式保持乾淨:
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="ie.css" />
<![endif]-->
需要提醒的是, IE10 之後已完全不再支援條件式註解,因此這套語法只在維護舊世代網站時才有意義;新專案請改用特性偵測(如 Modernizr)或標準化的 CSS 寫法來處理差異。