This content originally appeared on Bram.us and was authored by Bramus!
Part of the CSS Pseudo-Elements Level 4 Specification are ways to style spelling and grammar errors.
By default spelling errors — words you have mistyped — get a red dotted underline, thanks to the ::spelling-error
pseudo-class selector you can tweak that. Grammar errors — such as a missing capital letter at the beginning of a sentence — can be styled with the ::grammar-error
pseudo-class selector.
::spelling-error {
text-decoration: underline wavy red;
}
::grammar-error {
text-decoration: underline wavy blue;
}
~
Embedded below is a demo that shows the output of the browser you are visiting with, and the wanted output:
See the Pen The Future of CSS: Style Grammar and Spelling Errors (Demo) by Bramus (@bramus) on CodePen.
As you can see your browser does not yield the proper output, as ::spelling-error
/::grammar-error
currently have no support in any browser at the time of writing:
~
Once these highlight pseudo-elements do gain browser support, do note that they can only be styled by a limited set of properties that do not affect layout. Only following properties apply to the highlight pseudo-elements:
color
background-color
text-decoration
and its associated propertiestext-shadow
stroke-color
,fill-color
, andstroke-width
~
In case you are interested, here are the relevant bugs to flag/star/follow:
- Chromium: https://bugs.chromium.org/p/chromium/issues/detail?id=1035708
- Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1694053
- Safari: https://bugs.webkit.org/show_bug.cgi?id=175784
~
Thank me with a coffee.
I don't do this for profit but a small one-time donation would surely put a smile on my face. Thanks!
To stay in the loop you can follow @bramus or follow @bramusblog on Twitter.
~
? This post is part of a series called The future of CSS. Latest posts in this series:
- Style Spelling and Grammar Errors with the
::spelling-error
and::grammar-error
pseudo-elements February 21, 2021 - Style the target text from text-fragment links using the
::target-text
pseudo-element February 15, 2021 - The future of CSS: Higher Level Custom Properties to control multiple declarations December 30, 2020
- Native Aspect Ratio Boxes in CSS thanks to
aspect-ratio
November 30, 2020 - Container Queries are coming to Chromium! November 5, 2020
- CSS
leading-trim
– The Future of Digital Typesetting August 22, 2020 - Colors in CSS: Hello Space-Separated Functional Color Notations April 27, 2020
- Firefox 72: Individual CSS Transform Properties January 9, 2020
- How the CSS
:is()
selector will simplify things December 15, 2019 - The future of CSS: Nesting Selectors March 17, 2019
This content originally appeared on Bram.us and was authored by Bramus!

Bramus! | Sciencx (2021-02-21T20:43:56+00:00) Style Spelling and Grammar Errors with the ::spelling-error and ::grammar-error pseudo-elements. Retrieved from https://www.scien.cx/2021/02/21/style-spelling-and-grammar-errors-with-the-spelling-error-and-grammar-error-pseudo-elements/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.