Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

::grammar-error — highlighting grammatical errors

The ::grammar-error pseudo-element styles text ranges that the browser has flagged as grammatically incorrect. It does not perform grammar checking itself.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

::grammar-error { text-decoration: underline wavy blue; }

::grammar-error is a highlight pseudo-element, not a selector for invalid CSS syntax. It represents text the browser has flagged as grammatically incorrect; ::spelling-error concerns spelling. Use two colons and no arguments.

Only a limited set of properties that do not affect layout applies. The example uses text-decoration: underline wavy blue to give the marker a blue wavy underline.

The console message depends only on whether CSS.supports('selector(::grammar-error)') returns true: if it does, the script logs ::grammar-error selector syntax: supported; otherwise, it logs ::grammar-error selector syntax: unsupported. Whether a marker appears depends instead on grammar-checking support and behavior. The absence of a marker proves neither that the text is correct nor that the selector is unsupported. CSS does not force error detection.

Examples

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Grammar error highlighting</title>
  <style>
    .editor::grammar-error {
      text-decoration: underline wavy blue;
    }
  </style>
</head>
<body>
  <div class="editor" role="textbox" aria-label="Sample sentence" contenteditable="true" spellcheck="true">She go to school every day.</div>
  <script>
    const supported = CSS.supports('selector(::grammar-error)');
    console.log('::grammar-error selector syntax: ' + (supported ? 'supported' : 'unsupported'));
  </script>
</body>
</html>

Result

::grammar-error selector syntax: supported

The displayed code and declared console result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources