Responsive profile card
A friendly introduction with a flexible layout and a clear next step.
View exampleA good first building block
Choose a timezone and see its time and date using Intl.DateTimeFormat.
<main
><h1>A window into another time</h1><label for="zone">Timezone</label
><select id="zone"
><option value="UTC">UTC</option
><option value="America/New_York">New York</option
><option value="Europe/London">London</option
><option value="Asia/Tokyo">Tokyo</option
><option value="Pacific/Auckland">Auckland</option></select
><p><time id="world-time">Loading time…</time></p
><p id="world-date"></p
><button id="pause-clock" aria-pressed="false">Pause updates</button
><p id="world-note">Time comes from your device clock.</p></main
>:root {
font-family: system-ui, sans-serif;
color: #18223b;
}
* {
box-sizing: border-box;
}
body {
margin: 0;
min-height: 100vh;
padding: 24px;
background: #edf1ff;
display: grid;
place-items: center;
}
main {
width: min(100%, 480px);
background: white;
border-radius: 20px;
padding: 24px;
}
h1 {
font-size: 24px;
margin: 0 0 16px;
}
button,
input,
select,
textarea {
font: inherit;
}
button {
min-height: 44px;
border: 1px solid #afbddd;
border-radius: 10px;
padding: 10px 14px;
background: #eff3ff;
color: #18223b;
cursor: pointer;
}
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
outline: 3px solid #3658bf;
outline-offset: 3px;
}
p {
line-height: 1.65;
}
label {
display: block;
margin: 16px 0 6px;
}
input:not([type="checkbox"]),
select,
textarea {
max-width: 100%;
width: 100%;
padding: 10px;
border: 1px solid #7a8496;
border-radius: 8px;
}
button:disabled {
opacity: 0.5;
cursor: default;
}
time {
display: block;
font-size: clamp(30px, 8vw, 48px);
font-variant-numeric: tabular-nums;
font-weight: 700;
}const zone = document.querySelector("#zone"),
time = document.querySelector("#world-time"),
date = document.querySelector("#world-date"),
pause = document.querySelector("#pause-clock");
let paused = false;
function update() {
if (paused || document.hidden) return;
const now = new Date();
try {
time.textContent = new Intl.DateTimeFormat("en-GB", {
timeZone: zone.value,
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
hour12: false,
}).format(now);
time.dateTime = now.toISOString();
date.textContent = new Intl.DateTimeFormat("en-GB", {
timeZone: zone.value,
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
}).format(now);
} catch {
time.textContent = "This timezone is not available in your browser.";
date.textContent = "";
}
}
zone.addEventListener("change", () => {
const wasPaused = paused;
paused = false;
update();
paused = wasPaused;
});
pause.addEventListener("click", () => {
paused = !paused;
pause.setAttribute("aria-pressed", String(paused));
pause.textContent = paused ? "Resume updates" : "Pause updates";
update();
});
document.addEventListener("visibilitychange", update);
setInterval(update, 1000);
update();<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My code example</title>
<style>
:root {
font-family: system-ui, sans-serif;
color: #18223b;
}
* {
box-sizing: border-box;
}
body {
margin: 0;
min-height: 100vh;
padding: 24px;
background: #edf1ff;
display: grid;
place-items: center;
}
main {
width: min(100%, 480px);
background: white;
border-radius: 20px;
padding: 24px;
}
h1 {
font-size: 24px;
margin: 0 0 16px;
}
button,
input,
select,
textarea {
font: inherit;
}
button {
min-height: 44px;
border: 1px solid #afbddd;
border-radius: 10px;
padding: 10px 14px;
background: #eff3ff;
color: #18223b;
cursor: pointer;
}
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
outline: 3px solid #3658bf;
outline-offset: 3px;
}
p {
line-height: 1.65;
}
label {
display: block;
margin: 16px 0 6px;
}
input:not([type="checkbox"]),
select,
textarea {
max-width: 100%;
width: 100%;
padding: 10px;
border: 1px solid #7a8496;
border-radius: 8px;
}
button:disabled {
opacity: 0.5;
cursor: default;
}
time {
display: block;
font-size: clamp(30px, 8vw, 48px);
font-variant-numeric: tabular-nums;
font-weight: 700;
}
</style>
</head>
<body>
<main
><h1>A window into another time</h1><label for="zone">Timezone</label
><select id="zone"
><option value="UTC">UTC</option
><option value="America/New_York">New York</option
><option value="Europe/London">London</option
><option value="Asia/Tokyo">Tokyo</option
><option value="Pacific/Auckland">Auckland</option></select
><p><time id="world-time">Loading time…</time></p
><p id="world-date"></p
><button id="pause-clock" aria-pressed="false">Pause updates</button
><p id="world-note">Time comes from your device clock.</p></main
>
<script>
const zone = document.querySelector("#zone"),
time = document.querySelector("#world-time"),
date = document.querySelector("#world-date"),
pause = document.querySelector("#pause-clock");
let paused = false;
function update() {
if (paused || document.hidden) return;
const now = new Date();
try {
time.textContent = new Intl.DateTimeFormat("en-GB", {
timeZone: zone.value,
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
hour12: false,
}).format(now);
time.dateTime = now.toISOString();
date.textContent = new Intl.DateTimeFormat("en-GB", {
timeZone: zone.value,
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
}).format(now);
} catch {
time.textContent = "This timezone is not available in your browser.";
date.textContent = "";
}
}
zone.addEventListener("change", () => {
const wasPaused = paused;
paused = false;
update();
paused = wasPaused;
});
pause.addEventListener("click", () => {
paused = !paused;
pause.setAttribute("aria-pressed", String(paused));
pause.textContent = paused ? "Resume updates" : "Pause updates";
update();
});
document.addEventListener("visibilitychange", update);
setInterval(update, 1000);
update();
</script>
</body>
</html>example.html.Intl.DateTimeFormat applies the browser timezone data, including daylight-saving rules; fixed hour offsets do not. The machine-readable time is the same UTC instant while the display uses the selected zone. This is a device-clock demonstration, not a server-synchronized clock. Updates pause while the document is hidden.
Historical purpose: Historical title/link recorded at this exact path. The archived implementation was not recovered; this is newly authored code for the named purpose.
Intl formats supported IANA timezones using the device clock. Browser timezone data can vary; an unsupported zone should be handled before adding it. Pause stops updates, and refresh resumes them. It does not verify clock accuracy or contact a time service.
This is newly authored code. It uses system fonts and no external assets.
Keep the ideas going