The Most Secure Cross Browser Testing Platform since 2012

The Cross-Browser Compatibility Guide – CSS Selectors Browser Support

css selectors
BLOG / BrowserNews / Browsers / Cross Browser Testing / CSS / Tips / Web Development

The Cross-Browser Compatibility Guide – CSS Selectors Browser Support

Welcome to the third part of the cross-browser compatibility guide.

CSS selectors browser support

In this post I would like to show which CSS selectors are supported in the different browsers.

CSS 2 Selectors

CSS level 2 specification was developed by the W3C and published as a recommendation in May 1998. CSS2 is the improvement of CSS1. It removed the not fully interoperable features. It also included the browser extensions. Today all current versions of major browsers support every CSS 2 Selector.

SelectorChromeEdgeFirefoxSafariOperaDescription
E:active4.07.02.03.19.6Selects the active link
E:hover4.07.02.03.19.6Selects link on mouse over
E:focus4.08.02.03.19.6Selects the input element which has focus
*4.07.02.03.19.6Selects all elements
EYesYesYesYesYesMatches any E element (i.e., an element of type E).
E:before4.09.03.53.17.0Insert something before the content of each <E> element
E:after4.09.03.53.17.0Insert something after the content of each <E> element
.classYesYesYesYesYesE.g. , .intro means selects all elements with class=”intro”
#idYesYesYesYesYesE.g., #firstname selects the element with id=”firstname”
E FYesYesYesYesYesMatches any F element that is a descendant of an E element.
E > FYes7.0YesYesYes
Matches any F element that is a child of an element E.
E + FYes7.0YesYesYesMatches any F element immediately preceded by a sibling element E.
E[attr]4.07.02.03.19.6Matches any E element with the “attr” attribute set (whatever the value).
E[attr=val]4.07.02.03.19.6Matches any E element whose “attr” attribute value is exactly equal to “val”.
E[attr~=val]4.07.02.03.19.6Matches any E element whose “attr” attribute value is a list of space-separated values, one of which is exactly equal to “val”
E[attr|=val]4.07.02.03.19.6Matches any E element whose “attr” attribute has a hyphen-separated list of values beginning (from the left) with “val”.
E:first-child4.07.03.03.19.6Matches element E when E is the first child of its parent.
E:lang(en)4.08.02.03.19.6Selects every <E> element with a lang attribute equal to “en” (English)
E::first-letter1.09.01.01.07.0Selects the first letter of every <E> element
E::first-line1.09.01.01.07.0Selects the first line of every <E> element

CSS 3 Selectors

With all the new shiny CSS 3 selectors available things tend to get tricky. CSS3 is the most recent and currently used. Unlike CSS 2, which is a large single specification defining various features, CSS 3 is divided into several separate documents called “modules”. Each module adds new capabilities or extends features defined in CSS 2, preserving backward compatibility. Work on CSS level 3 started around the time of publication of the original CSS 2 recommendation. The earliest CSS 3 drafts were published in June 1999. CSS3 has support for almost all recent web browsers.

SelectorChromeEdgeFirefoxSafariOperaDescription
E[attr^=val]4.07.03.53.29.6Selects every <E> element whose href attribute value begins with “val”
E[attr$=val]4.07.03.53.29.6Selects every <E> element whose href attribute value ends with “val”
E[attr*=val]4.07.03.53.29.6Selects every <E> element whose href attribute value contains the substring “val”
E ~ F4.07.03.53.29.6Selects every <F> element that is preceded by a <E> element
:root4.09.03.53.29.6Selects the document’s root element
E:last-child4.09.03.53.29.6Selects every <E> element that is the last child of its parent
E:only-child4.09.03.53.29.6Selects every <E> element that is the only child of its parent
:nth-child()4.09.03.53.29.6Eg., p:nth-child(2) selects every <p> element that is the second child of its parent
:nth-last-child()4.09.03.53.29.6E.g., p:nth-last-child(2) selects every <p> element that is the second child of its parent, counting from the last child
E:first-of-type4.09.03.53.29.6Selects every <E> element that is the first <E> element of its parent
E:last-of-type4.09.03.53.29.6Selects every <E> element that is the last <E> element of its parent
E:only-of-type
4.09.03.53.29.6Selects every <E> element that is the only <E> element of its parent
:nth-of-type()4.09.03.53.29.6E.g., p:nth-of-type(2) selects every <p> element that is the second <p> element of its parent
:nth-last-of-type()4.09.03.53.29.6E.g., p:nth-last-of-type(2) selects every <p> element that is the second <p> element of its parent, counting from the last child
E:empty4.09.03.53.29.6Selects every <E> element that has no children (including text nodes)
:not()4.09.03.53.29.6E.g., :not(p) selects every element that is not a <p> element
E:target4.09.03.53.29.6Selects the current active E element
E:enabled4.09.03.53.29.6Selects every enabled <E> element
E:disabled4.09.03.53.29.6Selects every disabled <E> element
E:checked4.09.03.53.29.6Selects every checked <E> element

CSS 4

There is no single, integrated CSS4 specification, because the specification has been split into many separate modules which level independently. There were speculations around CSS4 coming. But it is still not a thing. According to officials, The CSS working group is now working on Selector Level 4. It has new proposed features and selectors.

These new introductions were supposed to come out as CSS4 but It’s not CSS4. It will be level 4 of a single specification.

Source: https://www.w3schools.com and https://en.wikipedia.org

Summary
Article Name
The Cross-Browser Compatibility Guide – CSS Selectors Browser Support
Description
CSS level 2 specification was developed by the W3C and published as a recommendation in May 1998. CSS2 is the improvement of CSS1. It removed the not fully interoperable features. It also included the browser extensions. Today all current versions of major browsers support every CSS 2 Selector.
Author
Publisher Name
Browse Em All
Publisher Logo