<main></main>
main:after {
  background: var(--background-color);
  content: var(--text);
}
function addStyle(styleString) {
  const style = document.createElement("style");
  style.textContent = styleString;
  document.head.append(style);
}

const text = "Hello from JS!!";
const background = '#ffccff'

addStyle(`
  :root {
    --text: "${text}";
    --background-color: ${background}
  }
`);
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.