Yes, Apple has provided such a way, with this in the <head>
:
<meta name="color-scheme" content="light dark">
<style type="text/css">
@media (prefers-color-scheme: dark) {
.darkmode { background-color: #1e1e1e !important; }
.darkmode p { color: #ffffff !important; }
}
</style>
Also, ensure your outermost element with the background-color has the class "darkmode", e.g.
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="center" class="darkmode" bgcolor="#ffffff" valign="top" style="padding: 0px 15px;">
So by default, you will have a white background, black text; and on darkmode it will be a dark background with light text.