UPDATE: Yes, this also works with Safari 18 on macOS Sequoia, iOS 18, iPadOS 18, and visionOS 2.

I just spent over 30 minutes looking for a way to only target Safari with CSS media queries and could not find a reliable way that works with Safari 17 without also targeting Chrome.

Looking through the compatibility table on caniuse.com you can spot that Safari 16 and above has a unique property which is not supported by Chrome or Firefox called hanging-punctuation.

Using that property and -webkit-appearance we can target Safari specifically until any other browser decides to support it.

styles.css
1@supports (hanging-punctuation: first) and (font: -apple-system-body) and (-webkit-appearance: none) {
2 .safari-only {
3 background-color: red;
4 }
5}

✦ 2024 Update: You can also chain it with font: -apple-system-body to make this more bulletproof. Thanks to Saber Hayati for the tip.

Demo

If you open this page in Safari, the right column will be red.

All Browsers

Safari only

Nice, but why does it also target Arc, Chrome, Firefox, Brave, Internet Explorer, etc. on my iPhone, iPad, or Vision Pro?

Because iOS and iPadOS (and visionOS) use the Mobile Safari rendering engine for all webviews. This means if you are using Chrome or any other “browser” on your iPhone it is still Safari under the hood.

That’s the case until these apps ship with their own rendering engines which will start being possible with iOS 17.4 for the EU.

Apple is finally allowing full versions of Chrome and Firefox to run on the iPhoneThe EU browser wars are about to take off in a big way.www.theverge.com/2024/1/25/24050478/apple-ios-17-4-browser-engines-eu

get notified when i write something new or launch a new project right into your inbox.

or

subscribe on telegram

Thanks for your time & attention.