Skip to content
A Go (golang) library for wrapping words in a string.
Branch: master
Clone or download
Latest commit 9e67c67 Aug 28, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information. Update README Oct 19, 2014
go.mod Add go.mod Aug 28, 2018
wordwrap.go Rewrote algorithm to wrap words before hitting the width limit Mar 13, 2015


go-wordwrap (Golang package: wordwrap) is a package for Go that automatically wraps words into multiple lines. The primary use case for this is in formatting CLI output, but of course word wrapping is a generally useful thing to do.

Installation and Usage

Install using go get

Full documentation is available at

Below is an example of its usage ignoring errors:

wrapped := wordwrap.WrapString("foo bar baz", 3)

Would output:


Word Wrap Algorithm

This library doesn't use any clever algorithm for word wrapping. The wrapping is actually very naive: whenever there is whitespace or an explicit linebreak. The goal of this library is for word wrapping CLI output, so the input is typically pretty well controlled human language. Because of this, the naive approach typically works just fine.

In the future, we'd like to make the algorithm more advanced. We would do so without breaking the API.

You can’t perform that action at this time.