According to the HTML Specification, multiple whitespace characters (spaces, tabs and form feeds) between non-whitespace characters (words and numbers) should be treated as a single space by the browser, eg:
will be rendered by the browser as
This sentence contains too many spaces
In order to keep the spaces when the content is displayed in the browser, all spaces except the last must be converted to a non-breaking space eg: