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

# Card Styling

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

The Card component supports the following style variants:

| Variant         | Description                                                  | Supported by |
| --------------- | ------------------------------------------------------------ | ------------ |
| `elevated`      | Adds an elevated appearance with a shadow effect             | Aura, Lumo   |
| `outlined`      | Adds a solid border outline to the card                      | Aura, Lumo   |
| `horizontal`    | Places card content horizontally alongside the media element | Aura, Lumo   |
| `stretch-media` | Stretches the media element to fill the card width or height | Aura, Lumo   |
| `cover-media`   | Allows the media element to cover the card’s padding area    | Aura, Lumo   |

**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.OUTLINED);

Card cardElevated = new Card();
cardElevated.addThemeVariants(CardVariant.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.HORIZONTAL);

card.setMedia(new Avatar("Lapland"));
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-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"
    style="background: rgba(0, 0, 0, 0.2)"
  ></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.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(new Div(
        "Lapland is the northern-most region of Finland and an active outdoor destination."));

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

Icon icon = LumoIcon.PHOTO.create();
icon.getStyle().setBackgroundColor("rgba(0, 0, 0, 0.2)");
iconCard.setMedia(icon);

iconCard.setTitle(new Div("Lapland"));
iconCard.setSubtitle(new Div("The Exotic North"));
iconCard.add(new Div(
        "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" style={{ background: 'rgba(0, 0, 0, 0.2)' }} />
  <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"
    style="background: rgba(0, 0, 0, 0.2)"
  ></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.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(new Div(
        "Lapland is the northern-most region of Finland and an active outdoor destination."));

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

Icon icon = LumoIcon.PHOTO.create();
icon.getStyle().setBackgroundColor("rgba(0, 0, 0, 0.2)");
iconCard.setMedia(icon);

iconCard.setTitle(new Div("Lapland"));
iconCard.setSubtitle(new Div("The Exotic North"));
iconCard.add(new Div(
        "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" style={{ background: 'rgba(0, 0, 0, 0.2)' }} />
  <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.OUTLINED,
        CardVariant.ELEVATED,
        CardVariant.HORIZONTAL,
        CardVariant.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 [Component Style Properties](https://vaadin.com/docs/latest/styling/styling-components.md#component-style-properties) for more information on style properties.

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

| Property                             | Supported by |
| ------------------------------------ | ------------ |
| `--vaadin-card-background`           | Aura, Lumo   |
| `--vaadin-card-shadow`               | Aura, Lumo   |
| `--vaadin-card-border-width`         | Aura, Lumo   |
| `--vaadin-card-border-color`         | Aura, Lumo   |
| `--vaadin-card-border-radius`        | Aura, Lumo   |
| `--vaadin-card-padding`              | Aura, Lumo   |
| `--vaadin-card-gap`                  | Aura, Lumo   |
| `--vaadin-card-media-aspect-ratio`   | Aura, Lumo   |
| `--vaadin-card-title-color`          | Aura, Lumo   |
| `--vaadin-card-title-font-size`      | Aura, Lumo   |
| `--vaadin-card-title-font-weight`    | Aura, Lumo   |
| `--vaadin-card-title-line-height`    | Aura, Lumo   |
| `--vaadin-card-subtitle-color`       | Aura, Lumo   |
| `--vaadin-card-subtitle-font-size`   | Aura, Lumo   |
| `--vaadin-card-subtitle-line-height` | Aura, Lumo   |

## <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/latest/styling.md) for more details on how to style components.

> **Important: Not for Shadow DOM**
>
> These selectors should be used in `styles.css` or another stylesheet loaded with the `@StyleSheet` annotation or the `@import` CSS rule. **They do not work in the shadow DOM of Vaadin components**, such as in stylesheets in the `components` sub-folder or loaded with the `@CssImport` annotation’s `themeFor` property.

---

- 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"]`
