Import and use the HTML components with Tailwind classes:
import { html } from"@/html";
exportfunctionMyComponent() {
return (
<html.divclassName="flex flex-col gap-4 p-4 bg-sf-bg"><html.h1className="text-2xl font-bold text-sf-text">
Hello World
</html.h1><html.pclassName="text-sf-text-2">
This works on both web and native!
</html.p><html.buttonclassName="px-4 py-2 bg-sf-blue text-white rounded-lg">
Click me
</html.button></html.div>
);
}
How It Works
Web
On web, react-strict-dom renders actual HTML elements (<div>, <button>, etc.) with the PostCSS plugin processing styles. The useCssElement wrapper enables Tailwind className support.
Native (iOS/Android)
On native, react-strict-dom transforms HTML elements into equivalent React Native components:
<div> → <View>
<span>, <p> → <Text>
<img> → <Image>
etc.
The Babel preset handles these transformations at build time.
Style Normalization
The normalizeStyle function handles platform-specific style differences:
Flattens style arrays using StyleSheet.flatten()
Converts backgroundImage to experimental_backgroundImage for native compatibility
Benefits
Semantic HTML: Write semantic HTML that works everywhere
Better SEO: Real HTML elements on web
Accessibility: Native HTML semantics for screen readers
Tailwind Integration: Full className support with react-native-css
Type Safety: Full TypeScript support with proper component props
Platform Optimizations: Platform-specific transforms at build time
Troubleshooting
"postcss-react-strict-dom version not found"
Use react-strict-dom@0.0.54 instead of the latest version. Version 0.0.55 has a missing dependency.
Styles not applying on native
Ensure the @react-strict-dom directive is at the top of your global CSS file.
TypeScript errors with displayName
Use type assertions when setting displayName:
(Componentasany).displayName = displayName;
backgroundImage not working on native
The normalizeStyle function handles this automatically by mapping to experimental_backgroundImage.