Are there easy methods than this js code for activating dark mode?

I have written some code to switch between Dark and Light modes in a website. But I had to write very big css file for that. I’ve used Java script for my switcher.

I’ve written tis code


function darkMode() 
{
var element = document.body;
var content = document.getElementById("DarkModetext");
element.className = "dark-mode";
content.innerText = "Dark Mode is ON";
}
function lightMode() 
{
var element = document.body;
var content = document.getElementById("DarkModetext");
element.className = "light-mode";
content.innerText = "Dark Mode is OFF";
}

Help me plese with another method for switching modes.

And the css file is too large for here.