If a user types in a long line without any spaces or white space, it will break formating by going wider than the current element. Something like:
HA
There is no "perfect" HTML/CSS solution.
The solutions either hide the overflow (ie scrolling or just hidden) or expand to fit. There is no magic.
Q: How can you fit a 100cm wide object into a space only 99cm wide?
A: You can't.
You can read break-word
EDIT
Please check out this solution How to apply a line wrap/continuation style and code formatting with css
or
How to prevent long words from breaking my div?