# Code Formatting

**URL:** <https://forums.ankiweb.net/t/code-formatting/31132>\
**Category:** Card Design\
**Created:** [June 11, 2023, 11:20pm UTC](https://forums.ankiweb.net/t/code-formatting/31132 "2023-06-11T23:20:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![isxodnik](https://avatars.discourse-cdn.com/v4/letter/i/bc79bd/32.png) [@isxodnik](https://forums.ankiweb.net/u/isxodnik)\
**Post date:** [June 11, 2023, 11:20pm UTC](https://forums.ankiweb.net/t/code-formatting/31132/1 "2023-06-11T23:20:47Z")

</div>

Hello!  
I’m exporting notes with code from Obsidian. How can I set up blocks of code, namely:

- background,
- font?  
Thank you!  
P.S. I searched the forum and tried the “Highlight Code” addon, but did not reach the goal.  
Obsidian:  
 ![1](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/2X/d/d0bbd069adf3bb689710719ba7a45cfac9245de0.png)  
Anki:  
 ![2](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/2X/a/af101b1210f647bf69ba826565fc9d627cdafd47.png)

---

<div class="post-metadata">

**Author:** ![Hildeguard](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@Hildeguard](https://forums.ankiweb.net/u/Hildeguard)\
**Post date:** [July 4, 2023, 6:28am UTC](https://forums.ankiweb.net/t/code-formatting/31132/2 "2023-07-04T06:28:23Z")

</div>

You can wrap your whole code section in html `<pre><code>{{MyCodeField}}</code></pre>` using the “edit notetype” button.

You can then style the background using css in the styling section:

```auto
pre {
	background-color: black;
}

code {
	font-family: "FreeMono";
}

```

Regarding the font, either choose a monospace font that is preinstalled on your operating system, or follow the instructions in the [documentation](https://docs.ankiweb.net/templates/styling.html#installing-fonts) to install your preferred monospace font.

For further styling, read this blog post by Arthur Milchior: [Syntax coloring of code in Anki - Arthur Milchior's personal blog](https://www.milchior.fr/blog_en/index.php/post/2022/03/22/Syntax-coloring-of-code-in-Anki)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/1X/8f1279ababc5879d54e4838989f606cfe55af8c7.jpeg) [@system](https://forums.ankiweb.net/u/system)\
**Post date:** [August 3, 2023, 6:29am UTC](https://forums.ankiweb.net/t/code-formatting/31132/3 "2023-08-03T06:29:19Z")

</div>

Closed on August 3, 2023, 6:29am UTC

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