Skip to content

White Space

Use whitespace-{value} utilities to control how whitespace and line breaks are handled inside text.


Use the whitespace-normal utility to cause text to wrap normally within an element. Newlines and spaces will be collapsed.

Style('whitespace-normal', child: Text('Hey everyone!\n\nIt\'s almost 2022 and we still don\'t know if there are aliens living among us, or do we? Maybe the person writing this is an alien.\n\nYou will never know.'))

Use the whitespace-nowrap utility to prevent text from wrapping within an element. Newlines and spaces will be collapsed.

Style('whitespace-nowrap', child: Text('Hey everyone!\n\nIt\'s almost 2022 and we still don\'t know if there are aliens living among us, or do we? Maybe the person writing this is an alien.\n\nYou will never know.'))

Use the whitespace-pre utility to preserve newlines and spaces within an element. Text will not be wrapped.

Style('whitespace-pre', child: Text('Hey everyone!\n\nIt\'s almost 2022 and we still don\'t know if there are aliens living among us, or do we? Maybe the person writing this is an alien.\n\nYou will never know.'))

Use the whitespace-pre-line utility to preserve newlines but not spaces within an element. Text will be wrapped normally.

Style('whitespace-pre-line', child: Text('Hey everyone!\n\nIt\'s almost 2022 and we still don\'t know if there are aliens living among us, or do we? Maybe the person writing this is an alien.\n\nYou will never know.'))

Use the whitespace-pre-wrap utility to preserve newlines and spaces within an element. Text will be wrapped normally.

Style('whitespace-pre-wrap', child: Text('Hey everyone!\n\nIt\'s almost 2022 and we still don\'t know if there are aliens living among us, or do we? Maybe the person writing this is an alien.\n\nYou will never know.'))

Use the whitespace-break-spaces utility to preserve newlines and spaces within an element. White space at the end of lines will not hang, but will wrap to the next line.

Style('whitespace-break-spaces', child: Text('Hey everyone!\n\nIt\'s almost 2022 and we still don\'t know if there are aliens living among us, or do we? Maybe the person writing this is an alien.\n\nYou will never know.'))
ClassBehavior
whitespace-normalCollapses whitespace runs to single spaces; wraps
whitespace-nowrapCollapses whitespace; no wrap
whitespace-prePreserves whitespace + newlines; no wrap
whitespace-pre-lineCollapses spaces; preserves newlines; wraps
whitespace-pre-wrapPreserves whitespace + newlines; wraps
whitespace-break-spacesLike pre-wrap; trailing spaces wrap

Flutter’s Text widget does not natively collapse CSS whitespace, so the library applies the equivalent string mutation in _applyTextStyle before the text is laid out. The breakSpaces mode is treated as preWrap since Flutter makes no distinction between trailing-space wrapping and normal wrapping.