Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to turn off spell checking (grammar correction) for HTML form elements?
The spellcheck attribute in HTML controls whether the browser's spell checking feature is enabled or disabled for text input fields. By default, most browsers enable spell checking on text inputs and textareas, showing red underlines for misspelled words.
Syntax
Following is the syntax for the spellcheck attribute −
<input type="text"> <textarea></textarea>
The spellcheck attribute accepts three values −
- true − Enables spell checking for the element
- false − Disables spell checking for the element
- default − Uses the browser's default spell check behavior
Disabling Spell Check
To disable spell checking on form elements, set the spellcheck attribute to "false". This is particularly useful for fields that contain technical terms, usernames, or other content where spell checking is not appropriate.
Example
<!DOCTYPE html>
<html>
<head>
<title>Disabling Spellcheck Example</title>
</head>
<body style="font-family: Arial, sans-serif; padding: 20px;">
<h1>Spellcheck Control Example</h1>
<form>
<p>Username (spellcheck disabled):</p>
<input type="text" name="username" style="padding: 8px; width: 300px;">
<p>About Yourself (spellcheck enabled):</p>
<textarea name="about" rows="4" cols="40" style="padding: 8px;"></textarea><br><br>
<input type="submit" value="Submit" style="padding: 8px 16px;">
</form>
<p><em>Type incorrect spellings in the fields above to see the difference</em></p>
</body>
</html>
In this example, the username field has spell checking disabled, while the textarea has it enabled. Try typing misspelled words in both fields to observe the behavior.
Enabling Spell Check
To explicitly enable spell checking, set the spellcheck attribute to "true". This ensures spell checking is active even if the browser's default behavior would disable it.
Example
<!DOCTYPE html>
<html>
<head>
<title>Enabling Spellcheck Example</title>
</head>
<body style="font-family: Arial, sans-serif; padding: 20px;">
<h2>Email Composition</h2>
<form>
<p>Subject:</p>
<input type="text" name="subject" style="padding: 8px; width: 400px;">
<p>Message Body:</p>
<textarea name="message" rows="6" cols="50" style="padding: 8px;"></textarea><br><br>
<input type="submit" value="Send Email" style="padding: 8px 16px;">
</form>
</body>
</html>
Both the subject line and message body have spell checking enabled, making it easier to catch typos in email composition.
Browser Compatibility
The spellcheck attribute is supported in all modern browsers including Chrome, Firefox, Safari, and Edge. However, the visual appearance of spell check indicators may vary between browsers −
- Chrome/Edge − Red wavy underlines for misspelled words
- Firefox − Red dotted underlines for misspelled words
- Safari − Red dotted underlines for misspelled words
Common Use Cases
Following are common scenarios where you might want to control spell checking −
| Disable Spellcheck (false) | Enable Spellcheck (true) |
|---|---|
| Username fields | Email composition |
| Code input areas | Blog post content |
| API keys or tokens | Comment sections |
| Technical identifiers | Form descriptions |
| Product codes | User feedback forms |
Example − Mixed Spellcheck Settings
Following example demonstrates different spellcheck settings in a single form −
<!DOCTYPE html>
<html>
<head>
<title>Mixed Spellcheck Settings</title>
</head>
<body style="font-family: Arial, sans-serif; padding: 20px;">
<h2>User Registration Form</h2>
<form>
<p>Username (no spellcheck):</p>
<input type="text" name="username" style="padding: 8px; width: 250px;">
<p>Email (no spellcheck):</p>
<input type="email" name="email" style="padding: 8px; width: 250px;">
<p>Bio (with spellcheck):</p>
<textarea name="bio" rows="4" cols="35" style="padding: 8px;"></textarea><br><br>
<p>Default behavior:</p>
<input type="text" name="other" style="padding: 8px; width: 250px;"><br><br>
<input type="submit" value="Register" style="padding: 10px 20px;">
</form>
</body>
</html>
This form shows practical use of the spellcheck attribute: technical fields like username and email have it disabled, while descriptive content like the bio has it enabled.
Conclusion
The spellcheck attribute provides fine-grained control over browser spell checking in HTML forms. Set it to "false" for technical fields like usernames or code inputs, and "true" for content fields where proper spelling matters, such as messages or descriptions.
