Tailwind CSS setup
Tailwind is already integrated into the build system. No additional configuration is needed.Import Tailwind
Import Tailwind in yourapp/globals.css:
app/globals.css
Link the stylesheet
Reference the compiled CSS in your root layout:app/root-layout.js
globals.css to style.css in the .cosmos-rsc/ directory.
Using Tailwind classes
Apply utility classes directly to your components:Common patterns from the demo
Here are styling patterns used in the COSMOS RSC demo:Layout containers
Card components
Grid layouts
Form inputs
Buttons
Links
Custom CSS and animations
Add custom styles and animations inglobals.css:
app/globals.css
NavigationTransition component for smooth page transitions.
Loading states
Create loading skeletons with Tailwind’s animation utilities:Responsive design
Use Tailwind’s responsive prefixes:sm:- 640px and upmd:- 768px and uplg:- 1024px and upxl:- 1280px and up
Dark mode
Tailwind supports dark mode with thedark: prefix:
Build process
The Webpack configuration handles CSS compilation:core/build/webpack.config.js
- Processes CSS files with PostCSS
- Runs Tailwind CSS to generate utilities
- Extracts the final CSS to
style.css
Best practices
Use semantic class names
Use semantic class names
Group related utilities together for readability:
Extract repeated patterns to components
Extract repeated patterns to components
If you’re using the same class combinations frequently, create a component:
Use consistent spacing
Use consistent spacing
Stick to Tailwind’s spacing scale (4, 8, 12, 16, etc.) for consistency:
Leverage color shades
Leverage color shades
Use Tailwind’s color scale for visual hierarchy: