How to fix glossy selects in webkit (Safari)
Cross-browser compatibility woes: Styling HTML <select>
elements in Safari
Maintaining consistent application behavior across different browser engines can be challenging. Recently, while developing devpad—a project where I intentionally avoided UI frameworks and relied heavily on base HTML elements—I encountered a peculiar issue with the <select>
element in Safari.
Initially, development proceeded smoothly using Arc (a Chromium-based browser). However, testing in Safari revealed an unexpected visual discrepancy:
This image showcases the jarring difference between the rendered <select>
element in Chromium and Safari:
The Safari rendering exhibited an outdated, glossy appearance, unlike the clean look in Chromium. After extensive research across Stack Overflow and ChatGPT, I finally found a solution.
A common Stack Overflow suggestion is to use -webkit-appearance: none;
. However, this removes the dropdown arrow indicator, impacting user experience.
A more promising approach, mentioned subsequently, involved using an SVG background image. This proved tricky when also applying a background color.
Leveraging Lucide.dev icons, I incorporated an SVG arrow. Initially, however, dynamic color changes via CSS variables failed. A @media
query within the select
element also proved ineffective:
select { -webkit-appearance: none; -moz-appearance: none; appearance: none; background: url('data:image/svg+xml;utf8,<svg fill="none" height="24" stroke="black" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewbox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M6 9 12 15 18 9"></path></svg>') no-repeat; /* ...rest of the CSS... */ }
The solution, thanks to ChatGPT, involved URL-encoding the SVG string:
select { -webkit-appearance: none; -moz-appearance: none; appearance: none; background: url('data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%2224%22%20height=%2224%22%20viewBox=%220%200%2024%2024%22%20fill=%22none%22%20stroke=%22black%22%20stroke-width=%222%22%20stroke-linecap=%22round%22%20stroke-linejoin=%22round%22%3E%3Cpath%20d=%22M6%209%2012%2015%2018%209%22/%3E%3C/svg%3E') no-repeat; background-size: 18px; background-position: calc(100% - 3px) 50%; background-repeat: no-repeat; background-color: var(--input-background); padding-right: 24px; } @media (prefers-color-scheme: dark) { select { background-image: url('data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%2224%22%20height=%2224%22%20viewBox=%220%200%2024%2024%22%20fill=%22none%22%20stroke=%22white%22%20stroke-width=%222%22%20stroke-linecap=%22round%22%20stroke-linejoin=%22round%22%3E%3Cpath%20d=%22M6%209%2012%2015%2018%209%22/%3E%3C/svg%3E') !important; } }
The final result: consistent, cross-browser compatible <select>
elements with dark/light mode support.
This solution should save others time and effort in tackling this common cross-browser styling challenge. For more details on the devpad project, please refer to my latest blog post.
The above is the detailed content of How to fix glossy selects in webkit (Safari). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Let’s attempt to coin a term here: "Static Form Provider." You bring your HTML

At the start of a new project, Sass compilation happens in the blink of an eye. This feels great, especially when it’s paired with Browsersync, which reloads

In this week's roundup of platform news, Chrome introduces a new attribute for loading, accessibility specifications for web developers, and the BBC moves

This is me looking at the HTML element for the first time. I've been aware of it for a while, but haven't taken it for a spin yet. It has some pretty cool and

Buy or build is a classic debate in technology. Building things yourself might feel less expensive because there is no line item on your credit card bill, but

In this week's roundup, a handy bookmarklet for inspecting typography, using await to tinker with how JavaScript modules import one another, plus Facebook's

For a while, iTunes was the big dog in podcasting, so if you linked "Subscribe to Podcast" to like:

There are loads of analytics platforms to help you track visitor and usage data on your sites. Perhaps most notably Google Analytics, which is widely used
