VideoModelStudio / docs /gradio /Styling Gradio.md
jbilcke-hf's picture
jbilcke-hf HF Staff
work on new multiprojects UI
b7cc217
  1. Other Tutorials
  2. Theming Guide

[

Styling The Gradio Dataframe

](../guides/styling-the-gradio-dataframe/)[

Understanding Gradio Share Links

](../guides/understanding-gradio-share-links/)

.wrapper { position: relative; padding-bottom: 56.25%; padding-top: 25px; height: 0; } .wrapper iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }

Theming

Introduction

Gradio features a built-in theming engine that lets you customize the look and feel of your app. You can choose from a variety of themes, or create your own. To do so, pass the theme= kwarg to the Blocks or Interface constructor. For example:

with gr.Blocks(theme=gr.themes.Soft()) as demo:
    ...

Gradio comes with a set of prebuilt themes which you can load from gr.themes.*. These are:

  • gr.themes.Base() - the "base" theme sets the primary color to blue but otherwise has minimal styling, making it particularly useful as a base for creating new, custom themes.
  • gr.themes.Default() - the "default" Gradio 5 theme, with a vibrant orange primary color and gray secondary color.
  • gr.themes.Origin() - the "origin" theme is most similar to Gradio 4 styling. Colors, especially in light mode, are more subdued than the Gradio 5 default theme.
  • gr.themes.Citrus() - the "citrus" theme uses a yellow primary color, highlights form elements that are in focus, and includes fun 3D effects when buttons are clicked.
  • gr.themes.Monochrome() - the "monochrome" theme uses a black primary and white secondary color, and uses serif-style fonts, giving the appearance of a black-and-white newspaper.
  • gr.themes.Soft() - the "soft" theme uses a purple primary color and white secondary color. It also increases the border radius around buttons and form elements and highlights labels.
  • gr.themes.Glass() - the "glass" theme has a blue primary color and a transclucent gray secondary color. The theme also uses vertical gradients to create a glassy effect.
  • gr.themes.Ocean() - the "ocean" theme has a blue-green primary color and gray secondary color. The theme also uses horizontal gradients, especially for buttons and some form elements.

Each of these themes set values for hundreds of CSS variables. You can use prebuilt themes as a starting point for your own custom themes, or you can create your own themes from scratch. Let's take a look at each approach.

Using the Theme Builder

The easiest way to build a theme is using the Theme Builder. To launch the Theme Builder locally, run the following code:

import gradio as gr

gr.themes.builder()

Undo Dark Mode

Source Theme Core Colors Core Sizing Core Fonts Body Attributes Element Colors Text Shadows Layout Atoms Component Atoms Buttons

Source Theme Core Colors Core Sizing Core Fonts Body Attributes

Element Colors Text Shadows Layout Atoms Component Atoms Buttons

Select a base theme below you would like to build off of. Note: when you click 'Load Theme', all variable values in other tabs will be overwritten!

Theme

Load Theme

Set the three hues of the theme: primary_hue, secondary_hue, and neutral_hue. Each of these is a palette ranging from 50 to 950 in brightness. Pick a preset palette - optionally, open the accordion to overwrite specific values. Note that these variables do not affect elements directly, but are referenced by other variables with asterisks, such as *primary_200 or *neutral_950.

Primary Hue

Primary Hue Palette ▼

primary_50

primary_100

primary_200

primary_300

primary_400

primary_500

primary_600

primary_700

primary_800

primary_900

primary_950

Secondary Hue

Secondary Hue Palette ▼

secondary_50

secondary_100

secondary_200

secondary_300

secondary_400

secondary_500

secondary_600

secondary_700

secondary_800

secondary_900

secondary_950

Neutral hue

Neutral Hue Palette ▼

neutral_50

neutral_100

neutral_200

neutral_300

neutral_400

neutral_500

neutral_600

neutral_700

neutral_800

neutral_900

neutral_950

Set the sizing of the theme via: text_size, spacing_size, and radius_size. Each of these is set to a collection of sizes ranging from xxs to xxl. Pick a preset size collection - optionally, open the accordion to overwrite specific values. Note that these variables do not affect elements directly, but are referenced by other variables with asterisks, such as *spacing_xl or *text_sm.

Text Size

Text Size Range ▼

text_xxs

text_xs

text_sm

text_md

text_lg

text_xl

text_xxl

Spacing Size

Spacing Size Range ▼

spacing_xxs

spacing_xs

spacing_sm

spacing_md

spacing_lg

spacing_xl

spacing_xxl

Radius Size

Radius Size Range ▼

radius_xxs

radius_xs

radius_sm

radius_md

radius_lg

radius_xl

radius_xxl

Set the main font and the monospace font_mono here. Set up to 4 values for each (fallbacks in case a font is not available). Check "Google Font" if font should be loaded from Google Fonts.

Main Font

Font 1

Google Font

Font 2

Google Font

Font 3

Google Font

Font 4

Google Font

Monospace Font

Font 1

Google Font

Font 2

Google Font

Font 3

Google Font

Font 4

Google Font

These set set the values for the entire body of the app. You can set these to one of the dropdown values, or clear the dropdown to set a custom value.

body_background_fill

The background of the entire app.

body_background_fill_dark

The background of the entire app in dark mode.

body_text_color

The default text color.

body_text_color_dark

The default text color in dark mode.

body_text_size

The default text size.

body_text_color_subdued

The text color used for softer, less important text.

body_text_color_subdued_dark

The text color used for softer, less important text in dark mode.

body_text_weight

The default text weight.

embed_radius

The corner radius used for embedding when the app is embedded within a page.

These set the colors for common elements. You can set these to one of the dropdown values, or clear the dropdown to set a custom value.

background_fill_primary

The background primarily used for items placed directly on the page.

background_fill_primary_dark

The background primarily used for items placed directly on the page in dark mode.

background_fill_secondary

The background primarily used for items placed on top of another item.

background_fill_secondary_dark

The background primarily used for items placed on top of another item in dark mode.

border_color_accent

The border color used for accented items.

border_color_accent_dark

The border color used for accented items in dark mode.

border_color_accent_subdued

The subdued border color for accented items.

border_color_accent_subdued_dark

The subdued border color for accented items in dark mode.

border_color_primary

The border color primarily used for items placed directly on the page.

border_color_primary_dark

The border color primarily used for items placed directly on the page in dark mode.

color_accent

The color used for accented items.

color_accent_soft

The softer color used for accented items.

color_accent_soft_dark

The softer color used for accented items in dark mode.

This sets the text styling for text elements. You can set these to one of the dropdown values, or clear the dropdown to set a custom value.

link_text_color

The text color used for links.

link_text_color_dark

The text color used for links in dark mode.

link_text_color_active

The text color used for links when they are active.

link_text_color_active_dark

The text color used for links when they are active in dark mode.

link_text_color_hover

The text color used for links when they are hovered over.

link_text_color_hover_dark

The text color used for links when they are hovered over in dark mode.

link_text_color_visited

The text color used for links when they have been visited.

link_text_color_visited_dark

The text color used for links when they have been visited in dark mode.

prose_text_size

The text size used for markdown and other prose.

prose_text_weight

The text weight used for markdown and other prose.

prose_header_text_weight

The text weight of a header used for markdown and other prose.

code_background_fill

The background color of code blocks.

code_background_fill_dark

The background color of code blocks in dark mode.

These set the high-level shadow rendering styles. These variables are often referenced by other component-specific shadow variables. You can set these to one of the dropdown values, or clear the dropdown to set a custom value.

shadow_drop

Drop shadow used by other shadowed items.

shadow_drop_lg

Larger drop shadow used by other shadowed items.

shadow_inset

Inset shadow used by other shadowed items.

shadow_spread

Size of shadow spread used by shadowed items.

shadow_spread_dark

Size of shadow spread used by shadowed items in dark mode.

These set the style for common layout elements, such as the blocks that wrap components. You can set these to one of the dropdown values, or clear the dropdown to set a custom value.

block_background_fill

The background around an item.

block_background_fill_dark

The background around an item in dark mode.

block_border_color

The border color around an item.

block_border_color_dark

The border color around an item in dark mode.

block_border_width

The border width around an item.

block_border_width_dark

The border width around an item in dark mode.

block_info_text_color

The color of the info text.

block_info_text_color_dark

The color of the info text in dark mode.

block_info_text_size

The size of the info text.

block_info_text_weight

The weight of the info text.

block_label_background_fill

The background of the title label of a media element (e.g. image).

block_label_background_fill_dark

The background of the title label of a media element (e.g. image) in dark mode.

block_label_border_color

The border color of the title label of a media element (e.g. image).

block_label_border_color_dark

The border color of the title label of a media element (e.g. image) in dark mode.

block_label_border_width

The border width of the title label of a media element (e.g. image).

block_label_border_width_dark

The border width of the title label of a media element (e.g. image) in dark mode.

block_label_shadow

The shadow of the title label of a media element (e.g. image).

block_label_text_color

The text color of the title label of a media element (e.g. image).

block_label_text_color_dark

The text color of the title label of a media element (e.g. image) in dark mode.

block_label_margin

The margin of the title label of a media element (e.g. image) from its surrounding container.

block_label_padding

The padding of the title label of a media element (e.g. image).

block_label_radius

The corner radius of the title label of a media element (e.g. image).

block_label_right_radius

The corner radius of a right-aligned helper label.

block_label_text_size

The text size of the title label of a media element (e.g. image).

block_label_text_weight

The text weight of the title label of a media element (e.g. image).

block_padding

The padding around an item.

block_radius

The corner radius around an item.

block_shadow

The shadow under an item.

block_shadow_dark

The shadow under an item in dark mode.

block_title_background_fill

The background of the title of a form element (e.g. textbox).

block_title_background_fill_dark

The background of the title of a form element (e.g. textbox) in dark mode.

block_title_border_color

The border color of the title of a form element (e.g. textbox).

block_title_border_color_dark

The border color of the title of a form element (e.g. textbox) in dark mode.

block_title_border_width

The border width of the title of a form element (e.g. textbox).

block_title_border_width_dark

The border width of the title of a form element (e.g. textbox) in dark mode.

block_title_text_color

The text color of the title of a form element (e.g. textbox).

block_title_text_color_dark

The text color of the title of a form element (e.g. textbox) in dark mode.

block_title_padding

The padding of the title of a form element (e.g. textbox).

block_title_radius

The corner radius of the title of a form element (e.g. textbox).

block_title_text_size

The text size of the title of a form element (e.g. textbox).

block_title_text_weight

The text weight of the title of a form element (e.g. textbox).

container_radius

The corner radius of a layout component that holds other content.

form_gap_width

The border gap between form elements, (e.g. consecutive textboxes).

layout_gap

The gap between items within a row or column.

panel_background_fill

The background of a panel.

panel_background_fill_dark

The background of a panel in dark mode.

panel_border_color

The border color of a panel.

panel_border_color_dark

The border color of a panel in dark mode.

panel_border_width

The border width of a panel.

panel_border_width_dark

The border width of a panel in dark mode.

section_header_text_size

The text size of a section header (e.g. tab name).

section_header_text_weight

The text weight of a section header (e.g. tab name).

These set the style for elements within components. You can set these to one of the dropdown values, or clear the dropdown to set a custom value.

accordion_text_color

The body text color in the accordion.

accordion_text_color_dark

The body text color in the accordion in dark mode.

table_text_color

The body text color in the table.

table_text_color_dark

The body text color in the table in dark mode.

checkbox_background_color

The background of a checkbox square or radio circle.

chatbot_text_size

The text size of the chatbot text.

checkbox_background_color_dark

The background of a checkbox square or radio circle in dark mode.

checkbox_background_color_focus

The background of a checkbox square or radio circle when focused.

checkbox_background_color_focus_dark

The background of a checkbox square or radio circle when focused in dark mode.

checkbox_background_color_hover

The background of a checkbox square or radio circle when hovered over.

checkbox_background_color_hover_dark

The background of a checkbox square or radio circle when hovered over in dark mode.

checkbox_background_color_selected

The background of a checkbox square or radio circle when selected.

checkbox_background_color_selected_dark

The background of a checkbox square or radio circle when selected in dark mode.

checkbox_border_color

The border color of a checkbox square or radio circle.

checkbox_border_color_dark

The border color of a checkbox square or radio circle in dark mode.

checkbox_border_color_focus

The border color of a checkbox square or radio circle when focused.

checkbox_border_color_focus_dark

The border color of a checkbox square or radio circle when focused in dark mode.

checkbox_border_color_hover

The border color of a checkbox square or radio circle when hovered over.

checkbox_border_color_hover_dark

The border color of a checkbox square or radio circle when hovered over in dark mode.

checkbox_border_color_selected

The border color of a checkbox square or radio circle when selected.

checkbox_border_color_selected_dark

The border color of a checkbox square or radio circle when selected in dark mode.

checkbox_border_radius

The corner radius of a checkbox square.

checkbox_border_width

The border width of a checkbox square or radio circle.

checkbox_border_width_dark

The border width of a checkbox square or radio circle in dark mode.

checkbox_check

The checkmark visual of a checkbox square.

radio_circle

The circle visual of a radio circle.

checkbox_shadow

The shadow of a checkbox square or radio circle.

checkbox_label_background_fill

The background of the surrounding button of a checkbox or radio element.

checkbox_label_background_fill_dark

The background of the surrounding button of a checkbox or radio element in dark mode.

checkbox_label_background_fill_hover

The background of the surrounding button of a checkbox or radio element when hovered over.

checkbox_label_background_fill_hover_dark

The background of the surrounding button of a checkbox or radio element when hovered over in dark mode.

checkbox_label_background_fill_selected

The background of the surrounding button of a checkbox or radio element when selected.

checkbox_label_background_fill_selected_dark

The background of the surrounding button of a checkbox or radio element when selected in dark mode.

checkbox_label_border_color

The border color of the surrounding button of a checkbox or radio element.

checkbox_label_border_color_dark

The border color of the surrounding button of a checkbox or radio element in dark mode.

checkbox_label_border_color_hover

The border color of the surrounding button of a checkbox or radio element when hovered over.

checkbox_label_border_color_hover_dark

The border color of the surrounding button of a checkbox or radio element when hovered over in dark mode.

checkbox_label_border_color_selected

The border color of the surrounding button of a checkbox or radio element when selected.

checkbox_label_border_color_selected_dark

The border color of the surrounding button of a checkbox or radio element when selected in dark mode.

checkbox_label_border_width

The border width of the surrounding button of a checkbox or radio element.

checkbox_label_border_width_dark

The border width of the surrounding button of a checkbox or radio element in dark mode.

checkbox_label_gap

The gap consecutive checkbox or radio elements.

checkbox_label_padding

The padding of the surrounding button of a checkbox or radio element.

checkbox_label_shadow

The shadow of the surrounding button of a checkbox or radio element.

checkbox_label_text_size

The text size of the label accompanying a checkbox or radio element.

checkbox_label_text_weight

The text weight of the label accompanying a checkbox or radio element.

checkbox_label_text_color

The text color of the label accompanying a checkbox or radio element.

checkbox_label_text_color_dark

The text color of the label accompanying a checkbox or radio element in dark mode.

checkbox_label_text_color_selected

The text color of the label accompanying a checkbox or radio element when selected.

checkbox_label_text_color_selected_dark

The text color of the label accompanying a checkbox or radio element when selected in dark mode.

error_background_fill

The background of an error message.

error_background_fill_dark

The background of an error message in dark mode.

error_border_color

The border color of an error message.

error_border_color_dark

The border color of an error message in dark mode.

error_border_width

The border width of an error message.

error_border_width_dark

The border width of an error message in dark mode.

error_text_color

The text color of an error message.

error_text_color_dark

The text color of an error message in dark mode.

error_icon_color

error_icon_color_dark

input_background_fill

The background of an input field.

input_background_fill_dark

The background of an input field in dark mode.

input_background_fill_focus

The background of an input field when focused.

input_background_fill_focus_dark

The background of an input field when focused in dark mode.

input_background_fill_hover

The background of an input field when hovered over.

input_background_fill_hover_dark

The background of an input field when hovered over in dark mode.

input_border_color

The border color of an input field.

input_border_color_dark

The border color of an input field in dark mode.

input_border_color_focus

The border color of an input field when focused.

input_border_color_focus_dark

The border color of an input field when focused in dark mode.

input_border_color_hover

The border color of an input field when hovered over.

input_border_color_hover_dark

The border color of an input field when hovered over in dark mode.

input_border_width

The border width of an input field.

input_border_width_dark

The border width of an input field in dark mode.

input_padding

The padding of an input field.

input_placeholder_color

The placeholder text color of an input field.

input_placeholder_color_dark

The placeholder text color of an input field in dark mode.

input_radius

The corner radius of an input field.

input_shadow

The shadow of an input field.

input_shadow_dark

The shadow of an input field in dark mode.

input_shadow_focus

The shadow of an input field when focused.

input_shadow_focus_dark

The shadow of an input field when focused in dark mode.

input_text_size

The text size of an input field.

input_text_weight

The text weight of an input field.

loader_color

The color of the loading animation while a request is pending.

loader_color_dark

The color of the loading animation while a request is pending in dark mode.

slider_color

The color of the slider in a range element.

slider_color_dark

The color of the slider in a range element in dark mode.

stat_background_fill

The background used for stats visuals (e.g. confidence bars in label).

stat_background_fill_dark

The background used for stats visuals (e.g. confidence bars in label) in dark mode.

table_border_color

The border color of a table.

table_border_color_dark

The border color of a table in dark mode.

table_even_background_fill

The background of even rows in a table.

table_even_background_fill_dark

The background of even rows in a table in dark mode.

table_odd_background_fill

The background of odd rows in a table.

table_odd_background_fill_dark

The background of odd rows in a table in dark mode.

table_radius

The corner radius of a table.

table_row_focus

The background of a focused row in a table.

table_row_focus_dark

The background of a focused row in a table in dark mode.

These set the style for buttons. You can set these to one of the dropdown values, or clear the dropdown to set a custom value.

button_border_width

The border width of a button.

button_border_width_dark

The border width of a button in dark mode.

button_transform_hover

The transform animation of a button on hover.

button_transform_active

The transform animation of a button when pressed.

button_transition

The transition animation duration of a button between regular, hover, and focused states.

button_large_padding

The padding of a button with the default "large" size.

button_large_radius

The corner radius of a button with the default "large" size.

button_large_text_size

The text size of a button with the default "large" size.

button_large_text_weight

The text weight of a button with the default "large" size.

button_small_padding

The padding of a button set to "small" size.

button_small_radius

The corner radius of a button set to "small" size.

button_small_text_size

The text size of a button set to "small" size.

button_small_text_weight

The text weight of a button set to "small" size.

button_medium_padding

The padding of a button set to "medium" size.

button_medium_radius

The corner radius of a button set to "medium" size.

button_medium_text_size

The text size of a button set to "medium" size.

button_medium_text_weight

The text weight of a button set to "medium" size.

button_primary_background_fill

The background of a button of "primary" variant.

button_primary_background_fill_dark

The background of a button of "primary" variant in dark mode.

button_primary_background_fill_hover

The background of a button of "primary" variant when hovered over.

button_primary_background_fill_hover_dark

The background of a button of "primary" variant when hovered over in dark mode.

button_primary_border_color

The border color of a button of "primary" variant.

button_primary_border_color_dark

The border color of a button of "primary" variant in dark mode.

button_primary_border_color_hover

The border color of a button of "primary" variant when hovered over.

button_primary_border_color_hover_dark

The border color of a button of "primary" variant when hovered over in dark mode.

button_primary_text_color

The text color of a button of "primary" variant.

button_primary_text_color_dark

The text color of a button of "primary" variant in dark mode.

button_primary_text_color_hover

The text color of a button of "primary" variant when hovered over.

button_primary_text_color_hover_dark

The text color of a button of "primary" variant when hovered over in dark mode.

button_primary_shadow

The shadow under a primary button.

button_primary_shadow_hover

The shadow under a primary button when hovered over.

button_primary_shadow_active

The shadow under a primary button when pressed.

button_primary_shadow_dark

The shadow under a primary button in dark mode.

button_primary_shadow_hover_dark

The shadow under a primary button when hovered over in dark mode.

button_primary_shadow_active_dark

The shadow under a primary button when pressed in dark mode.

button_secondary_background_fill

The background of a button of default "secondary" variant.

button_secondary_background_fill_dark

The background of a button of default "secondary" variant in dark mode.

button_secondary_background_fill_hover

The background of a button of default "secondary" variant when hovered over.

button_secondary_background_fill_hover_dark

The background of a button of default "secondary" variant when hovered over in dark mode.

button_secondary_border_color

The border color of a button of default "secondary" variant.

button_secondary_border_color_dark

The border color of a button of default "secondary" variant in dark mode.

button_secondary_border_color_hover

The border color of a button of default "secondary" variant when hovered over.

button_secondary_border_color_hover_dark

The border color of a button of default "secondary" variant when hovered over in dark mode.

button_secondary_text_color

The text color of a button of default "secondary" variant.

button_secondary_text_color_dark

The text color of a button of default "secondary" variant in dark mode.

button_secondary_text_color_hover

The text color of a button of default "secondary" variant when hovered over.

button_secondary_text_color_hover_dark

The text color of a button of default "secondary" variant when hovered over in dark mode.

button_secondary_shadow

The shadow under a secondary button.

button_secondary_shadow_hover

The shadow under a secondary button when hovered over.

button_secondary_shadow_active

The shadow under a secondary button when pressed.

button_secondary_shadow_dark

The shadow under a secondary button in dark mode.

button_secondary_shadow_hover_dark

The shadow under a secondary button when hovered over in dark mode.

button_secondary_shadow_active_dark

The shadow under a secondary button when pressed in dark mode.

button_cancel_background_fill

The background of a button of "cancel" variant.

button_cancel_background_fill_dark

The background of a button of "cancel" variant in dark mode.

button_cancel_background_fill_hover

The background of a button of "cancel" variant when hovered over.

button_cancel_background_fill_hover_dark

The background of a button of "cancel" variant when hovered over in dark mode.

button_cancel_border_color

The border color of a button of "cancel" variant.

button_cancel_border_color_dark

The border color of a button of "cancel" variant in dark mode.

button_cancel_border_color_hover

The border color of a button of "cancel" variant when hovered over.

button_cancel_border_color_hover_dark

The border color of a button of "cancel" variant when hovered over in dark mode.

button_cancel_text_color

The text color of a button of "cancel" variant.

button_cancel_text_color_dark

The text color of a button of "cancel" variant in dark mode.

button_cancel_text_color_hover

The text color of a button of "cancel" variant when hovered over.

button_cancel_text_color_hover_dark

The text color of a button of "cancel" variant when hovered over in dark mode.

Theme Builder

Welcome to the theme builder. The left panel is where you create the theme. The different aspects of the theme are broken down into different tabs. Here's how to navigate them:

  1. First, set the "Source Theme". This will set the default values that you can override.
  2. Set the "Core Colors", "Core Sizing" and "Core Fonts". These are the core variables that are used to build the rest of the theme.
  3. The rest of the tabs set specific CSS theme variables. These control finer aspects of the UI. Within these theme variables, you can reference the core variables and other theme variables using the variable name preceded by an asterisk, e.g. *primary_50 or *body_text_color. Clear the dropdown to set a custom value.
  4. Once you have finished your theme, click on "View Code" below to see how you can integrate the theme into your app. You can also click on "Upload to Hub" to upload your theme to the Hugging Face Hub, where others can download and use your theme.

View Code ▼

Code

9

1

2

3

4

5

6

import gradio as gr

theme = gr.themes.Base()

with gr.Blocks(theme=theme) as demo:

...

Upload to Hub ▼

You can save your theme on the Hugging Face Hub. HF API write token can be found here.

Theme Name

Hugging Face Write Token

Version

Upload to Hub

Below this panel is a dummy app to demo your theme.

Name

Full name, including middle name. No special characters.

x

Clear Submit

output

Slider 1

0 100

Slider 2

0 100

Checkbox Group

A B C

Panel 1

Radio

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

A B C

Dropdown

Dropdown

Option A

Go

Image

Go Clear

Button 1 Upload a File Stop

Examples

Radio

Dropdown

Go

A

Option 1

Option B

true

B

Option 2

Option B, Option C

false

Dataframe

Dataframe

1

2

3

1

2

3

1

2

3

1

2

3

4

5

6

7

8

9

JSON

{

"a": 1 ,

"b": 2 ,

"c": {

"test": "a" ,

"test2": [

"0": 1 ,

"1": 2 ,

"2": 3

]

}

}

Label

cat

cat

70%

dog

20%

fish

10%

File

Drop File Here - or - Click to Upload

ColorPicker

Video

0:00 / 0:31

Gallery

lion

lion

logo

logo

tower

tower

Chatbot

.cls-1 { fill: none; }

Hello

Hi

MultimodalTextbox

Add messages

Advanced Settings ▼

Hello

Chatbot control 1

Chatbot control 2

Chatbot control 3

Textbox

[

]

gradio/theme_builder built with Gradio. Hosted on Hugging Face Space Spaces

You can use the Theme Builder running on Spaces above, though it runs much faster when you launch it locally via gr.themes.builder().

As you edit the values in the Theme Builder, the app will preview updates in real time. You can download the code to generate the theme you've created so you can use it in any Gradio app.

In the rest of the guide, we will cover building themes programmatically.

Extending Themes via the Constructor

Although each theme has hundreds of CSS variables, the values for most these variables are drawn from 8 core variables which can be set through the constructor of each prebuilt theme. Modifying these 8 arguments allows you to quickly change the look and feel of your app.

Core Colors

The first 3 constructor arguments set the colors of the theme and are gradio.themes.Color objects. Internally, these Color objects hold brightness values for the palette of a single hue, ranging from 50, 100, 200..., 800, 900, 950. Other CSS variables are derived from these 3 colors.

The 3 color constructor arguments are:

  • primary_hue: This is the color draws attention in your theme. In the default theme, this is set to gradio.themes.colors.orange.
  • secondary_hue: This is the color that is used for secondary elements in your theme. In the default theme, this is set to gradio.themes.colors.blue.
  • neutral_hue: This is the color that is used for text and other neutral elements in your theme. In the default theme, this is set to gradio.themes.colors.gray.

You could modify these values using their string shortcuts, such as

with gr.Blocks(theme=gr.themes.Default(primary_hue="red", secondary_hue="pink")) as demo:
    ...

or you could use the Color objects directly, like this:

with gr.Blocks(theme=gr.themes.Default(primary_hue=gr.themes.colors.red, secondary_hue=gr.themes.colors.pink)) as demo:
    ...

Predefined colors are:

  • slate
  • gray
  • zinc
  • neutral
  • stone
  • red
  • orange
  • amber
  • yellow
  • lime
  • green
  • emerald
  • teal
  • cyan
  • sky
  • blue
  • indigo
  • violet
  • purple
  • fuchsia
  • pink
  • rose

You could also create your own custom Color objects and pass them in.

Core Sizing

The next 3 constructor arguments set the sizing of the theme and are gradio.themes.Size objects. Internally, these Size objects hold pixel size values that range from xxs to xxl. Other CSS variables are derived from these 3 sizes.

  • spacing_size: This sets the padding within and spacing between elements. In the default theme, this is set to gradio.themes.sizes.spacing_md.
  • radius_size: This sets the roundedness of corners of elements. In the default theme, this is set to gradio.themes.sizes.radius_md.
  • text_size: This sets the font size of text. In the default theme, this is set to gradio.themes.sizes.text_md.

You could modify these values using their string shortcuts, such as

with gr.Blocks(theme=gr.themes.Default(spacing_size="sm", radius_size="none")) as demo:
    ...

or you could use the Size objects directly, like this:

with gr.Blocks(theme=gr.themes.Default(spacing_size=gr.themes.sizes.spacing_sm, radius_size=gr.themes.sizes.radius_none)) as demo:
    ...

The predefined size objects are:

  • radius_none
  • radius_sm
  • radius_md
  • radius_lg
  • spacing_sm
  • spacing_md
  • spacing_lg
  • text_sm
  • text_md
  • text_lg

You could also create your own custom Size objects and pass them in.

Core Fonts

The final 2 constructor arguments set the fonts of the theme. You can pass a list of fonts to each of these arguments to specify fallbacks. If you provide a string, it will be loaded as a system font. If you provide a gradio.themes.GoogleFont, the font will be loaded from Google Fonts.

  • font: This sets the primary font of the theme. In the default theme, this is set to gradio.themes.GoogleFont("IBM Plex Sans").
  • font_mono: This sets the monospace font of the theme. In the default theme, this is set to gradio.themes.GoogleFont("IBM Plex Mono").

You could modify these values such as the following:

with gr.Blocks(theme=gr.themes.Default(font=[gr.themes.GoogleFont("Inconsolata"), "Arial", "sans-serif"])) as demo:
    ...

Extending Themes via .set()

You can also modify the values of CSS variables after the theme has been loaded. To do so, use the .set() method of the theme object to get access to the CSS variables. For example:

theme = gr.themes.Default(primary_hue="blue").set(
    loader_color="#FF0000",
    slider_color="#FF0000",
)

with gr.Blocks(theme=theme) as demo:
    ...

In the example above, we've set the loader_color and slider_color variables to #FF0000, despite the overall primary_color using the blue color palette. You can set any CSS variable that is defined in the theme in this manner.

Your IDE type hinting should help you navigate these variables. Since there are so many CSS variables, let's take a look at how these variables are named and organized.

CSS Variable Naming Conventions

CSS variable names can get quite long, like button_primary_background_fill_hover_dark! However they follow a common naming convention that makes it easy to understand what they do and to find the variable you're looking for. Separated by underscores, the variable name is made up of:

  1. The target element, such as button, slider, or block.
  2. The target element type or sub-element, such as button_primary, or block_label.
  3. The property, such as button_primary_background_fill, or block_label_border_width.
  4. Any relevant state, such as button_primary_background_fill_hover.
  5. If the value is different in dark mode, the suffix _dark. For example, input_border_color_focus_dark.

Of course, many CSS variable names are shorter than this, such as table_border_color, or input_shadow.

CSS Variable Organization

Though there are hundreds of CSS variables, they do not all have to have individual values. They draw their values by referencing a set of core variables and referencing each other. This allows us to only have to modify a few variables to change the look and feel of the entire theme, while also getting finer control of individual elements that we may want to modify.

Referencing Core Variables

To reference one of the core constructor variables, precede the variable name with an asterisk. To reference a core color, use the *primary_, *secondary_, or *neutral_ prefix, followed by the brightness value. For example:

theme = gr.themes.Default(primary_hue="blue").set(
    button_primary_background_fill="*primary_200",
    button_primary_background_fill_hover="*primary_300",
)

In the example above, we've set the button_primary_background_fill and button_primary_background_fill_hover variables to *primary_200 and *primary_300. These variables will be set to the 200 and 300 brightness values of the blue primary color palette, respectively.

Similarly, to reference a core size, use the *spacing_, *radius_, or *text_ prefix, followed by the size value. For example:

theme = gr.themes.Default(radius_size="md").set(
    button_primary_border_radius="*radius_xl",
)

In the example above, we've set the button_primary_border_radius variable to *radius_xl. This variable will be set to the xl setting of the medium radius size range.

Referencing Other Variables

Variables can also reference each other. For example, look at the example below:

theme = gr.themes.Default().set(
    button_primary_background_fill="#FF0000",
    button_primary_background_fill_hover="#FF0000",
    button_primary_border="#FF0000",
)

Having to set these values to a common color is a bit tedious. Instead, we can reference the button_primary_background_fill variable in the button_primary_background_fill_hover and button_primary_border variables, using a * prefix.

theme = gr.themes.Default().set(
    button_primary_background_fill="#FF0000",
    button_primary_background_fill_hover="*button_primary_background_fill",
    button_primary_border="*button_primary_background_fill",
)

Now, if we change the button_primary_background_fill variable, the button_primary_background_fill_hover and button_primary_border variables will automatically update as well.

This is particularly useful if you intend to share your theme - it makes it easy to modify the theme without having to change every variable.

Note that dark mode variables automatically reference each other. For example:

theme = gr.themes.Default().set(
    button_primary_background_fill="#FF0000",
    button_primary_background_fill_dark="#AAAAAA",
    button_primary_border="*button_primary_background_fill",
    button_primary_border_dark="*button_primary_background_fill_dark",
)

button_primary_border_dark will draw its value from button_primary_background_fill_dark, because dark mode always draw from the dark version of the variable.

Creating a Full Theme

Let's say you want to create a theme from scratch! We'll go through it step by step - you can also see the source of prebuilt themes in the gradio source repo for reference - here's the source for the Monochrome theme.

Our new theme class will inherit from gradio.themes.Base, a theme that sets a lot of convenient defaults. Let's make a simple demo that creates a dummy theme called Seafoam, and make a simple app that uses it.

import gradio as gr
from gradio.themes.base import Base
import time

class Seafoam(Base):
    pass

seafoam = Seafoam()

with gr.Blocks(theme=seafoam) as demo:
    textbox = gr.Textbox(label="Name")
    slider = gr.Slider(label="Count", minimum=0, maximum=100, step=1)
    with gr.Row():
        button = gr.Button("Submit", variant="primary")
        clear = gr.Button("Clear")
    output = gr.Textbox(label="Output")

    def repeat(name, count):
        time.sleep(3)
        return name * count

    button.click(repeat, [textbox, slider], output)

demo.launch()

The Base theme is very barebones, and uses gr.themes.Blue as it primary color - you'll note the primary button and the loading animation are both blue as a result. Let's change the defaults core arguments of our app. We'll overwrite the constructor and pass new defaults for the core constructor arguments.

We'll use gr.themes.Emerald as our primary color, and set secondary and neutral hues to gr.themes.Blue. We'll make our text larger using text_lg. We'll use Quicksand as our default font, loaded from Google Fonts.

from __future__ import annotations
from typing import Iterable
import gradio as gr
from gradio.themes.base import Base
from gradio.themes.utils import colors, fonts, sizes
import time

class Seafoam(Base):
    def __init__(
        self,
        *,
        primary_hue: colors.Color | str = colors.emerald,
        secondary_hue: colors.Color | str = colors.blue,
        neutral_hue: colors.Color | str = colors.gray,
        spacing_size: sizes.Size | str = sizes.spacing_md,
        radius_size: sizes.Size | str = sizes.radius_md,
        text_size: sizes.Size | str = sizes.text_lg,
        font: fonts.Font
        | str
        | Iterable[fonts.Font | str] = (
            fonts.GoogleFont("Quicksand"),
            "ui-sans-serif",
            "sans-serif",
        ),
        font_mono: fonts.Font
        | str
        | Iterable[fonts.Font | str] = (
            fonts.GoogleFont("IBM Plex Mono"),
            "ui-monospace",
            "monospace",
        ),
    ):
        super().__init__(
            primary_hue=primary_hue,
            secondary_hue=secondary_hue,
            neutral_hue=neutral_hue,
            spacing_size=spacing_size,
            radius_size=radius_size,
            text_size=text_size,
            font=font,
            font_mono=font_mono,
        )

seafoam = Seafoam()

with gr.Blocks(theme=seafoam) as demo:
    textbox = gr.Textbox(label="Name")
    slider = gr.Slider(label="Count", minimum=0, maximum=100, step=1)
    with gr.Row():
        button = gr.Button("Submit", variant="primary")
        clear = gr.Button("Clear")
    output = gr.Textbox(label="Output")

    def repeat(name, count):
        time.sleep(3)
        return name * count

    button.click(repeat, [textbox, slider], output)

demo.launch()

See how the primary button and the loading animation are now green? These CSS variables are tied to the primary_hue variable.

Let's modify the theme a bit more directly. We'll call the set() method to overwrite CSS variable values explicitly. We can use any CSS logic, and reference our core constructor arguments using the * prefix.

from __future__ import annotations
from typing import Iterable
import gradio as gr
from gradio.themes.base import Base
from gradio.themes.utils import colors, fonts, sizes
import time

class Seafoam(Base):
    def __init__(
        self,
        *,
        primary_hue: colors.Color | str = colors.emerald,
        secondary_hue: colors.Color | str = colors.blue,
        neutral_hue: colors.Color | str = colors.blue,
        spacing_size: sizes.Size | str = sizes.spacing_md,
        radius_size: sizes.Size | str = sizes.radius_md,
        text_size: sizes.Size | str = sizes.text_lg,
        font: fonts.Font
        | str
        | Iterable[fonts.Font | str] = (
            fonts.GoogleFont("Quicksand"),
            "ui-sans-serif",
            "sans-serif",
        ),
        font_mono: fonts.Font
        | str
        | Iterable[fonts.Font | str] = (
            fonts.GoogleFont("IBM Plex Mono"),
            "ui-monospace",
            "monospace",
        ),
    ):
        super().__init__(
            primary_hue=primary_hue,
            secondary_hue=secondary_hue,
            neutral_hue=neutral_hue,
            spacing_size=spacing_size,
            radius_size=radius_size,
            text_size=text_size,
            font=font,
            font_mono=font_mono,
        )
        super().set(
            body_background_fill="repeating-linear-gradient(45deg, *primary_200, *primary_200 10px, *primary_50 10px, *primary_50 20px)",
            body_background_fill_dark="repeating-linear-gradient(45deg, *primary_800, *primary_800 10px, *primary_900 10px, *primary_900 20px)",
            button_primary_background_fill="linear-gradient(90deg, *primary_300, *secondary_400)",
            button_primary_background_fill_hover="linear-gradient(90deg, *primary_200, *secondary_300)",
            button_primary_text_color="white",
            button_primary_background_fill_dark="linear-gradient(90deg, *primary_600, *secondary_800)",
            slider_color="*secondary_300",
            slider_color_dark="*secondary_600",
            block_title_text_weight="600",
            block_border_width="3px",
            block_shadow="*shadow_drop_lg",
            button_primary_shadow="*shadow_drop_lg",
            button_large_padding="32px",
        )

seafoam = Seafoam()

with gr.Blocks(theme=seafoam) as demo:
    textbox = gr.Textbox(label="Name")
    slider = gr.Slider(label="Count", minimum=0, maximum=100, step=1)
    with gr.Row():
        button = gr.Button("Submit", variant="primary")
        clear = gr.Button("Clear")
    output = gr.Textbox(label="Output")

    def repeat(name, count):
        time.sleep(3)
        return name * count

    button.click(repeat, [textbox, slider], output)

demo.launch()

Look how fun our theme looks now! With just a few variable changes, our theme looks completely different.

You may find it helpful to explore the source code of the other prebuilt themes to see how they modified the base theme. You can also find your browser's Inspector useful to select elements from the UI and see what CSS variables are being used in the styles panel.

Sharing Themes

Once you have created a theme, you can upload it to the HuggingFace Hub to let others view it, use it, and build off of it!

Uploading a Theme

There are two ways to upload a theme, via the theme class instance or the command line. We will cover both of them with the previously created seafoam theme.

  • Via the class instance

Each theme instance has a method called push_to_hub we can use to upload a theme to the HuggingFace hub.

seafoam.push_to_hub(repo_name="seafoam",
                    version="0.0.1",
                    hf_token="<token>")
  • Via the command line

First save the theme to disk

seafoam.dump(filename="seafoam.json")

Then use the upload_theme command:

upload_theme\
"seafoam.json"\
"seafoam"\
--version "0.0.1"\
--hf_token "<token>"

In order to upload a theme, you must have a HuggingFace account and pass your Access Token as the hf_token argument. However, if you log in via the HuggingFace command line (which comes installed with gradio), you can omit the hf_token argument.

The version argument lets you specify a valid semantic version string for your theme. That way your users are able to specify which version of your theme they want to use in their apps. This also lets you publish updates to your theme without worrying about changing how previously created apps look. The version argument is optional. If omitted, the next patch version is automatically applied.

Theme Previews

By calling push_to_hub or upload_theme, the theme assets will be stored in a HuggingFace space.

The theme preview for our seafoam theme is here: seafoam preview.

Discovering Themes

The Theme Gallery shows all the public gradio themes. After publishing your theme, it will automatically show up in the theme gallery after a couple of minutes.

You can sort the themes by the number of likes on the space and from most to least recently created as well as toggling themes between light and dark mode.

Downloading

To use a theme from the hub, use the from_hub method on the ThemeClass and pass it to your app:

my_theme = gr.Theme.from_hub("gradio/seafoam")

with gr.Blocks(theme=my_theme) as demo:
    ....

You can also pass the theme string directly to Blocks or Interface (gr.Blocks(theme="gradio/seafoam"))

You can pin your app to an upstream theme version by using semantic versioning expressions.

For example, the following would ensure the theme we load from the seafoam repo was between versions 0.0.1 and 0.1.0:

with gr.Blocks(theme="gradio/seafoam@>=0.0.1,<0.1.0") as demo:
    ....

Enjoy creating your own themes! If you make one you're proud of, please share it with the world by uploading it to the hub! If you tag us on Twitter we can give your theme a shout out!

[

Styling The Gradio Dataframe

](../guides/styling-the-gradio-dataframe/)[

Understanding Gradio Share Links

](../guides/understanding-gradio-share-links/)