Theme and Headers API Reference
To get headers with a default theme use hdrs=Theme.<color>.headers(). For example for the blue theme you would use hdrs=Theme.blue.headers(). The theme integrated together different frameworks and allows tailwind, FrankenUI, HighlighJS, and DaisyUI components to work well together.
Tailwind, FrankenUI and DaisyUI are imported by default. You must use DaisyUI headers to use anything in the daisy module, and FrankenUI headers to use anything in the franken module.
HighlightJS is not added by default, but you can add it by setting highlightjs=True in the headers function. The render_md function will use HighlightJS for code blocks.
Theme options are:
Theme.slate
Theme.stone
Theme.gray
Theme.neutral
Theme.red
Theme.rose
Theme.orange
Theme.green
Theme.blue
Theme.yellow
Theme.violet
Theme.zinc
Theme Picker
def ex_theme_switcher():
return ThemePicker()
ThemePicker
SourceThemePicker(color=True, radii=True, shadows=True, font=True, mode=True, cls='p-4', custom_themes=[]) Theme picker component with configurable sections
colorradiishadowsfontmodeclscustom_themes
Custom Themes
- You can use this theme as a starting point.
- Add the theme to your headers as a link like this
Link(rel="stylesheet", href="/custom_theme.css", type="text/css") - Then add the theme to the
ThemePickercomponent. For exampleThemePicker(custom_themes=[('Grass', '#10b981')])
Themes are controlled with bg-background text-foreground classes on the Body tag. fast_app and FastHTML will do this for you automatically so you typically do not have to do anything
fast_app
Sourcefast_app(*args, pico=False, db_file: Optional[str] = None, render: Optional[<built-in function callable>] = None, hdrs: Optional[tuple] = None, ftrs: Optional[tuple] = None, tbls: Optional[dict] = None, before: Union[tuple, NoneType, fasthtml.core.Beforeware] = None, middleware: Optional[tuple] = None, live: bool = False, debug: bool = False, title: str = 'FastHTML page', routes: Optional[tuple] = None, exception_handlers: Optional[dict] = None, on_startup: Optional[<built-in function callable>] = None, on_shutdown: Optional[<built-in function callable>] = None, lifespan: Optional[<built-in function callable>] = None, default_hdrs=True, surreal: Optional[bool] = True, htmx: Optional[bool] = True, exts: Union[list, str, NoneType] = None, canonical: bool = True, secret_key: Optional[str] = None, key_fname: str = '.sesskey', session_cookie: str = 'session_', max_age: int = 31536000, sess_path: str = '/', same_site: str = 'lax', sess_https_only: bool = False, sess_domain: Optional[str] = None, htmlkw: Optional[dict] = None, bodykw: Optional[dict] = None, reload_attempts: Optional[int] = 1, reload_interval: Optional[int] = 1000, static_path: str = '.', body_wrap: <built-in function callable> = <function noop_body at 0x7526eba6fce0>, nb_hdrs: bool = False) Create a FastHTML or FastHTMLWithLiveReload app with
bg-background text-foregroundto bodykw for frankenui themes
db_fileDatabase file name, if neededrenderFunction used to render default database classhdrsAdditional FT elements to add toftrsAdditional FT elements to add to end oftblsExperimental mapping from DB table names to dict table definitionsbeforeFunctions to call prior to calling handlermiddlewareStandard Starlette middlewareliveEnable live reloadingdebugPassed to Starlette, indicating if debug tracebacks should be returned on errorstitleDefault page titleroutesPassed to Starletteexception_handlersPassed to Starletteon_startupPassed to Starletteon_shutdownPassed to StarlettelifespanPassed to Starlettedefault_hdrsInclude default FastHTML headers such as HTMX script?picoInclude PicoCSS header?surrealInclude surreal.js/scope headers?htmxInclude HTMX header?extsHTMX extension names to includecanonicalAutomatically include canonical link?secret_keySigning key for sessionskey_fnameSession cookie signing key file namesession_cookieSession cookie namemax_ageSession cookie expiry timesess_pathSession cookie pathsame_siteSession cookie same site policysess_https_onlySession cookie HTTPS only?sess_domainSession cookie domainhtmlkwAttrs to add to the HTML tagbodykwAttrs to add to the Body tagreload_attemptsNumber of reload attempts when live reloadingreload_intervalTime between reload attempts in msstatic_pathWhere the static file route points to, defaults to root dirbody_wrapFT wrapper for body contentsnb_hdrsIf in notebook include headers inject headers in notebook DOM?args
FastHTML
SourceFastHTML(*args, pico=False, debug=False, routes=None, middleware=None, title: str = 'FastHTML page', exception_handlers=None, on_startup=None, on_shutdown=None, lifespan=None, hdrs=None, ftrs=None, exts=None, before=None, after=None, surreal=True, htmx=True, default_hdrs=True, sess_cls=<class 'starlette.middleware.sessions.SessionMiddleware'>, secret_key=None, session_cookie='session_', max_age=31536000, sess_path='/', same_site='lax', sess_https_only=False, sess_domain=None, key_fname='.sesskey', body_wrap=<function noop_body at 0x7526eba6fce0>, htmlkw=None, nb_hdrs=False, canonical=True) Create a FastHTML app and adds
bg-background text-foregroundto bodykw for frankenui themes
debugroutesmiddlewaretitleexception_handlerson_startupon_shutdownlifespanhdrsftrsextsbeforeaftersurrealhtmxdefault_hdrssess_clssecret_keysession_cookiemax_agesess_pathsame_sitesess_https_onlysess_domainkey_fnamebody_wraphtmlkwnb_hdrscanonicalargspico
Users have said this site is helpful in creating your own themes.