tamagui
Style React fast with 100% parity on React Native, an optional UI kit, and optimizing compiler.
Top Related Projects
Radix Primitives is an open-source UI component library for building high-quality, accessible design systems and web apps. Maintained by @workos.
⚡️ Simple, Modular & Accessible UI Components for your React Applications
Toolkit for building accessible web apps with React
[Not Actively Maintained] CSS-in-JS with near-zero runtime, SSR, multi-variant support, and a best-in-class developer experience.
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress 💅
👩🎤 CSS-in-JS library designed for high performance style composition
Quick Overview
Tamagui is a universal UI kit for React Native and Web, focusing on performance and developer experience. It provides a set of customizable components and a powerful theming system, allowing developers to create consistent and responsive user interfaces across platforms.
Pros
- High performance with atomic CSS-in-JS and compiler optimizations
- Flexible theming system with support for light/dark modes and custom themes
- Consistent API for both React Native and Web platforms
- Extensive set of pre-built, customizable components
Cons
- Learning curve for developers new to the Tamagui ecosystem
- Limited community support compared to more established UI libraries
- Potential compatibility issues with some existing React Native projects
- Documentation can be overwhelming for beginners
Code Examples
- Creating a simple button component:
import { Button } from 'tamagui'
export default function MyButton() {
return <Button>Click me</Button>
}
- Using the Stack component for layout:
import { Stack, Text } from 'tamagui'
export default function MyLayout() {
return (
<Stack space="$4" padding="$4">
<Text>Item 1</Text>
<Text>Item 2</Text>
<Text>Item 3</Text>
</Stack>
)
}
- Applying custom styles using Tamagui's styling system:
import { styled } from 'tamagui'
const StyledText = styled(Text, {
color: '$blue10',
fontSize: 18,
fontWeight: 'bold',
})
export default function CustomText() {
return <StyledText>Styled Text</StyledText>
}
Getting Started
To start using Tamagui in your project:
- Install Tamagui and its dependencies:
npm install tamagui @tamagui/core @tamagui/config
- Create a
tamagui.config.ts
file in your project root:
import { createTamagui } from 'tamagui'
import { shorthands } from '@tamagui/shorthands'
import { themes, tokens } from '@tamagui/theme-base'
const config = createTamagui({
shorthands,
themes,
tokens,
})
export type AppConfig = typeof config
export default config
- Wrap your app with the
TamaguiProvider
:
import { TamaguiProvider } from 'tamagui'
import config from './tamagui.config'
export default function App() {
return (
<TamaguiProvider config={config}>
{/* Your app content */}
</TamaguiProvider>
)
}
Now you can start using Tamagui components and styling in your application.
Competitor Comparisons
Radix Primitives is an open-source UI component library for building high-quality, accessible design systems and web apps. Maintained by @workos.
Pros of Primitives
- Highly accessible components with ARIA support out-of-the-box
- Unstyled and customizable, allowing for greater design flexibility
- Extensive documentation and examples for each component
Cons of Primitives
- Limited to web applications, not suitable for native mobile development
- Requires more setup and styling work compared to pre-styled components
- Steeper learning curve for developers new to headless UI concepts
Code Comparison
Primitives:
import * as Dialog from '@radix-ui/react-dialog';
<Dialog.Root>
<Dialog.Trigger>Open</Dialog.Trigger>
<Dialog.Content>
<Dialog.Title>Dialog Title</Dialog.Title>
<Dialog.Description>Dialog content here</Dialog.Description>
</Dialog.Content>
</Dialog.Root>
Tamagui:
import { Dialog, Button, H2, Paragraph } from 'tamagui'
<Dialog>
<Dialog.Trigger asChild><Button>Open</Button></Dialog.Trigger>
<Dialog.Portal>
<Dialog.Content>
<H2>Dialog Title</H2>
<Paragraph>Dialog content here</Paragraph>
</Dialog.Content>
</Dialog.Portal>
</Dialog>
Both libraries offer composable dialog components, but Tamagui provides pre-styled elements (like H2
and Paragraph
) while Primitives focuses on unstyled, accessible structure.
⚡️ Simple, Modular & Accessible UI Components for your React Applications
Pros of Chakra UI
- Extensive documentation and community support
- Highly customizable with a robust theming system
- Seamless integration with React and Next.js projects
Cons of Chakra UI
- Larger bundle size compared to Tamagui
- Limited support for native mobile development
- Steeper learning curve for beginners
Code Comparison
Chakra UI:
import { Box, Text } from '@chakra-ui/react'
const Example = () => (
<Box bg="tomato" p={4} color="white">
<Text fontSize="xl">Hello, Chakra UI!</Text>
</Box>
)
Tamagui:
import { YStack, Text } from 'tamagui'
const Example = () => (
<YStack bg="$red10" p="$4" color="$white">
<Text fontSize="$6">Hello, Tamagui!</Text>
</YStack>
)
Both libraries offer a similar component-based approach, but Tamagui uses a more concise syntax for styling and theming. Chakra UI relies on predefined theme values, while Tamagui uses a token-based system with a $
prefix. Tamagui's approach allows for better performance and smaller bundle sizes, especially in React Native projects. However, Chakra UI's extensive ecosystem and documentation may make it easier for developers to get started and find solutions to common problems.
Toolkit for building accessible web apps with React
Pros of Ariakit
- Focuses on accessibility and ARIA compliance, providing robust keyboard navigation and screen reader support
- Offers a wide range of customizable components with minimal styling, allowing for greater flexibility in design
- Provides thorough documentation and examples for each component
Cons of Ariakit
- Less emphasis on performance optimization compared to Tamagui
- Doesn't offer native mobile support out of the box
- May require more custom styling work to achieve desired visual aesthetics
Code Comparison
Ariakit:
import { Button } from "ariakit/button";
function MyButton() {
return <Button>Click me</Button>;
}
Tamagui:
import { Button } from "tamagui";
function MyButton() {
return <Button>Click me</Button>;
}
While the basic usage appears similar, Tamagui's Button component comes with built-in styling and theming capabilities, whereas Ariakit's Button focuses on accessibility features and requires additional styling.
[Not Actively Maintained] CSS-in-JS with near-zero runtime, SSR, multi-variant support, and a best-in-class developer experience.
Pros of Stitches
- Lightweight and focused on CSS-in-JS for web applications
- Excellent TypeScript support with zero-runtime CSS-in-JS
- Simple API with a familiar CSS-like syntax
Cons of Stitches
- Limited to web platforms, not designed for React Native
- Lacks built-in components or a comprehensive UI framework
- May require additional setup for responsive design and theming
Code Comparison
Stitches:
import { createStitches } from '@stitches/react';
const { styled } = createStitches({});
const Button = styled('button', {
backgroundColor: 'gainsboro',
borderRadius: '9999px',
});
Tamagui:
import { styled } from 'tamagui';
const Button = styled(Stack, {
backgroundColor: '$background',
borderRadius: '$4',
variants: {
size: {
small: { padding: '$2' },
large: { padding: '$4' },
},
},
});
Key Differences
- Tamagui offers a full UI kit and supports both web and native platforms
- Stitches focuses on CSS-in-JS for web, while Tamagui provides a more comprehensive solution for cross-platform development
- Tamagui includes built-in components and a design system, whereas Stitches requires additional libraries for a complete UI framework
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress 💅
Pros of styled-components
- Widely adopted and mature ecosystem with extensive community support
- Seamless integration with React components and props
- Supports server-side rendering out of the box
Cons of styled-components
- Performance overhead due to runtime CSS generation
- Larger bundle size compared to traditional CSS solutions
- Limited support for non-React environments
Code Comparison
styled-components:
const Button = styled.button`
background-color: ${props => props.primary ? 'blue' : 'white'};
color: ${props => props.primary ? 'white' : 'blue'};
padding: 10px 20px;
`;
Tamagui:
import { Button } from '@tamagui/core'
const MyButton = styled(Button, {
backgroundColor: '$blue',
color: '$white',
padding: '$2 $3',
})
Tamagui offers a more optimized approach with static extraction and compile-time optimizations, resulting in smaller bundle sizes and improved performance. It also provides a unified styling system for both React Native and web applications, which is not natively supported by styled-components. However, styled-components has a larger ecosystem and more widespread adoption, making it easier to find resources and community support.
👩🎤 CSS-in-JS library designed for high performance style composition
Pros of Emotion
- Mature and widely adopted CSS-in-JS solution with a large ecosystem
- Flexible API supporting both object and string styles
- Excellent TypeScript support and type inference
Cons of Emotion
- Larger bundle size compared to Tamagui
- Runtime performance overhead for style computation
- Lacks built-in UI components and design system features
Code Comparison
Emotion:
import { css } from '@emotion/react'
const style = css`
background-color: hotpink;
&:hover {
color: ${props => props.color};
}
`
Tamagui:
import { styled } from 'tamagui'
const StyledView = styled(View, {
backgroundColor: 'hotpink',
hoverStyle: {
color: '$color',
},
})
Tamagui offers a more concise syntax and built-in support for responsive styles and themes. Emotion provides greater flexibility in style definition but requires more verbose code. Tamagui's approach is optimized for performance and smaller bundle sizes, while Emotion focuses on developer experience and ecosystem compatibility.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Style and UI for React (web and native) meet an optimizing compiler
@tamagui/core
- Universal style library for React.@tamagui/static
- Optimizing compiler that works withcore
andtamagui
.tamagui
- UI kit that adapts to every platform.
See tamagui.dev for documentation.
Tamagui lets you share more code between web and native apps without sacrificing the two things that typically suffer when you do: performance and code quality.
It does this with an optimizing compiler that outputs platform-specific optimizations - it turns styled components, even with complex logic or cross-module imports, into a simple div
alongside atomic CSS on the web, or a View with its style objects hoisted on native.
The entirety of Tamagui works at compile time and runtime, and can be set up gradually, with initial usage as simple as importing it and using the base views and styled function.
We recommend checking out the starters with npm create tamagui@latest
, they range from a simple learning example to a production-ready monorepo.
The compiler optimizes most and ultimately flattens a majority of styled components. In the ~500px² responsive browser section of the Tamagui website, 49 of the 55 or so inline styled components are flattened to a div
. The homepage gains nearly 15% on Lighthouse with the compiler on.
Installing Tamagui
To install Tamagui with all its components run:
npm install tamagui @tamagui/config
Next, create a Tamagui config file named tamagui.config.ts
:
import { config } from '@tamagui/config/v3'
import { createTamagui } from 'tamagui'
const tamaguiConfig = createTamagui(config)
// this makes typescript properly type everything based on the config
type Conf = typeof tamaguiConfig
declare module 'tamagui' {
interface TamaguiCustomConfig extends Conf {}
}
export default tamaguiConfig
// depending on if you chose tamagui, @tamagui/core, or @tamagui/web
// be sure the import and declare module lines both use that same name
Note: The v3
config imports the @tamagui/animations-css
driver on web and @tamagui/animations-react-native
on native. You can change these as you please, we provide exports for animationsCSS
and animationsNative
. If you want to use Reanimated, you can copy and paste this code and pass it as animations
to createTamagui
.
Contributing
To contribute to Tamagui reference the contributing guide.
To contribute to documentation reference the writing guide.
Top Related Projects
Radix Primitives is an open-source UI component library for building high-quality, accessible design systems and web apps. Maintained by @workos.
⚡️ Simple, Modular & Accessible UI Components for your React Applications
Toolkit for building accessible web apps with React
[Not Actively Maintained] CSS-in-JS with near-zero runtime, SSR, multi-variant support, and a best-in-class developer experience.
Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress 💅
👩🎤 CSS-in-JS library designed for high performance style composition
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot