Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The caret-shape CSS property sets the shape of the insertion caret, the visible marker that appears in editable elements to indicate where the next character will be inserted or deleted.
caret-shape: auto;
caret-shape: bar;
caret-shape: block;
caret-shape: underscore;
<section class="default-example container" id="default-example">
<div>
<label for="example-element">Edit text field:</label>
<input id="example-element" type="text" value="Sample text" />
</div>
</section>
div {
text-align: left;
}
#example-element {
font-size: 1.2rem;
padding: 8px;
width: 300px;
}
/* Keyword values */ caret-shape: auto; caret-shape: bar; caret-shape: block; caret-shape: underscore; /* Global values */ caret-shape: inherit; caret-shape: initial; caret-shape: revert; caret-shape: revert-layer; caret-shape: unset;
autoThe default value. The browser determines the caret shape. This typically follows platform conventions and may change based on context.
barThe caret appears as a thin vertical line at the insertion point, positioned between characters rather than over them.
blockThe caret appears as a rectangle that overlaps the next character after the insertion point. If no character follows, it appears after the last character.
underscoreThe caret appears as a thin horizontal line underneath the next character after the insertion point. If no character follows, it appears after the last character.
The insertion caret is the blinking cursor that indicates where text will be inserted when typing. Different caret shapes can provide visual feedback about the current editing mode or offer visual customization.
Text editors typically operate in one of two modes:
Different caret shapes have traditional uses, for example:
The caret-shape property affects how the caret is visually rendered but doesn't change its logical position in the text. The caret always represents the insertion point between characters, regardless of its visual shape.
The caret shape adapts to the writing-mode of the text. In vertical writing modes, bar carets become horizontal, and underscore carets position themselves appropriately relative to the text direction.
| Initial value | auto |
|---|---|
| Applies to | elementsThatAcceptInput |
| Inherited | yes |
| Computed value | as specified |
| Animation type | by computed value type |
caret-shape =
auto |
bar |
block |
underscore
This example shows how to create a vintage terminal interface using caret-shape: block with animated caret color, replacing the old technique of using borders.
The key part is using the modern caret properties instead of the old border-based technique. We set the caret to block shape, disable the default blinking, and create our own custom animation.
<label for="terminal">Enter a command</label> <div class="old-screen"> <span>></span> <textarea id="terminal" class="terminal-input"></textarea> </div>
.terminal-input {
caret-shape: block;
caret-animation: manual;
animation: old-caret 2s infinite;
}
@keyframes old-caret {
0%,
50% {
caret-color: #00ad00;
}
75%,
100% {
caret-color: transparent;
}
}
This example demonstrates using caret-shape: underscore to create a console-style interface where the underscore caret complements the terminal aesthetic.
<label for="console">Enter a command</label>
<div class="console-demo">
<div class="console-output">
<p>user@host:css-ui-4 $ ls -a</p>
<p>. .. Overview.bs Overview.html</p>
</div>
<div class="console-input">
<span class="prompt">user@host:css-ui-4 $ </span>
<input type="text" id="console" class="console" value="cd" />
</div>
</div>
.console {
caret-shape: underscore;
}
caret-color, caret-animation
caret shorthand
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/caret-shape