What is Tamagui?
In the world of modern web and mobile development, creating consistent, performant user interfaces across different platforms has always been a challenge. Enter Tamagui, a revolutionary style library and UI kit that's changing how developers approach cross-platform React development. Tamagui isn't just another styling solution, it's a comprehensive ecosystem that brings together the best of both worlds: the flexibility of React Native and the power of web development.
At its core, Tamagui is built around three main pillars: Core, Static, and Tamagui itself. The Core library provides a universal style system for React and React Native with a large typed superset of the React Native style API, weighing in at just about 24KB with no external dependencies. The Static compiler is what makes Tamagui truly special, an optimizer that transforms your styled components into platform-ideal code through partial analysis, CSS extraction, tree flattening, and dead code elimination.
What sets Tamagui apart from other styling solutions is its optimizing compiler. This isn't just a build tool, it's a sophisticated system that analyzes your code at compile time and outputs perfectly optimized DOM elements on the web or View/Text components on native platforms. The compiler can flatten complex styled components into simple divs with atomic CSS, dramatically improving performance while maintaining the developer experience you love.
The beauty of Tamagui lies in its universal approach. You write your styles once using a familiar API, and Tamagui handles the complexity of making them work perfectly on both web and native platforms. Whether you're building a React web application, a React Native mobile app, or a universal app that runs everywhere, Tamagui provides the tools and components you need to create beautiful, performant user interfaces.
Getting Started with Tamagui
Getting started with Tamagui is surprisingly straightforward, thanks to their excellent starter templates and clear documentation. The team has created multiple starter projects that range from simple learning examples to production-ready monorepos, making it easy to find the right starting point for your project.
Quick Start with the Starter Template
The fastest way to get up and running with Tamagui is to use their starter template. This command will create a new project with all the necessary configuration and dependencies already set up:
# Create a new Tamagui project
npm create tamagui@latest
The starter template will guide you through a series of questions to configure your project, including whether you want a simple example or a more complex setup. It handles all the heavy lifting of setting up the configuration files, installing dependencies, and creating a basic project structure.
Manual Installation and Setup
If you prefer to set up Tamagui manually or add it to an existing project, you can install the core packages and configure everything yourself. Here's how to get started:
# Install the core Tamagui packages
npm install @tamagui/core @tamagui/config @tamagui/animations-react-native
Once installed, you'll need to create a configuration file. Create a tamagui.config.ts
file in
your project root:
import { createTamagui } from '@tamagui/core'
import { config } from '@tamagui/config/v3'
const tamaguiConfig = createTamagui(config)
export default tamaguiConfig
Next, you'll need to wrap your application with the TamaguiProvider to make the configuration available throughout your app:
import { TamaguiProvider } from '@tamagui/core'
import config from './tamagui.config'
export default function App() {
return (
<TamaguiProvider config={config}>
<YourAppContent />
</TamaguiProvider>
)
}
Your First Tamagui Component
Now you're ready to start using Tamagui components. Here's a simple example that demonstrates the power of Tamagui's styling system:
import { View, Text, Button } from '@tamagui/core'
export default function WelcomeScreen() {
return (
<View
flex={1}
justifyContent="center"
alignItems="center"
backgroundColor="$background"
padding="$4"
>
<Text
fontSize="$6"
fontWeight="bold"
color="$color"
marginBottom="$4"
>
Welcome to Tamagui
</Text>
<Button
backgroundColor="$blue10"
color="white"
padding="$3"
borderRadius="$4"
onPress={() => console.log('Button pressed!')}
>
Get Started
</Button>
</View>
)
}
This example showcases several key features of Tamagui: the use of design tokens (like $background
, $4
, $blue10
), the familiar
React Native style API, and the ability to write styles that work seamlessly across platforms.
NativeWind vs Tamagui
When it comes to styling React Native applications, two popular approaches often come up in discussions: NativeWind and Tamagui. While both aim to solve similar problems, they take fundamentally different approaches to styling and have distinct advantages depending on your project's needs.
Styling Philosophy and Approach
NativeWind brings the familiar Tailwind CSS utility classes to React Native, allowing developers who are already
comfortable with Tailwind to apply the same mental model to mobile development. You write styles using utility
classes like bg-blue-500
, p-4
, and text-center
, which are then
transformed into React Native style objects.
Tamagui, on the other hand, takes a more integrated approach with its CSS-in-JS style system. Instead of utility classes, you write styles using props and design tokens that are part of a comprehensive design system. This approach provides better type safety, more powerful theming capabilities, and deeper integration with React's component architecture.
Performance and Optimization
This is where Tamagui truly shines. While NativeWind focuses on providing a familiar syntax for writing styles, Tamagui includes a sophisticated optimizing compiler that can dramatically improve your application's performance. The compiler performs partial analysis, CSS extraction, tree flattening, and dead code elimination, transforming complex styled components into optimized platform-specific code.
On the web, Tamagui's compiler can flatten styled components into simple divs with atomic CSS, similar to what you'd get with a utility-first framework but with the flexibility of component-based styling. On React Native, it optimizes style objects and reduces the overhead of style calculations at runtime.
Cross-Platform Development
Both NativeWind and Tamagui support cross-platform development, but Tamagui's approach is more comprehensive. NativeWind primarily focuses on React Native with some web support, while Tamagui is designed from the ground up to be truly universal. The same components and styles work seamlessly across web, iOS, and Android platforms.
Tamagui's universal approach means you can share more code between your web and mobile applications, reducing development time and ensuring consistency across platforms. The design system approach also makes it easier to maintain brand consistency and implement design changes across your entire application suite.
When to Choose Each
Choose NativeWind if you're already familiar with Tailwind CSS and want to apply that same mental model to React Native development. It's particularly good for teams that are primarily focused on mobile development and want a lightweight, familiar styling solution.
Choose Tamagui if you're building cross-platform applications, need advanced theming capabilities, want the performance benefits of the optimizing compiler, or are looking for a more comprehensive design system approach. Tamagui is also a better choice if you need advanced features like animations, complex responsive behavior, or deep integration with React's component system.
Tamagui Bento: Ready-to-Use Components
One of the most exciting aspects of the Tamagui ecosystem is Tamagui Bento, a collection of copy-paste UI components that are designed to work seamlessly across React Native and React web applications. Bento takes the same philosophy that made libraries like shadcn/ui popular and applies it to the cross-platform world.
Tamagui Bento offers both free and paid components, with the free components providing lifetime rights and the paid ones offering more advanced functionality and premium designs. This model ensures that developers can get started quickly with high-quality components while supporting the continued development of the ecosystem.
What Makes Bento Special
The components in Tamagui Bento are designed to be truly universal. They adapt seamlessly to different platforms, screen sizes, and themes without requiring any platform-specific code. This means you can use the same component in your web application and your React Native mobile app, and it will look and behave appropriately on each platform.
Each component is also highly customizable and designed to be used independently. You're not locked into a specific design system or forced to use components in a particular way. The copy-paste approach means you own the source code and can modify it to fit your exact needs.
Example: A Bento Card Component
Here's an example of how you might use a Bento card component in your application:
import { Card, H3, Paragraph, Button, XStack, YStack } from '@tamagui/core'
export function ProductCard({ product }) {
return (
<Card
elevate
size="$4"
bordered
animation="bouncy"
pressStyle={{ scale: 0.975 }}
>
<Card.Header padded>
<H3>{product.name}</H3>
<Paragraph theme="alt2">{product.description}</Paragraph>
</Card.Header>
<Card.Footer padded>
<XStack justifyContent="space-between" alignItems="center">
<YStack>
<Paragraph size="$2">Price</Paragraph>
<H3 color="$green10">${product.price}</H3>
</YStack>
<Button theme="green">Add to Cart</Button>
</XStack>
</Card.Footer>
</Card>
)
}
This example demonstrates several key features of Bento components: the use of compound components (Card.Header, Card.Footer), built-in animations, responsive design tokens, and the ability to create complex layouts with minimal code. The same component would work perfectly on both web and mobile platforms.
The Bento Ecosystem
The Bento collection includes a wide variety of components, from simple buttons and inputs to complex data tables and navigation systems. Each component is carefully designed to follow modern UI/UX principles and includes comprehensive accessibility features.
The components are also designed to work together seamlessly. You can combine different Bento components to create complex interfaces, and they'll maintain consistent styling and behavior. This makes it easy to build cohesive user experiences without having to worry about design inconsistencies.
Advanced Features and Capabilities
Tamagui goes far beyond basic styling with a comprehensive set of advanced features that make it suitable for complex, production-ready applications. These features include sophisticated theming, responsive design, animations, and deep integration with React's ecosystem.
Smart Theming System
Tamagui's theming system is one of its most powerful features. It provides themes that act like CSS variables, overriding as they descend through your component tree and compiling to CSS to avoid re-renders. This means you can have different themes for different parts of your application, and the system will handle the complexity of applying the right styles at the right time.
import { Theme, Button } from '@tamagui/core'
export function ThemedButton() {
return (
<Theme name="dark">
<Button theme="blue">Dark Theme Button</Button>
</Theme>
)
}
Responsive Design Made Easy
Tamagui makes responsive design incredibly simple with its responsive props and hooks. You can write responsive styles that compile to atomic CSS on the web, ensuring optimal performance while maintaining the flexibility of component-based styling.
import { View, Text } from '@tamagui/core'
export function ResponsiveLayout() {
return (
<View
flexDirection="column"
$gtSm={{ flexDirection: "row" }}
padding="$4"
$gtMd={{ padding: "$6" }}
>
<Text
fontSize="$4"
$gtSm={{ fontSize: "$6" }}
$gtMd={{ fontSize: "$8" }}
>
Responsive Text
</Text>
</View>
)
}
Universal Animations
Tamagui includes a sophisticated animation system that works across all platforms. The animations are designed to be performant and provide better platform targeting with animation drivers that can be changed without changing your code.
import { Square, Button } from '@tamagui/core'
export function AnimatedSquare() {
const [position, setPosition] = React.useState(0)
return (
<>
<Square
animation="bouncy"
size={110}
backgroundColor="$pink10"
borderRadius="$9"
hoverStyle={{ scale: 1.1 }}
pressStyle={{ scale: 0.9 }}
x={position * 50}
y={position * 50}
/>
<Button onPress={() => setPosition(p => (p + 1) % 3)}>
Move Square
</Button>
</>
)
}
Why Tamagui Matters for Modern Development
In today's development landscape, the ability to build applications that work seamlessly across multiple platforms while maintaining high performance and developer experience is more important than ever. Tamagui addresses these needs by providing a comprehensive solution that doesn't compromise on any front.
The optimizing compiler is perhaps Tamagui's most revolutionary feature. By analyzing your code at compile time and outputting platform-optimal code, it eliminates many of the performance concerns that typically come with CSS-in-JS solutions. The compiler can flatten complex styled components into simple DOM elements with atomic CSS, providing the performance benefits of utility-first frameworks while maintaining the flexibility of component-based styling.
The universal approach means you can truly share code between your web and mobile applications. Instead of maintaining separate codebases or dealing with the complexity of React Native Web, you can write your components once and have them work perfectly on all platforms. This not only reduces development time but also ensures consistency across your entire application suite.
Tamagui's design system approach also makes it easier to maintain brand consistency and implement design changes. With centralized design tokens, themes, and components, you can update your entire application's appearance by changing a few configuration values. This is particularly valuable for teams that need to maintain multiple applications or frequently update their design systems.
Getting Started Today
Tamagui represents a significant step forward in cross-platform React development. Whether you're building a simple web application, a complex mobile app, or a universal application that needs to work everywhere, Tamagui provides the tools and components you need to create beautiful, performant user interfaces.
The best way to understand the power of Tamagui is to try it for yourself. Start with the starter template, explore the Bento components, and experiment with the theming and animation systems. You'll quickly see how Tamagui's approach to styling and component development can transform your development workflow.
Visit the Tamagui website to explore the documentation, try the interactive examples, and see the full range of components and features available. The Bento collection is also worth exploring for ready-to-use components that can accelerate your development process.
With its combination of performance optimization, cross-platform compatibility, and developer experience, Tamagui is well-positioned to become the go-to solution for modern React development. Whether you're a solo developer or part of a large team, Tamagui provides the tools you need to build applications that are both beautiful and performant across all platforms.