Easy way to remove inline styles

Published:

Here’s a simple way to remove inline styles from 3rd-party libraries.

// Replace .container with the HTML element you're targeting
const container = document.querySelector('.container')
const elements = container.querySelectorAll('*')

for (const element of elements) {
  element.removeAttribute('style')
}

The basic idea is we strip out the style tag from all elements within the container, so you don’t have to fight a never-winning CSS specificity war by using !important.

Want to become a better Frontend Developer?

Don’t worry about where to start. I’ll send you a library of articles frontend developers have found useful!

  • 60+ CSS articles
  • 90+ JavaScript articles

I’ll also send you one article every week to help you improve your FED skills crazy fast!