Skip to content

The root.tsx file in Remix

This tutorial will guide you through updating the user interface (UI) in one of the most important files of a Remix project: the root.tsx file.

We’ll start with the basics, so don’t worry if you’re not familiar with these technologies yet. Let’s dive in!

Before we begin, ensure you have npm (Node Package Manager) installed on your system as it’s essential for running our project server and managing our dependencies.

First, we need to start our development server. Open your terminal, navigate to your project directory, and run:

Running the server with npm
npm run dev

This command starts a local development server. Once it is up and running, you can view your project in a web browser by going to http://localhost:3000:

landing screen

The root.tsx file is located in the app directory of your project.

Look carefully through the project structure to find it in the VS Code file explorer (or your own code editor):

root.tsx file location

The root.tsx file in a Remix project serves as the entry point for your application’s user interface. It renders the initial HTML structure of your project, and provides the foundation for the rest of your application’s components and pages to be displayed.

Think of it as the starting point where all the UI elements come together and get rendered on the screen.

At the moment, it doesn’t seem all that impressive, but we’ll change that soon!

To change the existing text, locate the <h1> tag inside the App function of your root.tsx file:

app/root.tsx
10 collapsed lines
import { type LinksFunction } from '@remix-run/node'
import Document from '~/components/shared-layout/Document'
import { useNonce } from '~/utils/nonce-provider.ts'
import rootLinkElements from '~/utils/providers/rootLinkElements'
export const links: LinksFunction = () => {
return rootLinkElements
}
export { headers, meta } from './__root.client.tsx'
export { action, loader } from './__root.server.tsx'
export default function App() {
const nonce = useNonce()
return (
<Document nonce={nonce}>
<div className="flex h-screen flex-col justify-between">
<div className="flex-1">
<main className="grid h-full place-items-center">
<h1 className="text-mega">Welcome to Epic News!</h1>
</main>
</div>
</div>
</Document>
)
}

Change "Welcome to Epic News!" to any message you like, such as Your Journey Begins!.

app/root.tsx
<h1 className="text-mega">Your Journey Begins!</h1>

Save the file and your browser should automatically refresh, displaying the new message.

Let’s add a new paragraph (<p>) element below the <h1> tag. This will demonstrate how to insert new content into your page.

app/root.tsx
<main className="grid h-full place-items-center">
<h1 className="text-mega">Your Journey Begins!</h1>
<p>Welcome to Epic News, where the latest developments in tech are found.</p>
</main>

4. Style the New Element Using Tailwind Classes

Section titled “4. Style the New Element Using Tailwind Classes”

To style the paragraph, we’ll use TailwindCSS, a utility-first CSS framework. If you’re not familiar with Tailwind, it lets you style elements by adding class names directly in your HTML (or JSX in this case).

app/root.tsx
<p className="text-base text-gray-600">
Welcome to Epic News, where the latest developments in tech are found.
</p>

Tailwind makes creating responsive designs straightforward. To demonstrate, let’s make the font size of our paragraph larger on medium (md) and large (lg) screens.

app/root.tsx
<p className="text-base text-gray-600 md:text-lg lg:text-xl">
Welcome to Epic News, where the latest developments in tech are found.
</p>

There are actually lots of ways you could complete these challenges. Below are a few.


app/root.tsx
<div class="flex h-screen flex-col justify-between bg-blue-100">
app/root.tsx
<button class="px-4 py-2 bg-blue-500 text-white rounded-md">
Learn More
</button>
app/root.tsx
<button class="px-4 py-2 md:px-6 md:py-3 lg:px-8 lg:py-4 bg-blue-500 text-white rounded-md">
Learn More
</button>
Click to reveal

You’ve just updated your first Remix UI, added elements, styled them, and made them responsive with Tailwind.

Keep experimenting with different elements and styles to further enhance your page.