Light Dark System

Card

<p-card> | PCard
Since 1.0 stable

Cards can be used to group related subjects in a container.

A kitten sits patiently between a terracotta pot and decorative grasses. Mittens
This kitten is as cute as he is playful. Bring him home today!
6 weeks old
More Info
<p-card class="card-overview">
  <img
    slot="image"
    src="https://images.unsplash.com/photo-1559209172-0ff8f6d49ff7?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=80"
    alt="A kitten sits patiently between a terracotta pot and decorative grasses."
  />

  <strong>Mittens</strong><br />
  This kitten is as cute as he is playful. Bring him home today!<br />
  <small>6 weeks old</small>

  <div slot="footer">
    <p-button variant="primary" pill>More Info</p-button>
    <p-rating></p-rating>
  </div>
</p-card>

<style>
  .card-overview {
    max-width: 300px;
  }

  .card-overview small {
    color: var(--p-color-neutral-500);
  }

  .card-overview [slot='footer'] {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
</style>
import PButton from 'pure-uikit/dist/react/button';
import PCard from 'pure-uikit/dist/react/card';
import PRating from 'pure-uikit/dist/react/rating';

const css = `
  .card-overview {
    max-width: 300px;
  }

  .card-overview small {
    color: var(--p-color-neutral-500);
  }

  .card-overview [slot="footer"] {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
`;

const App = () => (
  <>
    <PCard className="card-overview">
      <img
        slot="image"
        src="https://images.unsplash.com/photo-1559209172-0ff8f6d49ff7?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=500&q=80"
        alt="A kitten sits patiently between a terracotta pot and decorative grasses."
      />
      <strong>Mittens</strong>
      <br />
      This kitten is as cute as he is playful. Bring him home today!
      <br />
      <small>6 weeks old</small>
      <div slot="footer">
        <PButton variant="primary" pill>
          More Info
        </PButton>
        <PRating></PRating>
      </div>
    </PCard>

    <style>{css}</style>
  </>
);

Examples

Basic Card

Basic cards aren’t very exciting, but they can display any content you want them to.

This is just a basic card. No image, no header, and no footer. Just your content.
<p-card class="card-basic">
  This is just a basic card. No image, no header, and no footer. Just your content.
</p-card>

<style>
  .card-basic {
    max-width: 300px;
  }
</style>
import PCard from 'pure-uikit/dist/react/card';

const css = `
  .card-basic {
    max-width: 300px;
  }
`;

const App = () => (
  <>
    <PCard className="card-basic">
      This is just a basic card. No image, no header, and no footer. Just your content.
    </PCard>

    <style>{css}</style>
  </>
);

Card with Header

Headers can be used to display titles and more.

Header Title
This card has a header. You can put all sorts of things in it!
<p-card class="card-header">
  <div slot="header">
    Header Title
    <p-icon-button name="gear" label="Settings"></p-icon-button>
  </div>

  This card has a header. You can put all sorts of things in it!
</p-card>

<style>
  .card-header {
    max-width: 300px;
  }

  .card-header [slot='header'] {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .card-header h3 {
    margin: 0;
  }

  .card-header p-icon-button {
    font-size: var(--p-font-size-medium);
  }
</style>
import PCard from 'pure-uikit/dist/react/card';
import PIconButton from 'pure-uikit/dist/react/icon-button';

const css = `
  .card-header {
    max-width: 300px;
  }

  .card-header [slot="header"] {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .card-header h3 {
    margin: 0;
  }

  .card-header p-icon-button {
    font-size: var(--p-font-size-medium);
  }
`;

const App = () => (
  <>
    <PCard className="card-header">
      <div slot="header">
        Header Title
        <PIconButton name="gear"></PIconButton>
      </div>
      This card has a header. You can put all sorts of things in it!
    </PCard>

    <style>{css}</style>
  </>
);

Footers can be used to display actions, summaries, or other relevant content.

This card has a footer. You can put all sorts of things in it!
Preview
<p-card class="card-footer">
  This card has a footer. You can put all sorts of things in it!

  <div slot="footer">
    <p-rating></p-rating>
    <p-button variant="primary">Preview</p-button>
  </div>
</p-card>

<style>
  .card-footer {
    max-width: 300px;
  }

  .card-footer [slot='footer'] {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
</style>
import PButton from 'pure-uikit/dist/react/button';
import PCard from 'pure-uikit/dist/react/card';
import PRating from 'pure-uikit/dist/react/rating';

const css = `
  .card-footer {
    max-width: 300px;
  }

  .card-footer [slot="footer"] {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
`;

const App = () => (
  <>
    <PCard className="card-footer">
      This card has a footer. You can put all sorts of things in it!
      <div slot="footer">
        <PRating></PRating>
        <PButton slot="footer" variant="primary">
          Preview
        </PButton>
      </div>
    </PCard>

    <style>{css}</style>
  </>
);

Images

Cards accept an image slot. The image is displayed atop the card and stretches to fit.

A kitten walks towards camera on top of pallet. This is a kitten, but not just any kitten. This kitten likes walking along pallets.
<p-card class="card-image">
  <img
    slot="image"
    src="https://images.unsplash.com/photo-1547191783-94d5f8f6d8b1?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=400&q=80"
    alt="A kitten walks towards camera on top of pallet."
  />
  This is a kitten, but not just any kitten. This kitten likes walking along pallets.
</p-card>

<style>
  .card-image {
    max-width: 300px;
  }
</style>
import PCard from 'pure-uikit/dist/react/card';

const css = `
  .card-image {
    max-width: 300px;
  }
`;

const App = () => (
  <>
    <PCard className="card-image">
      <img
        slot="image"
        src="https://images.unsplash.com/photo-1547191783-94d5f8f6d8b1?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=400&q=80"
        alt="A kitten walks towards camera on top of pallet."
      />
      This is a kitten, but not just any kitten. This kitten likes walking along pallets.
    </PCard>

    <style>{css}</style>
  </>
);

Importing

If you’re using the autoloader or the traditional loader, you can ignore this section. Otherwise, feel free to use any of the following snippets to cherry pick this component.

Script Import Bundler React

To import this component from the CDN using a script tag:

<script type="module" src="https://cdn.jsdelivr.net/npm/pure-uikit@1.3.13/cdn/components/card/card.js"></script>

To import this component from the CDN using a JavaScript import:

import 'https://cdn.jsdelivr.net/npm/pure-uikit@1.3.13/cdn/components/card/card.js';

To import this component using a bundler:

import 'pure-uikit/dist/components/card/card.js';

To import this component as a React component:

import PCard from 'pure-uikit/dist/react/card';

Slots

Name Description
(default) The card’s main content.
header An optional header for the card.
footer An optional footer for the card.
image An optional image to render at the start of the card.

Learn more about using slots.

Custom Properties

Name Description Default
--border-color The card’s border color, including borders that occur inside the card.
--border-radius The border radius for the card’s edges.
--border-width The width of the card’s borders.
--padding The padding to use for the card’s sections.

Learn more about customizing CSS custom properties.

Parts

Name Description
base The component’s base wrapper.
image The container that wraps the card’s image.
header The container that wraps the card’s header.
body The container that wraps the card’s main content.
footer The container that wraps the card’s footer.

Learn more about customizing CSS parts.