See the GitHub docs and this article for an explanation of #gh-dark-mode-only and #gh-light-mode-only.
You can use this repo of mine, which uses this feature, to test this functionality if you'd like.
Here is what my repo looks like in gh-markdown-preview:
Click to expand

And here is what it looks like rendered on GitHub:
Click to expand
