In CSS/JS, how to word-wrap at every nth word?

Issue

I want to add a paragraph to my web page but when I write, the text fills the full width of the screen.

<p>Some long text Some long text Some long text Some long text Some long text Some long text Some long text Some long text Some long text Some long text Some long text Some long text Some long text Some long text Some long text Some long text </p>

I want, for example, to specify that only 25 words can fit on each line with css or JavaScript, before wrapping to next line.

Solution

you need to specify the p width or put it within a container that has a defined width

p.longtext {
    width:200px; 
}
<p class='longtext'>Some long text Some long text Some long text Some long text Some long text Some long text Some long text Some long text </p>

Answered By – Radhouane Fazai

Answer Checked By – Mary Flores (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.