Section for Astro
Maintain consistent styles across your pages with the Section component.
Installation
bunx --bun shadcn@latest add @gnostic/sectionnpx shadcn@latest add @gnostic/sectionpnpm dlx shadcn@latest add @gnostic/sectionCheck your global Tailwind stylesheet
Add these variables to your Tailwind theme for responsive section title sizing.
src/styles/tailwind.css@theme inline { --text-section-title: clamp( calc(var(--typeset-size, 1rem) * var(--heading-min, 1.875)), calc(var(--typeset-size, 1rem) + 4cqi), calc(var(--typeset-size, 1rem) * var(--heading-max, 3)) ); --text-section-title--line-height: 1.2;}Copy the files
src/components/ui/section/types.tssrc/components/ui/section/index.tssrc/components/ui/section/section-container.astrosrc/components/ui/section/section-description.astrosrc/components/ui/section/section-header.astrosrc/components/ui/section/section-title.astrosrc/components/ui/section/section.astro
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.
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.
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.
API Reference
Section accepts variant="default" or variant="floating". Omit the prop for the default surface.
variant?ContainerVariants['variant']
Stack the children, use two columns, or put them in a responsive row.
ContainerVariants['variant']'default'order?ContainerVariants['order']
Move the first child to the last visual position with `reverse`.
ContainerVariants['order']'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
SectionTitleuses the Tailwind utilitytext-section-title. With the default--typeset-sizeof1rem, the title scales from1.875remto3remwith the container width. Its line height is1.2.- Set
--heading-minand--heading-maxon 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
--containerto change the maximum container width. Its default is Tailwind’s--container-7xl. - Set
classonSectionto adjust its vertical spacing. - Use
<Section class="inverted">to swap the surface and text colors. Children inherit the swapped color pairs.
