Style and formatting
The library provides several classes to define the style and formatting of shapes. These classes help customize the appearance of shapes, including their colors, borders, text styling, and margins.
FillStyle
- class pptx_shapes.style.FillStyle(color: str = 'transparent', opacity: float = 1.0)
Defines the fill color and opacity for a shape. The FillStyle class allows you to control the internal color of shapes like rectangles, ellipses, and more.
color(str) – the fill color (see supported color formats).opacity(float) – opacity of the fill (number,0-1).
StrokeStyle
- class pptx_shapes.style.StrokeStyle(color: str = 'black', thickness: float = 1.0, opacity: float = 1.0, dash: pptx_shapes.enums.line_dash.LineDash = <LineDash.SOLID: 'solid'>)
Defines the stroke (outline) of a shape, including its color, thickness, opacity, and line style. Use this class to customize the borders of shapes such as lines, rectangles, and ellipses.
color(str) – the stroke color (see supported color formats).thickness(float) – width of the stroke in pt.opacity(float) – opacity of the stroke (number,0-1).dash(LineDash) – stroke dash style, defaultLineDash.SOLID.
FontStyle
- class pptx_shapes.style.FontStyle(size: float = 14, color: str = '#000000', family: str = 'Calibri', align: pptx_shapes.enums.align.Align = <Align.CENTER: 'ctr'>, vertical_align: pptx_shapes.enums.vertical_align.VerticalAlign = <VerticalAlign.CENTER: 'ctr'>)
Defines the font style for text, including size, font family, color, alignment, and vertical alignment. Use this class to customize text appearance inside textboxes and other shape elements.
size(float) – font size in pt.family(str) – font family name (e.g.,"Arial","Calibri").color(str) – font color (see supported color formats).align(Align) – horizontal alignment of text. Default isAlign.CENTER.vertical_align(VerticalAlign) – vertical alignment of text. Default isVerticalAlign.CENTER.
FontFormat
- class pptx_shapes.style.FontFormat(bold: bool = False, italic: bool = False, underline: bool = False, strike: bool = False)
Specifies additional formatting options for text, such as bold, italic, underline, and strikethrough. Can be used alongside FontStyle to control text appearance.
bold(bool) – whether the text is bold, default isFalse.italic(bool) – whether the text is italic, default isFalse.underline(bool) – whether the text is underlined, default isFalse.strike(bool) – whether the text has a strikethrough, default isFalse.
Margin
- class pptx_shapes.style.Margin(left: float = 0.25, right: float = 0.25, top: float = 0.1, bottom: float = 0.1)
Defines internal margins for text container (TextBox). Margins are specified in centimeters.
left(float) – left margin in cm, default is0.25.right(float) – right margin in cm, default is0.25.top(float) – top margin in cm, default is0.1.bottom(float) – bottom margin in cm, default is0.1.
Supported color formats
Colors can be specified using one of the following formats:
- Named colors (case-insensitive):
A set of common color names, such as:
"black","white","red","green","blue","yellow","magenta","cyan"These are interpreted according to standard web color definitions.
- Hexadecimal strings:
Hex color codes are supported in two forms:
3-digit format:
"#f00"(equivalent to"#ff0000", red)6-digit format:
"#00ff00"(green)
Both uppercase and lowercase letters are allowed.
- RGB functional notation:
You may also use the CSS-like syntax:
"rgb(255, 0, 0)"(red)"rgb(0, 128, 255)"(blue-ish)
Values must be integers between 0 and 255.
If a color string is invalid or unsupported, an error will be raised at runtime.