Newlines to Spaces

Replaces every line break (Unix, Windows, or classic Mac style) with a single space, collapsing multi-line text into one continuous line. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-22

Overview

Introduction

Multi-line text sometimes needs to become a single continuous line, for a log entry, a single-line config value, or pasting into a field that doesn't accept line breaks.

This tool joins it in one step.

What Is Newlines to Spaces?

A converter that replaces every line break, regardless of style, with a single space character.

It runs entirely client-side as part of this site's String Tools collection, so nothing you paste is ever uploaded to a server.

How Newlines to Spaces Works

A regex matching \r\n, \r, or \n is replaced globally with a single space.

The transformation happens synchronously in JavaScript the moment you type, with no network round trip involved.

When To Use Newlines to Spaces

Use it when preparing multi-line text for a single-line field, or when flattening a paragraph for a log entry.

It's a fast way to get the answer without opening a code editor, a REPL, or writing a one-off script just to check.

Often used alongside Spaces to Newlines and Text Joiner.

Features

Advantages

  • Handles all three common line-ending styles in one pass.
  • Matches the two-character CRLF sequence ahead of the single-character forms, so a Windows line break yields one space rather than two.
  • Leaves every other character untouched, so tabs and existing spacing survive the conversion exactly as they were.

Limitations

  • Doesn't collapse the resulting spaces if the source had multiple consecutive line breaks; pair with Remove All Whitespace if you need fully collapsed spacing.
  • Converts each break to exactly one space and trims nothing, so text that began or ended with a newline picks up leading or trailing whitespace.

Examples

Joining lines

Input

one
two
three

Output

one two three

Each newline becomes a single space.

Best Practices & Notes

Best Practices

  • If the source has blank lines you want collapsed too, follow up with a whitespace-collapsing step.
  • Follow with the Extra Space Remover whenever the source contained blank lines, since each one contributes a space of its own.
  • Use it to flatten text before pasting into a single-line field such as a spreadsheet cell or a CSV value.

Developer Notes

The regex `/\r\n|\r|\n/g` matches all three line-ending conventions in priority order (checking the two-character \r\n first), so Windows-style line endings aren't split into two separate replacements.

Newlines to Spaces Use Cases

  • Flattening a multi-line paragraph into one line for a log entry
  • Preparing multi-line text for a single-line input field
  • Joining a multi-line address into one line

Common Mistakes

  • Expecting consecutive blank lines to collapse into a single space automatically.
  • Expecting paragraph structure to survive; every break is treated identically, so paragraph boundaries vanish along with the wrapping.

Tips

  • Use Spaces to Newlines to reverse this operation.
  • Two consecutive breaks become two spaces, so counting doubled spaces in the result is a quick way to see where the paragraphs used to be.

References

Frequently Asked Questions