CUSTOM CSS & THEMING: 10 REAL-TIME THEME EXAMPLES

Learn how to customize the appearance of Gradio applications using built-in themes (gr.themes) and custom CSS injection for enterprise branding.

⚡ Styling Gradio Apps with Themes & CSS

Gradio provides two primary ways to customize visual styling: Built-in Themes (like gr.themes.Soft, Glass, or Origin) which modify fonts, radiuses, and color palettes easily, and Custom CSS Injection via the css parameter inside gr.Blocks for precise enterprise branding.

Example 1: Applying Built-in Soft Theme (`gr.themes.Soft`)
Applies professional rounded borders and subtle pastel color tones using Gradio's built-in Soft theme engine.
Python (theme_ex1.py)
import gradio as gr

with gr.Blocks(theme=gr.themes.Soft()) as demo:
    gr.Markdown("# Soft Theme Dashboard")
    gr.Textbox(label="Enter Data")
    gr.Button("Submit", variant="primary")

if __name__ == "__main__":
    demo.launch()
🖥️ Live Web UI Visual Output Preview

# Soft Theme Dashboard

Enter Data Box (Soft rounded corners)
Example 2: Custom CSS Injection for Background Coloring
Injects raw CSS stylesheets directly into `gr.Blocks` to alter container backgrounds and typography.
Python (theme_ex2.py)
import gradio as gr

custom_css = """
body { background-color: #f0f4f8; }
.gradio-container { border-radius: 12px; border: 2px solid #3b82f6; }
"""

with gr.Blocks(css=custom_css) as demo:
    gr.Markdown("## Custom Styled Container")
    gr.Textbox(label="Custom Input")

if __name__ == "__main__":
    demo.launch()
🖥️ Live Web UI Visual Output Preview

## Custom Styled Container

Custom Input Field
Example 3: Dark Mode Custom Theme (`gr.themes.Monochrome`)
Utilizes Gradio's built-in Monochrome dark theme for high-contrast developer interfaces.
Python (theme_ex3.py)
import gradio as gr

with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
    gr.Markdown("# Monochrome Developer Console")
    gr.Code("print('Hello World')", language="python")
    gr.Button("Run Script")

if __name__ == "__main__":
    demo.launch()
🖥️ Live Web UI Visual Output Preview

# Monochrome Developer Console

print('Hello World')
Example 4: Custom Button Styling via CSS Classes
Applies custom CSS classes (`elem_classes`) to target specific buttons for specialized color formatting.
Python (theme_ex4.py)
import gradio as gr

css = ".special-btn { background: linear-gradient(90deg, #ff8008, #ffc837) !important; color: white !important; }"

with gr.Blocks(css=css) as demo:
    gr.Markdown("### Custom Gradient Button")
    gr.Button("Launch Rocket 🚀", elem_classes="special-btn")

if __name__ == "__main__":
    demo.launch()
🖥️ Live Web UI Visual Output Preview

### Custom Gradient Button

Example 5: Customizing Font Families & Typography
Overrides default font styling across all Gradio elements by injecting Google Fonts CSS rules.
Python (theme_ex5.py)
import gradio as gr

css = "@import url('https://fonts.googleapis.com/css2?family=Fira+Code&display=swap'); * { font-family: 'Fira Code', monospace !important; }"

with gr.Blocks(css=css) as demo:
    gr.Markdown("### Custom Monospace Typography")
    gr.Textbox(value="Testing custom font styling...", label="Editor")

if __name__ == "__main__":
    demo.launch()
🖥️ Live Web UI Visual Output Preview

### Custom Monospace Typography

Testing custom font styling...
Example 6: Custom Glassmorphism Card Effect
Applies modern frosted glassmorphism styling effects using backdrop filters and semi-transparent backgrounds.
Python (theme_ex6.py)
import gradio as gr

glass_css = """
.glass-box {
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    padding: 20px;
}
"""

with gr.Blocks(css=glass_css) as demo:
    gr.Markdown("

Glassmorphism Panel

Frosted glass aesthetic container.

") if __name__ == "__main__": demo.launch()
🖥️ Live Web UI Visual Output Preview

Glassmorphism Panel

Frosted glass aesthetic container.

Example 7: Customizing Component Border Radiuses & Shadows
Modifies global component border radiuses and adds soft drop shadows using custom theme constructors.
Python (theme_ex7.py)
import gradio as gr

theme = gr.themes.Glass(
    primary_hue="orange",
    secondary_hue="blue",
    radius_size=gr.themes.sizes.radius_lg
)

with gr.Blocks(theme=theme) as demo:
    gr.Markdown("# Glass Theme with Large Radiuses")
    gr.Button("Click Me", variant="primary")

if __name__ == "__main__":
    demo.launch()
🖥️ Live Web UI Visual Output Preview

# Glass Theme with Large Radiuses

Example 8: Hiding Footer Telemetry & Branding Elements
Removes default Gradio footer links and promotional badges using CSS visibility property overrides.
Python (theme_ex8.py)
import gradio as gr

hide_footer_css = "footer { display: none !important; }"

with gr.Blocks(css=hide_footer_css) as demo:
    gr.Markdown("### Clean White-Label Interface")
    gr.Textbox(label="Input Area")

if __name__ == "__main__":
    demo.launch()
🖥️ Live Web UI Visual Output Preview

### Clean White-Label Interface

Input Area
(Default Gradio footer successfully hidden via CSS)
Example 9: Custom Alert Notification Banners
Builds stylized alert boxes with custom icons and left color accent borders using embedded CSS.
Python (theme_ex9.py)
import gradio as gr

alert_css = """
.custom-alert {
    background-color: #eff6ff;
    border-left: 5px solid #2563eb;
    padding: 12px;
    color: #1e40af;
    border-radius: 4px;
}
"""

with gr.Blocks(css=alert_css) as demo:
    gr.Markdown("
Notice: System update scheduled for midnight.
") if __name__ == "__main__": demo.launch()
🖥️ Live Web UI Visual Output Preview
Notice: System update scheduled for midnight.
Example 10: Complete Enterprise Branded Design System
Combines custom fonts, primary color overrides, custom card borders, and hidden footers into a unified theme.
Python (theme_ex10.py)
import gradio as gr

enterprise_css = """
:root { --neutral-50: #f8fafc; }
.gradio-container { border: 1px solid #e2e8f0; box-shadow: 0 10px 25px rgba(0,0,0,0.05); }
button.primary { background-color: #f37626 !important; }
footer { display: none !important; }
"""

with gr.Blocks(css=enterprise_css, theme=gr.themes.Default()) as demo:
    gr.Markdown("

Nikita-Infotech Enterprise Portal

") with gr.Row(): gr.Textbox(label="Client Username") gr.Textbox(label="API Token", type="password") gr.Button("Authenticate Session", variant="primary") if __name__ == "__main__": demo.launch()
🖥️ Live Web UI Visual Output Preview

Nikita-Infotech Enterprise Portal

Client Username
API Token (********)