Skip to content

Text Styling ​

The templating engine provides a set of functions to apply style to a text:

FunctionEffectExample
boldBold{{bold .Text}}
italicItalic{{italic .Text}}
underlineUnderline{{underline .Text}}
strikeStrikethrough{{strike .Text}}
fontSizeFont size in points{{fontSize .Text 14}}
colorText color{{color .Text "FF0000"}}
highlightWord text highlight{{highlight .Text "yellow"}}
shadeTextBgBackground shading behind text{{shadeTextBg .Text "EEEEEE"}}

Color and shading functions accept a six-digit hexadecimal RGB value, with or without a leading #.
For example, "FF0000" or "#FF0000".

While highlight takes a Word highlight color name, such as yellow.

Combine styles ​

Use inlineStyledText to apply multiple styles to one value. Style order is flexible; use the tokens below:

text
{{inlineStyledText .Text "b" "i" "fs:14" "#FF0000" "bg:#C0FFEE"}}
StyleAccepted tokens
Boldb, bold
Italici, italic
Underlineu, underline
Strikethroughs, strike, strikethrough
Font sizefs:<size>, fontSize:<size> (for example, fs:14)
Text colorRRGGBB, #RRGGBB
Background shadingbg:RRGGBB, bg:#RRGGBB
HighlightA Word highlight color name, such as yellow

or you pass the styles as a list with styledText:

text
{{styledText .Text (list "b" "i" "fs:14")}}

list is a built-in helper that constructs the slice of style values.

Dynamic styles

This also enables a go slice to be passed as argument. Example:

{{styledText .Text .Style}}

where .Style contains the style tokens.

json
{
  "Text": "Hello World",
  "Style": ["#F0F0F0", "bg:#FF0000", "b", "i", "u", "s", "fs:20"]
}

Preserve line breaks ​

For values containing newline characters, choose how those newlines should appear in Word:

  • {{preserveNewline .Text}} turns newlines into line breaks within the same paragraph (Shift+Enter).
  • {{breakParagraph .Text}} turns newlines into separate paragraphs (Enter).

For the complete function reference, see Built-in functions.