The definitive source of the best
JavaScript libraries, frameworks, and plugins.

  • ×

    An easy to use javascript plugin offers you complete DOWN-TO-THE-LINE control for radical web typography.
    Filed under 

    • 🔾29%Overall
    • 914
    • 49 days
    • 🕩67
    • 👥4


    An easy to use javascript plugin offers you complete DOWN-TO-THE-LINE control for radical web typography.

    In CSS we already have the selector ::first-line to apply style on the first line of element. But there is no selector like ::nth-line(), ::nth-last-line() or even ::last-line. Then I read an article A Call for ::nth-everything from CSS tricks. ::nth-line() is actually really useful in some situation.

    There comes LINING.JS. It offers you complete DOWN-TO-THE-LINE control like this:

    <div class="poem" data-lining>Some text...</div>
    .poem .line[first] { /* `.poem::first-line`*/ }
    .poem .line[last] { /* `.poem::last-line` */ }
    .poem .line[index="5"] { /* `.poem::nth-line(5)` */ }
    .poem .line:nth-of-type(-n+2) { /* `.poem::nth-line(-n+2)` */ }
    .poem .line:nth-last-of-type(2n) { /* `.poem:::nth-last-line(2n)` */ }
    <script src="YOUR_PATH/lining.min.js"></script>

    Supported browsers Lastest Chrome Lastest Firefox Lastest Safari Lastest Mobile Safari Lastest Opera


    All you need to do is adding data-lining attribute on your block element and including the lining.min.js script. Then you can write css to control it's line style. For example:

    <div class="poem" data-lining>Some text...</div>
    .poem { /* default style for `.poem` */ }
    .nolining .poem { /* style for `.poem` when browser don't support lining.js */ }
    .poem[data-lining] { /* style for `.poem` when browser support lining.js */ }
    .poem[data-lining="end"] { /* style for `.poem` when `line` tags created */ }
    .poem .line { /* style for lines */ }
    <script src="YOUR_PATH/lining.min.js"></script>


    If you want your line style support Responsive web design. Make sure you add the data-auto-resize attribute. It will automatically relining when window resize event happen.

    <div class="poem" data-lining data-auto-resize>Some text...</div>

    Other attributes

    data-from and data-to help help you control which line tags to be created. For example:

    <div class="poem"
    First Line.<br/>
    Second Line.<br/>
    Third Line.<br/>
    Fourth Line.<br/>

    After lining, only the second and third line tag will be created. Check out the demo.

    And data-line-class help you control the class name of line tags, if you don't want to use the default class name: line.


    You can also create and manage line tags by javascript. And give you four events to do special things.

    <div id="poem">Some text..</div>
    var poem = document.getElementById('poem');
    poem.addEventListener('beforelining', function (e) {
        // prevent lining if you want
    }, false);
    poem.addEventListener('afterlining', function () {
        // do something after lining
    }, false);
    poem.addEventListener('beforeunlining', function () {
        // do something before unlining
        // can't prevent unlining
    }, false);
    poem.addEventListener('afterunlining', function () {
        // do something after unlining
    }, false);
    // start lining
    var poemLining = lining(poem, {
        // optional config
        'autoResize': true,
        'from': 2,
        'to': 3,
        'lineClass': 'my-class'
    // `unlining` method will remove all line tags.
    // `relining` method will call `unlining` first if needed,
    // then start lining again.

    lining.effect.js is an extra part of lining.js. It gives you the power to add appearances animation on your lines. Use it like this:

    <script src="YOUR_PATH/lining.min.js"></script>
    <script src="YOUR_PATH/lining.effect.min.js"></script>
    <div data-lining data-effect="rolling">
    Your text...


    DOWNLOAD or using bower to install like this:

    $ bower install lining.js


    jsDelivr provides free CDN hosting which helps speed webpage loading. Usage is simple:

    <script src="//"></script>

    then change VERSION with the version number you can find hosted at jsDelivr.
    If you want to also use effects, you can take advantage of collating and reduce a HTTP request:

    <script src="//"></script>


    Show All