DEV Community

Cover image for 9 UX Fixes That Make OTP Verification Screens Convert Better (with Code)
Authly
Authly

Posted on

9 UX Fixes That Make OTP Verification Screens Convert Better (with Code)

You can have the most reliable OTP delivery in the world and still lose users on the verification screen. Codes that are hard to type, resend buttons that don't work, and vague errors all cause drop-off at the exact moment someone is trying to sign up.

Here are nine fixes that make an OTP screen easier to complete, with front-end code you can copy. It pairs with my Node.js WhatsApp OTP tutorial, but the front-end works with any backend that has a "send code" and a "verify code" endpoint.

1. Use the right input types

Mobile keyboards matter. Use a telephone keyboard for the phone number and a numeric keypad for the code:

<input id="phone" type="tel" inputmode="tel" autocomplete="tel"
       placeholder="+1 415 555 2671" required />

<input id="code" type="text" inputmode="numeric"
       autocomplete="one-time-code" pattern="[0-9]*"
       maxlength="6" placeholder="123456" required />
Enter fullscreen mode Exit fullscreen mode

autocomplete="one-time-code" lets iOS and some Android browsers suggest the code straight from the incoming message, so users don't have to switch apps and copy it.

2. Tell users where the code is coming from

"We sent you a code" isn't enough. If the code arrives on WhatsApp, say so:

We sent a 6-digit code to +1 415 555 2671 on WhatsApp.

Users who expect an SMS and never see one will assume the system is broken. Naming the channel prevents most "I didn't get my code" requests.

3. Show a clear resend timer

Let users request a new code, but not instantly, and show the countdown:

function startResendTimer(button, seconds = 60) {
  let remaining = seconds;
  button.disabled = true;
  button.textContent = `Resend code in ${remaining}s`;

  const timer = setInterval(() => {
    remaining -= 1;
    if (remaining <= 0) {
      clearInterval(timer);
      button.disabled = false;
      button.textContent = "Resend code";
    } else {
      button.textContent = `Resend code in ${remaining}s`;
    }
  }, 1000);
}
Enter fullscreen mode Exit fullscreen mode

The countdown also reduces spam requests, which saves money on every message you send. Remember to enforce the cooldown on the server too, because anything in the browser can be bypassed.

4. Disable the button while the request is running

Double taps create two requests, two messages and two bills:

async function sendCode() {
  const sendBtn = document.getElementById("send");
  const phone = document.getElementById("phone").value.trim();

  sendBtn.disabled = true;
  sendBtn.textContent = "Sending...";

  try {
    const res = await fetch("/auth/send-otp", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ phone }),
    });
    const data = await res.json();

    if (!res.ok) throw new Error(data.error || "Could not send the code");

    window.otpId = data.otpId;
    showCodeStep(phone);
    startResendTimer(document.getElementById("resend"));
  } catch (err) {
    showError(err.message);
    sendBtn.disabled = false;
    sendBtn.textContent = "Send code";
  }
}
Enter fullscreen mode Exit fullscreen mode

5. Verify automatically when the last digit is typed

Removing the extra tap on "Verify" makes the flow feel fast:

const codeInput = document.getElementById("code");

codeInput.addEventListener("input", () => {
  codeInput.value = codeInput.value.replace(/\D/g, ""); // digits only
  if (codeInput.value.length === 6) verifyCode();       // match your code length
});

async function verifyCode() {
  const code = codeInput.value;
  codeInput.disabled = true;

  try {
    const res = await fetch("/auth/verify-otp", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ otpId: window.otpId, code }),
    });
    const data = await res.json();

    if (!res.ok || !data.verified) throw new Error(data.error || "Invalid code");
    onVerified();
  } catch (err) {
    showError(err.message);
    codeInput.disabled = false;
    codeInput.value = "";
    codeInput.focus();
  }
}
Enter fullscreen mode Exit fullscreen mode

Keep a visible "Verify" button as a fallback, for example for screen readers and people who paste a longer code.

6. Write error messages that help

Compare these:

Weak Better
"Error" "That code isn't right. Check it and try again."
"Request failed" "We couldn't send the code. Check the phone number and try again."
"Invalid" "That code has expired. Tap Resend to get a new one."

Keep messages helpful but not too specific about security details. For example, don't reveal whether an account exists.

7. Let users fix a wrong phone number

A typo in the phone number is one of the most common reasons codes never arrive. Always show the number the code was sent to, with a visible "Change number" link that returns to the first step without losing the rest of the form.

8. Offer another channel when the first one fails

If the user has waited and the code hasn't arrived, show a second option next to the resend button, such as "Send via Telegram" or "Send by email". Automatic fallback on the server helps, and a visible manual option covers cases where the user knows WhatsApp isn't available to them.

9. Don't forget accessibility and mobile

  • Put a <label> on every input
  • Use aria-live="polite" on the message area so screen readers announce errors
  • Make tap targets at least 44×44 px
  • Keep the page usable at 320px width
  • Don't rely on colour alone to show an error
<p id="message" role="status" aria-live="polite"></p>
Enter fullscreen mode Exit fullscreen mode

Quick checklist

  • [ ] Correct input types and autocomplete="one-time-code"
  • [ ] Channel and phone number shown on the code screen
  • [ ] Resend countdown, enforced on the server too
  • [ ] Buttons disabled while requests run
  • [ ] Auto-submit when the last digit is entered
  • [ ] Helpful error messages
  • [ ] "Change number" option
  • [ ] A second channel when delivery fails
  • [ ] Accessible labels and live error messages

Wrapping up

OTP screens are a small part of your product, but they sit in the path between a visitor and an account. Small UX improvements here usually lift completion rates more than tweaking the copy on your landing page.

For delivery over WhatsApp, Telegram and Email with automatic fallback, I'm building Authly, and the docs show how to wire up the backend. I'm the maker, and I'd like to hear which of these UX problems you've run into. Tell me in the comments.

Top comments (0)