> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

## Resource: Build a Mobile Site with Code

## Article: Displaying Elements in Mobile Only

## Article Link: https://dev.wix.com/docs/develop-websites/articles/coding-with-velo/frontend-code/mobile/build-a-mobile-site-with-code.md

## Article Content:

> The code in this article was written using the following module versions:
> 
> - @wix/site-window (v1.38.0)
>
> Learn how to install npm packages [in the editor](https://dev.wix.com/docs/develop-websites/articles/coding-with-velo/packages/work-with-npm-packages-in-the-editor.md) or [using the CLI](https://dev.wix.com/docs/develop-websites/articles/coding-with-velo/packages/work-with-npm-packages-with-the-wix-cli.md).

# Build a Mobile Site with Code

You can use code to control elements so they act or display differently in the mobile version of your site.

## Step 1 | Add the elements on your site

Add elements to your site that you’d like to customize for the mobile version.

## Step 2 | Open the page code file

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.

To open the code file:

**Editor:**

1. Go to the **Page Code** section of the code panel.
1. Select your page.

A page code file opens. The file includes a sample `onReady()` function.

**Wix IDE or your local IDE:**

Open the file in the `Pages` folder. The file includes a sample `onReady()` function.

## Step 3 | Check the device type

Check whether your site is being viewed on a mobile device.

1. In the first line of your code, import the [@wix/site-window](https://dev.wix.com/docs/sdk/frontend-modules/window/introduction.md) API. It lets you determine the type of device your site is being viewed on.

    ```js
    import { window } from '@wix/site-window';
    ```

    Learn more about using [npm packages](https://dev.wix.com/docs/develop-websites/articles/coding-with-velo/packages/about-npm-packages.md) when extending sites.

1. Wrap the code for the element in an `if` statement to handle the various devices on which the element exists.

    ```js
    $w.onReady(async function () {
    if (await window.formFactor() === "Mobile" 
    || await window.formFactor() === "Tablet") 
    {
      }
    else 
    {
      }
    });
    ```

## Step 4 | Customize actions on elements

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:

```js
import { window } from '@wix/site-window';

$w.onReady(async function () {
  if (await window.formFactor() === "Mobile" || await window.formFactor() === "Tablet") {
    $w("#button1").show();
  }
  else {
    $w("#button1").hide();
  }
});
```

## Step 5 | Test

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.

<blockquote class="important">

**Important:**
If you preview your site, it will always behave as if it is being viewed on a desktop device, even if you preview from the mobile editor.

</blockquote>

To test your site on a desktop machine as if it is being viewed on a mobile device:

1. Publish your site.
1. View the published site.
1. Open your browser's [developer tools](https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_are_browser_developer_tools).
1. Use your browser's developer tools to emulate a mobile device. For example, for Google Chrome, this is called **Toggle device toolbar** and turned on using this icon ![toggle device toolbar](https://d2x3xhvgiqkx42.cloudfront.net/12345678-1234-1234-1234-1234567890ab/dfff8cbb-ddcb-4376-8cae-3fedb2dd4458/2018/11/28/562c996b-8391-4ca0-9963-dc49b6ee3da7.png).
1. Refresh the page so your site now loads as if it were on a mobile device.

## See also

- [About Building a Mobile Site](https://dev.wix.com/docs/develop-websites/articles/coding-with-velo/frontend-code/mobile/building-a-mobile-site-with-code.md)