::highlight()
Baseline
2026
Newly available
Since March 2026, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
::highlight() CSS ìì¬ ììë ì¤íì¼ì ì¬ì©ì ì ì íì´ë¼ì´í¸ë¥¼ ì ì©í©ëë¤.
ì¬ì©ì ì ì íì´ë¼ì´í¸ë Range ê°ì²´ì ì§í©ì´ë©° ì¹ íì´ì§ì HighlightRegistry를 ì¬ì©íì¬ ì¹ íì´ì§ì ë±ë¡ë©ëë¤.
íì©ëë ìì±
ëª ê°ì í¹ì í CSS ìì±ë§ì´ ::highlight() ì í¨ê» ì¬ì©ë ì ììµëë¤.
colorbackground-colortext-decorationì ì´ì ì°ê´ë ìì±ë¤text-shadow-webkit-text-stroke-color,-webkit-text-fill-colorì-webkit-text-stroke-width
ë¶ë¶ì ì¼ë¡ background-imageë 무ìë©ëë¤.
구문
css
::highlight(custom-highlight-name)
ìì
>문ìì´ì íì´ë¼ì´í¸ ì ì©í기
HTML
html
<p id="rainbow-text">ì¬ì©ì ì ì íì´ë¼ì´í¸ API 무ì§ê°</p>
CSS
css
#rainbow-text {
font-family: monospace;
font-size: 1.5rem;
}
::highlight(rainbow-color-1) {
color: #ad26ad;
text-decoration: underline;
}
::highlight(rainbow-color-2) {
color: #5d0a99;
text-decoration: underline;
}
::highlight(rainbow-color-3) {
color: #0000ff;
text-decoration: underline;
}
::highlight(rainbow-color-4) {
color: #07c607;
text-decoration: underline;
}
::highlight(rainbow-color-5) {
color: #b3b308;
text-decoration: underline;
}
::highlight(rainbow-color-6) {
color: #ffa500;
text-decoration: underline;
}
::highlight(rainbow-color-7) {
color: #ff0000;
text-decoration: underline;
}
JavaScript
js
const textNode = document.getElementById("rainbow-text").firstChild;
if (!CSS.highlights) {
textNode.textContent =
"ì´ ë¸ë¼ì°ì ììë CSS ì¬ì©ì ì ì íì´ë¼ì´í¸ APIê° ì§ìëì§ ììµëë¤.";
}
// 무ì§ê°ì ìë ê°ê°ì ììì ìì±íê³ íì´ë¼ì´í¸ë¥¼ ë±ë¡í©ëë¤.
const highlights = [];
for (let i = 0; i < 7; i++) {
// í´ë¹ ììì ëí´ ìë¡ì´ íì´ë¼ì´í¸ë¥¼ ìì±í©ëë¤.
const colorHighlight = new Highlight();
highlights.push(colorHighlight);
// ì¬ì©ì ì ì ì´ë¦ì¼ë¡ ì´ íì´ë¼ì´í¸ë¥¼ ë±ë¡í©ëë¤.
CSS.highlights.set(`rainbow-color-${i + 1}`, colorHighlight);
}
// í
ì¤í¸ë¥¼ 문ì ë¨ìë¡ ë°ë³µí©ëë¤.
for (let i = 0; i < textNode.textContent.length; i++) {
// í´ë¹ 문ìì ëí ë²ì를 ìì±í©ëë¤.
const range = new Range();
range.setStart(textNode, i);
range.setEnd(textNode, i + 1);
// ë²ì를 ë¤ì ì¬ì© ê°ë¥í íì´ë¼ì´í¸ì ì¶ê°íê³ ,
// 7ë²ì§¸ì ëë¬íë©´ ë¤ì 첫ë²ì§¸ë¡ ëìê°ëë¤.
highlights[i % 7].add(range);
}
ê²°ê³¼
ëª ì¸ì
| Specification |
|---|
| CSS Custom Highlight API Module Level 1 > # custom-highlight-pseudo > |
| CSS Pseudo-Elements Module Level 4 > # selectordef-highlight-custom-ident > |