WeSearch

Preventing line breaks in <code> elements

·2 min read · 0 reactions · 0 comments · 2 views
#preventing#line#breaks#code#elements
Preventing line breaks in <code> elements
TL;DR · WeSearch summary

Preventing line breaks in <code> elementsPosted 18 July 2026One of my favourite tiny details in this website is my non-breaking spaces. My website is viewed at lots of different sizes, and browsers choose where to insert line breaks. For example, (?-u:…) was split into (?- and u:…), while the flag --multiline was split with - on one line and -multiline on the other.

Key facts
About this source

Hacker News (Front Page) files mainly under programming. We currently carry 549 of its stories. Top-voted stories on Hacker News.

Original article
Alexwlchan
Read full at Alexwlchan →
Opening excerpt (first ~120 words) tap to expand

Preventing line breaks in <code> elementsPosted 18 July 2026One of my favourite tiny details in this website is my non-breaking spaces. I have code that looks for phrases like “5 cm”, “New York”, or “Objective‑C”, and inserts a non-breaking space/hyphen so they’ll never be split across multiple lines.This is the sort of typographical nicety that would be handled by a professional typesetter if I was writing a printed book with a fixed layout, but that’s not how websites work. My website is viewed at lots of different sizes, and browsers choose where to insert line breaks.

Excerpt limited to ~120 words for fair-use compliance. The full article is at Alexwlchan.

Anonymous · no account needed
Share 𝕏 Facebook Reddit LinkedIn Threads WhatsApp Bluesky Mastodon Email

Discussion

0 comments

More from Alexwlchan