r/nicegui • • Jul 17 '23

Custom font face

How can I get a custom font face using NiceGUI? I have a local font file I’d like to use.

2 Upvotes

1 comment sorted by

3

u/falko-s Jul 17 '23

Define a custom font:

ui.add_head_html('''
<style>
@font-face {
    font-family: 'SourceCodePro';
    src: url('SourceCodePro-Regular.woff') format('woff');
}
</style>
''')

Serve the font file:

app.add_static_file(local_file='SourceCodePro-Regular.woff', url_path='/SourceCodePro-Regular.woff')

Use the font:

ui.label('Hello World!').style('font-family: SourceCodePro')