330 Locust Dr.
Verona, WI 53593
Download our free guide!
Powderkeg Web Design
Message Us

The Best way to override pesky 3rd party styles with important tags

October 17,2014

There is a common problem that many developers run in to over the course of their illustrious careers. Picture this scenario:

You’re developing a beautifully designed website. The designer did an exceptional job at making the perfect mockup that allows you to understand  every padding, margin, color, and border. You get to the part where it’s time to develop the mocked up form, and you suddenly remember that it has to be an embedded third party form that the client prefers to use.

You get a hold of the embed code and add it to your file only to find out that it auto injects it’s own stylings, and all of those styles use the “!important” tag. You try in vain to add your own styles to it, but they fall on deaf ears as the “!important” tags laughs mercilessly at them.

Contrary to popular belief, you CAN override these styles. The trick is pretty simple too. You just need to use a CSS selector that is more specific that the current one. For example, pretend this is the offending code that you are trying to override:

That will find the form with class “xyz-form” and add a red border to every input. This might be fine for some, but what if a red border absolutely trashes the site you want to put the form on? Simply adding your own code to override it usually won’t work.

The secret is to use the containing elements that you wrapped the form in as additional selectors. You still need to use the !important tag as well:

This is using LESS to compile CSS. You can do this in CSS as well:

Being the developer of this project, it is safe to assume I can put the embedded form in a <div> of my own. Now that my selector is more specific that the previous selector, it will take precedence over it. We now have an amazing looking green border that meshes perfectly with the rest of the site. The client loves it so much that they offer you early retirement and your own Hawaiian Island! Aren’t you glad you knew beforehand how to do this?

Senior Developer

Nick is an ambitious and versatile developer with a wide range of talents. He is an efficient coder that utilizes his resources in order to achieve both his and the clients’ goals. His Alma Mater is the University of Wisconsin – Stevens Point where he graduated with honors in Web and Digital Media Development.