Skip to content

Spacer Block Not Responsive, May Lead to Unexpected Results #10081

Closed

Description

@mrwweb

Describe the bug
The Spacer block is quite simple in that it applies a fixed height in pixels set by the editor.

To quickly take a step back, one general problem with WYSIWYG editors is that they encourage editors to overly optimize for the environment they're currently working in. This can lead to unintended consequences of editor decisions, often without the editor's knowledge.

Back to the issue, I think the Spacer likely will lead to unexpected results for editors when using this block on a large screen and not considering small screens. Arguably worse, even if editors want to consider small screens, there's no easy way to do so.

The screenshots below illustrate the issue. On my current monitor with a browser not even filling the entire screen, this spacer filled roughly 40% of the screen height. On an iPhone 7-size screen, it was 55%. It's not that hard to imagine a user making spacers that approach 100% of a smaller phone's screen.

I'm not sure of the best solution for this, but my first instinct would be that the spacer should be calculating a height as percentage of width and then implemented with a pseudo-element in the classic aspect ratio box technique. I'm sure there are other possibilities both for the behavior and implementation.

To Reproduce

  1. On a large screen, separate two visible blocks of any type with the largest reasonable spacer block you'd consider.
  2. Preview the page.
  3. Resize screen to a "phone" size

Expected behavior
Spacer adjusts to be reasonable on and screen size.

Screenshots
If applicable, add screenshots to help explain your problem.

Full Post on large screen
poem formatted with a spacer block

One screen's worth of the post on large screen:
the poem's spacer block takes up 40% of the screen height on large screens

Full Post on Small Screen
The same poem on a narrower screen

One screen's worth of the post on a small screen
On the narrow screen, the spacer block takes up 55% of the height

Activity

  1. added
    [Feature] Blocks
    Needs Design Feedback
    on Sep 21, 2018
  2. karmatosed commented on Oct 4, 2018

    @karmatosed
    Member

    'If' this can be done without any interface in phase one, I would prefer that. I can see a need once we enter site building to have more granular control but for now having something 'just work' seems like the best step.

  3. mrwweb commented on Oct 4, 2018

    @mrwweb
    Author

    Completely agreed. In fact I don't think there should be interface. It strikes me as a fairly reasonable assumption that users inserting a spacer are defining the height they want at the current document width, so a ratio-based "just works" solution makes sense.

    If users wanted to optimize heights at different breakpoints, I would think that's plugin-territory for a "Show only on [mobile/desktop]" feature (unless/until core added standardized responsive options for blocks).

  4. chrisvanpatten commented on Oct 4, 2018

    @chrisvanpatten
    Contributor

    I wonder if there's any way to re-use or extend the CSS used in the responsive video feature? Maybe similarly calculating the aspect ratio on the fly somehow…?

  5. karmatosed commented on Oct 8, 2018

    @karmatosed
    Member

    Removing the design feedback as we are opting for no interface so it's just a matter of a pull request on this now. I say that knowing 'just' involves some 'fun' maths.

  6. removed
    Needs Design Feedback
    on Oct 8, 2018
  7. DancingPigeon commented on Oct 25, 2018

    @DancingPigeon

    Isn't the core issue here that using PX as the primary/only unit type is guaranteed to lead to issues related to changing viewport size? Why not allow something based off vh or em?

  8. mrwweb commented on Oct 25, 2018

    @mrwweb
    Author

    @DancingPigeon That's certainly another way to put it. In trying to think about the ideal "just works" experience, something close to maintaining the aspect ratio of the sizer feels right, though I also think that it might be even better if there were min- and max-heights to "cap" the changes. Something similar is usually done when using vw units for type sizing.

    ems wouldn't maintain aspect ratio and only be responsive if the theme resizes typography, but vh units seem like a reasonable path forward. I didn't think the browser support was there, but reviewing that now (IE9+), makes me think that could be an even cleaner solution than the pseudo-element aspect ratio hack.

  9. DancingPigeon commented on Oct 26, 2018

    @DancingPigeon

    I can see arguments for either. Personally, I think dragging by PX is the least valuable way for the 'standard' user to use the current control, and its certainly at odds with the current trend in how white space should be handled with respect to content. I can see an argument for either vh or em, depending of course whether we're talking about space as it relates to typography or viewport. I can see value in either, for different purposes of spacing.

  10. melchoyce commented on Nov 15, 2018

    @melchoyce
    Contributor

    Maintaining aspect ratio and scaling down proportionally, IMO, is key. It should feel proportionally like the same amount of space, despite your screen size (though I agree we need a min/max cap).

    Pixels are easier to visualize when deciding how large something is — but the actual output should probably be something more flexible, like vh.

  11. dweidner commented on Dec 20, 2018

    @dweidner

    I would love to be able to customize the available spacer-heights, similar to how it is possible with the editor font sizes. For example:

    add_theme_support( 'editor-spacer-sizes', [
        [
            'name' => __( 'Small', 'acme' ),
            'size' => 27,
            'slug' => 'small',
        ],
        [
            'name' => __( 'Medium', 'acme' ),
            'size' => 54,
            'slug' => 'regular',
        ],
        [
            'name' => __( 'Large', 'acme' ),
            'size' => 108,
            'slug' => 'large',
        ],
    ]);
    add_theme_support( 'disable-custom-spacer-sizes' );
    

    Resulting in the following markup:

    <div class="wp-block-spacer is-large" aria-hidden="true"></div>
  12. mrwweb commented on Dec 20, 2018

    @mrwweb
    Author

    @dweidner seems like a good suggestion. I'd encourage you to make a separate ticket for that request as the direction of this ticket right now is probably UI-less.

  13. rafafields commented on May 13, 2019

    @rafafields

    I would love to be able to customize the available spacer-heights, similar to how it is possible with the editor font sizes. For example:

    add_theme_support( 'editor-spacer-sizes', [
        [
            'name' => __( 'Small', 'acme' ),
            'size' => 27,
            'slug' => 'small',
        ],
        [
            'name' => __( 'Medium', 'acme' ),
            'size' => 54,
            'slug' => 'regular',
        ],
        [
            'name' => __( 'Large', 'acme' ),
            'size' => 108,
            'slug' => 'large',
        ],
    ]);
    add_theme_support( 'disable-custom-spacer-sizes' );
    

    Resulting in the following markup:

    <div class="wp-block-spacer is-large" aria-hidden="true"></div>
    

    I think we all would love that solution. Until they implement something like that, I have coded a simple vanilla lightweight solution which you can configure with breakpoints. I hope it helps :)

    Source -> https://codepen.io/Wondermochi/pen/YbGQdW

    Edit: It looks like Gutenberg overwrite my javascript (even when I render it on head omg). Can someone tell why?

    Finally I decided to set an !important height value to all spacer blocks which I can control from my css to optimize space in every breakpoint. In case of needen more space, I will add the block twice. Not clean but functional.

  14. added
    Needs Dev
    on Dec 20, 2019
  15. 3 remaining items

  16. added
    [Block] Spacer
    on Feb 4, 2021
  17. Mamaduka commented on Jan 14, 2022

    @Mamaduka
    Member

    The Spacer block now supports different units for height, not just pixes, so I think we can close this issue. See #36186.

  18. mrwweb commented on Jan 14, 2022

    @mrwweb
    Author

    I'll just throw out that I think until the default value of the spacer block is changed to a responsive value (5vh?), the usability concerns expressed in this ticket—default usage leads to unresponsive bad results on small screens—are still valid.

  19. Rockstar907 commented on Jan 14, 2022

    @Rockstar907
  20. jordesign commented on Aug 1, 2023

    @jordesign
    Contributor

    I'll just throw out that I think until the default value of the spacer block is changed to a responsive value (5vh?), the usability concerns expressed in this ticket—default usage leads to unresponsive bad results on small screens—are still valid.

    @mrwweb - I'm seeing vh values being supported by the spacer block now - does that resolve the kind of thing you're talking about (for now)?

  21. added
    [Type] Enhancement
    on Aug 1, 2023
  22. mrwweb commented on Aug 7, 2023

    @mrwweb
    Author

    @jordesign I would not say that the addition of vh units resolves the problem since px units are still the default.

    I think until vh is the default unit or the spacer switches to an aspect-ratio approach, most users are still unlikely to change the default value and will still experience these problems.

  23. jordesign commented on Aug 8, 2023

    @jordesign
    Contributor

    @mrwweb Having that value as the default is likely a much bigger conversation to have - in terms of consistency with other blocks etc. I'll leave this open - but add a label for Design Feedback 👍

  24. added
    Needs Design Feedback
    and removed
    Needs Dev
    CSS Styling
    on Aug 8, 2023
  25. mrwweb commented on Aug 9, 2023

    @mrwweb
    Author

    Having that value as the default is likely a much bigger conversation to have

    Totally agree. The original concern with the ticket is that any user that doesn't have a strong grasp of px vs. other units (probably most users) or who isn't thinking about responsiveness (probably most users) and inserts a spacer and drags it to be larger is likely going to create a sub-par experience for their mobile visitors.

    I don't think that has changed, so I agree we should leave the ticket open. I'd love design feedback!

  26. karmatosed commented on May 7, 2025

    @karmatosed
    Member

    I feel like this has design feedback so I am unsure what we specifically need - forgive me for maybe not seeing that.

    I actually do think this now has a progressed to resolve in the current implementation based on the feedback here from design:

    Maintaining aspect ratio and scaling down proportionally, IMO, is key. It should feel proportionally like the same amount of space, despite your screen size (though I agree we need a min/max cap).

    Pixels are easier to visualize when deciding how large something is — but the actual output should probably be something more flexible, like vh.

    With that in mind my approach or recommendation would be to look at what exactly does need to be moved out of this and do that in other issues, for now closing this one to create smaller exact ones to improve the spacer block. I am going to do that and in doing so I want to make it clear I am ok reopening if others feel this isn't correct.

  27. mrwweb commented on May 7, 2025

    @mrwweb
    Author

    @karmatosed Moving this forward with those two key observations sounds fabulous! Could you be sure to mention this issue from those new ones so we can easily track them and this thread can provide context?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs Design Feedback[Block] Spacer[Feature] Blocks[Type] Enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions