--- title: caret-color slug: Web/CSS/caret-color tags: - CSS - CSS Property - CSS User Interface - Editing - HTML Colors - Input - Reference - Styling HTML - Text Editing - caret - caret-color - contenteditable - 'recipe:css-property' browser-compat: css.properties.caret-color translation_of: Web/CSS/caret-color ---
caret-color は CSS のプロパティで、次に入力された文字が挿入される位置を示す可視マーカーである入力キャレットの色を設定します。これはテキスト入力カーソルと呼ばれることもあります。キャレットは {{HTMLElement("input")}} または {{htmlattrxref("contenteditable")}} 属性のついた要素などの中に現れます。ふつうキャレットは細い垂直線で、気づきやすくなるように点滅します。既定では黒ですが、このプロパティで色を変更することができます。
なお、入力キャレットはキャレットのうちの一種類にすぎません。例えば、多くのブラウザーには「ナビゲーションキャレット」があり、入力キャレットと同様に動きますが、編集できないテキストの中を移動できるものがあります。一方、マウスカーソルが、 {{cssxref("cursor")}} プロパティが auto のときにテキスト上に移動した場合や、 cursor プロパティが text または vertical-text の場合に、キャレットのように見えることがありますが、キャレットではありません (カーソルです)。
/* キーワード値 */ caret-color: auto; caret-color: transparent; caret-color: currentcolor; /* <color> 値 */ caret-color: red; caret-color: #5729e9; caret-color: rgb(0, 200, 0); caret-color: hsla(228, 4%, 24%, 0.8); /* グローバル値 */ caret-color: inherit; caret-color: initial; caret-color: revert; caret-color: unset;
autocurrentcolor、背景色、影の色、その他の要因を考慮して、別な色を選択することがあります。
メモ: ユーザーエージェントは auto の値に currentcolor (通常はアニメーション可能) を使用することがありますが、 auto はトランジションやアニメーションでは補完されません。
{{cssinfo}}
<input value="このフィールドは既定のキャレットを使用します。" size="64"/> <input class="custom" value="キャレットが独自の色になります!" size="64"/> <p contenteditable class="custom">この段落は編集可能であり、 同様にキャレットが独自の色です!</p>
input {
caret-color: auto;
display: block;
margin-bottom: .5em;
}
input.custom {
caret-color: red;
}
p.custom {
caret-color: green;
}
{{EmbedLiveSample('Setting_a_custom_caret_color', 500, 200)}}
{{Compat}}