shadcn.io is not affiliated with official shadcn/ui
Item examples · Layout
Item with Header for React
Three model cards in a grid, each an item with a picture in its header above the model's name and description.
Some rows are better as tiles: a picture on top, a name and a line of text below. This React example turns an ItemGroup into a three-column grid and gives each outline Item an ItemHeader holding a 3:2 image, followed by the model's name and description in ItemContent. ItemHeader spans the full width of the Item, so the picture sits above the content instead of beside it.
Preview
Installation
FAQ
When should I use ItemHeader instead of ItemMedia?
Use ItemHeader when the visual should sit above the text at full width, as in this tile grid. Use ItemMedia for a small icon, avatar, or thumbnail beside the title. ItemHeader is basis-full, so it takes the whole row.
How do the header images keep their shape?
The image has aspect-3/2, w-full and object-cover, so it fills the tile's width at a fixed ratio and crops instead of stretching. The width and height attributes give the browser that ratio before the image loads, so the grid doesn't jump.
How does ItemGroup become a grid?
ItemGroup is a flex column by default; the example adds grid grid-cols-3 gap-4 to turn it into three columns. Use responsive classes, such as one column on small screens and three from md up, if the tiles get too narrow.
What should the header image's attributes be?
Set width and height to the source's ratio, and an alt text that says what the picture shows when it carries meaning. Here the pictures are decorative and the title names the model, so alt is empty. Add loading="lazy" for grids below the fold.
Related
- Item GroupThree people in an item group, divided by
- Item with Image MediaA list of songs as link items, each with
- Standard CardA basic card with a title, a description
- Item SizesA default-size item with an action button
- 16:9 Aspect Ratio (Widescreen)A 16:9 widescreen frame for video
- Item as LinkTwo items rendered as links: one to a