Search code examples
htmlcssword-break

How can I force break word in same length?


I have text like (without any space)

"abcdefgh",

I want to use html & css to change the style to make it looks like:

ab cd ef gh

Is there any way to do this with only html & css?

The text is always like "abcdefgh", cannot use JavaScript or manually to split it.

Thanks for your help.

Like in css there is a property called

work-spacing

but with this property there must have 'space' in my string. Which is not a good solution for me. Is there any property in css so that I can break my string in a certain length?

Like break length equal to 2 then my string became "ab cd ef gh".


Solution

  • Try something look like that:

    <div>abcdefgh</div>
    
    <style>
        div {
            width: 40px;
            letter-spacing:10;
            word-break: break-all;
        }
    </style>
    

    The result:
    a b
    c d
    e f
    g h