Character weights
X uses a weighted character counting system. Most characters count as 1, but some count as 2:Emoji counting
All emojis count as 2 characters, regardless of complexity:
Zero-width joiners (ZWJ) combine emojis visually but donβt add to the count.
URL handling
All URLs are wrapped witht.co shortener and count as 23 characters, regardless of the original length:
This applies to any valid URL detected in post text.
Special cases
Text encoding
The X API requires UTF-8 encoding. Character length is calculated using Unicode Normalization Form C (NFC). Example withcafΓ©:
X normalizes to NFC, so both encode to 4 characters.
Implementation
Use the official twitter-text library for accurate character counting:- JavaScript
- Python
Resources
twitter-text library
Official open-source library for text parsing.
Configuration file
Character weight definitions and Unicode ranges.