Free online text tool

Replace Spaces in Text

Replace Spaces changes every space in your text to an underscore, dash, comma or any text you choose. Paste your text, click the button and copy the result. It is free and runs in your browser.

Replace Spaces Tool

0Character Count
0Character Count (without spaces)
0Word Count
0Sentence Count
0Paragraph Count
0Line Count

Replace Spaces Example

Before (replace spaces with _)
He decided to move to a smaller house
After
He_decided_to_move_to_a_smaller_house

Bookmark: press Ctrl+D (Windows) or Cmd+D (Mac) to save this tool.

Suggest a New ToolProvide Feedback on This Tool

What does Replace Spaces do?

This tool replaces the spaces in your text with anything you type. Enter an underscore, a dash, a comma, a period or a whole word in the box, click the button, and every space is swapped for it.

Tabs and non-breaking spaces are replaced too, because they look like spaces. If your text has runs of several spaces, you can tick an option to treat each run as one, so you get one underscore instead of three. You can also keep the spaces at the start and end of each line.

Use it to make file names, URL slugs and variable names, to join words for hashtags, or to prepare text for a program that does not accept spaces.

Replace spaces examples

Each example shows what the Replace spaces with box held. Unless an option is named, every space is replaced, tabs count as spaces and spaces at the edges are replaced too.

SettingBeforeAfter
Underscore (_)
He decided to move to a smaller house
He_decided_to_move_to_a_smaller_house
Dash (-)
red green blue
red-green-blue
Comma and space (, )
one two three
one, two, three
Word (and)
salt pepper
saltandpepper
Several spaces, each replaced
a  b
a__b
Several spaces as one
a   b    c
a_b_c
Tabs replaced
a	b c
a_b_c
Tabs not replaced
a	b c
a	b_c
Spaces at the edges, replaced
  a b  
__a_b__
Spaces at the edges, kept
  a b  
  a_b  
Line breaks stay
a b
c d
a_b
c_d
Empty box, spaces removed
a b c
abc

How to replace spaces in text

  1. 1
    Add your text
    Type or paste your text into the box, or import a text file.
  2. 2
    Enter what to use instead
    Type the underscore, dash, comma or any text that should take the place of each space.
  3. 3
    Click Replace Spaces
    Every space is replaced. Use Undo if you change your mind.
  4. 4
    Copy it
    Click Copy and paste the result where you need it.

When to replace spaces

Good for

Making file names, URL slugs, hashtags and variable names, and preparing text for programs, forms or systems that do not accept spaces.

Check first

The text you type is used exactly as written, so to get a space after a comma, type a comma and a space. Spaces at the start and end of the text are replaced too, unless you keep them. The result replaces your text, so use Undo if you need the original.

Other tools

To delete spaces completely, try Remove Spaces. To turn spaces into new lines, try Convert Spaces to New Lines. To make double spaces single, try Convert Double Space to Single Space.

Replace spaces FAQ

What does the Replace Spaces tool do?

It replaces every space in your text with the text you enter, such as an underscore, a dash, a comma, a period or a word.

How do I replace spaces with underscores?

Paste your text, type an underscore in the Replace spaces with box, then click Replace Spaces.

What can I replace spaces with?

Anything you can type: one character like - or _, several characters like ', ', or a whole word.

Can I just remove the spaces?

Yes. Leave the Replace spaces with box empty and click the button, and the spaces are deleted.

What happens to several spaces in a row?

By default each space is replaced, so two spaces become two underscores. Tick Treat several spaces in a row as one to get a single replacement for the whole run.

Does it replace tabs and non-breaking spaces?

Yes, by default, because they look like spaces. Untick that option to replace normal spaces only.

Can I keep the spaces at the start and end of a line?

Yes. Tick Keep spaces at the start and end of each line, and only the spaces between words are replaced.

Does it change line breaks or other text?

No. Line breaks, letters, numbers and punctuation stay as they are. If there are no spaces the tool shows a message and leaves your text as it is.

Is this tool free and is my text private?

Yes. It is free, needs no account and runs in your browser, so your text is not uploaded to a server.

Looking for more text tools?

Browse Replace Tools

Last updated: 14 November 2026