# Custom code block CSS

**URL:** <https://discuss.write.as/t/custom-code-block-css/11846>\
**Category:** Customization\
**Created:** [April 18, 2024, 11:55am UTC](https://discuss.write.as/t/custom-code-block-css/11846 "2024-04-18T11:55:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![phillip](https://discuss.write.as/user_avatar/discuss.write.as/phillip/32/3699_2.png) [@phillip](https://discuss.write.as/u/phillip)\
**Post date:** [April 18, 2024, 11:55am UTC](https://discuss.write.as/t/custom-code-block-css/11846/1 "2024-04-18T11:55:10Z")

</div>

I’m wanting to customize how a code block looks, but I am having a hard time figuring out how to do this in the CSS. Anyone have an idea of how I can do this? Thanks in advance.

Edit: after not giving up tinkering with the CSS and inspecting the source code in Firefox, I found out that the `body#post pre` and `body#post pre code` need to be specified separately to customize the entire code block. At least they did in my case. Hope that’s helpful for anyone else who stumbles upon this.

---

<div class="post-metadata">

**Author:** ![nigel](https://discuss.write.as/user_avatar/discuss.write.as/nigel/32/3690_2.png) [@nigel](https://discuss.write.as/u/nigel)\
**Post date:** [April 20, 2024, 2:47am UTC](https://discuss.write.as/t/custom-code-block-css/11846/2 "2024-04-20T02:47:45Z")

</div>

`pre` and `code` are the ones you want… found an example that looks like a good place to start. I need to sort code blocks on mine too so good timing 😆

```auto
body#collection pre,
body#post pre,
body#subpage pre {
  max-width:100%;
  margin:0;
  background:#1b1c1d;
  border:1px solid #ccc;
  padding:.375em .625em;
  font-size:.86em;
  -webkit-border-radius:.25em;
  -moz-border-radius:.25em;
  border-radius:.25em
}

body#collection code, body#post code, body#subpage code {
  background-color: #1b1b1b;
  margin: none;
  border: none;
}

.code-block {
  margin:0;
  background:#1b1c1d;
  border:1px solid #ccc;
  padding:.375em .625em;
  font-size:.86em;
  -webkit-border-radius:.25em;
  -moz-border-radius:.25em;
  border-radius:.25em
}

```
