# Light and dark code themes per block in PDF

One word in the info string sets the theme of a single block, so a terminal session can be dark on a light page. Most converters offer one theme for the whole document.

A block's info string overrides the document's code theme: theme=dark for a terminal look on a light page, theme=light to keep one block light on a dark page. Also: C, Java, Kotlin, HTML, CSS, TOML.

- PDF: https://legivel.com/examples/code-blocks/light-dark-code-themes.pdf
- Page: https://legivel.com/examples/code-blocks/light-dark-code-themes
- Open in the editor: https://legivel.com/markdown-to-pdf?sample=code-themes
- More code blocks with syntax highlighting in PDF: https://legivel.com/examples/code-blocks

## Markdown source

````markdown
# Code themes per block

The document is light, so code is light by default. Add `theme=dark` after the language to set one block on the dark palette, the way a terminal screenshot would look:

```bash theme=dark
$ ssh ops@gateway.example.net
$ systemctl status scheduler
● scheduler.service - Nightly batch scheduler
     Active: active (running) since Mon 2026-04-13 02:00:04 UTC; 6h ago
```

```c
#include <stdint.h>

uint16_t crc16(const uint8_t *data, size_t len) {
    uint16_t crc = 0xFFFF;
    for (size_t i = 0; i < len; i++) {
        crc ^= data[i];
        for (int b = 0; b < 8; b++)
            crc = (crc & 1) ? (crc >> 1) ^ 0xA001 : crc >> 1;
    }
    return crc;
}
```

```java
public record Invoice(String number, List<Line> lines) {
    public BigDecimal total() {
        return lines.stream().map(Line::amount).reduce(BigDecimal.ZERO, BigDecimal::add);
    }
}
```

```kotlin theme=dark
data class Reading(val sensor: String, val celsius: Double)

fun List<Reading>.hottest(): Reading? = maxByOrNull { it.celsius }
```

```html
<article class="card">
  <h2>Northwind Freight</h2>
  <p>Same-day dispatch before <time datetime="14:00">14:00</time>.</p>
</article>
```

```css
.card { border-radius: 12px; padding: 1rem 1.25rem; box-shadow: 0 1px 3px rgb(0 0 0 / 0.2); }
.card h2 { margin: 0; font-size: 1.125rem; }
```

```toml theme=light
[server]
host = "0.0.0.0"
port = 8080

[limits]
max_upload_mb = 25
```

The last block is tagged `theme=light`. Switch the whole document to dark and the untagged blocks follow, the two `theme=dark` blocks stay dark, and the `theme=light` block stays light.
````
