Class TextStyle Stay organized with collections Save and categorize content based on your preferences.
Page Summary
Read methods in this class return
nullif the correspondingTextRangespans multiple text runs with different style values.To accurately query text styles across multiple text runs, use the
TextRange.getRuns()method.Using methods that edit how text fits within a shape will deactivate any autofit settings applied to the text styles.
The
TextStyleclass provides methods to get and set various text formatting properties such as color, font, size, weight, and style options like bold, italic, and underline.You can set or remove links on the text using methods like
setLinkSlide,setLinkUrl, andremoveLink.
The style of text.
Read methods in this class returnnull if the correspondingText spansmultiple text runs, and those runs have different values for the read method being called. Toavoid this, query for text styles using theTexts returned by theText method.
If you use methods that edit how text fits within a shape, any autofit settings applied to thetext styles are deactivated.
Methods
| Method | Return type | Brief description |
|---|---|---|
get | Color|null | Returns the background color of the text, ornull if there are multiple styles on thetext. |
get | Text | Returns the vertical offset of text from its normal position, ornull if there aremultiple styles on the text. |
get | String|null | Returns the font family of the text, ornull if there are multiple styles on the text. |
get | Number|null | Returns the font size of the text in points, ornull if there are multiple styles onthe text. |
get | Integer|null | Returns the font weight of the text, ornull if there are multiple styles on the text. |
get | Color|null | Returns the foreground color of the text, ornull if there are multiple styles on thetext. |
get | Link|null | Returns theLink on the text, ornull if there is no link or if the link is onpart of the text or if there are multiple links. |
has | Boolean|null | Returnstrue if there is link on the text,false if not, ornull if thelink is on part of the text or there are multiple links. |
is | Boolean|null | Returnstrue if the background of the text is transparent,false if not, ornull if there are multiple styles on the text. |
is | Boolean|null | Returnstrue if the text is rendered as bold,false if not, ornull ifthere are multiple styles on the text. |
is | Boolean|null | Returnstrue if the text is italicized,false if not, ornull if thereare multiple styles on the text. |
is | Boolean|null | Returnstrue if the text is in small capital letters,false if not, ornull if there are multiple styles on the text. |
is | Boolean|null | Returnstrue if the text is struck through,false if not, ornull ifthere are multiple styles on the text. |
is | Boolean|null | Returnstrue if the text is underlined,false if not, ornull if thereare multiple styles on the text. |
remove | Text | Removes aLink. |
set | Text | Sets the background color of the text. |
set | Text | Sets the background color of the text to the given RGB values from 0 to 255. |
set | Text | Sets the background color of the text to the given hex color string. |
set | Text | Sets the background color of the text to the givenTheme. |
set | Text | Sets the background color of the text to transparent. |
set | Text | Sets the vertical offset of the text relative to its normal position. |
set | Text | Sets whether the text should be rendered as bold. |
set | Text | Sets the font family of the text . |
set | Text | Sets the font family and weight of the text. |
set | Text | Sets the font size of the text, in points. |
set | Text | Sets the foreground color of the text. |
set | Text | Sets the foreground color of the text to the given RGB values from 0 to 255. |
set | Text | Sets the foreground color of the text to the given hex color string. |
set | Text | Sets the foreground color of the text to the givenTheme. |
set | Text | Sets the whether the text is italicized. |
set | Text | Sets aLink to the givenSlide using the zero-based index of the slide. |
set | Text | Sets aLink to the givenSlide, the link is set by the given slide ID. |
set | Text | Sets aLink to the givenSlide using the relative position of the slide. |
set | Text | Sets aLink to the given non-empty URL string. |
set | Text | Sets whether the text is rendered in small capital letters. |
set | Text | Sets whether the text is struck through. |
set | Text | Sets whether the text is underlined. |
Detailed documentation
getBackgroundColor()
Returns the background color of the text, ornull if there are multiple styles on thetext.
Return
Color|null
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
getBaselineOffset()
Returns the vertical offset of text from its normal position, ornull if there aremultiple styles on the text.
Return
Text
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
getFontFamily()
Returns the font family of the text, ornull if there are multiple styles on the text.
Return
String|null
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
getFontSize()
Returns the font size of the text in points, ornull if there are multiple styles onthe text.
Return
Number|null
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
getFontWeight()
Returns the font weight of the text, ornull if there are multiple styles on the text.
The weight is a multiple of 100 between 100 and 900, inclusive. This range corresponds tothe numerical values described in the CSS 2.1 Specification,section 15.6, withnon-numerical values disallowed. Weights greater than or equal to 700 are considered bold, inwhich caseis returnstrue. The default value is 400("normal").
Return
Integer|null
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
getForegroundColor()
Returns the foreground color of the text, ornull if there are multiple styles on thetext.
Return
Color|null
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
getLink()
Returns theLink on the text, ornull if there is no link or if the link is onpart of the text or if there are multiple links. Callhas to determine whetherthe text has no link.
constshape=SlidesApp.getActivePresentation().getSlides()[0].getShapes()[0];consttextLink=shape.getText().getTextStyle().getLink();if(textLink!=null){Logger.log(`Shape text has a link of type:${textLink.getLinkType()}`);}
Return
Link|null
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
hasLink()
Returnstrue if there is link on the text,false if not, ornull if thelink is on part of the text or there are multiple links.
Links cannot be set on newline characters. Therefore, if theText contains anewline character, this method always returns eithernull orfalse.
Return
Boolean|null
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
isBackgroundTransparent()
Returnstrue if the background of the text is transparent,false if not, ornull if there are multiple styles on the text.
Return
Boolean|null
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
isBold()
Returnstrue if the text is rendered as bold,false if not, ornull ifthere are multiple styles on the text.
Return
Boolean|null
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
isItalic()
Returnstrue if the text is italicized,false if not, ornull if thereare multiple styles on the text.
Return
Boolean|null
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
isSmallCaps()
Returnstrue if the text is in small capital letters,false if not, ornull if there are multiple styles on the text.
Return
Boolean|null
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
isStrikethrough()
Returnstrue if the text is struck through,false if not, ornull ifthere are multiple styles on the text.
Return
Boolean|null
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
isUnderline()
Returnstrue if the text is underlined,false if not, ornull if thereare multiple styles on the text.
Return
Boolean|null
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
removeLink()
Removes aLink.
Removing a link removes the hyperlink foreground color and underline style on the text. Ifpossible, these styles are applied to match the text preceding the link.
consttextRange=SlidesApp.getActivePresentation().getSlides()[0].getShapes()[0].getText();textRange.getTextStyle().removeLink();
Return
setBackgroundColor(color)
setBackgroundColor(red, green, blue)
Sets the background color of the text to the given RGB values from 0 to 255.
Parameters
| Name | Type | Description |
|---|---|---|
red | Integer | |
green | Integer | |
blue | Integer |
Return
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
setBackgroundColor(hexColor)
Sets the background color of the text to the given hex color string.
The hex string must be in the format '#RRGGBB'. For example, pink would be represented as'#FFC0CB'.
Parameters
| Name | Type | Description |
|---|---|---|
hex | String |
Return
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
setBackgroundColor(color)
Sets the background color of the text to the givenTheme.
Parameters
| Name | Type | Description |
|---|---|---|
color | Theme |
Return
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
setBackgroundColorTransparent()
setBaselineOffset(offset)
Sets the vertical offset of the text relative to its normal position.
Parameters
| Name | Type | Description |
|---|---|---|
offset | Text |
Return
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
setBold(bold)
Sets whether the text should be rendered as bold.
Changing the text's boldness updates the font weight used to render the text.
Parameters
| Name | Type | Description |
|---|---|---|
bold | Boolean |
Return
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
setFontFamily(fontFamily)
Sets the font family of the text .
Parameters
| Name | Type | Description |
|---|---|---|
font | String |
Return
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
setFontFamilyAndWeight(fontFamily, fontWeight)
Sets the font family and weight of the text.
The weight is a multiple of 100 between 100 and 900, inclusive. This range corresponds tothe numerical values described in the CSS 2.1 Specification,section 15.6, withnon-numerical values disallowed. Weights greater than or equal to 700 are considered bold, inwhich caseis returnstrue. The default value is 400("normal").
Parameters
| Name | Type | Description |
|---|---|---|
font | String | |
font | Integer |
Return
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
setFontSize(fontSize)
Sets the font size of the text, in points.
Parameters
| Name | Type | Description |
|---|---|---|
font | Number |
Return
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
setForegroundColor(foregroundColor)
setForegroundColor(red, green, blue)
Sets the foreground color of the text to the given RGB values from 0 to 255.
Parameters
| Name | Type | Description |
|---|---|---|
red | Integer | |
green | Integer | |
blue | Integer |
Return
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
setForegroundColor(hexColor)
Sets the foreground color of the text to the given hex color string.
The hex string must be in the format '#RRGGBB'. For example, pink would be represented as'#FFC0CB'.
Parameters
| Name | Type | Description |
|---|---|---|
hex | String |
Return
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
setForegroundColor(color)
Sets the foreground color of the text to the givenTheme.
Parameters
| Name | Type | Description |
|---|---|---|
color | Theme |
Return
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
setItalic(italic)
Sets the whether the text is italicized.
Parameters
| Name | Type | Description |
|---|---|---|
italic | Boolean |
Return
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
setLinkSlide(slideIndex)
Sets aLink to the givenSlide using the zero-based index of the slide.
Setting a link changes the style of the text to be underlined and to have aTheme foreground color. This can be changed viaset andset.
Since links cannot be set on newline characters, newline characters in theTextare ignored.
// Set a link to the first slide of the presentation.constpresentation=SlidesApp.getActivePresentation();constslide=presentation.getSlides()[0];consttextRange=slide.getShapes()[0].getText();textRange.getTextStyle().setLinkSlide(0);
Parameters
| Name | Type | Description |
|---|---|---|
slide | Integer | The zero-based index to the slide. |
Return
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
setLinkSlide(slide)
Sets aLink to the givenSlide, the link is set by the given slide ID.
Setting a link changes the style of the text to be underlined and to have aTheme foreground color. This can be changed viaset andset.
Since links cannot be set on newline characters, newline characters in theTextare ignored.
// Set a link to the first slide of the presentation.constpresentation=SlidesApp.getActivePresentation();constslide=presentation.getSlides()[0];consttextRange=slide.getShapes()[0].getText();textRange.getTextStyle().setLinkSlide(slide);
Parameters
| Name | Type | Description |
|---|---|---|
slide | Slide | TheSlide to be linked. |
Return
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
setLinkSlide(slidePosition)
Sets aLink to the givenSlide using the relative position of the slide.
Setting a link changes the style of the text to be underlined and to have aTheme foreground color. This can be changed viaset andset.
Since links cannot be set on newline characters, newline characters in theTextare ignored.
// Set a link to the first slide of the presentation.consttextRange=SlidesApp.getActivePresentation().getSlides()[0].getShapes()[0].getText();textRange.getTextStyle().setLinkSlide(SlidesApp.SlidePosition.FIRST_SLIDE);
Parameters
| Name | Type | Description |
|---|---|---|
slide | Slide | The relativeSlide. |
Return
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
setLinkUrl(url)
Sets aLink to the given non-empty URL string.
Setting a link changes the style of the text to be underlined and to have aTheme foreground color. This can be changed viaset andset.
Since links cannot be set on newline characters, newline characters in theTextare ignored.
// Set a link to the URL.consttextRange=SlidesApp.getActivePresentation().getSlides()[0].getShapes()[0].getText();textRange.getTextStyle().setLinkUrl('https://slides.google.com');
Parameters
| Name | Type | Description |
|---|---|---|
url | String | The URL string. |
Return
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
setSmallCaps(smallCaps)
Sets whether the text is rendered in small capital letters.
Parameters
| Name | Type | Description |
|---|---|---|
small | Boolean |
Return
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
setStrikethrough(strikethrough)
Sets whether the text is struck through.
Parameters
| Name | Type | Description |
|---|---|---|
strikethrough | Boolean |
Return
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
setUnderline(underline)
Sets whether the text is underlined.
Parameters
| Name | Type | Description |
|---|---|---|
underline | Boolean |
Return
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/presentations.currentonlyhttps://www.googleapis.com/auth/presentations
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-11 UTC.