How to keep whitespace formatting

I think I might be close to a solution.
I think the problem with using monospace alone is that whitespaces donโ€™t have the same width as other characters. Therefore, it would be optimal to replace whitespaces with

<span style="width: 1ch;"> </span> in order to let it have the same width as other characters.

st.code does not have unsafe_allow_html, so I tried putting the chessboard between a bloc of three backticks and using st.write. I set unsafe_allow_html=True and replaced whitespaces inside the code block, but now I get the whole HTML as text within the code block. This is because, for some reason, โ€œ&ltโ€ and โ€œ&gtโ€ are put in the HTML instead of the tags.
I guess, it is not possible to insert HTML inside a code block, but at the same time I need a code block in order to preserve the whitespaces.
However, thank you a lot for your previous answers. Do you have any idea on how I could move on?