11.6    Related Topic: Web Browser Prefixes (CSS Vendor Prefixes)

CSS, like HTML, is constantly evolving, and web browser vendors are doing their best to release newer versions with new features at ever-shorter intervals. As a web developer, this rapid progress also benefits you because many web browser vendors like to implement new experimental CSS features in the very early state of the standard version.

With the help of a special web browser prefix or vendor prefix, you can thus already use CSS features experimentally that are still in draft or beta state. Once the corresponding CSS module is in the final version, and the web browser fully supports the feature, you can remove the web browser prefix. Alternatively, you can leave it in place, allowing older web browsers to use this feature, if necessary, if the CSS feature is already included in the final recommendation.

From Working Draft to Recommendation

The development process toward a finished W3C Recommendation is divided into several stages. It all usually starts with a working draft. Often, multiple working drafts are developed and not all make it to the recommendation stage. The next stage is the last call working draft, which is something like the last planned working draft. Once the working drafts are done, the next stage is the candidate recommendation, where technical details of the new technology are already known. The next-to-last stage is the proposed recommendation, where additional implementations can be added to the existing ones. This stage is also the last stage at which one can still influence the development process. If the members finally agree to the recommendation proposal, the proposal is given the final status of a recommendation. Recommendations may be withdrawn for revision at any time.

As a simple example, we’ll use the CSS feature text-emphasis, which is to be newly introduced in CSS selectors level 4 and can only be used experimentally in some web browsers (at the time of print) using web browser prefixes. This CSS feature allows you to highlight the emphasis of text with a different color and style, for example, with circles, points, or triangles. However, this isn’t about the feature in detail, but about the browser prefixes. Here’s an example:

h1 {
text-emphasis: filled double-circle blue;
}

This is used to particularly highlight the h1 heading with blue double circles if the web browser can handle the CSS feature text-emphasis, which wasn’t the case when this book went into print. However, because some web browsers have already implemented this CSS feature experimentally, you can use and test browser prefixes as follows:

...
h1 {
-moz-text-emphasis: filled double-circle blue;
-webkit-text-emphasis: filled double-circle blue;
text-emphasis: filled double-circle blue;
}

Listing 11.14     /examples/chapter011/11_6/css/style.css

The procedure is relatively simple. You introduce such experimental CSS features with a vendor-specific abbreviation (e.g., with -moz- for Mozilla Firefox). Then you can test these CSS features and feed your experience with them back to the web browser manufacturers, if necessary. This vendor-specific CSS feature is understood only by a particular web browser or web browser family.

If a web browser can’t do anything with the web browser prefix features, you don’t need to bother about it because this feature gets ignored anyway. The web browser itself picks out what it knows and can do. And if a web browser doesn’t know text-emphasis at all, nothing of the sort will be used, and you may need to provide an alternative for such a web browser.

See Table 11.3 for a list of common web browser prefixes.

Code

Vendor

-webkit-

Chrome, Safari, Edge

-moz-

Mozilla Firefox

-o-

Opera

Table 11.3     List of Common Web Browsers and Their Prefixes

Regarding such examples, it should be noted that you’re nevertheless responsible for compliance with the standard version yourself. This means that a browser-specific CSS feature that you’ve written with a web browser prefix can change again or perhaps be deleted altogether.

Using or Not Using Web Browser Prefixes?

The web browser prefixes make the CSS code ugly and more voluminous. Nevertheless, they’ve become a favorite tool of web developers. It often happens that you don’t even know whether a certain CSS module has already been fully implemented or not. It isn’t always easy to keep track of everything, and there’s a risk that the web browser hasn’t even fully implemented the feature yet. However, you have the advantage of being able to use a feature of the future standard version that isn’t yet complete. A good overview of this is provided at http://caniuse.com. There you’ll find tables about the current versions and about how far certain web browsers support a certain CSS feature (and also HTML feature) and/or from which version the web browser prefix can or should be used.