Support for use of calc()
in media queries is browser-dependent HOWEVER the use of mixed units (e.g. em and px at same time) have limited or no current support. Please take a look at this JSFiddle (which tests 4 current browsers - Chrome 80.0.3987.163, Opera 67.0.3575.115, Firefox 74.0.1, and Microsoft Edge 44.18362.449.0) to verify.
For example, these media queries are valid for certain browsers (Chrome 80.0.3987.163, Opera 67.0.3575.115, and Firefox 74.0.1 but NOT Microsoft Edge 44.18362.449.0)
@media (min-width:calc(2em - 1em)) { div { color: green } } // valid
@media (min-width:calc(2px - 1px)) { div { color: green } } // valid
whereas this media query is only valid in Firefox 74.0.1
@media (min-width:calc(1em - 1px)) { div { color: green } } // different units are "mixed" in same calc() -----> invalid except Firefox
UPDATE December 2020: Other functions within the calc()
family of functions (that is, functions which perform an operation on one or more calc-sums) can also be used within a media query. This JSFiddle demonstrates the utility of the comparison functions max()
, min()
, and clamp()
. These functions are currently supported within a media query by the browsers:
- Chrome 87
- Edge 87
- Firefox 82
- Opera 72
However, using mixed units within each comparison function is only supported by the following browsers (from the list above):
- Firefox 82