> Markdown version of [Styling](https://vaadin.com/docs/v24/components/card/styling). Section index: [llms.txt](https://vaadin.com/docs/v24/components/llms.txt)

# Styling

## <a id="style-variants"></a>Style Variants

The Card component supports the following style variants:

**Lit** — `card-variants.ts`

```html
<vaadin-card card-title="Default">
  <div>This is the default card style.</div>
</vaadin-card>

<vaadin-card card-title="Outlined" theme="outlined">
  <div>Adds a solid outline around the card.</div>
</vaadin-card>

<vaadin-card card-title="Elevated" theme="elevated">
  <div>This variant works better on a shaded background.</div>
</vaadin-card>
```

**Flow** — `CardVariants.java`

```java
Card cardDefault = new Card();

Card cardOutlined = new Card();
cardOutlined.addThemeVariants(CardVariant.LUMO_OUTLINED);        

Card cardElevated = new Card();
cardElevated.addThemeVariants(CardVariant.LUMO_ELEVATED);
```

**React** — `card-variants.tsx`

```tsx
<Card cardTitle="Default">
  <div>This is the default card style.</div>
</Card>

<Card  cardTitle="Outlined" theme="outlined">
  <div>Adds a solid outline around the card.</div>
</Card>

<Card  cardTitle="Elevated" theme="elevated">
  <div>This variant works better on a shaded background.</div>
</Card>
```

### <a id="horizontal"></a>Horizontal

Place all card content on the side of the media element, if provided.

**Lit** — `card-horizontal.ts`

```html
<!-- tag::[] -->
<vaadin-card theme="horizontal">
  <!-- end::[] -->
  <vaadin-avatar slot="media" name="Lapland"></vaadin-avatar>
  <div slot="title">Lapland</div>
  <div slot="subtitle">The Exotic North</div>
  <div>Lapland is the northern-most region of Finland and an active outdoor destination.</div>
</vaadin-card>
```

**Flow** — `CardHorizontal.java`

```java
Card card = new Card();
card.addThemeVariants(CardVariant.LUMO_HORIZONTAL);

card.setMedia(new Avatar("Lapland"));
card.setTitle(new Div("Lapland"));
card.setSubtitle(new Div("The Exotic North"));
card.add("Lapland is the northern-most region of Finland and an active outdoor destination.");
```

**React** — `card-horizontal.tsx`

```tsx
{/* tag::[] */}
<Card theme="horizontal">
  {/* end::[] */}
  <Avatar slot="media" name="Lapland" />
  <div slot="title">Lapland</div>
  <div slot="subtitle">The Exotic North</div>
  <div>Lapland is the northern-most region of Finland and an active outdoor destination.</div>
</Card>
```

### <a id="stretch-media"></a>Stretch Media

Stretches the media element as wide – or tall, if combined with the horizontal variant – as the card, if the media element is an image, video, or an icon.

**Lit** — `card-stretch-media.ts`

```html
<!-- tag::[] -->
<vaadin-card theme="stretch-media">
  <!-- end::[] -->
  <img slot="media" width="100" src="${img}" alt="" />
  <div slot="title">Lapland</div>
  <div slot="subtitle">The Exotic North</div>
  <div>
    Lapland is the northern-most region of Finland and an active outdoor destination.
  </div>
</vaadin-card>

<!-- tag::[] -->
<vaadin-card theme="stretch-media">
  <!-- end::[] -->
  <vaadin-icon
    slot="media"
    icon="lumo:photo"
    class="bg-primary-10 text-primary"
  ></vaadin-icon>
  <div slot="title">Lapland</div>
  <div slot="subtitle">The Exotic North</div>
  <div>
    Lapland is the northern-most region of Finland and an active outdoor destination.
  </div>
</vaadin-card>
```

**Flow** — `CardStretchMedia.java`

```java
// Card with stretched image
Card imageCard = new Card();
imageCard.addThemeVariants(CardVariant.LUMO_STRETCH_MEDIA);

DownloadHandler imageHandler = DownloadHandler.forClassResource(
        getClass(), "/images/lapland.avif", "lapland.avif");
Image image = new Image(imageHandler, "");
imageCard.setMedia(image);

imageCard.setTitle(new Div("Lapland"));
imageCard.setSubtitle(new Div("The Exotic North"));
imageCard.add("Lapland is the northern-most region of Finland and an active outdoor destination.");

// Card with stretched icon
Card iconCard = new Card();
iconCard.addThemeVariants(CardVariant.LUMO_STRETCH_MEDIA);

Icon icon = LumoIcon.PHOTO.create();
icon.getStyle()
        .setColor("var(--lumo-primary-color)")
        .setBackgroundColor("var(--lumo-primary-color-10pct)");
iconCard.setMedia(icon);

iconCard.setTitle(new Div("Lapland"));
iconCard.setSubtitle(new Div("The Exotic North"));
iconCard.add("Lapland is the northern-most region of Finland and an active outdoor destination.");
```

**React** — `card-stretch-media.tsx`

```tsx
{/* tag::[] */}
<Card theme="stretch-media">
  {/* end::[] */}
  <img slot="media" width="200" src={img} alt="" />
  <div slot="title">Lapland</div>
  <div slot="subtitle">The Exotic North</div>
  <div>Lapland is the northern-most region of Finland and an active outdoor destination.</div>
</Card>

{/* tag::[] */}
<Card theme="stretch-media">
  {/* end::[] */}
  <Icon slot="media" icon="lumo:photo" className="bg-primary-10 text-primary" />
  <div slot="title">Lapland</div>
  <div slot="subtitle">The Exotic North</div>
  <div>Lapland is the northern-most region of Finland and an active outdoor destination.</div>
</Card>
```

### <a id="cover-media"></a>Cover Media

Similar to the stretch-media variant, but this variant allows the media element to also cover the padding area of the card. This variant overrides the stretch-media variant.

**Lit** — `card-cover-media.ts`

```html
<!-- tag::[] -->
<vaadin-card theme="cover-media">
  <!-- end::[] -->
  <img slot="media" width="100" src="${img}" alt="" />
  <div slot="title">Lapland</div>
  <div slot="subtitle">The Exotic North</div>
  <div>
    Lapland is the northern-most region of Finland and an active outdoor destination.
  </div>
</vaadin-card>

<!-- tag::[] -->
<vaadin-card theme="cover-media">
  <!-- end::[] -->
  <vaadin-icon
    slot="media"
    icon="lumo:photo"
    class="bg-primary-10 text-primary"
  ></vaadin-icon>
  <div slot="title">Lapland</div>
  <div slot="subtitle">The Exotic North</div>
  <div>
    Lapland is the northern-most region of Finland and an active outdoor destination.
  </div>
</vaadin-card>
```

**Flow** — `CardCoverMedia.java`

```java
// Card with cover image
Card imageCard = new Card();
imageCard.addThemeVariants(CardVariant.LUMO_COVER_MEDIA);

DownloadHandler imageHandler = DownloadHandler.forClassResource(
        getClass(), "/images/lapland.avif", "lapland.avif");
Image image = new Image(imageHandler, "");
imageCard.setMedia(image);

imageCard.setTitle(new Div("Lapland"));
imageCard.setSubtitle(new Div("The Exotic North"));
imageCard.add("Lapland is the northern-most region of Finland and an active outdoor destination.");

// Card with cover icon
Card iconCard = new Card();
iconCard.addThemeVariants(CardVariant.LUMO_COVER_MEDIA);

Icon icon = LumoIcon.PHOTO.create();
icon.getStyle()
        .setColor("var(--lumo-primary-color)")
        .setBackgroundColor("var(--lumo-primary-color-10pct)");
iconCard.setMedia(icon);

iconCard.setTitle(new Div("Lapland"));
iconCard.setSubtitle(new Div("The Exotic North"));
iconCard.add("Lapland is the northern-most region of Finland and an active outdoor destination.");
```

**React** — `card-cover-media.tsx`

```tsx
{/* tag::[] */}
<Card theme="cover-media">
  {/* end::[] */}
  <img slot="media" width="200" src={img} alt="" />
  <div slot="title">Lapland</div>
  <div slot="subtitle">The Exotic North</div>
  <div>Lapland is the northern-most region of Finland and an active outdoor destination.</div>
</Card>

{/* tag::[] */}
<Card theme="cover-media">
  {/* end::[] */}
  <Icon slot="media" icon="lumo:photo" className="bg-primary-10 text-primary" />
  <div slot="title">Lapland</div>
  <div slot="subtitle">The Exotic North</div>
  <div>Lapland is the northern-most region of Finland and an active outdoor destination.</div>
</Card>
```

### <a id="combine-variants"></a>Combine Variants

You can combine all style variants together.

**Lit** — `card-combine-variants.ts`

```html
<!-- tag::[] -->
<vaadin-card theme="outlined elevated horizontal cover-media">
  <!-- end::[] -->
  <img slot="media" width="100" src="${img}" alt="" />
  <div slot="title">Lapland</div>
  <div slot="subtitle">The Exotic North</div>
  <div>Lapland is the northern-most region of Finland and an active outdoor destination.</div>
</vaadin-card>
```

**Flow** — `CardCombineVariants.java`

```java
Card card = new Card();
card.addThemeVariants(
        CardVariant.LUMO_OUTLINED,
        CardVariant.LUMO_ELEVATED,
        CardVariant.LUMO_HORIZONTAL,
        CardVariant.LUMO_COVER_MEDIA
);

DownloadHandler imageHandler = DownloadHandler.forClassResource(
        getClass(), "/images/lapland.avif", "lapland.avif");
Image image = new Image(imageHandler, "");
image.setWidth("200px");
card.setMedia(image);

card.setTitle(new Div("Lapland"));
card.setSubtitle(new Div("The Exotic North"));
card.add(new Div("Lapland is the northern-most region of Finland and an active outdoor destination."));
```

**React** — `card-combine-variants.tsx`

```tsx
{/* tag::[] */}
<Card theme="outlined elevated horizontal cover-media">
  {/* end::[] */}
  <img slot="media" width="200" src={img} alt="" />
  <div slot="title">Lapland</div>
  <div slot="subtitle">The Exotic North</div>
  <div>Lapland is the northern-most region of Finland and an active outdoor destination.</div>
</Card>
```

## <a id="style-properties"></a>Style Properties

The following style properties can be used in CSS stylesheets to customize the appearance of this component.

To apply values to these properties globally in your application UI, place them in a CSS block using the `html {…​}` selector. See [Lumo Style Properties](https://vaadin.com/docs/v24/styling/lumo/lumo-style-properties.md) for more information on style properties.

### <a id="common-properties"></a>Common Properties

| Feature            | Property                           | Default Value                                                                                                   |
| ------------------ | ---------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| Background         | `--vaadin-card-background`         | `--lumo-shade-5pct`                                                                                             |
| Box Shadow         | `--vaadin-card-box-shadow`         | `none`                                                                                                          |
| Border Width       | `--vaadin-card-border-width`       | `0`                                                                                                             |
| Border Color       | `--vaadin-card-border-color`       | `--lumo-contrast-20pct`                                                                                         |
| Border Radius      | `--vaadin-card-border-radius`      | `--lumo-border-radius-l`                                                                                        |
| Padding            | `--vaadin-card-padding`            | `--lumo-space-m`                                                                                                |
| Gap                | `--vaadin-card-gap`                | `--lumo-space-m`                                                                                                |
| Media Aspect Ratio | `--vaadin-card-media-aspect-ratio` | `16/9`, when the `stretch-media` or `cover-media` style variant is used without the `horizontal` style variant. |

## <a id="css-selectors"></a>CSS Selectors

The following CSS selectors can be used in stylesheets to target the various parts and states of the component. See the [Styling documentation](https://vaadin.com/docs/v24/styling.md) for more details on how to style components.

- Root element

  `vaadin-card`

### <a id="parts"></a>Parts

- Media

  `vaadin-card::part(media)`

- Header

  `vaadin-card::part(header)`

- Content

  `vaadin-card::part(content)`

- Footer

  `vaadin-card::part(footer)`

- Title

  `vaadin-card [slot="title"]`

### <a id="style-variants-2"></a>Style Variants

- Outlined

  `vaadin-card[theme~="outlined"]`

- Elevated

  `vaadin-card[theme~="elevated"]`

- Horizontal

  `vaadin-card[theme~="horizontal"]`

- Stretch Media

  `vaadin-card[theme~="stretch-media"]`

- Cover Media

  `vaadin-card[theme~="cover-media"]`
