Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

caret-shape — insertion caret shape

The caret-shape property specifies the insertion caret’s shape in editable text, not the mouse pointer.

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

Syntax

caret-shape: auto | bar | block | underscore;

caret-shape controls the insertion caret’s shape. It is inherited; its initial value is auto, and its computed value is the specified keyword.

auto lets the browser choose. bar is a thin bar between characters; block overlaps the next visible character; underscore draws a line beneath it. At the end of the text, the latter two appear after the last visible character. Orientation respects the writing mode.

The shape neither enables overwrite mode nor controls blinking. Definition in the CSS UI Level 4 draft does not establish browser support; the example requires local verification.

Examples

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Insertion caret shape</title>
  <style>
    #editor { font: 24px monospace; caret-shape: block; }
  </style>
</head>
<body>
  <label for="editor">Text</label>
  <input id="editor" type="text" value="ABC">
  <script>
    const editor = document.getElementById('editor');
    editor.focus();
    editor.setSelectionRange(1, 1);

    const property = 'caret-shape';
    const result = CSS.supports(property, 'block')
      ? `supported (computed: ${getComputedStyle(editor).getPropertyValue(property).trim()})`
      : 'unsupported';
    const start = editor.selectionStart;
    const position = document.activeElement === editor && start === editor.selectionEnd
      ? `${editor.value.slice(0, start)}|${editor.value.slice(start)}`
      : 'no focused insertion point';
    console.log(`${property}: ${result}; insertion point: ${position}`);
  </script>
</body>
</html>

Result

caret-shape: supported (computed: block); insertion point: A|BC

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

Sources