3

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

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

Can I insert inline css code with #+ATT_HTML

2 Answers 2

7

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;
#+BEGIN_EXAMPLE
hello world!
#+END_EXAMPLE

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

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

You can try this:

#+HTML_HEAD: <style type="text/css">.example {background-color: #eff0f1; color: #ff0000;}</style>
2
  • 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
    Mar 18, 2017 at 20:54
  • How could the same be achieved for a pdf document using LaTeX?
    – tokami
    Mar 10, 2019 at 9:18

Your Answer

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

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