1

I have got a question. How to change font-size of :root, using javascript? I need to make a button to resize font in a whole website.

4
  • You mean changing the stylesheet rules ? Commented Mar 1, 2018 at 13:49
  • Root means body or html Commented Mar 1, 2018 at 13:49
  • Or as in a CSS variable? Like :root { --font-size: 16px; } Commented Mar 1, 2018 at 13:50
  • Also see possible duplicate at stackoverflow.com/a/33598560/2177147 Commented Mar 1, 2018 at 13:52

2 Answers 2

1

While I have no idea what --font-size should be, accessing :root itself seems to be working with CSSStyleSheet.insertRule()

function doThing(){
  document.styleSheets[0].insertRule(':root { font-size: 26px; }');
}
HelloWord<br>
<button onclick="doThing()">Clicky</button>

Sign up to request clarification or add additional context in comments.

Comments

0

If you change the document.body.style.fontSize you are basically changing the :root. As long as the rest of your styles use em or rem font-sizes, all the text on the site should change accordingly.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.