Javascript Logo

How to detect dark mode in Javascript?

< 1 min readYou can detect whether the user’s operating system or device is currently in dark mode by checking the prefers-color-scheme media query in JavaScript. This media query provides information about the user’s preference for light or dark color schemes. Here’s how you can use it: In this example, the isDarkMode() function checks if the user’s preference…

Read More
Javascript Logo

How to generate random colors in Javascript?

< 1 min readYou can generate a random color in JavaScript by generating random values for the red, green, and blue components of the color. Here’s a simple example using the Math.random() function: This code generates random values for red, green, and blue components and combines them into an RGB color format. If you prefer using hexadecimal color…

Read More