Sign Up Sign In

Long code lines are not wrapped


This is a small bug (cosmetic) that I have noticed while adding some code in a post:

Code with very long lines not being wrapped

I have artificially added some whitespace here and there, otherwise the line would have been way longer.

Why should this post be closed?


Maybe I don't understand the problem, but code shouldn't get automatically line-wrapped, since doing so might affect the behavior of it in a lot of languages. ‭Lundin‭ 24 days ago

@Lundin - I think the wrap can be achieved by using overflow-wrap: break-word; or similar. You will get the text displayed on multiple lines, but no actual line breaks are there (copy-pasting it in a text editor will get a single line). A similar behaviour is happening while editing code with long lines. ‭Alexei‭ 24 days ago

Or the code blocks with lines too long for the space should get scrollbars so they stay in bounds without anything getting truncated. I don't know what's better here, scrolling or auto-wrap, but either would be better than letting them get so wide that they don't fit and over/underlap other content. ‭Monica Cellio‭ 24 days ago

I'm thinking the root of the problem might be the programmer who writes 140 symbols long LoC and not the site? ‭Lundin‭ 23 days ago

2 answers


As Lundin points out, there are quite a few whitespace-sensitive programming languages out there, where automatic wrapping would change the apparent meaning of the code, such as Phython or JavaScript. In particular, wrapped lines must be properly indented in many contexts, which goes way beyond the capabilities of CSS.

I therefore vote for overflow-x: auto, i.e. displaying a horizontal scroll bar if lines are to long to fit the layout. That way, we get to see the question the author meant to ask, OP is nudged to manually format the question in readable way, but can still ask the questions that need long lines (and yes, if you want to talk about the HasThisTypePatternTriedToSneakInSomeGenericOrParameterizedTypePatternMatchingStuffAnywhereVisitor or extend a ClassFilterAwareUnionIntroductionAwareMethodMatcher you probably need a long line ;-)

(yes, these are actual class name from popular open source projects :D)

1 comment

Also, what counts as a long line for display purposes is affected by display size and zoom. Code that looks just fine on a full-size monitor might be sad on a phone. You can never format your code so that it'll never have problems, so regardless of what the poster does, the site might still need to handle long lines (for a local definition of "long"). ‭Monica Cellio‭ 17 days ago


Code blocks that are wider than the column they're trying to fit in now get horizontal scrollbars. As noted in another answer, it's not safe to assume that line-wrapping won't change the correctness of code.


Sign up to answer this question »