This minimal example chooses only the font family for the base text, headings and monospace. These fonts will be sourced, by default, from Google Fonts.
_brand.yml
typography:base: Open Sansheadings: Roboto Slabmonospace: Fira Code
By default, fonts are sourced from Google Fonts, but you can also provide font sources in fonts. Here we’re using a system font for “Open Sans” and Google Fonts for the others.
_brand.yml
typography:fonts:-family: Open Sanssource: systembase: Open Sansheadings: Roboto Slabmonospace: Fira Code
In addition to setting the font family for key elements, you can choose other typographic properties. This example sets the line height and font size for base text, uses the primary accent color for headings and reduces the font size for monospace code, in addition to choosing the font family for each.
Or from Bunny Fonts (a GDPR-compliant) alternative to Google Fonts.
Each font family should be declared in a list item provided to typography.fonts. Local font files can be stored adjacent to the _brand.yml file, and each file for a given family needs to be declared in the files key. Typically these font files cover a specific font weight and style.
A list of font family definitions. Each definition in the list describes a font family that is available to the brand. Fonts may be stored in files (either adjacent to _brand.yml or hosted online) or may be provided by Google Fonts or Font Bunny (a GDPR-compliant Google Fonts alternative).
Create the CSS declarations needed to use the font family.
to_css
typography.BrandTypographyFontSource.to_css()
Create the CSS declarations needed to use the font family.
BrandTypographyFontFiles
typography.BrandTypographyFontFiles()
A font family defined by a collection of font files.
This class represents a font family that is specified using individual font files, either from local files or files hosted online. A font family is generally composed of multiple font files for different weights and styles within the same family. Currently, TrueType (.ttf), OpenType (.otf), and WOFF (.woff or .woff2) formats are supported.
Examples
typography:fonts: # Local font files-family: Open Sansfiles:-path: fonts/open-sans/OpenSans-Bold.ttfstyle: bold-path: fonts/open-sans/OpenSans-Italic.ttfstyle: italic # Online files-family: Closed Sansfiles:-path: https://example.com/Closed-Sans-Bold.woff2weight: bold-path: https://example.com/Closed-Sans-Italic.woff2style: italic
BrandTypographyFontGoogle
typography.BrandTypographyFontGoogle()
A font family provided by Google Fonts.
This class represents a font family that is sourced from Google Fonts. It allows you to specify the font family name, weight range, and style.
In this example, the Inter font is imported with all font weights and both normal and italic styles (these are the defaults). Additionally, the Roboto Slab font is sourced from Google Fonts with three specific font weights – 400, 600, 800 – and only the normal style.
yaml typography: fonts: - family: Inter source: google - family: Roboto Slab source: google weight: [400, 600, 800] style: normal
BrandTypographyFontBunny
typography.BrandTypographyFontBunny()
A font family provided by Bunny Fonts.
This class represents a font family that is sourced from Bunny Fonts. It allows you to specify the font family name, weight range, and style.
A font source that utilizes the Google Fonts (or a compatible) API.
This class provides a way to fetch and manage typography assets from Google Fonts, allowing for easy integration with brand-specific typographic styles.
Represents a range of font weights for Google Fonts.
This class is used to specify a continuous range of font weights to be imported from Google Fonts for variable fonts that support a range of font weights. The weight range is represented as a list of two integers, where the first integer is the start of the range and the second is the end.
Examples
300..700: Represents a range from light (300) to bold (700)
100..900: Represents the full range of weights from thin to black
Note
When serialized, this class will convert the range to a string format (e.g., “300..700”) for compatibility with the Google Fonts API.
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
Args: mode: The mode in which to_python should run. If mode is ‘json’, the output will only contain JSON serializable types. If mode is ‘python’, the output may contain non-JSON-serializable Python objects. include: A set of fields to include in the output. exclude: A set of fields to exclude from the output. context: Additional context to pass to the serializer. by_alias: Whether to use the field’s alias in the dictionary key if defined. exclude_unset: Whether to exclude fields that have not been explicitly set. exclude_defaults: Whether to exclude fields that are set to their default value. exclude_none: Whether to exclude fields that have a value of None. round_trip: If True, dumped values should be valid as input for non-idempotent types such as Json[T]. warnings: How to handle serialization errors. False/“none” ignores them, True/“warn” logs errors, “error” raises a [PydanticSerializationError][pydantic_core.PydanticSerializationError]. serialize_as_any: Whether to serialize fields with duck-typing serialization behavior.
Returns: A dictionary representation of the model.
BrandTypographyBase
typography.BrandTypographyBase()
Typographic settings for base (or body) text.
Notes
In some cases, you may wish to convert the base font size to an appropriate unit, such as rem (i.e. a font size relative to the root element’s font size). Use typography_base_size_unit in pydantic’s serialization context to request the units for the base font size. (Note that currently only "rem" is supported.)
from brand_yml import Brandbrand = Brand.from_yaml_str(f""" typography: base: size: 18px """)brand.typography.model_dump( exclude_none =True, context={"typography_base_size_unit": "rem"})
{'fonts': [], 'base': {'size': '1.125rem'}}
Attributes
family
The font family to be used. Note that the font family name should match a resource in typography.fonts.
weight
The font weight (boldness) of the text.
size
The font size of the text. Should be a CSS length unit (e.g., 14px).
line_height
The line height of the text. Line height refers to the vertical space between lines of text.
BrandTypographyHeadings
typography.BrandTypographyHeadings()
Typographic settings for headings and titles.
Attributes
family
The font family used for headings. Note that this should match a resource in typography.fonts.
weight
The font weight (or boldness) of the text.
style
The font style for the heading, i.e., whether it should be styled in a "normal" or "italic" style.
line_height
The line height of the heading. Line height refers to the vertical space between lines of text.
color
The color of the text.
Examples
This example sets up typography settings for headings using the Inter font at a weight of 600 and with a line height that is 1.2 times the font size.
This class defines typography options for inline monospace text, typically used for code snippets or technical terms within regular text. It inherits properties from brand_yml.typography.BrandTypographyMonospace with additional options for foreground and background colors.
Attributes
family
The font family to be used for inline monospace text. Note that the font family name should match a resource in typography.fonts.
weight
The font weight (boldness) of the inline monospace text. Can be a numeric value between 100 and 900, or a string like “normal” or “bold”.
size
The font size of the inline monospace text. Should be a CSS length unit (e.g., “0.9em”, “14px”).
color
The color of the inline monospace text. Can be any CSS-compatible color definition or a reference to a color defined in the brand’s color palette.
background_color
The background color of the inline monospace text. Can be any CSS-compatible color definition or a reference to a color defined in the brand’s color palette.
Examples
This example sets up typography settings for inline monospace text using the Fira Code font at a slightly smaller size than the base text, with custom colors:
This class defines typography options for block monospace text, typically used for code blocks or other larger sections of monospaced content. It inherits properties from brand_yml.typography.BrandTypographyMonospace and adds options for line height, foreground color, and background color.
Attributes
family
The font family to be used for block monospace text. Note that the font family name should match a resource in typography.fonts.
weight
The font weight (boldness) of the block monospace text. Can be a numeric value between 100 and 900, or a string like “normal” or “bold”.
size
The font size of the block monospace text. Should be a CSS length unit (e.g., “0.9em”, “14px”).
line_height
The line height of the block monospace text. Line height refers to the vertical space between lines of text.
color
The color of the block monospace text. Can be any CSS-compatible color definition or a reference to a color defined in the brand’s color palette.
background_color
The background color of the block monospace text. Can be any CSS-compatible color definition or a reference to a color defined in the brand’s color palette.
Examples
This example sets up typography settings for block monospace text using the Fira Code font at a slightly smaller size than the base text, with custom colors: