Loading...
Loading...
Customize Rspress themes using CSS variables, Layout slots, component wrapping, or component ejection. Use when a user wants to change the look and feel of an Rspress site, override theme components, add custom navigation/sidebar/footer content, inject global providers, or modify the default Rspress theme in any way. Also use when a user mentions theme/index.tsx, Layout slots, BEM class overrides, or rspress eject.
npx skill4agent add rstackjs/agent-skills rspress-custom-themetheme/index.tsx@rspress/core/*rspress/*| User wants to... | Level | Approach |
|---|---|---|
| Change brand colors, fonts, spacing, shadows | 1 | CSS variables |
| Adjust a specific component's style (borders, padding, etc.) | 2 | BEM class overrides |
| Add content around existing components (banners, footers, logos) | 3 | Layout slots (wrap) |
Override MDX rendering (custom | 3 | |
| Wrap the app in a provider (state, analytics, auth) | 4 | Eject |
| Replace built-in icons (logo, GitHub, search, etc.) | — | Icon re-export |
| Completely replace a built-in component | 4 | Eject that component |
| Add a global floating component (back-to-top, chat widget) | — | |
| Control page layout structure (hide sidebar, blank page) | — | Frontmatter |
theme/index.tsxdocs/project/
├── docs/
├── theme/
│ ├── index.tsx # Theme entry — re-exports + overrides
│ ├── index.css # CSS variable / BEM overrides (optional)
│ └── components/ # Ejected components (Level 4)
└── rspress.config.ts// theme/index.tsx
import './index.css'; // optional
export * from '@rspress/core/theme-original';theme/@rspress/core/theme-original@rspress/core/themetheme/index.tsxdocs/@rspress/core/themetheme/index.csstheme/index.tsx/* theme/index.css */
:root {
--rp-c-brand: #7c3aed;
--rp-c-brand-light: #8b5cf6;
--rp-c-brand-dark: #6d28d9;
}
.dark {
--rp-c-brand: #a78bfa;
}globalStyles// rspress.config.ts
export default defineConfig({
globalStyles: path.join(__dirname, 'styles/custom.css'),
});Full variable list: Readfor all available CSS variables with light/dark defaults.references/css-variables.md
.rp-[component]__[element]--[modifier].rp-nav.rp-link.rp-tabs.rp-codeblock.rp-codeblock__title.rp-nav-menu__item--activeLayouttheme/index.tsx// theme/index.tsx
import { Layout as OriginalLayout } from '@rspress/core/theme-original';
export * from '@rspress/core/theme-original';
export function Layout() {
return (
<OriginalLayout beforeNavTitle={<MyLogo />} bottom={<CustomFooter />} />
);
}@rspress/core/runtimeuseDark()useLang()useVersion()usePage()useSite()useFrontmatter()useI18n()All slots & examples: Readfor the complete slot list and usage patterns including i18n and MDX component overrides.references/layout-slots.md
rspress eject # list available components
rspress eject DocFooter # eject to theme/components/DocFooter/theme/index.tsxexport * from '@rspress/core/theme-original';
export { DocFooter } from './components/DocFooter';Component list & patterns: Readfor available components, workflow, and common patterns.references/eject-components.md
theme/index.tsximport type { FC, SVGProps } from 'react';
type Icon = FC<SVGProps<SVGSVGElement>> | string;// theme/index.tsx
export * from '@rspress/core/theme-original';
// Named export overrides the wildcard — replaces the GitHub icon site-wide
export const IconGithub = (props: React.SVGProps<SVGSVGElement>) => (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" {...props}>
<path d="M12 2C6.477 2 2 6.484 2 12.017c0 ..." fill="currentColor" />
</svg>
);// theme/index.tsx
export * from '@rspress/core/theme-original';
import CustomGithubIcon from './icons/github.svg?react';
export const IconGithub = CustomGithubIcon;SvgWrapperimport { SvgWrapper, IconGithub } from '@rspress/core/theme';
<SvgWrapper icon={IconGithub} width={24} height={24} />IconArrowDownIconArrowRightIconCloseIconCopyIconDeprecatedIconDownIconEditIconEmptyIconExperimentalIconExternalLinkIconFileIconGithubIconGitlabIconHeaderIconJumpIconLinkIconLoadingIconMenuIconMoonIconScrollToTopIconSearchIconSmallMenuIconSuccessIconSunIconTitleIconWrapIconWrappedSource: See the icons source for default implementations.
// rspress.config.ts
export default defineConfig({
globalUIComponents: [
path.join(__dirname, 'components', 'BackToTop.tsx'),
[
path.join(__dirname, 'components', 'Analytics.tsx'),
{ trackingId: '...' },
],
],
});pageType| Value | Description |
|---|---|
| Home page with navbar |
| Standard doc with sidebar and outline |
| Doc without sidebar/outline |
| Custom content with navbar only |
| Custom content without navbar |
| 404 error page |
navbar: falsesidebar: falseoutline: falsefooter: false@rspress/core/theme@rspress/core/theme-originaltheme/export * from '@rspress/core/theme-original'theme/index.tsxrspress/theme@rspress/theme-default@rspress/core/theme-original