# Background color of iFrame not working

**URL:** https://meta.discourse.org/t/background-color-of-iframe-not-working/232916
**Category:** Support
**Created:** [July 14, 2022, 9:48pm UTC](https://meta.discourse.org/t/background-color-of-iframe-not-working/232916 "2022-07-14T21:48:01Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![lyt](https://avatars.discourse-cdn.com/v4/letter/l/c6cbf5/32.png) [@lyt](https://meta.discourse.org/u/lyt)
#### Post date: [July 14, 2022, 9:48pm UTC](https://meta.discourse.org/t/background-color-of-iframe-not-working/232916/1 "2022-07-14T21:48:01Z")

</div>

I recently embedded some visualizations into a forum (powered by discourse) post and they look unfortunately terrible in dark mode because the iframes have transparent backgrounds.

So I tried to change the background color of the iframes. I found how and tested it on hackmd; it worked well. But when I submit it on the discourse forum, it doesn’t work! Dark mode prevails.

Here is the structure of code I am using:

`<iframe width="100%" height="300" style="background-color: #FFFFFF" src="https://dune.com/embeds/1002945/1734962/fe28df65-99a3-4b98-8cb4-e97f132c8165" frameborder="0"></iframe>`

---

<div class="post-metadata">

### Author: ![SaraDev](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/saradev/32/335139_2.png) [@SaraDev](https://meta.discourse.org/u/SaraDev)
#### Post date: [July 14, 2022, 11:03pm UTC](https://meta.discourse.org/t/background-color-of-iframe-not-working/232916/2 "2022-07-14T23:03:04Z")

</div>

You’ll likely need to use custom CSS to set a custom background color for your iframe, as styles/classes are stripped out of all posts on Discourse by default.

> [@Custom css inside a post / adding custom classes](https://meta.discourse.org/t/custom-css-inside-a-post-adding-custom-classes/143072):
>
> Is it possible to give a \<div\> inside a post some custom styling? I’ve [seen](https://meta.discourse.org/t/adding-custom-class-to-img-tag/21425/7) that any non-whitelisted classes are stripped out, and I’ve tried addingstyle= to my divs and spans to no avail , so does anyone know if there’s a way to do that? Basically I have a bot that posts from an internal tool and I’d like to have it post with something that looks like the tool to make it obvious that it’s not a regular disourse post, something like this: It’s got a couple of nested divs/spans to ma…

For example, within a topic you could use:

```plaintext
<div data-theme-1>
<iframe width="100%" height="300" src="https://dune.com/embeds/1002945/1734962/fe28df65-99a3-4b98-8cb4-e97f132c8165" frameborder="0"></iframe>
</div>

```

And then in the custom CSS for the theme you’re using add:

```plaintext
div[data-theme-1] {
  background-color: #FFFFFF;
}

```

If you’re interested in whitelisting styles/classes on your site, this must be done with a plugin.

> [@What are the different ways to customize content inside a post (custom attributes and such)](https://meta.discourse.org/t/what-are-the-different-ways-to-customize-content-inside-a-post-custom-attributes-and-such/226747/5):
>
> It is possible to uses some HTML classes in Discourse, however, most HTML in a post is sanitized for security reasons, and only very strict whitelisted HTML is allowed in markdown. To add classes to the white-list you must use a plugin, the sanitization happens server side as well as client side. Check out [Whitelisting HTML tags / attributes](https://meta.discourse.org/t/whitelisting-html-tags-attributes/159653) for some details on where to add the whitelisted attributes, and I believe it would look similar to something like this: [Discourse HTML Whitelist](https://github.com/pnewell/discourse-html-whitelist). and a…

---

<div class="post-metadata">

### Author: ![lyt](https://avatars.discourse-cdn.com/v4/letter/l/c6cbf5/32.png) [@lyt](https://meta.discourse.org/u/lyt)
#### Post date: [July 15, 2022, 6:30pm UTC](https://meta.discourse.org/t/background-color-of-iframe-not-working/232916/3 "2022-07-15T18:30:37Z")

</div>

Thanks so much, that worked!

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [August 14, 2022, 6:31pm UTC](https://meta.discourse.org/t/background-color-of-iframe-not-working/232916/4 "2022-08-14T18:31:02Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
