Unfortunately, there isn't a foolproof way to determine if a user is viewing your email on a mobile browser or app, so targeting specific platforms with CSS is not an option. However, there are strategies you can employ to tackle the issue of color inversion in dark mode on mobile devices:
Opt for high-contrast colors: Consider using colors with a high contrast ratio like black and white to ensure readability in both light and dark modes.
Utilize the color-scheme media query: This query enables you to define distinct styles for different color schemes (e.g., light mode and dark mode). For instance:
@media (prefers-color-scheme: light) {
/* styles for light mode */
}
@media (prefers-color-scheme: dark) {
/* styles for dark mode */
}
Employ the @media media query for targeting specific devices: You can utilize this query to apply customized styles to particular devices. For example:
@media (min-width: 601px) {
/* styles for devices with a minimum width of 601px */
}
While this approach allows for differentiation among devices, it's important to note that it's not foolproof as it doesn't distinguish between mobile browsers and apps.
Keep in mind that certain email providers like Gmail and Outlook may not support the color-scheme or @media queries. In such instances, sticking to high-contrast colors remains a reliable method to ensure readability across various modes.