Showing and hiding blocks
Hide any block from the live page, or only on phones, tablets or desktops, while keeping it in the editor.
Every block can be Shown (the default) or Hidden, and a shown block can also be hidden on phone, tablet or desktop screens. Hidden blocks stay in the editor, grayed out and fully editable, so you can prepare content and switch it on later. Needs payload-puck 0.12.0 or later.
In the editor
- Sidebar: the Visibility control sits at the top of every block's settings: Shown / Hidden, then Hide on phone, Hide on tablet and Hide on desktop.
- Action bar: the eye button on a block's action bar switches it between Hide block and Show block. It's an ordinary edit, so undo and redo cover it. It isn't shown on blocks you may not edit (Puck
permissions.edit: false). - Canvas: a hidden block is grayed out with a dashed outline and a Hidden badge. You can still select, drag and edit it, and it still renders the blocks inside it. A block hidden on some screen sizes carries a badge such as Hidden on phone, and is grayed out only when the viewport switcher shows that size. If you turn off Puck's canvas iframe (
iframe={{ enabled: false }}), that graying follows the browser window's width instead. - Interactive preview: Puck's interactive mode shows the page as visitors see it, so Hidden blocks are left out there.
- Outline: a hidden block's row is dimmed and tagged Hidden. A block hidden on some sizes is tagged, for example Hidden on phone and tablet.
Duplicating a block keeps its visibility. Reset to defaults resets the block's other settings but leaves visibility alone.
Ticking all three screen sizes is the same as choosing Hidden.
On the live page
- Hidden: the block renders nothing. It isn't in the page's HTML, and the blocks inside it don't run.
- Hidden on a screen size: the block is hidden from view on that size with CSS. The content is still in the page's HTML, so don't use it for anything that must stay private.
Hidden blocks, including ones hidden only on some screen sizes, remain in the saved page data your API returns. Don't use hiding for secrets or embargoed content.
The screen sizes are:
| Size | Width |
|---|---|
| Phone | below 768px |
| Tablet | from 768px up to (not including) 1024px |
| Desktop | 1024px and wider |
The editor's Mobile, Tablet and Desktop previews fall in these ranges. The values are exported as SCREEN_BREAKPOINTS and SCREEN_MEDIA_QUERIES.
Per-size hiding wraps the block in a <div class="payload-puck-visibility …" style="display:contents"> and adds one small stylesheet that React places in the page <head>. If your site's Content Security Policy blocks inline styles, per-size hiding won't take effect; Hidden still works because it leaves the block out entirely.
display: contents keeps the box layout (flex, grid, gaps) unchanged, but the wrapper is still an element:
- Child selectors see the wrapper, not your block. Rules like
> *,space-y-*,divide-y-*,:first-child,:last-childand:nth-child()on the parent match the wrapper. A parent can reach through it with> .payload-puck-visibility > *(the built-in Flex block does). - It's invalid inside lists and tables. A
<div>can't sit between<ul>and<li>, or between table parts and<tr>/<td>.
For block types where that matters, offer Shown and Hidden only. Their blocks are never wrapped:
const ListItem: ComponentConfig<{ text: string }> = {
blockVisibility: { screenSizes: false },
fields: { text: { type: 'text' } },
render: ({ text }) => <li>{text}</li>,
}The blockVisibility key is typed when you import anything from @delmaredigital/payload-puck/render, /email or /visibility. None of the built-in blocks need it.
Setup
None for most sites. PuckEditor, PageRenderer, HybridPageRenderer, EmailRenderer and renderToEmailHtml add show/hide to every block in the config they're given, including your own blocks and blocks from integrations.
If you pass a config straight to Puck's <Render>, wrap it yourself, or hidden blocks will appear:
import { Render } from '@puckeditor/core'
import { withBlockVisibility } from '@delmaredigital/payload-puck/render'
<Render config={withBlockVisibility(config)} data={page.puckData} />withBlockVisibility is safe to call more than once, and on configs built from already wrapped blocks: a block copied with its own render is wrapped again. A block that defines its own _visibility field is left as it is, and logs one warning in development.
If you call Puck's resolveAllData yourself, it still runs resolveData for hidden blocks; only rendering skips them.
Email blocks offer Shown and Hidden only. Screen-size rules depend on media queries, which many email clients ignore. Blocks you add to emailEditorConfig follow the same rule. For an email config you build from scratch, use withBlockVisibility(config, { screenSizes: false }).
Reading visibility on the server
@delmaredigital/payload-puck/visibility has no React or Puck runtime code, so you can use it in Payload hooks, endpoints and other plugins.
import {
isBlockHidden,
isBlockHiddenOn,
getBlockVisibility,
walkShownBlocks,
} from '@delmaredigital/payload-puck/visibility'
isBlockHidden(block) // true if left out of the page (Hidden, or hidden on every size)
isBlockHiddenOn(block, 'phone') // true if not visible on phones
getBlockVisibility(block) // { hidden: boolean, hideOn: ('phone' | 'tablet' | 'desktop')[] }
// Every block that appears on the page, top-down. Hidden blocks are skipped
// together with everything inside them; blocks hidden on only some sizes are
// included, because they are still in the page.
walkShownBlocks(page.puckData, config, (block, { parentId, zone }) => {
// ...
})walkShownBlocks follows slots, including slots inside array and object fields, and legacy DropZone zones. It never throws, whatever the data. It can't see slots a component adds only at runtime through resolveFields, so blocks inside those aren't visited.
The stored value
Each block stores its setting as props._visibility. The shape is a stable public contract, so other code may read it directly:
{ hidden?: true, hideOn?: ('phone' | 'tablet' | 'desktop')[] }- A missing or malformed value means shown.
hidden: truemeans hidden everywhere, whateverhideOnsays.- Hidden on all three sizes means fully hidden: left out of the page, like
hidden: true.
The helpers above apply those rules for you.
How the editor marks hidden blocks
The canvas badge and graying are styled through the data-puck-component attribute Puck puts on every block. The Outline tag relies on data-puck-layer-tree-id, an attribute on Puck's Outline rows that Puck doesn't document. payload-puck's test suite checks that the supported Puck version still renders it. If a future Puck release drops it, the Outline tag disappears and nothing else breaks.

