--- package: "@svenskaspel/ui" version: "4.4.0" document_type: "component-documentation" source: "@svenskaspel/ui/docs/card.md" canonical_url: "/components/card" usage_source: "src/app/(docs)/components/card/page.mdx" --- # Card Card is a container that holds information and actions related to a single concept or object. ![Card](/images/components/card/card-card-16-5112-0.webp) *** ## Usage Use a card to display content and actions on a single topic. Cards should be easy to scan for relevant and actionable information. Elements like text and images should be placed on cards in a way that clearly indicates hierarchy. Cards can give information prominence and create predictable patterns. While they’re very flexible, it’s important to use them consistently for particular use cases across experiences. ### Type of cards There are three types of cards: - Elevated - Filled - Outlined ![Type of cards](/images/components/card/card-type-of-cards-16-5115-0.webp) 1. Elevated card 2. Filled card 3. Outlined card #### Elevated cards Elevated cards have a drop shadow providing more separation from the background than filled cards, but less than outlined cards. #### Filled cards Filled cards provide subtle separation from the background. This has less emphasis than elevated or outlined cards. #### Outlined cards Outlined cards have a visual boundary around the container. This can provide greater emphasis than other types. ### Defining properties #### Contained Each card is a standalone object, even within a card group. The actions and information within one card are distinct from others. #### Summarized A card focuses on high-level details to inform users of the card’s purpose and aid in deciding whether to interact with more content. #### Interactive Cards are, by default, interactive whether they have nested actions or not. #### Reusable While a card doesn’t automatically have to be placed in multiple contexts, it’s by default a reusable component. ### Card or Container A card is, by default, interactive, but it isn't defined by its interactivity — it's defined by semantic independence. A container isn't defined by its flatness — it's defined by structural purpose. Both can be reusable, what separates them is whether the component represents a thing or holds things. ![Card or Container](/images/components/card/card-figma-89bfb.webp) 1. Outlined card 2. Container #### Summary of distinctions | Attribute | Card | Container | | ------------------ | ---------------------------- | ---------------------------- | | Represents | A distinct subject or entity | A group or section | | Standalone meaning | Yes | No | | Interactive | Optional (by default, yes) | Usually not (by default, no) | | Reusability scope | Cross-content | Contextual | *** ## Anatomy The card container is the only required element in a card. Card layouts can vary to support the types of content they contain. Below is a common configuration of elements. ![Anatomy](/images/components/card/card-anatomy-37-1068-0.webp) A. Container B. Headline C. Preamble D. Supporting text E. Image F. Button ### Padding Cards use 16 px (p-4) internal padding by default. This should be the standard choice in most cases, as it provides a consistent content layout and spacing within the component. Padding options include small (8 px), medium (16 px), large (24 px), and none (0 px). In some cases, the padding may need to be adjusted to better suit the content. For example, images may need to span the full width of the card, or headings may need less spacing if the typography already adds enough space. The amount of padding should also be guided by the content density inside the card — denser layouts often need less padding, while lighter layouts can allow for more generous spacing. ![Padding – 1](/images/components/card/card-padding-6872-6969-0.webp) Example of a card using the default 16 px internal padding. ![Padding – 2](/images/components/card/card-padding-6872-6969-1.webp) Example of a card where the internal padding has been modified to support the content layout. *** ## Layout ### Cards in a collection Multiple cards can be grouped together into collections displayed in a grid or carousel. By default, cards in a collection are coplanar, sharing the same resting elevation unless they are picked up or dragged. ![Cards in a collection](/images/components/card/card-cards-in-a-collection-105-1031-0.webp) Multiple cards can be grouped into collections with a shared resting elevation. ### Organize Organize card collections so that they are easy to use. Their layout affects how they are perceived. ![Organize](/images/components/card/card-organize-105-1058-0.webp) Place cards in a collection in a straightforward, easy-to-use manner. ### Grid Cards can be displayed together in a grid. ![Grid](/images/components/card/card-grid-145-562-0.webp) Cards displayed in a grid. The default grid can be customized to show cards in staggered or mosaic grids. ![Grid – 1](/images/components/card/card-grid-145-580-0.webp) Customized mosaic grid. ![Grid – 2](/images/components/card/card-grid-145-580-1.webp) Customized staggered grid. ### Vertical list Cards can be displayed together in a vertical list. ![Vertical list](/images/components/card/card-vertical-list-145-598-0.webp) Cards shown in a vertical list. ### Carousel Cards can be displayed together in a horizontal row or carousel. ![Carousel](/images/components/card/card-carousel-145-613-0.webp) Cards displayed together in a horizontal row or carousel. *** ## Interactions Cards can provide people with interactions in a number of ways. When there are multiple available actions, a card can hold buttons and links. ![Interactions](/images/components/card/card-interactions-171-826-0.webp) If there is one obvious action, the entire card surface can function as a button. ![Interactions](/images/components/card/card-interactions-172-827-0.webp) Cards can also be used to let people make a selection, similar to checkboxes or radio groups. ![Interactions](/images/components/card/card-interactions-234-1236-0.webp) *** ## Expanding cards Cards can be expanded to show additional information and actions. It's important to keep the expanded content short and contextual. The expanded card will, by default, push other content down as it should only expand its height. ![Expanding cards](/images/components/card/card-expanding-cards-227-1015-0.webp) ### Clear indicators The affordance of an expandable card will become stronger to the user if an indicator, such as a chevron, is added. ![Clear indicators](/images/components/card/card-clear-indicators-228-7534-0.webp) A. A chevron is most commonly placed in the top right of a card, but the most important part is to be consistent across cards in the same context. ### Alternatives If the content is too long, open up a sheet or navigate to a page instead of expanding the card. ![Alternatives](/images/components/card/card-alternatives-227-1023-0.webp) A bottom sheet can hold more information than an expanded card. ### Scrolling Card content that’s taller than the maximum height of a collapsed card is truncated and doesn’t scroll, but can be displayed by expanding the height of a card. A card can expand beyond the maximum height of the screen, in which case the card scrolls within the screen. ![Scrolling – 1](/images/components/card/card-scrolling-234-1200-0.webp) > **Do:** On a mobile device, cards can expand to reveal more content, scrolling within the screen. Content within cards doesn’t scroll. ![Scrolling – 2](/images/components/card/card-scrolling-234-1200-1.webp) > **Don't:** On a mobile device, cards can't internally scroll, as it could cause two scroll bars to be displayed. ### Scrolling on desktop On a desktop device, card content can expand and scroll within a card. ![Scrolling on desktop](/images/components/card/card-scrolling-on-desktop-227-1031-0.webp) On a desktop, scrolling within an expanded card is an alternative to forcing the content of a grid to reflow. --- # Readme / API # Card The `Card` component provides a flexible container for organizing and displaying content. It is built using TypeScript, powered by Base UI's `useRender` hook, and styled using `class-variance-authority`. Padding is controlled at the `Card` level via the `hasPadding` prop; `CardContent` is a simple content wrapper and does not apply its own padding. ## Importing ```typescript import { Card, CardContent } from '@svenskaspel/ui/react/card'; ``` ## Props The `Card` component accepts all props that a standard HTML `
` element would. It also accepts an optional `render` prop from Base UI's `useRender` hook, which replaces the default `
` with another element (for example a `