research/hiding-a-honeypot-field
Hiding a Honeypot Field: What Bots, Keyboards and Screen Readers See, Tested With Playwright
Engineering Note · November 25, 2026 · 8 minute read · Forms · Accessibility · Playwright · Spam
To hide a honeypot field, use display: none, the hidden attribute or visibility: hidden. In Chromium 158, all three kept the field out of the accessibility tree and out of the Tab order, so screen-reader and keyboard users never reach it, while a bot that fills every input in the HTML still filled it. The two “visually hidden” methods many tutorials suggest, moving the field off-screen or using an sr-only class, left the field announced as a textbox and reachable with Tab: a keyboard user typed into the trap and would have had their message thrown away. An <input type="hidden"> caught no bots at all.
Everything below was run on Linux with Node.js 22.23.5, Playwright 1.63.0 and its bundled Chromium 158.0.8127.36, headless. The outputs are the real ones from these runs.
What is a honeypot, and why does hiding it matter?
A honeypot is an extra form field that people never fill in. Simple spam scripts read the form’s HTML and put a value in every field, so if the honeypot comes back filled, the server drops the submission. It is cheap and invisible to visitors, which is why it sits first in the form pipeline we described in Isolating Failures in a Form Pipeline.
The catch is “invisible to visitors.” Visitors are not only people looking at a screen. Keyboard users move with Tab, and screen-reader users hear what the browser’s accessibility tree contains. If the field is hidden from the eye but not from those two, a real person can land in it, type something, and lose their message. The server will never tell them.
So the question for each hiding method is: does the field stay away from people while staying in front of bots?
What did we test?
One form with Name, Email and Message fields, plus a honeypot named website with a visible label, hidden seven different ways:
| Method | Markup around the honeypot |
|---|---|
display:none | wrapper div with style="display:none" |
| hidden attribute | wrapper div hidden |
visibility:hidden | wrapper div with style="visibility:hidden" |
| off-screen | wrapper with position:absolute; left:-9999px |
| off-screen + aria/tab | as above, plus aria-hidden="true" on the wrapper, tabindex="-1" and autocomplete="off" on the input |
| sr-only class | the usual “screen-reader only” clip-to-1px styles |
type="hidden" | <input type="hidden" name="website"> |
For each one we checked four things:
- Screen readers: is there a textbox named “Website” in the form’s accessibility tree? We used Playwright’s
ariaSnapshot(), which serializes the tree Chromium exposes to assistive technology. - Keyboard users: starting in Name, press Tab and type one letter in each field reached. Which fields did focus visit, and did the honeypot end up with a value?
- Bot A, an HTML filler: a script that sets
.valueon everyinputandtextareathat isn’ttype="hidden". This is the classic form-spam script. - Bot B, a browser driver: a script that calls Playwright’s
page.fill()on each field by selector. Playwright waits for an element to be visible and editable before it types, so this stands in for bots that drive a real browser.
The test script
// honeypot.mjs: seven ways to hide a honeypot field, checked in Chromium with Playwright.
import { createRequire } from 'node:module';
const { chromium } = createRequire(import.meta.url)('playwright');
const SR_ONLY = 'position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0';
const variants = {
'display:none': `<div style="display:none"><label for="website">Website</label><input id="website" name="website"></div>`,
'hidden attribute': `<div hidden><label for="website">Website</label><input id="website" name="website"></div>`,
'visibility:hidden': `<div style="visibility:hidden"><label for="website">Website</label><input id="website" name="website"></div>`,
'off-screen': `<div style="position:absolute;left:-9999px"><label for="website">Website</label><input id="website" name="website"></div>`,
'off-screen + aria/tab': `<div style="position:absolute;left:-9999px" aria-hidden="true"><label for="website">Website</label><input id="website" name="website" tabindex="-1" autocomplete="off"></div>`,
'sr-only class': `<div style="${SR_ONLY}"><label for="website">Website</label><input id="website" name="website"></div>`,
'type="hidden"': `<input type="hidden" id="website" name="website">`,
};
const page_ = (trap) => `<!doctype html><title>t</title>
<form id="f">
<label for="name">Name</label><input id="name" name="name" autocomplete="name">
<label for="email">Email</label><input id="email" name="email" type="email" autocomplete="email">
${trap}
<label for="message">Message</label><textarea id="message" name="message"></textarea>
<button>Send</button>
</form>`;
const browser = await chromium.launch();
const rows = [];
for (const [label, trap] of Object.entries(variants)) {
const ctx = await browser.newContext();
const page = await ctx.newPage();
await page.setContent(page_(trap));
// 1. Does the accessibility tree (what a screen reader reads) contain the field?
const tree = await page.locator('#f').ariaSnapshot();
const inTree = /textbox "Website"/.test(tree);
// 2. A keyboard user: Tab from Name to the button, typing a letter in every field reached.
await page.focus('#name');
const stops = [];
for (let i = 0; i < 6; i++) {
const id = await page.evaluate(() => document.activeElement.id || document.activeElement.tagName);
stops.push(id);
if (id === 'BUTTON') break;
await page.keyboard.type('a');
await page.keyboard.press('Tab');
}
const keyboardFilled = (await page.evaluate(() => document.querySelector('#website').value)) !== '';
// 3. Bot A: sets .value on every input and textarea it finds in the HTML, except type=hidden.
await page.setContent(page_(trap));
await page.evaluate(() => {
for (const el of document.querySelectorAll('input, textarea'))
if (el.type !== 'hidden') el.value = 'spam';
});
const botA = await page.evaluate(() => new FormData(document.querySelector('#f')).get('website'));
// 4. Bot B: drives the browser like a person, filling each field Playwright considers fillable.
await page.setContent(page_(trap));
for (const sel of ['#name', '#email', '#website', '#message']) {
try { await page.fill(sel, sel === '#email' ? 'a@b.co' : 'spam', { timeout: 300 }); } catch {}
}
const botB = await page.evaluate(() => new FormData(document.querySelector('#f')).get('website'));
rows.push({ label, inTree, keyboardStops: stops.join('>'), keyboardFilled, botA: botA === 'spam', botB: botB === 'spam' });
await ctx.close();
}
console.log(`Chromium ${browser.version()}`);
console.table(rows);
await browser.close();
We ran it with NODE_PATH=$(npm root -g) node honeypot.mjs, using the globally installed Playwright. The createRequire line is there because ES modules ignore NODE_PATH.
What happened?
Chromium 158.0.8127.36
┌─────────┬─────────────────────────┬────────┬─────────────────────────────────────┬────────────────┬───────┬───────┐
│ (index) │ label │ inTree │ keyboardStops │ keyboardFilled │ botA │ botB │
├─────────┼─────────────────────────┼────────┼─────────────────────────────────────┼────────────────┼───────┼───────┤
│ 0 │ 'display:none' │ false │ 'name>email>message>BUTTON' │ false │ true │ false │
│ 1 │ 'hidden attribute' │ false │ 'name>email>message>BUTTON' │ false │ true │ false │
│ 2 │ 'visibility:hidden' │ false │ 'name>email>message>BUTTON' │ false │ true │ false │
│ 3 │ 'off-screen' │ true │ 'name>email>website>message>BUTTON' │ true │ true │ true │
│ 4 │ 'off-screen + aria/tab' │ false │ 'name>email>message>BUTTON' │ false │ true │ true │
│ 5 │ 'sr-only class' │ true │ 'name>email>website>message>BUTTON' │ true │ true │ true │
│ 6 │ 'type="hidden"' │ false │ 'name>email>message>BUTTON' │ false │ false │ false │
└─────────┴─────────────────────────┴────────┴─────────────────────────────────────┴────────────────┴───────┴───────┘
Reading it row by row:
display:none,hiddenandvisibility:hiddenbehaved the same. Not in the accessibility tree, skipped by Tab, filled by the HTML filler (Bot A), skipped by the browser driver (Bot B). People are safe, and the classic spam script is caught.- Off-screen is the dangerous one. The field stayed in the accessibility tree as a textbox named “Website”, focus went Name, Email, Website, Message, and the keyboard user’s “a” landed in the trap. On a real site, that person’s message would be silently dropped. Bot B filled it too, because an off-screen element still has a size, so Playwright counts it as visible.
- The
sr-onlyclass is the same mistake with a different name. It is designed to hide things from the eye and keep them for screen readers, which is the opposite of what a honeypot needs. - Off-screen plus
aria-hiddenandtabindex="-1"fixed the people problem and caught both bots. It is the only method that caught Bot B. It also relies on three attributes staying in sync; forgettabindex="-1"in a later edit and keyboard users are back in the trap. type="hidden"caught nothing. Bot A skipped it on purpose, as real scripts do, because hidden inputs usually carry tokens.
Which one should you use?
For most contact forms, display: none on a wrapper that contains both the label and the input. It is one property, it is hard to undo by accident, and it hides the field from every kind of person we tested while still catching the commonest spam scripts.
If you see bots that drive a real browser getting through, the off-screen method with aria-hidden="true" on the wrapper and tabindex="-1" on the input catches more. If you use it, add a test like the one above to your suite, so a future edit that drops one of those attributes fails a build instead of quietly trapping keyboard users.
Whichever you choose:
- Give the field a plain name like
websiteand a label, so it looks real in the HTML. - Drop a trapped submission with a normal success response, so the bot learns nothing. The Turnstile checklist shows the server side.
- Count what you drop. If the honeypot count jumps after a site change, check that real people are not falling in. The monthly test in today’s article, Your Contact Form Is a Sales Channel, would catch a real person’s message going missing.
- Keep the other layers. A honeypot only stops scripts that fill fields blindly. A bot check and a rate limit cover what it misses.
Limitations
- Only Chromium was tested. Firefox and Safari build their accessibility trees separately and may differ in details, though the CSS rules involved are standard.
- The accessibility check used Playwright’s
ariaSnapshot(), which reads the tree Chromium exposes. We did not run a real screen reader such as NVDA, JAWS or VoiceOver. - We did not test browser autofill. Autofill needs a saved profile in a real browser, which we could not set up meaningfully in a headless run, so we can’t say whether Chromium would fill a hidden field named
website. Theautocomplete="off"in one variant was not tested for effect. - The two bots are simple stand-ins we wrote. Real spam tools vary, and some read CSS or wait for human-like timing.
- The test ran a static page with
page.setContent(); it did not submit to a server.
Related reading
- Isolating Failures in a Form Pipeline: Save First, Notify Independently
- A Cloudflare Turnstile Integration Checklist for Contact Forms
- Telling Screen-Reader Users a Link Opens a New Tab: Hidden Text or aria-label?
Frequently asked questions
What is a honeypot field on a form?
It is an extra input that real visitors never see or fill in, such as a field named "website" hidden from view. Simple spam scripts fill every field they find in the HTML, so a submission with that field filled is treated as spam and dropped. It costs visitors nothing, unlike a puzzle or challenge.
What is the best way to hide a honeypot field?
In our Chromium test, display:none, the hidden attribute and visibility:hidden all kept the field out of the accessibility tree and the Tab order, while a bot that sets every input's value still filled it. Any of the three works. We use display:none on a wrapper that also holds the label.
Can a honeypot field confuse screen-reader users?
Yes, if it is hidden only visually. A field moved off-screen, or hidden with a screen-reader-only class, stayed in the accessibility tree as a textbox named "Website" in our test, so a screen reader would announce it. A visitor who fills it in would then have their message dropped as spam.
Does a honeypot stop bots that drive a real browser?
Only some of them. A bot that uses a browser automation tool to fill visible fields skipped the field hidden with display:none, the hidden attribute or visibility:hidden, because the tool refuses to type into elements that are not visible. Treat a honeypot as one cheap layer next to a bot check and a rate limit, not a complete defense.
Should a honeypot use an input with type="hidden"?
No. In our test, a bot that fills every input skipped type="hidden", and so did a browser-driving bot, so it caught nothing. Bots expect hidden inputs to carry values like tokens and leave them alone. A honeypot needs to look like a normal text field in the HTML.