Class CardHeader

  • CardHeader represents the header for a Card in Google Workspace add-ons and Google Chat apps.

  • You can set the title, subtitle, image URL, image style, and image alt text for a CardHeader using its methods.

  • The setImageUrl method accepts either a publicly accessible URL or a base64 encoded image string.

  • Methods like setTitle and setSubtitle are used to define the text content of the header.

CardHeader

The header of a Card .

Available for Google Workspace add-ons and Google Chat apps.

constcardHeader=CardService.newCardHeader()
.setTitle('Card header title')
.setSubtitle('Card header subtitle')
.setImageStyle(CardService.ImageStyle.CIRCLE)
.setImageUrl('https://image.png');

Methods

MethodReturn typeBrief description
setImageAltText(imageAltText) CardHeader Sets the alternative text for the header image.
setImageStyle(imageStyle) CardHeader Sets the cropping of the icon in the card header.
setImageUrl(imageUrl) CardHeader Sets the image to use in the header by providing its URL or data string.
setSubtitle(subtitle) CardHeader Sets the subtitle of the card header.
setTitle(title) CardHeader Sets the title of the card header.

Detailed documentation

setImageAltText(imageAltText)

Sets the alternative text for the header image.

Parameters

NameTypeDescription
imageAltTextStringThe alternative text for the header image.

Return

CardHeader — This object, for chaining.


setImageStyle(imageStyle)

Sets the cropping of the icon in the card header. Defaults to no crop. Optional.

Parameters

NameTypeDescription
imageStyleImageStyle The style setting.

Return

CardHeader — This object, for chaining.


setImageUrl(imageUrl)

Sets the image to use in the header by providing its URL or data string.

The provided URL can either be a publicly accessible URL or a base64 encoded image string. To obtain the latter, you can use the following code to create an encoded image string from an image in your Google Drive, then store that string for later use with setImageUrl(imageUrl) . This method prevents the need for your add-on to access a publicly available image URL:

// The following assumes you have the image to use in Google Drive and have its
// ID.
constimageBytes=DriveApp.getFileById('123abc').getBlob().getBytes();
constencodedImageURL=
`data:image/jpeg;base64,${Utilities.base64Encode(imageBytes)}`;
// You can store encodeImageURL and use it as a parameter to
// CardHeader.setImageUrl(imageUrl).

Parameters

NameTypeDescription
imageUrlStringThe URL address of a hosted image to use, or an encoded image string.

Return

CardHeader — This object, for chaining.


setSubtitle(subtitle)

Sets the subtitle of the card header. Optional.

Parameters

NameTypeDescription
subtitleStringThe header subtitle text.

Return

CardHeader — This object, for chaining.


setTitle(title)

Sets the title of the card header. Required.

Parameters

NameTypeDescription
titleStringThe header text.

Return

CardHeader — This object, for chaining.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年12月03日 UTC.