Tailwind CSS Whitespace
The whitespace utility class in Tailwind CSS allows you to control the handling of whitespace within elements.
Tailwind Whitespace
The whitespace utility class in Tailwind CSS allows you to control the handling of whitespace within elements. With Tailwind's whitespace class, you can easily modify the whitespace behavior to achieve the desired text and layout effects.
Applying Tailwind Whitespace
To apply a specific whitespace behavior to an element, you can use the whitespace-{value}
utility class, where {value}
represents the desired whitespace behavior. Here are some common values you can use:
- whitespace-normal: Allows normal whitespace behavior, where multiple consecutive spaces are collapsed into a single space and line breaks are treated as a single space.
- whitespace-nowrap: Prevents line breaks and truncates text if it exceeds the container's width.
- whitespace-pre: Preserves whitespace and line breaks as they appear in the source code.
- whitespace-pre-line: Preserves line breaks but collapses multiple consecutive spaces into a single space.
- whitespace-pre-wrap: Preserves whitespace and line breaks, wrapping text as necessary.
<p class="whitespace-nowrap"> This text will not wrap and will be truncated if it exceeds the container's width.</p>
Preview
This text will not wrap and will be truncated if it exceeds the container's width.
Responsive Whitespace
Tailwind CSS allows you to apply whitespace classes responsively at different breakpoints. To use responsive whitespace classes, you can append the breakpoint prefix to the utility class. For example, md:whitespace-pre-wrap
sets the whitespace behavior to preserve whitespace and line breaks, wrapping text as necessary starting from the medium breakpoint and above.
<p class="whitespace-normal md:whitespace-pre-wrap"> This text will have normal whitespace behavior by default, but starting from the medium breakpoint and above, it will preserve whitespace and line breaks, wrapping text as necessary.</p>
Preview
This text will have normal whitespace behavior by default, but starting from the medium breakpoint and above, it will preserve whitespace and line breaks, wrapping text as necessary.
In the above example, the whitespace behavior of the <p>
element is set to normal by default (whitespace-normal
), but starting from the medium breakpoint and above, it changes to preserve whitespace and line breaks, wrapping text as necessary (md:whitespace-pre-wrap
).
Tailwind CSS WhiteSpace Class Table
Class | Properties |
---|---|
whitespace-normal | white-space: normal; |
whitespace-nowrap | white-space: nowrap; |
whitespace-pre | white-space: pre; |
whitespace-pre-line | white-space: pre-line; |
whitespace-pre-wrap | white-space: pre-wrap; |
Windframe Tailwind blocks
Windframe is a drag and drop builder for rapidly building tailwind css websites and UIs