CSS Reference ยท Pseudo-elements
The ::spelling-error pseudo-element
Reference for the CSS ::spelling-error pseudo-element: style words flagged by the browser's spell checker. Limited browser support, so use with care.
The ::spelling-error pseudo-element styles text that the browser's spell checker has flagged as misspelled. Its sibling ::grammar-error does the same for grammar mistakes. Normally the browser draws a red wavy underline; these pseudo-elements let a page change that look.
Support is limited. Only some Chromium-based browsers implement it, and the underline of the operating system's spell checker may still appear. Treat it as an enhancement, never as something your design depends on.
textarea::spelling-error { text-decoration: underline wavy #e8590c; }
Try it
Spell checking usually starts only after the field has focus and the user has typed, and some browsers do not check inside embedded frames, so you may see no change.
Syntax
selector::spelling-error { } selector::grammar-error { }
| Property | Value |
|---|---|
| Applies to | Text the spell checker marked, in editable content |
| Inherited | Inherits from the element that contains the text |
| Animatable | No |
Values
The pseudo-element takes no arguments. Like other highlight pseudo-elements, it allows only paint-related properties:
| Property | Description |
|---|---|
color |
Text color of the flagged word. |
background-color |
Fill behind the flagged word. |
text-decoration and related |
Underline style, color and thickness. |
text-shadow |
Shadow behind the text. |
Usage notes
- Editable content only. It applies to text in inputs, textareas and
contenteditableelements that are spell-checked. - Browser decides what is wrong. The page cannot change which words are flagged, only how they look.
spellcheck="false"turns checking off for an element. - Don't hide errors. Removing the underline entirely makes mistakes harder to notice. Restyle, do not remove.
- Accessibility. Never rely on color alone; keep a decoration such as an underline.
- Fallback. Browsers without support simply show their default look, so there is nothing to polyfill.
- Custom needs. To mark your own errors, such as lint results, use the Custom Highlight API instead.
Browser support
Limited: implemented in Chromium-based browsers, with no support in Firefox or Safari at the time of writing. Check current compatibility data before relying on it.