Whitespace

    Normal

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

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

    Whitespace - 图2

    1. <div class="whitespace-no-wrap overflow-x-auto">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Omnis quidem itaque beatae, rem tenetur quia iure,
    2. eum natus enim maxime
    3. laudantium quibusdam illo nihil,
    4. reprehenderit saepe quam aliquid odio accusamus.</div>

    Pre

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

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

    Whitespace - 图4

    1. <div class="whitespace-pre-line">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Omnis quidem itaque beatae, rem tenetur quia iure,
    2. reprehenderit saepe quam aliquid odio accusamus.</div>

    Pre Wrap

    To control the whitespace property of an element only at a specific breakpoint, add a {screen}: prefix to any existing whitespace utility. For example, adding the class md:whitespace-pre to an element would apply the whitespace-pre utility at medium screen sizes and above.

    For more information about Tailwind’s responsive design features, check out the documentation.

    Whitespace - 图6

    all

    sm

    Whitespace - 图8

    lg

    Whitespace - 图10

    xl

    1. <div class="whitespace-normal sm:whitespace-no-wrap md:whitespace-pre lg:whitespace-pre-line xl:whitespace-pre-wrap ...">...</div>

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Omnis quidem itaque beatae, rem tenetur quia iure, eum natus enim maxime laudantium quibusdam illo nihil, reprehenderit saepe quam aliquid odio accusamus.

    Customizing

    By default, only responsive variants are generated for whitespace utilities.

    You can control which variants are generated for the whitespace utilities by modifying the whitespace property in the section of your tailwind.config.js file.

    For example, this config will also generate hover and focus variants:

    Disabling

    1. // tailwind.config.js
    2. module.exports = {
    3. corePlugins: {
    4. // ...
    5. + whitespace: false,
    6. }

    ← Vertical Align