I am working on a new project using the T3 stack, and I want to be able to toggle from light and dark mode. However, only the text colour changes, and the background is always set to the system's preferences.
If I set the browser theme to light, then the background is light, and if I set the browser theme to dark, then the background is dark. While either is set, I toggle light and dark theme within the Web app and the text colour changes, but the background remains the same.
Is there a specific class I need to set to some element, other than what is described in the documentation, in order for the theme to properly switch between light and dark?
In other words, are bg-base-100
and bg-base-content
, etc. CSS classes that are dynamically set to the proper colours, or do I have to explicitly set the colours of every elements in my app?
Edit
This is a representation side-by-side between Google Chrome (left) and Firefox (right) of the exact same site. The background changes because I have added bg-slate-100 text-slate-800 dark:bg-slate-800 dark:text-slate-100
to the content container element.
Note how the toolbar (i.e. navbar bg-neutral text-neutral-content
) and the table (i.e. table table-compact
) do not change background color, but the text color is correctly applied.
My theme switching function was like the one found in the documentation, that is :
However, I am using DaisyUI, so I missed this part :
In other words, the
data-theme
HTML attribute. Modifying myapplyTheme
function to :Makes it work.