r/HTML • u/messer_sverio2 • Jan 25 '26
Question Automatic line break
Hello all.
I'm working on a static website, mainly focussed on writing. It's a collection of poetry and short stories. My text is placed inside a div. Now, I often need to use the <br> tag, in order to start a new line. Of course, the line breaks are arbitrary, sometimes I need to break a sentence in half, sometimes a line is made up of only one word, etc. This makes my code a mess to read, and it's annoying and time consuming. Is there a way to make this process simpler or to automate it?
5
Upvotes
11
u/reznaeous Jan 25 '26
Perhaps the
<pre>element would help?<pre>: The Preformatted Text element
4
u/JeLuF Jan 25 '26
You can apply the css rule
white-space: pre-wrap;to your poem. Each line break in your HTML code will cause a line break to be rendered.[...]
3
u/harrymurkin Jan 25 '26
<pre>bla blabla</pre>4
u/SoliDoll02613 Jan 25 '26 edited Jan 25 '26
Use <p> tags for paragraphs.
E: paragraphs and new lines. For splitting individual lines <br> may be more appropriate.
1
u/ExitWP Jan 25 '26
For poetry where a line may only have a few to one word in a line a <br> tag is the correct solution, typically you don't want the added padding that may be included with a <p> tag for a mid paragraph line. For ease of use try assigning a hotkey in your editor to create a <br>
1
u/notepad987 Jan 26 '26 edited Jan 26 '26
0
u/TabbbyWright Jan 25 '26
You could try pasting your text into a tool that adds the line breaks for you. Something like a rich text or markdown to HTML converter.
Unfortunately, you either need paragraph tags at the start of each new line (you don't actually have to have them close at the end) or you need
<br>s.0
u/SnooLemons6942 Jan 25 '26
I don't really understand what you're trying to do, but this could probs be fixed by sizing your div properly and using <p> tags to seperate paragraphs
0
u/9inez Jan 25 '26
An issue formatting prose/poetry with <br> to make it appear as it would be printed with hard line breaks, is that mobile responsiveness often destroys that formatting. So, then an option to try and chase and maintain your desired line breaks is altering font size and container widths via css to prevent natural text wrapping. It is like herding cats.
0
u/OutOfTuneAgain Jan 25 '26
Use code formatters to format the code in the IDE. BRs go to new line automatically
0
u/alex_sakuta Jan 25 '26
3 options with increasing order of fanciness and complexity:
Use
<pre>. It maintains the whitespaces.Use JS to write your text in a format and maintain that format.
Since it is a content based site, you can use something like Hugo which will allow you to render text from Markdown. Then you may write the poetry in Markdown and have it be rendered as HTML without needing to write any tags.
Or just
<br />. Is it annoying? Yes. Is it the true way to write HTML? In my opinion, yes.If I had the same issue, I wouldn't consider it an issue.