This solution does not rely on JavaScript being turned on.
@-moz-document url-prefix() { h1 { color: red; } } <h1>This should be red in FF</h1> It'sThis is based on yet another Mozilla-specific CSS extension. There's a whole list of these CSS extensions right here: Mozilla-specific CSS Extensionsextension. Like most of these, it is deprecated. However, this extension's deprecation has an exception specifically for browser detection. The Firefox note in ⚠ Do note that they are mostly deprecated!@document § browser compatibility states that Firefox 61+ "only supports an empty url-prefix() value, which is supported due to its use in Firefox browser detection. Still supported in user stylesheets."
For more information about this specific CSS extension, see this question: What does @-moz-document url-prefix() do?