Manipulating Style Properties

In general, it is recommended to change styling with classList.toggle(), classList.add(), and/or classList.remove() whenever possible, especially when alternating between two states. However, if more direct or continuous control is required, style.setProperty() may be a better fit.

style.setProperty("property-name", "value");

The "property-name" string can be any familiar CSS styling property, such as "background-color" or "font-size". For the "value", units usually need to be appended using string concatenation e.g. by adding "px" or "rem" to the end of a variable or number.

See the Pen Manipulating Style Properties (IMS322 Docs) by Eric Sheffield (@ersheff) on CodePen.