I wish to change the code block background color in org mode but below example doesn't work.

#+ATTR_HTML: :background-color #eff0f1;
hello world!

Can I insert inline css code with #+ATT_HTML

2 Answers 2


Yes, you can do what you want with #+ATTR_HTML. However, your HTML is incorrect. If you look at the output you will see <pre class="example" background-color="#eff0f1;"> but there is no background-color attribute in HTML. Instead, use this:

#+ATTR_HTML: :style background-color:#eff0f1;
hello world!

This will generate <pre class="example" style="background-color:#eff0f1;">, which will apply color to that block only.

  • Thanks. Seems to only be applicable to example or verse block.
    – alls0rts
    Commented Jan 27, 2023 at 18:29

You can try this:

#+HTML_HEAD: <style type="text/css">.example {background-color: #eff0f1; color: #ff0000;}</style>
  • Thanks, this solution works for everything block. Is it possible to add a attribute only apply to current code block? then I can apply different color for different block.
    – lucky1928
    Commented Mar 18, 2017 at 20:54
  • How could the same be achieved for a pdf document using LaTeX?
    – tokami
    Commented Mar 10, 2019 at 9:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.