How to Test Local Website on Mobile Devices
When developing a website, it's essential to ensure it works well not just on desktops but also on mobile devices. While browser dev tools can simulate mobile views, nothing beats testing on a real phone to experience touch interaction and actual responsiveness.
In this article, you'll learn how to preview your local website on your mobile device in just three simple steps. This technique is especially useful if you're using the Live Server extension in Visual Studio Code (VS Code).
Prerequisites
- Install VS Code Editor on your desktop.
- Install the Live Server extension in VS Code.
- Connect your mobile device and desktop to the same WiFi network.
Steps to Test Your Local Website on a Phone
Step 1: Run the Live Server
Open your project folder in VS Code. Once opened, find and click the "Go Live" button located at the bottom-right corner of the editor window.
This action launches your local website in a web browser and starts a development server, typically on port 5000 (though it may vary).
Example: If your project opens at
Step 2: Find Your Local IPv4 Address
To access your site from a phone, you'll need your desktop's local IP address. Follow these steps:
- Open Command Prompt (CMD).
- Type
ipconfig and press Enter. - Look under the section named Wireless LAN adapter Wi-Fi.
- Find the line labeled IPv4 Address. It may look like
192.168.1.68 .
Note: This IP address might change if new devices join or leave the network. You should check it again if something stops working.
Step 3: View Your Website on Your Phone
Now that you know your IPv4 address and port number, open the browser on your phone and enter the following in the address bar:
If your main HTML file is not named index.html, you need to specify the filename like this:
You should now see a live preview of your website directly on your mobile phone!
Live Reloading
One of the major benefits of using Live Server is that any changes you make to your code in VS Code will instantly reflect on your phone without needing to refresh the browser manually.
Troubleshooting Common Issues
If you're unable to access your site on the phone, here are a few things to check:
- Correct IP and Port: Make sure you typed the correct local IP address and port number in your phone's browser.
- Same Network: Ensure both your phone and computer are connected to the same WiFi network.
- HTML File Name: If your file is not named index.html, include the correct file name in the URL.
- Firewall: Sometimes, a firewall blocks the connection. You may need to allow access through the firewall for the Live Server port.
Conclusion
Testing your local website on a real mobile device is an excellent way to ensure your design is responsive and functions as expected. Using VS Code and the Live Server extension, you can preview your project in real-time with ease.
This approach works with static sites made with HTML, CSS, and JavaScript, as well as with frameworks like React or Vue that use local development servers.
If you found this guide useful, share it with fellow developers!