Setting multiple features:
// Retrieve font size value from a slider control named "Font Size"
var s = effect("Font Size")("Slider").value;
// Get the existing TextDocument from the Source Text property
var t = text.sourceText;
// Modify the text style by chaining style methods:
// - .setFont("Montserrat-Light") sets the default font.
// - .setFont("Gigantic", 0, 6) applies the "Gigantic" font to characters from index 0 for 6 characters.
// - .setFont("Gigantic", 10, 6) applies it for characters starting at index 10 for 6 characters.
// - .setFont("Gigantic", 20) applies it from index 20 to the end of the text.
// - .setFontSize(s) sets the font size based on the slider value.
// - .setLeading(80, 0, 30) sets the leading (line spacing) to 80 for characters starting at index 0 covering 30 characters.
var newText = t.style
.setFont("Montserrat-Light") // Default font for the text layer
.setFont("Gigantic", 0, 6) // Apply "Gigantic" font to first 6 characters
.setFont("Gigantic", 10, 6) // Apply "Gigantic" font to characters 10 to 15
.setFont("Gigantic", 20) // Apply "Gigantic" font from character 20 onward
.setFontSize(s) // Set the font size from the slider control
.setLeading(80, 0, 30); // Set leading (line spacing) to 80 for characters 0 to 30
newText;
Here are some other settings:
Here are the set of functions available for text styling in After Effects expressions (all used on the style
object):
Function | Purpose |
---|---|
setFont(fontName, [startIndex], [endIndex]) | Set font by PostScript/system name |
setFontSize(size, [startIndex], [endIndex]) | Set font size |
setFauxBold(boolean, [startIndex], [endIndex]) | Enable/disable faux bold |
setFauxItalics(boolean, [startIndex], [endIndex]) | Enable/disable faux italics |
setAllCaps(boolean, [startIndex], [endIndex]) | Enable/disable all caps |
setSmallCaps(boolean, [startIndex], [endIndex]) | Enable/disable small caps |
setTracking(value, [startIndex], [endIndex]) | Set character tracking |
setLeading(value, [startIndex], [endIndex]) | Set line leading |
setAutoLeading(boolean) | Enable/disable auto-leading |
setBaselineShift(value, [startIndex], [endIndex]) | Set baseline shift |
setStrokeWidth(value, [startIndex], [endIndex]) | Set stroke width |
setApplyFill(boolean) | Enable/disable fill |
setFillColor(colorArray, [startIndex], [endIndex]) | Set fill color (RGB array) |
setApplyStroke(boolean) | Enable/disable stroke |
setStrokeColor(colorArray, [startIndex], [endIndex]) | Set stroke color (RGB array) |
setBaselineOption(option, startIndex, endIndex) | Set baseline option (e.g. “superscript”, “subscript”) |
These functions can be chained together to modify multiple style attributes at once—for example:
jsCopy codetext.sourceText.style
.setApplyFill(true)
.setFillColor(hexToRgb("FFFFFF"))
.setBaselineShift(10)
.setTracking(25)
.setAutoLeading(true);
✅ Basic Styling (from Adobe Help)
setFont(fontName, [startIndex], [endIndex])
setFontSize(size, [startIndex], [endIndex])
setFauxBold(boolean, [startIndex], [endIndex])
setFauxItalics(boolean, [startIndex], [endIndex])
setAllCaps(boolean, [startIndex], [endIndex])
setSmallCaps(boolean, [startIndex], [endIndex])
setTracking(value, [startIndex], [endIndex])
setLeading(value, [startIndex], [endIndex])
setAutoLeading(boolean)
setBaselineShift(value, [startIndex], [endIndex])
setStrokeWidth(value, [startIndex], [endIndex])
setApplyFill(boolean)
setFillColor(colorArray, [startIndex], [endIndex])
setApplyStroke(boolean)
setStrokeColor(colorArray, [startIndex], [endIndex])
setText(textValue)
— set the text content via style object
✨ Advanced & Per-Character / Paragraph Styling (new in AE 25+)
These are documented in the expanded Text Style API ae-expressions.docsforadobe.dev+11ae-expressions.docsforadobe.dev+11ae-expressions.docsforadobe.dev+11ae-scripting.docsforadobe.dev+3ae-expressions.docsforadobe.dev+3ae-expressions.docsforadobe.dev+3:
- Per-character styling (accepts optional
startIndex
,endIndex
):setHangingRoman(boolean)
setHorizontalScaling(value)
setJustification(option)
setKerning(value)
setKerningType(type)
setLeadingType(type)
setLeftMargin(value)
setLigature(boolean)
setLineJoin(type)
setRightMargin(value)
setSpaceAfter(value)
setSpaceBefore(value)
setTsume(value)
setVerticalScaling(value)
setDigitSet(option)
setBaselineDirection(option)
setBaselineOption(option)
replaceText(newText, [startIndex], [endIndex])
- Paragraph-specific methods (apply to entire layer):
setDirection(direction)
— e.g. “ltr” or “rtl”setEveryLineComposer(boolean)
setFirstLineIndent(value)
setHangingRoman(boolean)
— also listed abovesetJustification(option)
setLeadingType(type)
setLeftMargin(value)
setRightMargin(value)
setSpaceAfter(value)
setSpaceBefore(value)
These additions provide fine‑grained typographic control—covering spacing, directionality, indentation, margins, kerning, ligatures, line joins, typographic scaling, and even Venetian typographic styles like hanging roman punctuation ae-expressions.docsforadobe.dev+2ae-expressions.docsforadobe.dev+2ae-expressions.docsforadobe.dev+2helpx.adobe.com+2helpx.adobe.com+2motiondeveloper.com+2ae-expressions.docsforadobe.dev.
🧩 Summary Table: All TextStyle set…
Methods
Category | Methods |
---|---|
Basic (font/size/style) | setFont , setFontSize , setFauxBold , setFauxItalics , setAllCaps , setSmallCaps , setAutoLeading , setBaselineShift , setApplyFill , setFillColor , setApplyStroke , setStrokeColor , setStrokeWidth , setText |
Spacing/Tracking | setTracking , setLeading , setKerning , setKerningType , setTsume |
Scaling & Transformation | setHorizontalScaling , setVerticalScaling |
Typography features | setLigature , setLineJoin , setDigitSet |
Paragraph & Direction | setDirection , setBaselineDirection , setBaselineOption , setEveryLineComposer , setJustification , setLeadingType , setHangingRoman , setFirstLineIndent , setLeftMargin , setRightMargin , setSpaceAfter , setSpaceBefore |
Text Replacement | replaceText(newText, [startIndex], [endIndex]) |
Quick Tip:
If you want to retrieve currently used font’s name you can use the following expression:
text.sourceText.style.font