JSFiddle - React, Tailwind, and code Playground

by raddevus

HTML

<button onclick="incdec(1)">+</button>
<button onclick="incdec(-1)">-</button>
<input type="text" id="output" >

JavaScript

// this next line is just a quick way of showing initialization 
// which should be moved to your onload event so when page loads 
// your localStorage values are read in If they exist)
var fontSize = 12;
initializeValue()

function initializeValue(){
	fontSize = Number(localStorage.getItem("fontSize"));
  if (fontSize <=0 ){
     fontSize = 12;
  }
  
	document.querySelector("#output").value = fontSize;
}

function incdec(value){
	fontSize += value;  // 
  document.querySelector("#output").value = fontSize;
	localStorage.setItem("fontSize",fontSize);
}