Nanfeng

Notes on software development, code, and curious ideas

A Valentine's Day Message Page for Programmers

A hand-made web page is a simple way to combine programming with a personal Valentine’s Day message. The example below reveals text one character at a time and includes controls that remain usable without a mouse.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>A Message for You</title>
<style>
body { min-height: 100vh; margin: 0; display: grid; place-items: center;
font: 1.1rem/1.7 system-ui, sans-serif; background: #fff0f4; color: #572b3a; }
article { width: min(38rem, 88vw); padding: 2rem; background: white;
border-radius: 1rem; box-shadow: 0 1rem 3rem #7b334422; }
button { padding: .7rem 1rem; border: 0; border-radius: 999px;
color: white; background: #e43f6f; cursor: pointer; }
</style>
</head>
<body>
<article>
<h1>For someone wonderful</h1>
<p id="message"></p>
<button id="start">Read my message</button>
</article>
<script>
const text = "Thank you for making ordinary days feel special. Happy Valentine's Day!";
const output = document.querySelector("#message");
const button = document.querySelector("#start");

button.addEventListener("click", () => {
button.disabled = true;
let index = 0;
const typing = setInterval(() => {
output.textContent += text[index++];
if (index === text.length) clearInterval(typing);
}, 55);
}, { once: true });
</script>
</body>
</html>

Customize the message, colors, and heading, then save the file as index.html. Use textContent rather than injecting untrusted HTML, and ask permission before publishing somebody’s name, photo, or private story.

+