home ~ main site ~ other sites ~ podcast ~ mastodon

Center A <pre> Tag

Centering a <pre> tag in another element can be done by making the parent element use `display: grid;` and then `justify-self: center;` on the <pre> tag itself. For example, this HTML:

<div id="wrapper">
  <pre id="theCode">This is the content</pre>
</div>

and this CSS:

#wrapper {
  display: grid;
}
#theCode {
  justify-self: center;
}

produce this result:

This is the content

Notes