Introduction
Remix lets you choose different ways to style your app so you can pick what feels easiest and works best for your project.
Remix lets you choose different ways to style your app so you can pick what feels easiest and works best for your project.
/* Example of importing CSS in Remix */ import stylesUrl from './styles.css?url'; export function links() { return [{ rel: 'stylesheet', href: stylesUrl }]; }
links function that returns stylesheets./* Importing global CSS */ import globalStyles from './global.css?url'; export function links() { return [{ rel: 'stylesheet', href: globalStyles }]; }
/* Using CSS modules */ import styles from './Button.module.css'; import stylesUrl from './Button.module.css?url'; export function links() { return [{ rel: 'stylesheet', href: stylesUrl }]; } export function Button() { return <button className={styles.primary}>Click me</button>; }
/* Using Tailwind CSS */ // Tailwind classes are added directly in JSX export function Header() { return <h1 className="text-3xl font-bold text-blue-600">Welcome</h1>; }
This example shows how to add a global CSS file and use classes in your component.
import stylesUrl from './styles.css?url'; export function links() { return [{ rel: 'stylesheet', href: stylesUrl }]; } export default function Home() { return ( <main> <h1 className="title">Hello Remix</h1> <p className="description">Styling your app your way!</p> </main> ); }
Remix does not force one styling method, so you can mix approaches as needed.
Using the links export is key to adding stylesheets in Remix.
Component-scoped styles help avoid style conflicts in bigger apps.
Remix supports many styling methods to fit your preferences.
You add styles by exporting a links function or using CSS-in-JS.
This flexibility helps you build apps that look great and are easy to maintain.
links export?links function must return an array of objects with rel and href keys.rel: 'stylesheet' and href.import { useState } from 'react';
export default function Button() {
const [active, setActive] = useState(false);
return (
setActive(!active)}
>
Click me
);
}active state starts as false.active is false, backgroundColor is 'gray'.links function that tries to add a stylesheet?export function links() {
return { rel: 'stylesheet', href: '/main.css' };
}links function must return an array of link descriptor objects.links export and CSS-in-JS inside components for scoped styles.links function for global CSS and using CSS-in-JS inside components correctly describes combining global CSS with component-level CSS-in-JS.Pass the test and this pattern moves unknown