Gitea × shadcn/ui Theme
A custom Gitea theme that brings shadcn/ui design tokens, component aesthetics, motion, and dark-mode polish to a self-hosted Gitea instance.
Features
- shadcn/ui design tokens - Neutral palette in the OKLCH color space
- Geist and Geist Mono, self-hosted - The typefaces shadcn ships, applied to the UI, code views, diffs, and the editor. No external requests.
- Light, Dark, and Auto themes - Auto switches on OS preference
- A real motion layer - Enter/exit animations for dropdowns, modals, tooltips, flash messages, spinners, and skeletons, with a
prefers-reduced-motionguard - One unified radius scale - Gitea's native
--border-radiusand every override resolve to the same four-step ramp, so nested surfaces never disagree on a corner - CSS variable bridge - Maps Gitea's ~200 CSS variables to shadcn tokens, written once and shared by all three themes
- No external requests - Fonts and CSS are served entirely from your instance; works air-gapped
- No runtime JS required - Pure CSS, loaded via
<link>tags - PostCSS build -
@importis inlined at build time, so each theme ships as one self-contained file
Quick Start
npm install
npm run build
GITEA_CUSTOM=/etc/gitea/custom ./scripts/deploy.sh
Project Structure
gitea-shadcn-theme/
├── package.json # PostCSS build pipeline
├── postcss.config.js # postcss-import + autoprefixer + cssnano
├── components.json # shadcn config (neutral base, CSS vars)
├── src/
│ ├── _radius.css # Radius scale (mode independent)
│ ├── _tokens-light.css # shadcn color + elevation tokens, light
│ ├── _tokens-dark.css # shadcn color + elevation tokens, dark
│ ├── _bridge.css # Gitea var → shadcn token bridge (single copy)
│ ├── _fonts.css # @font-face + Geist stacks (generated)
│ ├── fonts/ # 11 self-hosted variable woff2 files
│ ├── _fallbacks.css # Reverse bridge, so overrides work under stock themes
│ ├── _motion.css # Keyframes, motion tokens, reduced-motion guard
│ ├── overrides.css # Component-level Gitea DOM styling
│ └── themes/
│ ├── theme-shadcn-light.css # Entry: radius + light tokens + bridge
│ ├── theme-shadcn-dark.css # Entry: radius + dark tokens + bridge
│ └── theme-shadcn-auto.css # Entry: light by default, dark under @media
├── templates/custom/
│ ├── header.tmpl # Injects shadcn-overrides.css (bump ?v= on redeploy)
│ └── footer.tmpl # Keeps Monaco in step with the page theme
├── scripts/
│ ├── build.sh # npm install + build + verify outputs
│ ├── deploy.sh # Copy to $GITEA_CUSTOM
│ ├── copy-fonts.mjs # src/fonts → dist/fonts
│ └── fetch-fonts.mjs # Re-download Geist (rarely needed)
└── dist/ # Built output (gitignored)
├── *.css
└── fonts/ # woff2, deployed beside the CSS
Files prefixed with _ are partials. Only src/themes/*.css and src/overrides.css are build entries.
Installation
1. Build
npm install
npm run build
Produces four self-contained files in dist/:
| File | Purpose |
|---|---|
theme-shadcn-light.css |
Light theme |
theme-shadcn-dark.css |
Dark theme |
theme-shadcn-auto.css |
Auto-switching theme |
shadcn-overrides.css |
Component styling + motion (shared, loaded on every page) |
fonts/*.woff2 |
Geist and Geist Mono, deployed to assets/fonts/ |
2. Deploy
export GITEA_CUSTOM=/etc/gitea/custom
./scripts/deploy.sh
Or manually:
cp dist/*.css "$GITEA_CUSTOM/public/assets/css/"
cp dist/fonts/*.woff2 "$GITEA_CUSTOM/public/assets/fonts/"
cp templates/custom/*.tmpl "$GITEA_CUSTOM/templates/custom/"
css/ and fonts/ must stay siblings - the @font-face rules use url(../fonts/...).
3. Register the themes in app.ini
[ui]
THEMES = gitea-light,gitea-dark,gitea-auto,shadcn-light,shadcn-dark,shadcn-auto
DEFAULT_THEME = shadcn-auto
4. Restart
systemctl restart gitea
Hard-reload the browser afterwards. Bump the ?v= query in templates/custom/header.tmpl every time you redeploy changed CSS - browsers cache it aggressively and Gitea does not fingerprint custom assets.
Development
npm run dev # rebuild themes on change
How It Works
The bridge is written once
Gitea exposes ~200 CSS variables (--color-primary, --color-body, …). src/_bridge.css aliases all of them to shadcn tokens.
It exists in exactly one copy. Because custom properties resolve lazily, redefining the shadcn tokens for dark mode re-resolves the entire bridge automatically - there is no dark variant of it to keep in sync. Derived values mix toward --background (softer, recedes) or --foreground (stronger, advances) rather than toward literal black and white, which is what makes a single set of derivations correct in both modes.
postcss-import inlines the partials at build time, so each theme still ships as one file. Gitea cannot resolve @import at runtime.
@importmust precede every other statement in a CSS file. In the theme entries the imports come before thegitea-theme-meta-infoblock for that reason - postcss-import silently skips any import that does not.
One radius scale
src/_radius.css defines shadcn's four-step ramp, and _bridge.css maps Gitea's own radius variables onto it:
| Token | Value | Used by |
|---|---|---|
--radius-sm |
6px | Labels, menu items, inline code |
--radius-md |
8px | Buttons, inputs - also Gitea's --border-radius |
--radius-lg |
10px | Cards, modals, tables, menus - also --border-radius-medium |
--radius-xl |
14px | Reserved |
This matters more than it sounds. Gitea composes most boxes as a Fomantic attached stack - a .ui.top.attached header above a .ui.attached table - where only the ends of the stack may carry a radius. If a native container and an overridden child disagree on their corner, you get a visible offset double-corner at the joint.
Every boxed component therefore reads its corners from one shared pair of custom properties, --box-radius-top and --box-radius-bottom, and declares border-radius exactly once. .ui.segment, .ui.table, and .ui.attached are all single-class selectors, so when each declared its own border-radius the winner came down to source order - and .ui.segment won, rounding every attached segment on all four corners wherever it sat in the stack. With variables, the "Box corners in an attached stack" section decides the ends outright; it sits after the components it adjusts, since its variable declarations tie with theirs on specificity and win on order.
Position matters as much as the classes: Gitea marks the head of a stack top attached but routinely leaves the closing member a plain .ui.attached, relying on where it sits. The rules match :first-child / :last-child alongside .top / .bottom for that reason - a rendered README is one of the boxes that closes without a bottom class.
Two related cases are handled the same way: a .ui.table that fills a bordered wrapper drops its own border and corners rather than drawing a second box inside the first, and a .file-view.markup (a rendered README) draws no surface at all, because the .ui.attached.segment around it already does.
Typography
Geist and Geist Mono, the typefaces shadcn ships with its starter and docs site. Both are self-hosted - the woff2 files live in src/fonts/, deploy to assets/fonts/, and nothing is ever fetched from Google at page load.
Both families are variable fonts spanning weights 100–900, so each subset is a single file rather than one per weight. Every @font-face keeps its unicode-range, so a browser downloads only the subsets a page actually uses - in practice just latin, about 29 KB and 23 KB. All 11 files together are 172 KB.
src/_fonts.css is generated; edit scripts/fetch-fonts.mjs instead and re-run:
npm run fonts:fetch
That is only needed to adopt a new upstream release. A normal npm run build never touches the network.
_bridge.css points Gitea's own --fonts-proportional and --fonts-monospace at --font-sans / --font-mono. Gitea derives --fonts-regular from --fonts-proportional and applies these throughout, so the UI, code views, diffs, and blame all follow from those two lines.
The editor is deliberately not restyled in CSS. Gitea feeds --fonts-monospace to Monaco, and Monaco measures character widths from its configured font - overriding that with a CSS font-family rule desyncs the metrics and misplaces the cursor.
Every stack names "Geist" first and falls back to the system UI face, so a missing or unreachable font file degrades quietly rather than breaking the layout.
Motion
src/_motion.css is imported into shadcn-overrides.css, so animations apply under every theme.
Gitea's overlays are Fomantic UI, driven by JS-applied .transition.visible / .animating.in classes; tooltips are tippy.js. The keyframes target those states directly. Durations and easing live in tokens (--duration-fast|base|slow, --ease-out-quart|quint) so the whole feel is tunable from one place.
Two known limits, both deliberate:
- Fomantic writes an inline
animation-durationonto.animatingelements, so those selectors need!importantto win. - Fomantic removes elements from the DOM on its own JS timer, so exit animations can be clipped. Exit is applied where the class lifecycle allows it; some overlays only animate on enter. Fixing this properly would mean patching Gitea's JS, which this theme deliberately does not do.
tippy popovers animate on enter only, and there is deliberately no [data-state="hidden"] rule. tippy mounts a popper in the hidden state before flipping it to visible, so a fade-out keyed on that attribute plays at mount time - opacity 1 → 0 on a panel that was never shown. On a tooltip that reads as a blink; on the repo Code panel it was an unmistakable flash of the whole menu just before it opened. No selector distinguishes "hidden because it is closing" from "hidden because it has not opened yet", so exit is left to tippy's own opacity transition, which JS drives at the right moment.
Accordions use a fade-and-slide rather than a height animation: the grid-rows technique needs display: grid and overflow: hidden on the panel, and both break Gitea - display overrides the display: none that keeps collapsed panels shut, and overflow clips the dropdowns inside repo settings accordions.
Everything is suppressed under prefers-reduced-motion: reduce, except spinners, which still need to spin.
Working under stock themes
header.tmpl loads shadcn-overrides.css on every page, whatever theme is active. Under gitea-light or any other stock theme the shadcn tokens do not exist, so src/_fallbacks.css maps them back onto Gitea's own variables - a reverse bridge. Without it the override sheet would square off every corner and, worse, apply outline: none for focus while the replacement ring resolved to nothing.
Those fallbacks live in a @layer. Unlayered styles beat layered ones regardless of source order, so a real shadcn theme wins even though it loads first.
The Monaco editor
footer.tmpl re-themes the Monaco code editor when the OS flips between light and dark mid-session, which only matters under the auto theme.
It reads --is-dark-theme and nothing else. That property is authoritative for all three themes - auto sets it to true inside its @media (prefers-color-scheme: dark) block - so there is no need to consult matchMedia for the value, only for the event. An earlier version forced dark whenever the OS preferred dark regardless of the chosen theme, so anyone on Shadcn Light with a dark OS got a dark editor on a light page.
Browser Support
- Chrome 111+ (March 2023)
- Firefox 113+ (May 2023)
- Safari 16.2+ (Dec 2022)
Requires color-mix() and oklch().
License
MIT