--- description: Customize your site's appearance through creating your own theme components --- # Swizzling In this section, we will introduce how customization of layout is done in Docusaurus. > Déjà vu...? This section is similar to [Styling and Layout](./styling-layout.mdx), but this time, we will customize React components themselves, rather than what they look like. We will talk about a central concept in Docusaurus: **swizzling**, which allows **deeper site customizations**. In practice, swizzling permits to **swap a theme component with your own implementation**, and it comes in 2 patterns: - [**Ejecting**](#ejecting): creates a **copy** of the original theme component, which you can fully **customize** - [**Wrapping**](#wrapping): creates a **wrapper** around the original theme component, which you can **enhance**
Why is it called swizzling? **The name comes from Objective-C and Swift-UI**: [method swizzling](https://pspdfkit.com/blog/2019/swizzling-in-swift/) is the process of changing the implementation of an existing selector (method). **For Docusaurus, component swizzling means providing an alternative component that takes precedence over the component provided by the theme.** You can think of it as [Monkey Patching](https://en.wikipedia.org/wiki/Monkey_patch) for React components, enabling you to override the default implementation. Gatsby has a similar concept called [theme shadowing](https://www.gatsbyjs.com/docs/how-to/plugins-and-themes/shadowing/). To gain a deeper understanding of this, you have to understand [how theme components are resolved](./advanced/client.mdx#theme-aliases).
## Swizzling Process ### Overview Docusaurus provides a convenient **interactive CLI** to swizzle components. You generally only need to remember the following command: ```bash npm2yarn npm run swizzle ``` It will generate a new component in your `src/theme` directory, which should look like this example: ```mdx-code-block ``` ```jsx title="src/theme/SomeComponent.js" import React from 'react'; export default function SomeComponent(props) { // You can fully customize this implementation // including changing the JSX, CSS and React hooks return (

Some Component

Some component implementation details

); } ``` ```mdx-code-block
``` ```jsx title="src/theme/SomeComponent.js" import React from 'react'; import SomeComponent from '@theme-original/SomeComponent'; export default function SomeComponentWrapper(props) { // You can enhance the original component, // including adding extra props or JSX elements around it return ( <> ); } ``` ```mdx-code-block
``` To get an overview of all the themes and components available to swizzle, run: ```bash npm2yarn npm run swizzle -- --list ``` Use `--help` to see all available CLI options, or refer to the reference [swizzle CLI documentation](./cli.mdx#docusaurus-swizzle). :::note After swizzling a component, **restart your dev server** in order for Docusaurus to know about the new component. ::: :::warning Prefer staying on the safe side Be sure to understand [which components are **safe to swizzle**](#what-is-safe-to-swizzle). Some components are **internal implementation details** of a theme. ::: :::info `docusaurus swizzle` is only an automated way to help you swizzle the component. You can also create the `src/theme/SomeComponent.js` file manually, and Docusaurus will [resolve it](./advanced/client.mdx#theme-aliases). There's no internal magic behind this command! ::: ### Ejecting {#ejecting} Ejecting a theme component is the process of **creating a copy** of the original theme component, which you can **fully customize and override**. To eject a theme component, use the swizzle CLI interactively, or with the `--eject` option: ```bash npm2yarn npm run swizzle [theme name] [component name] -- --eject ``` An example: ```bash npm2yarn npm run swizzle @docusaurus/theme-classic Footer -- --eject ``` This will copy the current `