A practical guide ·
“Will you be my Valentine?” HTML code vs. a ready-made page
How the runaway No button works in HTML and JavaScript, the phone and sharing problems to expect, and an honest look at coding it versus using a ready page.
Yes, you can build it in one HTML file
A “Will you be my Valentine?” page with a runaway No button needs one HTML file: a heading, two buttons, a little CSS and about fifteen lines of JavaScript that move No whenever someone reaches for it. Coding it is a fun evening project if you already know some web basics; if you want it sent tonight, a ready-made page is faster.
The code itself is the easy part. What takes time is making it behave on a phone, putting it online so it opens from a link, and polishing it so it looks like a gift rather than a test page. This guide walks through how the trick works, what usually breaks, and how to decide which route suits you.
How the runaway No button works
The idea is simple: when the pointer gets near No, you move it to a random spot on the screen before it can be pressed. Give the No button position: fixed so you can place it anywhere, then listen for the pointer touching it. Pointer events cover a mouse, a pen and a finger with one set of events, so a single listener for pointerenter plus one for pointerdown handles desktop and phone.
In the handler, pick a new place inside the window: no.style.left = Math.random() * (innerWidth - no.offsetWidth) + 'px', and the same for top using innerHeight and offsetHeight. Subtracting the button’s own size keeps it from escaping off the edge. That’s the whole trick. Everything else is presentation.
Making Yes grow and No talk back
Keep a counter that goes up each time No runs away. Use it to scale the Yes button, something like yes.style.transform = 'scale(' + (1 + tries * 0.15) + ')', and cap it so Yes never covers the whole screen and hides the question. Swap the No label from a short list on each escape: “Are you sure?”, “Really?”, “Last chance”, “Okay, now you’re just being stubborn.”
When Yes is clicked, hide both buttons and show your message, a photo or a simple shower of hearts. Write that message like a person, not a programmer: “I knew you’d crack eventually. Dinner at Lucia’s, Saturday at 7?” A specific plan on the final screen turns a coding joke into a real invitation.
What breaks on phones
Most of these pages are written on a laptop and opened on a phone, and that’s where the bugs show up. There’s no hover on a touchscreen, so a page that only listens for mouse movement lets No get tapped right away. A button moved to a random spot can land under the Yes button, behind a notch, or half off a small screen when the phone rotates.
Test on a real phone, not just a resized browser window. Try it in portrait and landscape, with the text size turned up, and with your thumb jabbing quickly. Add a meta viewport tag so the page isn’t shrunk to a tiny desktop layout. And check that the final message reads well on a narrow screen, since that’s the moment they’ll screenshot.
The part tutorials skip: getting it to them
A file sitting on your laptop isn’t a link. If you text someone the HTML file as an attachment, many phones show it as raw code or a download they can’t easily open. To share it properly, the file has to live on a web host so it has an address that opens in any browser.
There are free static hosting services that do this, but each needs an account and a few steps, and the address you get may look odd in a text preview. Before you send it, open the link yourself on mobile data, not your home Wi-Fi, to make sure it loads for someone else. Then send it with a line that explains it: “I made you a tiny website. Open it on your phone.”
Code it or use a ready page? An honest comparison
Write the code yourself if you enjoy it, if the person you’re asking would love that you built it, or if you want jokes and animations no template has. “I wrote this for you” is a real part of the gift, especially for someone who knows what an evening of debugging costs.
Use a ready-made page if you want it working in a few minutes, tested on phones, with a proper link. A builder like ours puts their name on the question, has four themes, a No button that runs and a Yes that grows, plus a share link and QR code. The tradeoff is fewer custom touches. Neither choice is more romantic. The words and the plan inside matter more than who wrote the JavaScript.
Either way, the real answer stays free
On a page like this, No can’t win, and that’s the joke. In real life, it always can. Whether you coded it or not, say so in the message you send with it: “The No button is rigged, but you can still say no to me for real, and I’ll take it well.”
Only send it to someone who’ll find the chase funny, usually a partner or a person you’re already close to. For a new crush, a page that won’t let them decline can feel like pressure, so a plain, honest question works better. And if they tap Yes, follow up within a day with the real plan, so the code leads somewhere: “You said yes, so Saturday is tacos and the late movie.”
Sources
Keep reading
Funny ways to ask "Will you be my valentine?" →
How to make a “Will you be my Valentine?” link (no code) →
The “yes or no” Valentine page: how the runaway No works →