Honeypot fields remain a viable anti-spam measure in 2025, so a reCAPTCHA-style challenge isn't strictly necessary. The catch is that bots have learned to recognize the naive implementation, so a couple of deliberate choices are required for the trap to function.
The author publishes a Honeypot component that packages the techniques below:
<script>
import { Honeypot } from '@splendidlabz/svelte'
</script>
<Honeypot name="honeypot-name" />
For Astro, the usage looks like this:
---
import { Honeypot } from '@splendidlabz/svelte'
---
<Honeypot name="honeypot-name" />
What Not to Do
Two implementations reliably give the field away:
- Avoid
<input type=hidden>. - Avoid hiding the honeypot with inline CSS.
Modern bots recognize both patterns as traps and skip the field. The working alternative is a text input hidden through CSS that is not inline:
<input class="honeypot" type="text" name="honeypot" />
<style>
.honeypot {
display: none;
}
</style>
Placing the <style> tag close to the honeypot currently works, though that practice may not hold up in the future.
Enhancements You Can Skip
Common honeypot write-ups suggest adding aria-hidden so screen readers ignore the field, plus autocomplete=off and tabindex="-1" to keep it from being selected:
<input ... aria-hidden autocomplete="off" tabindex="-1" />
None of these are needed, since display: none already accomplishes what those attributes are meant to do.
Hardening Against Smarter Bots
Bots improve continuously, so the possibility that they will eventually detect the field above can't be ruled out. A few measures taken now make the honeypot more durable:
- Give the
nameattribute a plausible value such aswebsiteormobilerather than something obvious likespamorhoneypot. - Use believable CSS class names such as
.form-helperinstead of.honeypot. - Move the CSS into a separate file, so the distance between the stylesheet and the field makes the connection harder to establish.
The goal is to convince the spam bot that this is a legitimate field worth filling in.
<input class="form-helper" ... name="occupation" />
<!-- Put this into your CSS file, not directly in the HTML -->
<style>
.form-helper {
display: none;
}
</style>
Done this way, there's a strong chance bots cannot tell the honeypot apart from the real inputs.
Signals at the Form Level
Additional checks belong on the <form> element rather than the field. These attempt to establish whether a human is behind the submission, and every one of them requires JavaScript:
- Detecting a
mousemoveevent somewhere on the page. - Detecting a keyboard event somewhere on the page.
- Confirming the form wasn't completed unusually fast, since people don't work that quickly.
The simplest route the author knows is the Form component from Splendid Labz:
<script>
import { Form, Honeypot } from '@splendidlabz/svelte'
</script>
<Form>
<Honeypot name="honeypot" />
</Form>
In Astro, JavaScript has to be enabled with a client directive:
---
import { Form, Honeypot } from '@splendidlabz/svelte'
---
<Form client:idle>
<Honeypot name="honeypot" />
</Form>
Outside Svelte or Astro, a preventSpam utility performs all three checks:
import { preventSpam } from '@splendidlabz/utils/dom'
let form = document.querySelector('form')
form = preventSpam(form, { honeypotField: 'honeypot' })
form.addEventListener('submit', event => {
event.preventDefault()
if (form.containsSpam()) return
else form.submit()
})
Anyone avoiding those options can apply the underlying idea directly — use JavaScript to detect whether the user interacted with the page at all:
export function preventSpam(
form,
{ honeypotField = 'honeypot', honeypotDuration = 2000 } = {}
) {
const startTime = Date.now()
let hasInteraction = false
// Check for user interaction
function checkForInteraction() {
hasInteraction = true
}
// Listen for a couple of events to check interaction
const events = ['keydown', 'mousemove', 'touchstart', 'click']
events.forEach(event => {
form.addEventListener(event, checkForInteraction, { once: true })
})
// Check for spam via all the available methods
form.containsSpam = function () {
const fillTime = Date.now() - startTime
const isTooFast = fillTime < honeypotDuration
const honeypotInput = form.querySelector(`[name="${honeypotField}"]`)
const hasHoneypotValue = honeypotInput?.value?.trim()
const noInteraction = !hasInteraction
// Clean up event listeners after use
events.forEach(event =>
form.removeEventListener(event, checkForInteraction)
)
return isTooFast || !!hasHoneypotValue || noInteraction
}
}
Pending Work
The author is assembling a broader forms solution: standard HTML elements with simpler syntax and strong accessibility. The set covers Form, Honeypot, text input, textarea, radios, checkboxes, switches, button groups and more, with a landing page already up for anyone who wants early access.
The most effective approach is likely to disguise the honeypot as an ordinary field. For those unwilling to rely on deception, the JavaScript-based bot-detection methods described above serve as an alternative.



