Conditional Comments เป็นฟีเจอร์เฉพาะของ Internet Explorer (IE 5-9) ใช้สำหรับโหลดโค้ด/สไตล์เฉพาะ IE ไม่ส่งผลต่อ browser อื่น
รูปแบบ
<!--[if IE 9]> <link rel="stylesheet" href="ie9.css"> <![endif]-->
เงื่อนไขที่ใช้ได้
| เงื่อนไข | ความหมาย |
|---|---|
IE | ทุกเวอร์ชัน IE |
IE 9 | เฉพาะ IE 9 |
gt IE 8 | มากกว่า IE 8 (IE 9+) |
gte IE 8 | มากกว่าหรือเท่ากับ IE 8 |
lt IE 9 | น้อยกว่า IE 9 |
lte IE 7 | น้อยกว่าหรือเท่ากับ IE 7 |
!IE | ไม่ใช่ IE (browser อื่น) |
ตัวอย่าง
<!DOCTYPE html>
<html>
<head>
<title>HTML Conditional Comments</title>
<!--[if IE 9]>
<style> body { color: red; } </style>
<![endif]-->
</head>
<body>
<p>This is demo content.</p>
</body>
</html>
สถานะปัจจุบัน
IE 10+ และ Edge ไม่รองรับ conditional comments แล้ว ใช้ feature detection (Modernizr) หรือ CSS hacks แทน หากไม่ต้องรองรับ IE เก่า ควรไม่ใช้