Styles are attributes in the tts: namespace. They can sit directly on the
text, or in named style elements that the text refers to. The value types
used in the table below, such as <color> and
<length>, are defined in Style values.
Styling elements
| Element | In | Attributes | Content | Meaning |
|---|---|---|---|---|
styling | head | xml | metadata*, initial* (TTML2), style* | Holds the document’s styles. |
style | styling, or region | xml:id, style, condition (TTML2), any tts: attribute | metadata* | A named set of style values. Inside a region it styles that region only and cannot be referred to. |
initial | styling | condition, any tts: attribute | metadata* | TTML2: replaces the initial value of the properties it sets for the whole document. If two set the same property, the later one wins. |
Applying styles
| Method | How |
|---|---|
| Inline | tts: attributes written on the content element itself. |
| Referential | A style="s1 s2" attribute naming style elements by xml:id; each is merged in turn, so a later one overrides an earlier one. |
| Chained | A style element that itself has a style attribute pulls in other styles first. Loops are errors. |
| Nested | style children of a region, which style that region. |
For one element, referenced styles are applied first, then nested ones, and inline
attributes last, so inline values win. Properties marked inherited then pass from
parent to child: body inherits from the region it is shown in, so styles
on a region reach the text that flows into it. A property that is neither set nor
inherited takes its initial value.
Style attributes
Fifty-one attributes in TTML2. The 24 of TTML1 are marked 1; the rest came with TTML2. “Applies to” is TTML2’s list. An inherited attribute written on some other element still passes down to that element’s children.
| Attribute | Values | Initial | Applies to | Inherited | Since |
|---|---|---|---|---|---|
tts:backgroundClip | border, content, padding | border | body, div, image, p, region, span | no | 2 |
tts:backgroundColor | <color> | transparent | body, div, image, p, region, span | no | 1 |
tts:backgroundExtent | <extent>: auto, contain, cover or width and height | auto | body, div, image, p, region, span | no | 2 |
tts:backgroundImage | none or <image> (a URI) | none | body, div, image, p, region, span | no | 2 |
tts:backgroundOrigin | border, content, padding | padding | body, div, image, p, region, span | no | 2 |
tts:backgroundPosition | <position> | 0% 0% | body, div, image, p, region, span | no | 2 |
tts:backgroundRepeat | repeat, repeatX, repeatY, noRepeat | repeat | body, div, image, p, region, span | no | 2 |
tts:border | <border>: thickness, style, colour and radii in any order | none | body, div, image, p, region, span | no | 2 |
tts:bpd | <measure> | auto | body, div, p, span | no | 2 |
tts:color | <color> | chosen by the processor | span | yes | 1 |
tts:direction | ltr, rtl | ltr | p, span | yes | 1 |
tts:disparity | <length> | 0px | region | no | 2 |
tts:display | auto, none, inlineBlock (TTML2) | auto | body, div, image, p, region, span | no | 1 |
tts:displayAlign | before, center, after, justify (TTML2) | before | body, div, p, region | no | 1 |
tts:extent | <extent> | auto | tt, region, image | no | 1 |
tts:fontFamily | <font-families>: comma-separated names and generic names | default | span | yes | 1 |
tts:fontKerning | none, normal | normal | span | yes | 2 |
tts:fontSelectionStrategy | auto, character | auto | span | yes | 2 |
tts:fontShear | <percentage> | 0% | span | yes | 2 |
tts:fontSize | one <length>, or two (width and height) | 1c | span | yes | 1 |
tts:fontStyle | normal, italic, oblique | normal | span | yes | 1 |
tts:fontVariant | <font-variant> | normal | span | yes | 2 |
tts:fontWeight | normal, bold | normal | span | yes | 1 |
tts:ipd | <measure> | auto | body, div, p, span | no | 2 |
tts:letterSpacing | normal or <length> | normal | span | yes | 2 |
tts:lineHeight | normal or <length> | normal | p | yes | 1 |
tts:lineShear | <percentage> | 0% | p | yes | 2 |
tts:luminanceGain | number, 0 or more | 1.0 | region | no | 2 |
tts:opacity | <alpha>: 0.0 to 1.0 | 1.0 | body, div, image, p, region, span | no | 1 |
tts:origin | auto, or two <length> values (x and y) | auto | region | no | 1 |
tts:overflow | visible, hidden | hidden | region | no | 1 |
tts:padding | one to four <length> values | 0px | body, div, image, p, region, span | no | 1 |
tts:position | <position> | top left | region | no | 2 |
tts:ruby | none, container, base, baseContainer, text, textContainer, delimiter | none | span | no | 2 |
tts:rubyAlign | start, center, end, spaceAround, spaceBetween, withBase | center | span with tts:ruby="container" | yes | 2 |
tts:rubyPosition | before, after, outside | outside | span with tts:ruby text or textContainer | yes | 2 |
tts:rubyReserve | none, or both, before, after or outside, optionally with a <length> | none | p | yes | 2 |
tts:shear | <percentage> | 0% | p | yes | 2 |
tts:showBackground | always, whenActive | always | region | no | 1 |
tts:textAlign | left, center, right, start, end, justify (TTML2) | start | p | yes | 1 |
tts:textCombine | none, all | none | span | yes | 2 |
tts:textDecoration | none, or any of underline/noUnderline, lineThrough/noLineThrough, overline/noOverline | none | span | yes, each of the three parts separately | 1 |
tts:textEmphasis | <text-emphasis>: style, colour and position in any order | none | span | yes | 2 |
tts:textOrientation | mixed, sideways, upright | mixed | span | yes | 2 |
tts:textOutline | none, or an optional <color>, a thickness and an optional blur radius | none | span | yes | 1 |
tts:textShadow | none, or one or more <shadow> values separated by commas | none | span | yes | 2 |
tts:unicodeBidi | normal, embed, bidiOverride, isolate (TTML2) | normal | p, span | no | 1 |
tts:visibility | visible, hidden | visible | body, div, image, p, region, span | yes | 1 |
tts:wrapOption | wrap, noWrap | wrap | span | yes | 1 |
tts:writingMode | lrtb, rltb, tbrl, tblr, lr, rl, tb | lrtb | region | no | 1 |
tts:zIndex | auto or a whole number | auto | region | no | 1 |
The TTML2 audio styles tta:gain, tta:pan,
tta:pitch and tta:speak are on
Embedded content.
tts:origin, tts:extent, tts:position and
tts:disparity may also be written on a div or
p, where they create an anonymous region for it (TTML2).
What the less obvious ones do
| Attribute | Meaning |
|---|---|
tts:displayAlign | Where the block of lines sits in the region, along the block direction: at the start (before, the top in horizontal text), the middle, the end, or spread out. |
tts:showBackground | Whether a region’s background is drawn all the time or only while some text is active in it. |
tts:writingMode | The direction of lines and of their progression: lrtb left to right, lines top to bottom (lr is the same); rltb right to left (rl); tbrl vertical, lines right to left (tb); tblr vertical, lines left to right. |
tts:bpd, tts:ipd | The size of an area in the block direction and the inline direction (height and width, in horizontal text). |
tts:disparity | For stereoscopic 3D: the horizontal offset between the left-eye and right-eye images of a region. |
tts:luminanceGain | For high-dynamic-range video: scales the brightness of the region’s content. |
tts:fontShear, tts:lineShear, tts:shear | Slant applied to the glyphs, to each line, or to the whole paragraph block, given as a percentage. |
tts:fontSelectionStrategy | auto picks a font for a run of text; character picks one per character from the family list. |
tts:textCombine | In vertical text, all sets a short run (such as digits) across the line, tate-chū-yoko. |
tts:ruby and the tts:ruby… attributes | Ruby annotation, small text set beside base text, built from nested spans whose roles tts:ruby names. |
Worked example
<styling>
<style xml:id="base" tts:fontFamily="proportionalSansSerif" tts:fontSize="100%" tts:color="white"/>
<style xml:id="boxed" style="base" tts:backgroundColor="#000000c0" tts:textAlign="center"/>
</styling>
…
<p style="boxed" tts:color="yellow">Where are we going?</p>
boxed, which first pulls in
base. Its inline tts:color overrides the white of
base, so the text is yellow on a black box with alpha c0 (192 of 255, about 75%
opaque).