Disable spell-checking on HTML textfields

HtmlForms

Html Problem Overview


Can I somehow disable spell-checking on HTML textfields (as seen in e.g. Safari)?

Html Solutions


Solution 1 - Html

Update: As suggested by a commenter (additional credit to https://stackoverflow.com/questions/3416867/how-can-i-disable-the-spell-checker-on-text-inputs-on-the-iphone), use this to handle all desktop and mobile browsers.

<tag autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>

Original answer: Javascript cannot override user settings, so unless you use another mechanism other than textfields, this is not (or shouldn't be) possible.

Solution 2 - Html

Yes, use spellcheck="false", as defined by HTML5, for example:

<textarea spellcheck="false">
    ...
</textarea>

Solution 3 - Html

For Grammarly you can use:

<textarea data-gramm="false" />

Solution 4 - Html

An IFrame WILL "trigger" the spell checker (if it has content-editable set to true) just as a textfield, at least in Chrome.

Solution 5 - Html

The following code snippet disables it for all textarea and input[type=text] elements:

(function () {
    function disableSpellCheck() {
        let selector = 'input[type=text], textarea';
        let textFields = document.querySelectorAll(selector);

        textFields.forEach(
            function (field, _currentIndex, _listObj) {
                field.spellcheck = false;
            }
        );
    }

    disableSpellCheck();
})();

Solution 6 - Html

While specifying spellcheck="false" in the < tag > will certainly disable that feature, it's handy to be able to toggle that functionality on and off as needed after the page has loaded. So here's a non-jQuery way to set the spellcheck attribute programmatically:

푯푻푴푳:

<textarea id="my-ta" spellcheck="whatever">abcd dcba</textarea>

푱푨푽푨푺푪푹푰푷푻:

function setSpellCheck( mode ) {
    var myTextArea = document.getElementById( "my-ta" )
        , myTextAreaValue = myTextArea.value
    ;
    myTextArea.value = '';
    myTextArea.setAttribute( "spellcheck", String( mode ) );
    myTextArea.value = myTextAreaValue;
    myTextArea.focus();
}

푼푺푨푮푬:

setSpellCheck( true );
setSpellCheck( 'false' );

The function argument may be either boolean or string.

No need to loop through the textarea contents, we just cut 'n paste what's there, and then set focus.

Tested in blink engines (Chrome(ium), Edge, etc.)

Solution 7 - Html

If you have created your HTML element dynamically, you'll want to disable the attribute via JS. There is a little trap however:

When setting elem.contentEditable you can use either the boolean false or the string "false". But when you set elem.spellcheck, you can only use the boolean - for some reason. Your options are thus:

elem.spellcheck = false;

Or the option Mac provided in his answer:

elem.setAttribute("spellcheck", "false"); // Both string and boolean work here. 

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMichiel de MareView Question on Stackoverflow
Solution 1 - HtmlEric WendelinView Answer on Stackoverflow
Solution 2 - HtmlMs2gerView Answer on Stackoverflow
Solution 3 - HtmlsensorView Answer on Stackoverflow
Solution 4 - HtmlJCOC611View Answer on Stackoverflow
Solution 5 - HtmlArturView Answer on Stackoverflow
Solution 6 - HtmlMacView Answer on Stackoverflow
Solution 7 - HtmlFomView Answer on Stackoverflow