Will you be my Valentine code you can copy

Looking for “will you be my Valentine” code you can copy and run? The example below is a complete HTML document, with its CSS and JavaScript included in the same file. It displays a responsive Valentine card and two working buttons. The example does not require any external fonts, JavaScript libraries, API keys or a database.

Copy the complete HTML example

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>My Valentine</title>
  <style>
    * { box-sizing: border-box; }
    body {
      margin: 0; min-height: 100vh; display: grid;
      place-items: center; padding: 20px;
      background: #fff0f4; color: #70223f;
      font: 18px/1.5 system-ui, sans-serif;
    }
    main {
      width: min(100%, 420px); padding: 32px;
      border-radius: 24px; background: white;
      text-align: center;
    }
    h1 { font: bold 36px/1.1 Georgia, serif; }
    button {
      font: inherit; padding: 12px 18px;
      border: 1px solid #a62c57;
      border-radius: 24px; margin: 4px;
      color: #70223f; background: white;
      cursor: pointer;
    }
    #yes { color: white; background: #a62c57; }
    button:focus-visible { outline: 3px solid #70223f; outline-offset: 4px; }
  </style>
</head>
<body>
  <main>
    <h1>Will you be my Valentine?</h1>
    <p>I would love to spend the day with you.</p>
    <button id="yes" type="button">Yes!</button>
    <button id="no" type="button">No, thank you</button>
    <p id="answer" role="status"></p>
  </main>
  <script>
    const answer = document.getElementById("answer");
    document.getElementById("yes").addEventListener("click", () => {
      answer.textContent = "You made my day!";
    });
    document.getElementById("no").addEventListener("click", () => {
      answer.textContent = "Thank you for being honest.";
    });
  </script>
</body>
</html>

Run the code on your own computer

Open a plain-text editor such as Notepad or a code editor. Copy the entire document above, beginning with the doctype declaration and ending with the closing HTML tag. Save it as index.html. If your editor adds a text extension automatically, check that the saved filename ends in .html rather than .html.txt.

Double-click the saved file to open it in a browser. You should see a centered white card against a soft pink background. Click Yes and check the positive response. Click No and check that the polite acknowledgment appears instead. No server or internet connection is needed for this local test.

If you only see the source text rather than a web page, check the extension and make sure you saved the raw HTML instead of a formatted document. If a button does nothing, check that the closing script tag and the JavaScript lines were copied completely.

Understand the three parts of the example

The HTML defines the structure. The main element contains a heading, a short note, two buttons and an empty response paragraph. Each button has a distinct ID, so JavaScript can find the correct element.

The CSS defines the appearance. The body uses a grid layout to center the card, and the main element uses a width that adapts to the available space. Button padding and focus outlines help with touch and keyboard interactions. These are ordinary CSS declarations, so you can modify them without introducing a dependency.

The JavaScript defines the behavior. Each button has a click listener that changes the response paragraph using textContent. It does not send a network request or store the answer. The status role helps assistive technology announce the changed message.

Customize the question and your note

Replace the text inside the h1 element with your own question. Change the paragraph immediately beneath it to your personal note. Keep the button IDs as they are unless you also update the matching JavaScript selectors.

You can add a first name or nickname directly to the heading. For a public hosted page, avoid personal details such as full names, addresses, phone numbers or private information. Consider using a nickname, especially if the page is intended to be a one-time surprise.

The response strings appear at the bottom of the example, inside the two click listeners. Change them to something that sounds like you. Keep the No response respectful and let both buttons remain usable.

Change the colors and typography

The background and text color declarations in the body control the page's overall palette. The main element sets the card's background and spacing. Change its border-radius if you prefer a more classic rectangular card. The button rules set their border, padding and text colors.

The example uses system fonts and Georgia, which avoids loading remote font files. You can choose another installed typeface, but remember that a font available on your computer might not be installed on the recipient's device. Keep a generic fallback in the font declaration.

When changing the colors, preserve readable contrast. A pale pink button with white text can be difficult to read. Test the design at a small browser width before you publish it.

Share a working website, not a local file path

A local index.html file is only accessible on your device until you send the file itself or host it on the web. For an ordinary clickable invitation link, use a static hosting service such as GitHub Pages. Upload the file, enable static publishing and test the generated public address in a different browser. The Valentine website guide explains this approach in more detail.

This example is deliberately self-contained. It cannot notify you when someone presses a button, and hosting it on a static server does not add that ability automatically. Let the recipient reply in your chat instead.

Prefer a no-code Valentine link?

If you only need to send a personalized invitation rather than learn HTML, use our free Valentine link generator. It provides a live preview, four card themes, an animated envelope and shareable links without a separate hosting project. For a more minimal interaction, see the yes or no invitation guide.

Frequently asked questions

Does this example require a JavaScript library?

No. It uses standard HTML, CSS and browser JavaScript in a single file.

Can I change the answer messages?

Yes. Edit the two textContent strings inside the click listeners.

Does the code send answers to me?

No. The response is only displayed in the browser.