下表整理主流瀏覽器對 CSS2.1 與 CSS3 選擇器的支援情況(資料基於歷史版本,現代瀏覽器已全面支援)。綠色 = 完整支援,黃色 = 部分/有 Bug,紅色 = 不支援。
| 選擇器 | 模式 | IE6 | IE7 | IE8 | IE9+ | Firefox 3+ | Safari 3+ | Chrome 5+ | Opera 9.6+ |
|---|---|---|---|---|---|---|---|---|---|
| 通用選擇器 | * | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 子代選擇器 | E > F | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 相鄰兄弟選擇器 | E + F | ❌ | ✅1 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 屬性選擇器 | E[attr] | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 屬性值完全匹配 | E[attr="val"] | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 屬性值包含單詞 | E[attr~="val"] | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 偽類 :first-child | E:first-child | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 偽類 :hover (非 a) | E:hover | ⚠️2 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 偽類 :focus | E:focus | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 偽元素 :before/:after | E:before | ❌ | ❌ | ✅3 | ✅ | ✅ | ✅ | ✅ | ✅ |
1 IE7 若註釋位於元素間可能失效。
2 IE6 僅支援 a:hover。
3 IE8 偽元素需雙冒號 ::before 不支援,單冒號可用;content 屬性有 Bug。
| 選擇器 | 模式 | IE6 | IE7 | IE8 | IE9+ | Firefox 3.5+ | Safari 4+ | Chrome 5+ | Opera 10+ |
|---|---|---|---|---|---|---|---|---|---|
| 一般兄弟選擇器 | E ~ F | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 屬性開頭匹配 | E[attr^="val"] | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 屬性結尾匹配 | E[attr$="val"] | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 屬性任意位置匹配 | E[attr*="val"] | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 屬性連字號匹配 | E[attr|="val"] | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 偽類 :root | :root | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 偽類 :nth-child() | E:nth-child(n) | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 偽類 :nth-last-child() | E:nth-last-child(n) | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 偽類 :nth-of-type() | E:nth-of-type(n) | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 偽類 :first-of-type | E:first-of-type | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 偽類 :last-of-type | E:last-of-type | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 偽類 :only-child | E:only-child | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 偽類 :only-of-type | E:only-of-type | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 偽類 :empty | E:empty | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 目標偽類 :target | E:target | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ |
| UI 狀態偽類 | :enabled/:disabled/:checked | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 否定偽類 | E:not(s) | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ |
| 偽元素 ::before/::after | ::before | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ |
:where()、:is()、:has()(CSS Selectors Level 4)簡化邏輯。::before/::after 雙冒號寫法(用單冒號)、避免 :not() 複雜參數、謹慎使用 ~ 一般兄弟選擇器。.nav ul li a span),優先使用類別選擇器。document.querySelectorAll('selector') 即時驗證。