Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

Section for Astro

Maintain consistent styles across your pages with the Section component.

Launch checklist

Plan the next release

Set the scope, review the changes, and choose a release date.

  1. Set scope
  2. Review changes
  3. Ship release

Installation

bunx --bun shadcn@latest add @gnostic/section

Usage

Section sets the background and vertical spacing. The default SectionContainer centers its children and stacks them in a column. Use one container when the header and body share a layout. Add a second container when a group needs its own width or alignment.

---
import {
  Section,
  SectionContainer,
  SectionDescription,
  SectionHeader,
  SectionTitle,
} from "@/components/ui/section"
---

<Section>
  <SectionContainer class="max-w-2xl text-center">
    <SectionHeader>
      <SectionTitle>Projects</SectionTitle>
      <SectionDescription>Recent work from the studio.</SectionDescription>
    </SectionHeader>
  </SectionContainer>
  <SectionContainer variant="split">
    <slot />
  </SectionContainer>
</Section>

SectionHeader renders a <header>. Put an optional link or button in its default slot. SectionHeading is a deprecated alias for SectionHeader.

Examples

Floating section

Use variant="floating" on Section to inset the whole section and give it a border and rounded corners.

Customer story

How a small team keeps track of each release.

“Now we can see who reviews each change and when it ships.”

Split container

Use variant="split" on SectionContainer to place an image group beside the section header. The two groups stack until the section reaches the @2xl container width. Set order="reverse" to move the first group to the end of the visual layout.

A storm gathers around a tower on the plain.

Distant worlds

Three landscape studies of winter light and passing storms.

Responsive container

Use variant="responsive" on SectionContainer to put a header and an action on the same row. They stack when the section is narrower than the @sm container width. Resize the preview to see the change.

Studio visits

Book a tour of the print workshop.

Request a visit

API Reference

Section accepts variant="default" or variant="floating". Omit the prop for the default surface.

PropType
variant?ContainerVariants['variant']

Stack the children, use two columns, or put them in a responsive row.

TypeContainerVariants['variant']
Default'default'
order?ContainerVariants['order']

Move the first child to the last visual position with `reverse`.

TypeContainerVariants['order']
Default'default'

Read the installed source for the complete prop types.

Keyboard and behavior

SectionTitle renders an <h2>. Set its as prop to match the page heading order. Add an ID to the section when a navigation link points to it.

Theme and layout

  • SectionTitle uses the Tailwind utility text-section-title. With the default --typeset-size of 1rem, the title scales from 1.875rem to 3rem with the container width. Its line height is 1.2.
  • Set --heading-min and --heading-max on a title to change its size limits. For example, <SectionTitle class="[--heading-min:2] [--heading-max:4]"> sets the limits to two and four times the base size. The Manual tab under Installation includes the global CSS for this utility.
  • Set --container to change the maximum container width. Its default is Tailwind’s --container-7xl.
  • Set class on Section to adjust its vertical spacing.
  • Use <Section class="inverted"> to swap the surface and text colors. Children inherit the swapped color pairs.