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.

Learn To Up Your Development Game

You'll get articles to help you improve your game as a web developer. These articles can be related to CSS, JavaScript, Astro, Svelte, or even general web development tips.