Introduction

A card is a component with several placeholders, which arranges them in order to build a card:

The way to declare it is as follows:

  • Fluent
  • Declarative

    Card.builder()
        .title(new Text("Cover media"))
        .subtitle(new Text("Subtitle"))
        .content(new Text("Some content, bla, bla, bla"))
        .media(new Image("https://picsum.photos/seed/picsum/200/300"))
        .variants(List.of(CardVariant.coverMedia))
        .build()
copy

  @Title("Title")
  @Subtitle("Subtitle")
  @Media(image="https://picsum.photos/seed/picsum/200/300")
  @Variants({
    CardVariant.coverMedia
  })
  class MyCard implements Card {
  
    @RawContent
    String content = "Some content, bla, bla, bla";
  
  }
copy

or


  @Variants({
    CardVariant.coverMedia
  })
  class MyCard implements Card {
  
    @Title
    Text title = new Text("Title");

    @Subtitle
    Text subtitle = new Text("Subtitle");

    @Media
    String image = "https://picsum.photos/seed/picsum/200/300";
  
    @RawContent
    String content = "Some content, bla, bla, bla";
  
  }
copy

Available properties

This is the list of available properties for a card:

PropertyDescriptionNotes
idid for this component
cssClasseslist of css classescontent of the css attribute
styleinline style attributescontent of the style attribute
titlecontent to be placed in the title slot
subtitlecontent to be placed in the subtitle slot
mediacontent to be placed in the media slot
headercontent to be placed in the header slot
headerPrefixcontent to be placed in the header prefix slot
headerSuffixcontent to be placed in the header suffix slot
contentcontent to be placed in the card
footercontent to be placed in the footer slot

This is the list of available variants for a card:

PropertyDescriptionNotes
outlineddraws a border around the card
elevateddraws a shadow around the card
horizontalputs the media on the left
stretchMediaadjusts the media size
coverMediathe media fits the border of the card

You can see a full explanation of those properties at https://vaadin.com/docs/latest/components/card