The code in this article was written using the following module versions:
Learn how to install npm packages in the editor or using the CLI.
You can use code to control elements so they act or display differently in the mobile version of your site.
Add elements to your site that you'd like to customize for the mobile version.
Open the code file for your page where you added the elements. The way you open the file depends on the IDE you're using.
Check whether your site is being viewed on a mobile device.
In the first line of your code, import the @wix/site-window API. It lets you determine the type of device your site is being viewed on.
Learn more about using npm packages when developing sites.
Wrap the code for the element in an if statement to handle the various devices on which the element exists.
In the conditional statement write any actions you’d like to do with your elements in the mobile version.
For example, here is code for hiding a button when viewed on a desktop screen, but showing the button on mobile and tablet screens:
If you want to test how your code works on mobile devices, publish your site and view the published version on a mobile device or in a mobile device emulator.
Important: If you preview your site, it will always behave as if it's being viewed on a desktop device, even if you preview from the mobile editor.
To test your site on a desktop machine as if it's being viewed on a mobile device:
.