Space Between

    v1.3.0+

    Utilities for controlling the space between child elements.

    Add horizontal space between children

    Control the horizontal space between elements using the utilities.

    Control the vertical space between elements using the space-y-{amount} utilities.

    Space Between - 图2

    1. <div class="space-y-6">
    2. <div>1</div>
    3. <div>3</div>
    4. </div>

    Reversing children order

    If your elements are in reverse order (using say flex-row-reverse or flex-col-reverse), use the space-x-reverse or space-y-reverse utilities to ensure the space is added to the correct side of each element.


    To control the space between elements at a specific breakpoint, add a {screen}: prefix to any existing space utility. For example, adding the class md:space-x-8 to an element would apply the space-x-8 utility at medium screen sizes and above.

    Space Between - 图4

    all

    sm

    Space Between - 图6

    md

    lg

    Space Between - 图8

    1. <div class="flex space-x-2 sm:space-x-4 md:space-x-6 lg:space-x-8 xl:space-x-12">
    2. <div>2</div>
    3. <div>3</div>
    4. </div>

    1

    2

    3


    Customizing

    If you’d like to customize your values for space between, padding, margin, width, and height all at once, use the theme.spacing section of your tailwind.config.js file.

    To customize only the space between values, use the theme.space section of your tailwind.config.js file.

    1. // tailwind.config.js
    2. module.exports = {
    3. theme: {
    4. space: {
    5. + md: '16px',
    6. + lg: '24px',
    7. }
    8. }
    9. }

    Learn more about customizing the default theme in the .

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

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

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

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

    ← Margin