HTML5
Beginner
Accessible Forms
· 6 min read
The spellcheck Attribute
Lesson 33 of 36 in the HTML5 learning path.
How do I turn spell checking off for code and on for prose?
spellcheck is a hint to the browser checker. false leaves code alone. true is reasonable for a blurb.
It is not a grammar service you control, and it can be a privacy issue on secret text.
Syntax & Parameters
<textarea spellcheck="false"></textarea>
Example
Interactive preview available<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Editor</title>
<style>
body{font:1rem/1.5 sans-serif;margin:2rem} label{display:block;margin:.4rem 0}
</style>
</head>
<body>
<form method="post" action="/notes"><label for="code">Starter code</label><textarea id="code" name="code" spellcheck="false" rows="4">const seats = 20;</textarea><label for="blurb">Blurb</label><textarea id="blurb" name="blurb" spellcheck="true" rows="3"></textarea><button>Save</button></form>
</body>
</html>
Expected Output
const is not underlined in the code box. The blurb box may flag misspellings.
Line-by-Line Walkthrough
- The code box holds a JavaScript line.
- spellcheck false asks the browser not to underline tokens.
- The blurb is prose, so spellcheck true fits.
- rows sets a starting height.
- The form still posts both values.
- The checker does not block submit.
- Users can override the hint in settings.
- Leave spellcheck off for secrets.
Common Pitfalls & Security
spellcheck is a hint and a privacy choice.
- Checking code hides real prose mistakes in the same form.
- Password fields should not be checked.
- Some systems send checked text off the device.
- The checker is not a content review.
Best Practices & Modern Standards
Turn it off for code, slugs, and identifiers. Leave it on for titles and blurbs.
Never treat it as validation.
Real-World Use
The lesson editor spellchecks the blurb and leaves the sample box alone so instructors stop fighting underlines on const.
Frequently Asked Questions
Does it block submit?
No. It only decorates text.
Can the user override it?
Yes. Browser settings can ignore the attribute.
Should code be unchecked?
Yes. Identifiers are not dictionary words.
Is it safe for secrets?
Turn it off. Some checkers leave the device.