Introduction
In this tutorial, you'll learn how to create a simple foldable device interface simulation using HTML, CSS, and JavaScript. This hands-on project will teach you the fundamentals of responsive design and interactive UI components that could be similar to what Apple might be developing for their future foldable iPhone. You'll build a working prototype that simulates how content might adapt when a device folds and unfolds.
Prerequisites
To follow this tutorial, you'll need:
- A basic understanding of HTML, CSS, and JavaScript
- A text editor (like VS Code or Sublime Text)
- A web browser to test your code
- Basic knowledge of how to create and save HTML files
This tutorial will help you understand how foldable device interfaces work by creating a simulation that shows content adapting to different screen states.
Step-by-Step Instructions
Step 1: Create the HTML Structure
First, we'll create the basic HTML structure for our foldable device simulator. This will include a container that represents our device and the content that will change based on the fold state.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>iPhone Foldable Simulator</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="device" id="device">
<div class="screen" id="screen">
<div class="content" id="content">
<h1>Foldable Device Simulator</h1>
<p>Click the fold button to see content adapt</p>
<div class="fold-button" id="foldButton">Fold Device</div>
</div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
Why we do this: This HTML structure sets up the foundation of our device simulator. The device container represents the physical phone, and the screen inside it will display our content. The fold button will allow us to toggle between folded and unfolded states.
Step 2: Create the CSS Styles
Now we'll create the CSS to style our device and make it look like a foldable phone. This will include the device styling and the responsive behavior for the fold states.
body {
margin: 0;
padding: 20px;
font-family: Arial, sans-serif;
background-color: #f0f0f0;
}
.device {
width: 320px;
height: 640px;
background-color: #000;
border-radius: 40px;
position: relative;
margin: 0 auto;
overflow: hidden;
box-shadow: 0 20px 50px rgba(0,0,0,0.5);
transition: all 0.5s ease;
}
.screen {
width: 100%;
height: 100%;
background-color: #fff;
padding: 20px;
box-sizing: border-box;
}
.content {
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
}
.fold-button {
margin-top: 20px;
padding: 10px 20px;
background-color: #007AFF;
color: white;
border-radius: 20px;
cursor: pointer;
transition: background-color 0.3s;
}
.fold-button:hover {
background-color: #0056b3;
}
/* Folded state styles */
.folded .screen {
height: 50%;
transform: rotateX(180deg);
transform-origin: bottom;
background-color: #fff;
}
.folded .content {
font-size: 14px;
}
/* Unfolded state styles */
.unfolded .screen {
height: 100%;
transform: rotateX(0deg);
background-color: #fff;
}
Why we do this: The CSS creates the visual representation of our foldable device. We define the device dimensions, styling, and use CSS transitions for smooth animations. The folded and unfolded classes will control how the screen behaves when the device is folded.
Step 3: Add JavaScript Functionality
Next, we'll add JavaScript to handle the fold/unfold functionality and make our simulator interactive.
document.addEventListener('DOMContentLoaded', function() {
const device = document.getElementById('device');
const foldButton = document.getElementById('foldButton');
const content = document.getElementById('content');
let isFolded = false;
foldButton.addEventListener('click', function() {
isFolded = !isFolded;
if (isFolded) {
device.classList.add('folded');
device.classList.remove('unfolded');
foldButton.textContent = 'Unfold Device';
content.innerHTML = 'Folded View
Content is now in a compact view
Notice how the interface adapts to the smaller screen
';
} else {
device.classList.add('unfolded');
device.classList.remove('folded');
foldButton.textContent = 'Fold Device';
content.innerHTML = 'Foldable Device Simulator
Click the fold button to see content adapt
';
}
});
});
Why we do this: The JavaScript handles the interactive behavior of our simulator. When the user clicks the fold button, it toggles between folded and unfolded states, changes the button text, and updates the content to show how the interface would change in each state.
Step 4: Test Your Simulator
Save all three files (index.html, style.css, and script.js) in the same folder. Open the index.html file in your web browser to test your foldable device simulator.
Click the 'Fold Device' button to see how the interface adapts. Notice how the content changes and the screen area adjusts to simulate the folding effect. This demonstrates how foldable devices might present different layouts for different screen states.
Step 5: Enhance Your Simulator (Optional)
For a more advanced experience, you can add more sophisticated features like:
- Multiple content sections that appear in different states
- Animation effects for smoother transitions
- Responsive design that adapts to different screen sizes
- More realistic device styling with curved edges
These enhancements would help you understand how real foldable device interfaces might work with more complex content layouts.
Summary
In this tutorial, you've created a simple foldable device interface simulator using HTML, CSS, and JavaScript. You learned how to:
- Structure a foldable device simulation with HTML
- Style the device using CSS with responsive design principles
- Add interactivity with JavaScript to toggle between folded and unfolded states
- Understand how content adapts to different screen configurations
This project demonstrates fundamental concepts that Apple and other companies are exploring for their future foldable devices. The skills you've learned are essential for understanding responsive design and how user interfaces adapt to different device configurations.
While this is a simplified simulation, it gives you a foundation for understanding how foldable device interfaces work. Real foldable phones like the Samsung Galaxy Fold or Motorola Razr would use more complex approaches, but this basic concept shows the core principle of adapting content to screen size changes.



