Layout
The Elements layout system provides a declarative approach to creating layouts using CSS flexbox and grid. This system enables complex, adaptive layouts with minimal markup and custom CSS.
Learn more about CSS layout fundamentals in the MDN CSS Layout guide and CSS-Tricks Flexbox guide.
Installation
The layout system is part of the core Elements styles package:
npm install @nvidia-elements/styles @nvidia-elements/themes
/* Import the layout CSS into your project */
@import '@nvidia-elements/styles/dist/layout.css';
The base layout system provides static layouts. For responsive behavior, the team plans extra modules for container and viewport breakpoint-based responsive design.
Layout System Overview
The nve-layout attribute provides a unified API for three layout modes:
- Horizontal Layout (
row): Flexbox-based horizontal arrangements - Vertical Layout (
column): Flexbox-based vertical stacking - Grid Layout (
grid): CSS Grid-based multi-dimensional layouts
Each layout mode supports spacing, alignment, and responsive behavior through a consistent syntax.
<!-- Simple horizontal layout with spacing -->
<div nve-layout="row gap:sm">
<nve-button>Save</nve-button>
<nve-button>Cancel</nve-button>
<nve-button>Delete</nve-button>
</div>
<!-- Centered vertical layout with padding -->
<section nve-layout="column gap:md pad:lg align:center">
<h2>Welcome</h2>
<p>Create beautiful layouts with ease</p>
<nve-button>Get Started</nve-button>
</section>
<!-- Responsive grid layout using semantic HTML -->
<section nve-layout="grid gap:md span-items:3 pad:xl">
<nve-card>Feature 1</nve-card>
<nve-card>Feature 2</nve-card>
<nve-card>Feature 3</nve-card>
</section>
Apply Layout to Native HTML Elements
Elements components use Web Components with Shadow DOM encapsulation. Many components manage their own internal layout, for example:
nve-card components have built-in layout for nve-card-header, nve-card-content, and nve-card-footer. Applying nve-layout directly to these components may not work as expected due to Shadow DOM boundaries.
Apply the nve-layout attribute to native HTML elements rather than Elements components. Use semantic HTML elements like <section>, <main>, <nav>, <aside>, or generic containers like <div> as your layout containers. Similarly, form components have built-in layout capabilities.
For more details, see the documentation on the internal-host pattern and slots which the library uses in development, as well as MDN docs on the Shadow DOM.
<!-- ✓ Correct: Apply to native HTML elements -->
<section nve-layout="row gap:md">
<nve-card>Card 1</nve-card>
<nve-card>Card 2</nve-card>
</section>
<!-- ✗ Incorrect: Don't apply directly to Elements components -->
<nve-card nve-layout="row gap:md">
Content...
</nve-card>
When to Use Each Layout Type
Use Horizontal Layout (row) when:
- Arranging items side-by-side (navigation bars, button groups, toolbars)
- Creating inline forms or control groups
- Building card layouts that flow horizontally
- Aligning items along a single horizontal axis
Use Vertical Layout (column) when:
- Stacking content vertically (forms, card content, sidebars)
- Creating centered hero sections or landing pages
- Building mobile-first layouts that stack naturally
- Organizing content in a top-to-bottom flow
Use Grid Layout (grid) when:
- Creating multi-column layouts (dashboards, galleries)
- Building complex page structures with precise control
- Implementing magazine-style layouts
- Needing both row and column control simultaneously
Core Features
The layout system provides consistent features across all layout types:
Gap Spacing
Control the space between elements using t-shirt sizing values that maintain visual consistency:
gap:nonegap:xxxsgap:xxsgap:xsgap:smgap:mdgap:lggap:xlgap:xxlgap:xxxl
Gap xxxs
Gap xxs
Gap xs
Gap sm
Gap md
Gap lg
Gap xl
Gap xxl
Gap xxxl
No Gap
Padding
Add internal spacing to containers using the same t-shirt sizing system:
pad:nonepad:xxxspad:xxspad:xspad:smpad:mdpad:lgpad:xlpad:xxlpad:xxxl
By default padding applies to all 4 sides of container, to specify padding on a single side use:
pad-top:mdpad-right:mdpad-bottom:mdpad-left:md
Or use the short hand to just pad the x and y axes.
pad-x:mdpad-y:md
<section nve-layout="row pad-left:md">
Padding Top
Padding Left
Padding Right
Padding Bottom
Padding X
Padding Y
Padding xxxs
Padding xxs
Padding xs
Padding sm
Padding md
Padding lg
Padding xl
Padding xxl
Padding xxxl
No Padding
Gap affects space between child elements, while padding affects space inside the container. Use gap for consistent spacing between items and padding for breathing room around content.
Full width/height on container
For convenience you can set a full option to give the container 100% width & height. This is often useful for giving the root element of a page full height.
<section nve-layout="full">
Layout Composition
You can compose layout attributes to create sophisticated designs:
<!-- Centered hero section with vertical layout -->
<section nve-layout="column gap:lg pad:xxxl align:center full">
<nve-logo size="xl"></nve-logo>
<h1 nve-text="heading xl">Build Faster</h1>
<p nve-text="lg muted">Create stunning layouts without writing CSS</p>
<div nve-layout="row gap:sm">
<nve-button variant="primary">Start Building</nve-button>
<nve-button>Learn More</nve-button>
</div>
</section>
<!-- Complex dashboard layout using semantic HTML -->
<div nve-layout="row gap:md pad:lg align:horizontal-stretch full">
<aside style="width: 250px">
<nve-panel expanded>
<nve-panel-header>
<div slot="title">Navigation menu</div>
</nve-panel-header>
<nve-panel-content>
User profile
</nve-panel-content>
</nve-panel>
</aside>
<main nve-layout="column gap:lg pad:xl">
<header nve-layout="row gap:md align:vertical-center align:space-between">
<h1>Dashboard</h1>
<nve-button>Settings</nve-button>
</header>
<section nve-layout="grid gap:md span-items:3">
<nve-card>Metric 1</nve-card>
<nve-card>Metric 2</nve-card>
<nve-card>Metric 3</nve-card>
</section>
</main>
</div>
Best Practices
- Apply to native HTML: Use
nve-layouton HTML elements, not Elements components - Start with semantic HTML: Use appropriate elements (
<nav>,<main>,<aside>) with layout attributes - Mobile-first approach: Design for narrow screens first, then enhance for larger displays
- Consistent spacing: Use the t-shirt sizing system rather than custom values
- Combine thoughtfully: Layer layout attributes to achieve complex designs
- Test responsively: Ensure layouts work across all device sizes
While the layout system is highly optimized, avoid deeply nested layouts when simpler structures suffice. Modern browsers handle flexbox and grid efficiently, but excessive nesting can impact performance on lower-end devices.
Next Steps
- Explore Horizontal Layouts for side-by-side arrangements
- Learn about Vertical Layouts for stacked content
- Understand Grid Layouts for multi-dimensional designs