Login screen in SwiftUI, Flutter, React Native and HTML/CSS
A complete login screen in all four targets, with every layout number explained.
A login screen is the smallest screen that still has every awkward part of a real one: a heading, two text fields (one of them secure), a text link, and a button that has to do something. We drew this one once on the canvas at 390 by 844 (an iPhone 14) and exported it to all four targets. The code below is the generator's output, unedited.
What we drew
Every number below is a choice, and every one of them appears literally in the code.
| Element | Position | Size | Notes |
|---|---|---|---|
| Title, "Welcome back" | x 24, y 120 | 342 x 36 | 28px, bold |
| Subtitle | x 24, y 164 | 342 x 22 | 15px, grey |
| Email field | x 24, y 232 | 342 x 48 | 1px border, radius 12, email keyboard |
| Password field | x 24, y 296 | 342 x 48 | same, secure entry |
| "Forgot password?" | x 24, y 360 | 160 x 20 | 14px, medium |
| Sign in button | x 24, y 412 | 342 x 52 | radius 14, label centred, calls handleSignIn |
The side margin is 24 and the content width is 342, so the right margin is also 24 (24 + 342 + 24 = 390). Fields are 48 tall and the button is 52, which keeps both comfortably above the 44-point minimum touch target Apple recommends. The gap between the two fields is 16 (280 to 296).
React Native
Placement is a literal left and top on each style. The button and its label sit inside one Pressable, so tapping the label presses the button.
import React from 'react';
import { View, Text, Pressable, TextInput, StyleSheet } from 'react-native';
export default function Login() {
const handleSignIn = () => {};
return (
<View style={styles.screen}>
<Text style={styles.title}>{"Welcome back"}</Text>
<Text style={styles.subtitle}>{"Sign in to pick up where you left off."}</Text>
<TextInput style={styles.email} placeholder={"Email"} placeholderTextColor="#9ca3af" keyboardType="email-address" />
<TextInput style={styles.password} placeholder={"Password"} placeholderTextColor="#9ca3af" secureTextEntry />
<Text style={styles.forgot}>{"Forgot password?"}</Text>
<Pressable onPress={handleSignIn} style={({ pressed }) => [styles.group, pressed && styles.pressed]}>
<View style={styles.signIn} />
<View style={styles.signInLabel}><Text style={styles.signInLabelText}>{"Sign in"}</Text></View>
</Pressable>
</View>
);
}
const styles = StyleSheet.create({
screen: {
flex: 1,
backgroundColor: '#ffffff',
},
title: {
position: 'absolute',
left: 24,
top: 120,
width: 342,
height: 36,
color: '#17171A',
fontFamily: 'Inter',
fontSize: 28,
lineHeight: 36,
textAlign: 'left',
fontWeight: '700',
},
subtitle: {
position: 'absolute',
left: 24,
top: 164,
width: 342,
height: 22,
color: '#5B5B63',
fontFamily: 'Inter',
fontSize: 15,
lineHeight: 21,
textAlign: 'left',
},
email: {
position: 'absolute',
left: 24,
top: 232,
width: 342,
height: 48,
backgroundColor: '#ffffff',
color: '#17171A',
fontFamily: 'Inter',
fontSize: 16,
paddingHorizontal: 12,
textAlign: 'left',
borderRadius: 12,
borderWidth: 1,
borderColor: '#E4E1D8',
},
password: {
position: 'absolute',
left: 24,
top: 296,
width: 342,
height: 48,
backgroundColor: '#ffffff',
color: '#17171A',
fontFamily: 'Inter',
fontSize: 16,
paddingHorizontal: 12,
textAlign: 'left',
borderRadius: 12,
borderWidth: 1,
borderColor: '#E4E1D8',
},
forgot: {
position: 'absolute',
left: 24,
top: 360,
width: 160,
height: 20,
color: '#2A50D8',
fontFamily: 'Inter',
fontSize: 14,
lineHeight: 18,
textAlign: 'left',
fontWeight: '500',
},
group: {
position: 'absolute',
left: 24,
top: 412,
width: 342,
height: 52,
},
signIn: {
position: 'absolute',
left: 0,
top: 0,
width: 342,
height: 52,
borderRadius: 14,
backgroundColor: '#2A50D8',
},
signInLabel: {
position: 'absolute',
left: 0,
top: 0,
width: 342,
height: 52,
justifyContent: 'center',
},
signInLabelText: {
color: '#ffffff',
fontFamily: 'Inter',
fontSize: 16,
lineHeight: 21,
textAlign: 'center',
fontWeight: '600',
},
pressed: {
opacity: 0.6,
},
});SwiftUI
SwiftUI's .position(x:, y:) takes the centre of a view, not its corner, so the generator converts: the title at x 24 with width 342 becomes x: 195 (24 + 342 / 2), and at y 120 with height 36 becomes y: 138. The email field is a TextField bound to a generated @State string; the password field is a SecureField.
import SwiftUI
struct Login: View {
@State private var field3: String = ""
@State private var field4: String = ""
private func handleSignIn() {}
var body: some View {
ZStack(alignment: .topLeading) {
Color(red: 1, green: 1, blue: 1)
.frame(width: 390, height: 844)
Text("Welcome back")
.font(.custom("Inter", size: 28))
.fontWeight(.bold)
.lineSpacing(8.4)
.foregroundColor(Color(red: 0.09, green: 0.09, blue: 0.1))
.multilineTextAlignment(.leading)
.frame(width: 342, height: 36, alignment: .topLeading)
.position(x: 195, y: 138)
Text("Sign in to pick up where you left off.")
.font(.custom("Inter", size: 15))
.lineSpacing(6)
.foregroundColor(Color(red: 0.36, green: 0.36, blue: 0.39))
.multilineTextAlignment(.leading)
.frame(width: 342, height: 22, alignment: .topLeading)
.position(x: 195, y: 175)
TextField("Email", text: $field3)
.font(.custom("Inter", size: 16))
.foregroundColor(Color(red: 0.09, green: 0.09, blue: 0.1))
.multilineTextAlignment(.leading)
.keyboardType(.emailAddress)
.padding(.horizontal, 12)
.frame(width: 342, height: 48, alignment: .leading)
.background(Color(red: 1, green: 1, blue: 1))
.cornerRadius(12)
.overlay(RoundedRectangle(cornerRadius: 12).strokeBorder(Color(red: 0.89, green: 0.88, blue: 0.85), lineWidth: 1))
.position(x: 195, y: 256)
SecureField("Password", text: $field4)
.font(.custom("Inter", size: 16))
.foregroundColor(Color(red: 0.09, green: 0.09, blue: 0.1))
.multilineTextAlignment(.leading)
.padding(.horizontal, 12)
.frame(width: 342, height: 48, alignment: .leading)
.background(Color(red: 1, green: 1, blue: 1))
.cornerRadius(12)
.overlay(RoundedRectangle(cornerRadius: 12).strokeBorder(Color(red: 0.89, green: 0.88, blue: 0.85), lineWidth: 1))
.position(x: 195, y: 320)
Text("Forgot password?")
.font(.custom("Inter", size: 14))
.fontWeight(.medium)
.lineSpacing(4.2)
.foregroundColor(Color(red: 0.16, green: 0.31, blue: 0.85))
.multilineTextAlignment(.leading)
.frame(width: 160, height: 20, alignment: .topLeading)
.position(x: 104, y: 370)
Button(action: handleSignIn) {
ZStack(alignment: .topLeading) {
RoundedRectangle(cornerRadius: 14)
.fill(Color(red: 0.16, green: 0.31, blue: 0.85))
.frame(width: 342, height: 52)
.position(x: 171, y: 26)
Text("Sign in")
.font(.custom("Inter", size: 16))
.fontWeight(.semibold)
.lineSpacing(4.8)
.foregroundColor(Color(red: 1, green: 1, blue: 1))
.multilineTextAlignment(.center)
.frame(width: 342, height: 52, alignment: .center)
.position(x: 171, y: 26)
}
.frame(width: 342, height: 52)
}
.buttonStyle(PressStyle())
.position(x: 195, y: 438)
}
.frame(width: 390, height: 844)
}
}
struct PressStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label.opacity(configuration.isPressed ? 0.6 : 1)
}
}Flutter
Each element is a Positioned inside one fixed-size Stack. The fields are real TextField widgets with the hint text, keyboard type and padding set.
import 'package:flutter/material.dart';
class Login extends StatelessWidget {
const Login({super.key});
void handleSignIn() {}
@override
Widget build(BuildContext context) {
return SizedBox(
width: 390,
height: 844,
child: Stack(
children: [
Positioned.fill(child: Container(color: Color(0xFFFFFFFF))),
Positioned(
left: 24,
top: 120,
child: SizedBox(
width: 342,
height: 36,
child: Text(
'Welcome back',
textAlign: TextAlign.left,
style: TextStyle(
fontFamily: 'Inter',
fontSize: 28,
color: Color(0xFF17171A),
height: 1.3,
fontWeight: FontWeight.w700,
),
),
),
),
Positioned(
left: 24,
top: 164,
child: SizedBox(
width: 342,
height: 22,
child: Text(
'Sign in to pick up where you left off.',
textAlign: TextAlign.left,
style: TextStyle(
fontFamily: 'Inter',
fontSize: 15,
color: Color(0xFF5B5B63),
height: 1.4,
),
),
),
),
Positioned(
left: 24,
top: 232,
child: Container(
width: 342,
height: 48,
decoration: BoxDecoration(
color: Color(0xFFFFFFFF),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Color(0xFFE4E1D8), width: 1),
),
child: TextField(
keyboardType: TextInputType.emailAddress,
maxLines: 1,
textAlign: TextAlign.left,
style: TextStyle(
color: Color(0xFF17171A),
fontFamily: 'Inter',
fontSize: 16,
),
decoration: InputDecoration(
hintText: 'Email',
hintStyle: const TextStyle(color: Color(0xFF9CA3AF)),
border: InputBorder.none,
isDense: true,
contentPadding: const EdgeInsets.symmetric(horizontal: 12),
),
),
),
),
Positioned(
left: 24,
top: 296,
child: Container(
width: 342,
height: 48,
decoration: BoxDecoration(
color: Color(0xFFFFFFFF),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Color(0xFFE4E1D8), width: 1),
),
child: TextField(
obscureText: true,
maxLines: 1,
textAlign: TextAlign.left,
style: TextStyle(
color: Color(0xFF17171A),
fontFamily: 'Inter',
fontSize: 16,
),
decoration: InputDecoration(
hintText: 'Password',
hintStyle: const TextStyle(color: Color(0xFF9CA3AF)),
border: InputBorder.none,
isDense: true,
contentPadding: const EdgeInsets.symmetric(horizontal: 12),
),
),
),
),
Positioned(
left: 24,
top: 360,
child: SizedBox(
width: 160,
height: 20,
child: Text(
'Forgot password?',
textAlign: TextAlign.left,
style: TextStyle(
fontFamily: 'Inter',
fontSize: 14,
color: Color(0xFF2A50D8),
height: 1.3,
fontWeight: FontWeight.w500,
),
),
),
),
Positioned(
left: 24,
top: 412,
child: _Pressable(
onTap: handleSignIn,
child: SizedBox(
width: 342,
height: 52,
child: Stack(
children: [
Positioned(
left: 0,
top: 0,
child: Container(
width: 342,
height: 52,
decoration: BoxDecoration(
color: Color(0xFF2A50D8),
borderRadius: BorderRadius.circular(14),
),
),
),
Positioned(
left: 0,
top: 0,
child: SizedBox(
width: 342,
height: 52,
child: Align(
alignment: Alignment.center,
child: Text(
'Sign in',
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: 'Inter',
fontSize: 16,
color: Color(0xFFFFFFFF),
height: 1.3,
fontWeight: FontWeight.w600,
),
),
),
),
),
],
),
),
),
),
],
),
);
}
}
class _Pressable extends StatefulWidget {
final VoidCallback onTap;
final Widget child;
const _Pressable({required this.onTap, required this.child});
@override
State<_Pressable> createState() => _PressableState();
}
class _PressableState extends State<_Pressable> {
bool _pressed = false;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: widget.onTap,
onTapDown: (_) => setState(() => _pressed = true),
onTapUp: (_) => setState(() => _pressed = false),
onTapCancel: () => setState(() => _pressed = false),
child: Opacity(opacity: _pressed ? 0.6 : 1.0, child: widget.child),
);
}
}HTML and CSS
One file with embedded styles: a position: relative screen, and each element absolutely positioned with the same numbers.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Login</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link href="https://fonts.googleapis.com/css2?family=Inter&display=swap" rel="stylesheet" />
<style>
html, body {
margin: 0;
padding: 0;
background: #ffffff;
}
.screen {
position: relative;
width: 390px;
height: 844px;
overflow-x: hidden;
overflow-y: auto;
scrollbar-width: none;
background: #ffffff;
}
.screen::-webkit-scrollbar {
display: none;
}
.title {
position: absolute;
left: 24px;
top: 120px;
width: 342px;
height: 36px;
color: #17171A;
font-family: 'Inter', sans-serif;
font-size: 28px;
font-weight: 700;
text-align: left;
line-height: 1.3;
white-space: pre-wrap;
}
.subtitle {
position: absolute;
left: 24px;
top: 164px;
width: 342px;
height: 22px;
color: #5B5B63;
font-family: 'Inter', sans-serif;
font-size: 15px;
text-align: left;
line-height: 1.4;
white-space: pre-wrap;
}
.email {
position: absolute;
left: 24px;
top: 232px;
width: 342px;
height: 48px;
background: #ffffff;
color: #17171A;
font-family: 'Inter', sans-serif;
font-size: 16px;
text-align: left;
padding: 0 12px;
box-sizing: border-box;
outline: none;
border-radius: 12px;
border: 1px solid #E4E1D8;
}
.email::placeholder {
color: #9ca3af;
}
.password {
position: absolute;
left: 24px;
top: 296px;
width: 342px;
height: 48px;
background: #ffffff;
color: #17171A;
font-family: 'Inter', sans-serif;
font-size: 16px;
text-align: left;
padding: 0 12px;
box-sizing: border-box;
outline: none;
border-radius: 12px;
border: 1px solid #E4E1D8;
}
.password::placeholder {
color: #9ca3af;
}
.forgot {
position: absolute;
left: 24px;
top: 360px;
width: 160px;
height: 20px;
color: #2A50D8;
font-family: 'Inter', sans-serif;
font-size: 14px;
font-weight: 500;
text-align: left;
line-height: 1.3;
white-space: pre-wrap;
}
.group {
position: absolute;
left: 24px;
top: 412px;
width: 342px;
height: 52px;
cursor: pointer;
}
.signIn {
position: absolute;
left: 0px;
top: 0px;
width: 342px;
height: 52px;
background: #2A50D8;
border-radius: 14px;
}
.signInLabel {
position: absolute;
left: 0px;
top: 0px;
width: 342px;
height: 52px;
color: #ffffff;
font-family: 'Inter', sans-serif;
font-size: 16px;
font-weight: 600;
text-align: center;
line-height: 1.3;
white-space: pre-wrap;
display: flex;
flex-direction: column;
justify-content: center;
}
.tappable {
appearance: none;
border: none;
padding: 0;
background: transparent;
font: inherit;
color: inherit;
text-align: inherit;
}
.tappable:active {
opacity: 0.6;
}
</style>
</head>
<body>
<div class="screen">
<div class="title">Welcome back</div>
<div class="subtitle">Sign in to pick up where you left off.</div>
<input class="email" type="email" placeholder="Email" />
<input class="password" type="password" placeholder="Password" />
<div class="forgot">Forgot password?</div>
<button type="button" class="tappable group" onclick="handleSignIn()">
<div class="signIn"></div>
<div class="signInLabel">Sign in</div>
</button>
</div>
<script>
function handleSignIn() {}
</script>
</body>
</html>What this does not do
This is a layout, and the generated code is honest about that:
- No logic.
handleSignInis an empty function. Calling your auth API, validating the email and showing errors are yours to add. The fields are uncontrolled in React Native and Flutter, and bound to throwaway state in SwiftUI. - Fixed size. The screen is 390 by 844 and does not reflow. On a smaller or larger phone you would draw another screen at that size.
- No keyboard avoidance. Nothing moves when the keyboard opens. If your layout needs that, wrap the screen in your platform's keyboard-avoiding view.
- Fonts by name. The code asks for
Interby family name and does not embed the font file, so add it to your project (the HTML export links it from Google Fonts).
Make your own
Open the editor, change any number, and the four files above change with it. What you can build lists every control and property the canvas supports, limits included.