DEV Community

Berra
Berra

Posted on

1

Hyphenate anything

If you're like me and keep running low on horizontal space in web design nowadays. Don't worry - I have a nice solution.

Hyphenate!

If you do not care at all about language and words and breaking them in the "correct" way this is the way to do it.

function addSoftHyphensToWord(word) {
    return word.split('').join(String.fromCharCode(173));
}

function addSoftHyphens(text) {
    return text.split(' ').map(addSoftHyphensToWord).join(' ');
}
Enter fullscreen mode Exit fullscreen mode

And in your CSS you add these rules.

.break-with-manual-hyphens {
    word-break: break-all;
    hyphens: manual;
}
Enter fullscreen mode Exit fullscreen mode

Now your text will break anywhere. This is great.

Until next time.

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more