Character counters
Show remaining characters for constrained text fields in real time.
Live preview
/ 120 characters
HTML
<div class="xsh-field xsh-measure">
<label class="xsh-label" for="xsh-bio">Short biography</label>
<textarea class="xsh-textarea" id="xsh-bio" maxlength="120" data-xsh-count="xsh-bio-count">Building carefully engineered web interfaces.</textarea>
<small class="xsh-help">
<output id="xsh-bio-count">46</output> / 120 characters</small>
</div>Installation & markup
Include the local stylesheet and script once on the page, then place the component inside a data-xsh-ui root. The example above works without a build system.
<link rel="stylesheet" href="/dist/xshna-ui.css">
<div data-xsh-ui>
<!-- Add the HTML example above -->
</div>
<script defer src="/dist/xshna-ui.js"></script>Component API
Public classes, attributes and hooks used by this example. Keep the xsh- prefix intact.
| Identifier | Contract |
|---|---|
xsh-textarea | Used by the example markup and component styles or behavior. |
maxlength | Used by the example markup and component styles or behavior. |
data-xsh-count | Used by the example markup and component styles or behavior. |
output | Used by the example markup and component styles or behavior. |
Accessibility & keyboard
Counts update as the user types, including after paste.
Implementation note. Never use a character counter to replace essential validation feedback.
Interaction contract
Behavioral components use the shared delegated runtime; visual-only primitives rely on semantic HTML and CSS. Runtime controls emit bubbling xsh:* CustomEvents; bind application handlers to those events when server persistence, API data or navigation is required.