Overview
A cover fills at least a given height (the full viewport by default) and centres one principal child vertically in it, with optional content pinned to the top and bottom. It is a flex column (display: flex; flex-direction: column) with a min-block-size, so it grows with its content instead of clipping it.
How children are placed. The child with data-layout-principal gets margin-block: auto, which centres it in the free space. A <header> (or any child with data-layout-cover-top) is pushed to the top and a <footer> (or data-layout-cover-bottom) to the bottom. A sole child centres itself without any attribute. With two or more children and no principal, no child is centred on purpose: plain children stack from the top, and a pinned header and footer only split the free space between them. Mark the principal explicitly.
The xl height is 100dvh, not 100vh: dynamic viewport units track the mobile browser chrome, so a full-height cover is not cropped on phones.
Element and attribute forms
Any element can be a cover with data-layout="cover". The same data-layout-* modifiers and child attributes work on both forms; the two below are identical.
1234567891011121314151617
<layout-cover data-layout-centered style="--layout-min: 14rem"> <header><small>Header</small></header> <hgroup data-layout-principal> <h3>Launching soon</h3> <p>The principal is centred vertically.</p> </hgroup> <footer><small>Footer</small></footer></layout-cover> <section data-layout="cover" data-layout-centered aria-label="Launch" style="--layout-min: 14rem"> <header><small>Header</small></header> <hgroup data-layout-principal> <h3>Launching soon</h3> <p>The principal is centred vertically.</p> </hgroup> <footer><small>Footer</small></footer></section>
Which to choose: use the attribute form when a semantic element is already the full-height region: usually the page's <main> or a hero <section>. Use <layout-cover> when there is no such element and you would otherwise add a wrapper. In the attribute form, main, article, section and aside are also container-query containers, which the element is not, so container queries inside the cover resolve against it. See data-layout for the full comparison and Semantic Layouts for the approach.
Examples
Basic usage
The cover vertically centres its principal element while the header and footer stay at their edges.
1234567891011
<layout-cover data-layout-min="xl" data-layout-padding="m" data-layout-centered> <header><small>Header content</small></header> <section data-layout-principal> <layout-stack data-layout-gap="s" data-layout-align="center"> <h2>Principal Content</h2> <p>This content is vertically centered using data-layout-principal</p> <button type="button">Call to Action</button> </layout-stack> </section> <footer><small>Footer content</small></footer></layout-cover>
The demo uses data-layout-min="auto" with a fixed height so it fits the preview frame.
Height
The data-layout-min attribute controls the minimum height of the cover.
12345678
<layout-cover data-layout-min="auto">...</layout-cover> <layout-cover data-layout-min="s">...</layout-cover> <layout-cover data-layout-min="m">...</layout-cover> <layout-cover data-layout-min="l">...</layout-cover> <layout-cover data-layout-min="xl">...</layout-cover> <layout-cover style="--layout-min: 9rem">...</layout-cover>
The demo omits xl because a full-viewport cover fills the whole preview frame.
Custom height
For a one-off height that no token matches, set --layout-min inline on the cover, as in the last cover of the height demo above. It wins over data-layout-min, and because it is registered with inherits: false it does not leak into a nested cover or grid. This is the same escape hatch <layout-grid> uses for its minimum column width, and the conformance checker allows it as an inline style.
<section data-layout="cover" data-layout-centered style="--layout-min: 65vh"> ...</section>
A stylesheet rule that sets --layout-min on the cover works too, when the same height is reused.
Padding
The data-layout-padding attribute controls internal spacing.
123456
<layout-cover data-layout-min="auto" data-layout-padding="none" data-layout-centered> <p data-layout-principal><code>padding="none"</code></p></layout-cover><layout-cover data-layout-min="auto" data-layout-padding="s" data-layout-centered>...</layout-cover><layout-cover data-layout-min="auto" data-layout-padding="l" data-layout-centered>...</layout-cover><layout-cover data-layout-min="auto" data-layout-padding="xl" data-layout-centered>...</layout-cover>
Gap and centering
Without modifiers the principal is centred vertically but keeps the start alignment of the line. data-layout-centered centres it horizontally too and centres the text, while the header and footer keep the full width (they stretch, so a brand/nav row inside them can still spread out). data-layout-gap sets a minimum space between all children; it shows when the cover is short, as with data-layout-min="auto", because the auto margins otherwise take up all the free space.
1234567891011121314151617
<layout-cover style="--layout-min: 14rem"> <header><small>Header</small></header> <p data-layout-principal>Principal, start-aligned</p> <footer><small>Footer</small></footer></layout-cover> <layout-cover data-layout-centered style="--layout-min: 14rem"> <header><small>Header (full width)</small></header> <p data-layout-principal>Principal, centred</p> <footer><small>Footer (full width)</small></footer></layout-cover> <layout-cover data-layout-min="auto" data-layout-gap="l"> <header><small>Header</small></header> <p data-layout-principal>Principal</p> <footer><small>Footer</small></footer></layout-cover>
Hero section
With data-layout-centered the principal shrinks to its content and centres, while the <header> and <footer> keep the full width — so the header can carry its own data-layout="cluster" and spread the brand and nav with justify="between", with no wrapper inside it. (The demo uses data-layout-min="auto" and a fixed height to fit the preview frame.)
12345678910111213141516171819
<layout-cover data-layout-min="xl" data-layout-padding="xl" data-layout-centered> <header data-layout="cluster" data-layout-gap="m" data-layout-justify="between"> <strong>Brand</strong> <nav aria-label="Main" data-layout="cluster" data-layout-gap="m">...</nav> </header> <section data-layout-principal> <layout-stack data-layout-gap="l" data-layout-align="center"> <h1>Welcome to Our Platform</h1> <p>Build amazing experiences with our tools.</p> <layout-cluster data-layout-gap="m"> <button type="button">Get Started</button> <button type="button" class="secondary">Learn More</button> </layout-cluster> </layout-stack> </section> <footer> <small>Scroll down to explore</small> </footer></layout-cover>
Login page
.login-card { inline-size: 100%; max-inline-size: 22rem;}
1234567891011121314151617181920
<layout-cover data-layout-min="xl" data-layout-padding="l" data-layout-centered> <header> <strong>Brand Logo</strong> </header> <section data-layout-principal> <layout-card class="login-card"> <form data-layout="stack" data-layout-gap="m" action="/login" method="post"> <h2>Sign In</h2> <label for="email">Email</label> <input type="email" id="email" name="email" autocomplete="email" required /> <label for="password">Password</label> <input type="password" id="password" name="password" autocomplete="current-password" required /> <button type="submit">Sign In</button> </form> </layout-card> </section> <footer> <small>Don't have an account? <a href="#">Sign up</a></small> </footer></layout-cover>
Error page (404)
The page's <main> carries the layout, so no wrapper is needed, and it fills the viewport with the default xl height. Go Home
navigates, so it is a link styled as a button, not a <button>.
12345678910
<main data-layout="cover" data-layout-padding="l" data-layout-centered> <section data-layout-principal> <layout-stack data-layout-gap="m" data-layout-align="center"> <p class="display-heading">404</p> <h1>Page Not Found</h1> <p>The page you're looking for doesn't exist.</p> <a href="/" class="button">Go Home</a> </layout-stack> </section></main>
Custom top and bottom elements
123456789101112131415161718192021222324
<layout-cover data-layout-min="xl" data-layout-padding="m" data-layout-gap="m"> <nav class="breadcrumb" data-layout-cover-top aria-label="Breadcrumb"> <ol> <li><a href="#">Home</a></li> <li><a href="#">Products</a></li> <li><span aria-current="page">Item</span></li> </ol> </nav> <section data-layout-principal> <layout-stack data-layout-gap="s"> <strong>Product Details</strong> <p>Main content centered vertically.</p> </layout-stack> </section> <section data-layout-cover-bottom> <layout-cluster data-layout-gap="s" data-layout-justify="between"> <span>Step 2 of 4</span> <layout-cluster data-layout-gap="s"> <button type="button" class="secondary">Back</button> <button type="button">Next</button> </layout-cluster> </layout-cluster> </section></layout-cover>