Switch CSS Based on Window Size using jQuery

Here we are going to see an example to switch CSS file dynamically based on the window size. In this example code, we are having two CSS files. One is for the web and the other is for the mobile viewport.

We are having a jQuery function to switch CSS based on window size. This function will be executed on page load to load CSS for the current window size. It will be executed on the window resizing event also.

jQuery Function to Switch CSS

This jQuery script will contain a function to switch CSS files based on the screen size. This function is invoked on the page load and the window resizing event. While invoking this function We are passing the window size. The script is,