HTML Basic
HTML Reference
- HTML Tags
- HTML Deprecated Tags
- HTML Events
- HTML Attributes
- accept
- accept-charset
- accesskey
- action
- align
- alt
- as
- async
- autocomplete
- autofocus
- autoplay
- bgcolor
- border
- charset
- checked
- cite
- class
- color
- cols
- colspan
- content
- contenteditable
- controls
- coords
- data
- data-*
- datetime
- default
- defer
- dir
- dirname
- disabled
- download
- draggable
- enctype
- enterkeyhint
- for
- form
- formaction
- headers
- height
- hidden
- high
- href
- hreflang
- http-equiv
- id
- inert
- inputmode
- ismap
- kind
- label
- lang
- list
- loop
- low
- max
- maxlength
- media
- method
- min
- multiple
- muted
- name
- novalidate
- onabort
- onafterprint
- onbeforeprint
- onbeforeunload
- onblur
- oncanplay
- oncanplaythrough
- onchange
- onclick
- oncontextmenu
- oncopy
- oncuechange
- oncut
- ondblclick
- ondrag
- ondragend
- ondragenter
- ondragleave
- ondragover
- ondragstart
- ondrop
- ondurationchange
- onemptied
- onended
- onerror
- onfocus
- onhashchange
- oninput
- oninvalid
- onkeydown
- onkeypress
- onkeyup
- onload
- onloadeddata
- onloadedmetadata
- onloadstart
- onmousedown
- onmousemove
- onmouseout
- onmouseover
- onmouseup
- onmousewheel
- onoffline
- ononline
- onpagehide
- onpageshow
- onpaste
- onpause
- onplay
- onplaying
- onpopstate
- onprogress
- onratechange
- onreset
- onresize
- onscroll
- onsearch
- onseeked
- onseeking
- onselect
- onstalled
- onstorage
- onsubmit
- onsuspend
- ontimeupdate
- ontoggle
- onunload
- onvolumechange
- onwaiting
- onwheel
- open
- optimum
- pattern
- placeholder
- popover
- popovertarget
- popovertargetaction
- poster
- preload
- readonly
- rel
- required
- reversed
- rows
- rowspan
- sandbox
- scope
- selected
- shape
- size
- sizes
- span
- spellcheck
- src
- srcdoc
- srclang
- srcset
- start
- step
- style
- tabindex
- target
- title
- translate
- type
- usemap
- value
- width
- wrap
- HTML Global Attributes
- HTML Status Code
- HTML Language Code
- HTML Country Code
- HTML Charset
- MIME Types
HTML spellcheck Attribute
Photo Credit to CodeToFun
🙋 Introduction
The spellcheck
attribute in HTML is a feature that allows developers to control the spell-checking behavior of text content within editable elements.
It's a valuable tool for enhancing the user experience by providing real-time feedback on spelling errors.
🎯 Purpose of spellcheck
The primary purpose of the spellcheck
attribute is to determine whether the browser should check the spelling of text content within an editable element.
By default, most browsers have spell-checking enabled, but the spellcheck
attribute provides developers with the flexibility to customize this behavior.
💎 Values
The spellcheck
attribute accepts two main values:
- true: This is the default value. It indicates that the browser should perform spell-checking on the text content within the editable element.
- false: This value disables spell-checking for the editable element. Use this when you want to turn off the browser's built-in spell-checking feature.
📄 Example
Let's look at a simple example of how to use the spellcheck
attribute in an HTML document:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Spellcheck Attribute Example</title>
</head>
<body>
<div contenteditable="true" spellcheck="true">
<p>This is an editable content with spell-checking enabled.</p>
</div>
<div contenteditable="true" spellcheck="false">
<p>This is an editable content with spell-checking disabled.</p>
</div>
</body>
</html>
🧠 How it Works
In this example, two div elements with editable content are presented. The first one has spell-checking enabled (spellcheck="true"), while the second one has spell-checking disabled (spellcheck="false").
🔄 Dynamic Values with JavaScript
Similar to other HTML attributes, you can dynamically set the spellcheck
attribute using JavaScript. This can be useful when you want to toggle spell-checking based on user interactions or other conditions. Here's an example:
<script>
// Dynamically set spellcheck for an editable element
document.getElementById("dynamicElement").spellcheck = false;
</script>
🧠 How it Works
In this script, the spellcheck
attribute is dynamically set to false for an editable element with the id dynamicElement.
🏆 Best Practices
- Consider user experience when deciding whether to enable or disable spell-checking. For example, you might want to disable spell-checking in areas where specialized terminology or code snippets are present.
- Test the spell-checking behavior across different browsers to ensure consistent user experience.
🎉 Conclusion
The spellcheck
attribute in HTML is a powerful tool for controlling spell-checking behavior within editable elements.
By understanding and utilizing this attribute appropriately, you can provide users with a more tailored and efficient text input experience.
👨💻 Join our Community:
Author
For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.
Buy me a coffee to make codetofun.com free for everyone.
Buy me a Coffee
If you have any doubts regarding this article (HTML spellcheck Attribute), please comment here. I will help you immediately.