You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Spacer Block Not Responsive, May Lead to Unexpected Results #10081
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
On a large screen, separate two visible blocks of any type with the largest reasonable spacer block you'd consider.
Preview the page.
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.
'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.
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).
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…?
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.
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?
@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.
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.
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.
Reacted by klihelp, rather, Thomas Kräftner, K Belardinelli, Mel Choyce-Dwan, John Puddephatt, Mark, Ellen Bauer, Nicholas Rowe, Resolution-Sam and 1 more
@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.
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 :)
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.
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.
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)?
@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.
@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 👍
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!
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.
@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?
Activity
karmatosed commentedon Oct 4, 2018
'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.
mrwweb commentedon Oct 4, 2018
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).
chrisvanpatten commentedon Oct 4, 2018
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…?
karmatosed commentedon Oct 8, 2018
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.
DancingPigeon commentedon Oct 25, 2018
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?
mrwweb commentedon Oct 25, 2018
@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.
DancingPigeon commentedon Oct 26, 2018
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.
melchoyce commentedon Nov 15, 2018
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.dweidner commentedon Dec 20, 2018
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:
Resulting in the following markup:
mrwweb commentedon Dec 20, 2018
@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.
rafafields commentedon May 13, 2019
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.
3 remaining items
Mamaduka commentedon Jan 14, 2022
The Spacer block now supports different units for height, not just pixes, so I think we can close this issue. See #36186.
mrwweb commentedon Jan 14, 2022
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.Rockstar907 commentedon Jan 14, 2022
jordesign commentedon Aug 1, 2023
@mrwweb - I'm seeing
vhvalues being supported by the spacer block now - does that resolve the kind of thing you're talking about (for now)?mrwweb commentedon Aug 7, 2023
@jordesign I would not say that the addition of
vhunits resolves the problem sincepxunits are still the default.I think until
vhis 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.jordesign commentedon Aug 8, 2023
@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 👍
mrwweb commentedon Aug 9, 2023
Totally agree. The original concern with the ticket is that any user that doesn't have a strong grasp of
pxvs. 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!
karmatosed commentedon May 7, 2025
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:
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.
mrwweb commentedon May 7, 2025
@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?