Whitespace

    Utilities for controlling an element’s white-space property.

    Use to cause text to wrap normally within an element. Newlines and spaces will be collapsed.

    No Wrap

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

    1. <div class="w-3/4 overflow-x-auto ...">
    2. <div class="whitespace-nowrap ...">Hey everyone!
    3. It's almost 2022 and we still don't know if there is aliens living among us, or do we? Maybe the person writing this is an alien.
    4. You will never know.</div>

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

    Whitespace - 图3

    Pre Line

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

    1. <div class="whitespace-pre-line ...">Hey everyone!
    2. It's almost 2022 and we still don't know if there is aliens living among us, or do we? Maybe the person writing this is an alien.
    3. </div>

    Whitespace - 图5


    Hover, focus, and other states

    Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:whitespace-pre to only apply the whitespace-pre utility on hover.

    1. <div class="whitespace-normal hover:whitespace-pre">
    2. <!-- ... -->

    For a complete list of all available state modifiers, check out the documentation.

    You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use to apply the whitespace-pre utility at only medium screen sizes and above.