Character counter for textareas with Stimulus

3516
0

A character counter is small, but it removes uncertainty for users (especially when there’s a limit). I implement it with Stimulus so it stays reusable: attach to a wrapper, declare input + output targets, and compute remaining characters based on an optional max value. This keeps the markup clean and avoids custom JS per form. I also like to update on connect() so the counter is accurate when editing existing text. In a Turbo app, this is stable across visits because Stimulus reconnects automatically after frame replacements. Finally, I tend to add a subtle warning style when remaining chars drop below a threshold.