data-emoji
Replace :shortcode: text with Unicode emoji characters. Progressive enhancement for any container element — without JS, shortcodes stay as readable text.
Overview
The data-emoji attribute enables automatic replacement of :shortcode: patterns with Unicode emoji characters inside any container element. It scans text nodes using a TreeWalker and performs pure text replacement — no wrapping elements are added.
Attributes
| Attribute | Values | Default | Description |
|---|---|---|---|
data-emoji |
— | — | Enables emoji enhancement on the container. |
data-emoji-scan |
once, observe |
once |
Scan mode. observe watches for dynamic content changes via MutationObserver. |
data-emoji-unknown |
keep, strip |
keep |
How to handle unresolved shortcodes. keep leaves them as-is; strip removes the colon markers. |
Block-Level Usage
Apply data-emoji to any container. All text nodes within are scanned, including nested elements. Elements like code, pre, script, style, and textarea are skipped automatically.
Observe Mode
Set data-emoji-scan="observe" to watch for dynamically added or changed content. A MutationObserver watches the subtree and debounces rescans (100ms).
Unknown Shortcodes
By default, unresolved shortcodes are left as-is. Set data-emoji-unknown="strip" to remove the colon markers from unrecognized codes.
Dynamic Content
Elements with data-emoji added to the page after load are automatically enhanced via a global MutationObserver.
Live Input Replacement
Add data-emoji directly to a <textarea> or <input> to enable live shortcode replacement as the user types. When the closing : completes a valid shortcode, it's instantly replaced with the emoji character.
Unknown shortcodes are always kept as-is in inputs (the data-emoji-unknown="strip" option only applies to container elements, not inputs — stripping text while typing would be jarring).
Skipped Elements
When data-emoji is on a container, text inside these child elements is never processed:
<script><style><code><pre><textarea>(usedata-emojidirectly on the textarea for live replacement)- Any element with
contenteditable
Supported Shortcodes
The core set includes approximately 200 curated emoji across 9 categories: Smileys, People, Animals & Nature, Food & Drink, Travel & Places, Activities, Objects, Symbols, and Flags. Common aliases are supported (e.g., :heart: for :red_heart:, :+1: for :thumbsup:).
See the emoji-picker component for a visual browser of all available emoji. Use data-emoji when users know the shortcode; use emoji-picker when they need to browse and discover. Both share the same dataset and work well together.
Extended Emoji Set
Need the full GitHub/Slack shortcode library? Load the extended emoji file to add ~1,700 more shortcodes (the complete gemoji set). It supplements the core set — no configuration needed.
| Set | Shortcodes | Size (gzipped) | Loaded |
|---|---|---|---|
| Core (default) | ~200 | Included in main bundle | Always |
| Extended (opt-in) | ~1,700 additional | ~23 KB | Separate script tag |