# Match FusionAuth Themes to a React Application

Learn how to make the FusionAuth hosted login pages match a React application.

> For the index of this section of the site, see [llms.txt](https://fusionauth.io/docs/llms.txt)

When your application uses React, including server-side rendering frameworks such as Next.js, you can style the [hosted login pages](https://fusionauth.io/docs/concepts/integration-points.md#hosted-login-pages) to match the application. FusionAuth renders the hosted login pages from the FreeMarker templates in an [advanced theme](https://fusionauth.io/docs/theme/advanced-themes.md). A theme holds templates, a stylesheet, and messages, so React components don't run in a theme.

You have the following options:

*   Share the application's styles and markup with an advanced theme. The hosted login pages keep every FusionAuth login flow, such as multi-factor authentication, passkeys, and federated login.
*   Build the login pages in React with the Login API. Your application then builds the user interface for every login flow.

## Share Your Application's Styles

Before you start, you need the following:

*   An advanced theme. For more information, see [Create a Theme](https://fusionauth.io/docs/theme/advanced-themes.md#create-a-theme).
*   An API key with `GET` and `PATCH` permissions for `/api/theme/`.
*   Node.js and the [FusionAuth CLI](https://github.com/FusionAuth/fusionauth-node-cli).

To share the styles:

1.  Download the theme with the FusionAuth CLI. Replace `<themeId>` and `<apiKey>` with the Id of the theme and the API key:
    
    ```shell-session
    $ npx fusionauth theme:download <themeId> -k <apiKey> -h http://localhost:9011
    ```
    
    The CLI writes the templates to `.ftl` files in the `tpl` directory, and the stylesheet to `tpl/stylesheet.css`.
    
2.  Add the application's CSS to the theme. Choose one of the following methods:
    
    *   Configure the React build to write the application's global CSS to `tpl/stylesheet.css`. FusionAuth includes the stylesheet in every hosted login page.
        
    *   Link to the stylesheet that the application already serves. Add a `link` tag to the `head` macro in `tpl/helpers.ftl`. The hosted login pages then pick up style changes without a theme upload, but the pages depend on the application's host.
        
        ```html
        <link rel="stylesheet" href="https://app.example.com/styles.css"/>
        ```
        
    
    Class names that a build generates, such as CSS Modules hashes, change between builds. In the templates, use global class names and CSS custom properties.
    
3.  Copy the markup of the application's layout into the templates. To get the HTML that a React component renders, view the source of a rendered page, or render the component with `renderToStaticMarkup` from `react-dom/server`. Put shared elements, such as the header and footer, in the `header` and `footer` macros in `tpl/helpers.ftl`.
    
    Keep the `form` tags and the FreeMarker macros, such as `[@helpers.oauthHiddenFields/]` and `[@helpers.input]`. The forms post the hidden fields that FusionAuth needs to complete the login. For more information, see [Themes Helper Macros](https://fusionauth.io/docs/theme/advanced-themes/helpers.md).
    
4.  When the default FusionAuth styles conflict with the application's styles, remove the `fusionauth-hosted.css` `link` tag from the `head` macro in `tpl/helpers.ftl`.
    
5.  Upload the theme:
    
    ```shell-session
    $ npx fusionauth theme:upload <themeId> -k <apiKey> -h http://localhost:9011
    ```
    
    During development, run `theme:watch` with the same options instead. The CLI then uploads each change to a file in the `tpl` directory.
    
6.  Navigate to Customization -> Themes , choose the theme, and click view to preview the hosted login pages.
    

When the application uses Tailwind CSS, the build can scan the templates for class names. For more information, see [Tailwind CSS](https://fusionauth.io/docs/theme/advanced-themes/tailwind.md).

## Build the Login Pages in React

When the login pages must use the application's React components, skip the hosted login pages and call the Login API from the application. The application then receives the user's credentials and must protect the credentials. The application also needs a user interface for each login flow that the hosted login pages would handle, such as multi-factor authentication, passkeys, and federated login. For more information, see [Build a Login Page with the Login API](https://fusionauth.io/docs/authentication/login-api.md).

Related

[Theme Advanced Themes Learn how to theme and the FusionAuth login pages (including forgot password, two-factor authentication and others). freemarkercss customization](https://fusionauth.io/docs/theme/advanced-themes.md)

[Theme Style FusionAuth Themes with Tailwind CSS Learn how to style the FusionAuth hosted login pages with Tailwind CSS. login page stylingadvanced theme](https://fusionauth.io/docs/theme/advanced-themes/tailwind.md)

[APIs Create an Email Template API API documentation for the FusionAuth Create an Email Template API. freemarker](https://fusionauth.io/docs/apis/emails/create-an-email-template.md)

[APIs Email API Learn about the APIs for creating, retrieving, updating and deleting email templates as well as sending emails to users. freemarker](https://fusionauth.io/docs/apis/emails.md)
---

## Other pages in Advanced Themes

> For the full index of this section, see [Theme](https://fusionauth.io/docs/llms-theme.txt).

- [Client-side Password Rule Validation](https://fusionauth.io/docs/theme/advanced-themes/client-side-password-rule-validation.md): Learn how to configure FusionAuth to check passwords client-side.
- [Theme Examples](https://fusionauth.io/docs/theme/advanced-themes/examples.md): A list of FusionAuth themes examples.
- [Themes Helper Macros](https://fusionauth.io/docs/theme/advanced-themes/helpers.md): Reference for the FreeMarker macros and functions that FusionAuth themes use to render pages, forms, social login buttons, and CAPTCHA challenges.
- [Advanced Themes](https://fusionauth.io/docs/theme/advanced-themes.md): Learn how to theme and the FusionAuth login pages (including forgot password, two-factor authentication and others).
- [Add a Theme to a Kickstart](https://fusionauth.io/docs/theme/advanced-themes/kickstart-custom-theme.md): Learn how to use Kickstart to create a FusionAuth Instance with a custom theme.
- [Style FusionAuth Themes with Tailwind CSS](https://fusionauth.io/docs/theme/advanced-themes/tailwind.md): Learn how to style the FusionAuth hosted login pages with Tailwind CSS.
- [Theme Template Variables](https://fusionauth.io/docs/theme/advanced-themes/template-variables.md): Detailed documentation about the theme template variables.
- [Advanced Theme Update Guides](https://fusionauth.io/docs/theme/advanced-themes/update-guides.md): Detailed information about required theme changes between versions of FusionAuth.
- [Update an Advanced Theme](https://fusionauth.io/docs/theme/advanced-themes/update.md): Learn how to update a custom theme when you update FusionAuth to a new version.
