You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/3.guides/7.styling.md
+60Lines changed: 60 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -79,6 +79,66 @@ The module automatically detects your CSS framework:
79
79
- **UnoCSS:** Active if you enable `@unocss/nuxt`.
80
80
- **Nuxt UI v3:** Automatically imports colors and theme variables.
81
81
82
+
## Theme Switching (`data-theme`)
83
+
84
+
By default, OG images render with dark-mode semantic tokens (e.g. Nuxt UI's `bg-inverted`, `text-default`). To opt into theme-aware token resolution, set `data-theme` on the **root element** of your component. Tailwind v4 only.
When the build detects a `:data-theme` binding on the root element, it resolves classes for both themes at build time and emits paired `bg-[#...] dark:bg-[#...]` arbitrary classes. The renderer then picks the correct value based on the `colorMode` prop you pass to `defineOgImage`.
133
+
134
+
::note
135
+
The dynamic binding only works on the **root element** of the OG component. Nested elements inherit the resolved theme from the build pass.
136
+
::
137
+
138
+
::tip
139
+
Templates that don't set `data-theme` keep the existing dark-mode default; this feature is opt-in and non-breaking.
140
+
::
141
+
82
142
## Inline Styles
83
143
84
144
Use the `:style` binding for dynamic values that change based on props.
If you need to render the same component in different themes for different pages (e.g. a light variant and a dark variant of a hero image), bind `:data-theme` on the component's root element to a `colorMode` prop. See [Theme Switching](/docs/og-image/guides/styling#theme-switching-data-theme) in the styling guide.
0 commit comments