There's gotta be a better way to do this....<br>

I’m trying to put some code in <code>, but have it also keep its format. I’ve googled and found someone recommending using <span>. Is there a better way of doing this without using <br>?
This is what I’m dealing with…

You could try putting the code in a <textarea> element?

// Code here

Is how you should do it. The preformatted text tag (pre) is how you indicate that the text should be rendered as-is, retaining the formatting you want (you can also use CSS’ white-space rules if you’re doing something wierd, but 99.9% of the time, pre and code tags)

For inline code, just the code tags, for blocks of code, the pre and the code tags

Edit: also,

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

Please use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks are not single quotes.


1 Like