HTML-aware text truncation in Javascript.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Ellipsifier is a Javascript library that truncates HTML. It will retain the tag structure, counting only visible characters in the resulting text.


Ellipsifier requires underscore.js and John Resig's htmlparser.js. Both can be found in the vendor directory.


Creating a new Ellipsifier instance will set the result property to have the ellipsified text. It will use a "…" character to indicate that the text has been truncated.

new Ellipsifier("to be or not to be", 5).result
//              "to be …"

It won't count HTML markup as part of the character limit, and if the truncation occurs inside HTML tags, it will properly close those tags.

new Ellipsifier('to <strong>be or</strong> not to be', 20).result
//              "to <strong>be or</strong> not to be"

new Ellipsifier('to <strong>be or</strong> not to be', 5).result
//              "to <strong>be</strong>&nbsp;&hellip;"

Optionally, you can pass a class option, which will wrap an ellipsis in a span with that class.

new Ellipsifier("to be or not to be", 5, {class: 'ellipsified'}).result
//              "to be&nbsp;<span class=\"ellipsified\">&hellip;</span>"


Copyright (c) 2012 HowAboutWe. See MIT-LICENSE for further details.