Next.js Discord

Discord Forum

How to dynamically add styles from database.

Unanswered
Sun bear posted this in #help-forum
Open in Discord
Sun bearOP
Is there a way to dynamically set some CSS in the <head> via <style> in the app router ? I want to set it for one of the child layout.

I have font style saved to user database, for user page i want to apply this font where style to be added to <head> section (update the css variable with font style from the database)

<head> should include <style> as below

<style> :root { --content-font-family: "OpenSans"; } </style>

CSS will have class using this variable
.font-test { font-family: var(--content-font-family) !important; }

Using Nextjs13.4

0 Replies