Marking up blocks of code

Paul Hammond is wondering how to mark up blocks of code in HTML. He references a few methods, such as <pre>...</pre>, or <p><code>...</code></p>. His worries with the first method are that preformatted text destroys layouts, and that it’s an uneasy mix of presentation and markup. I can’t help the first, but I’m more prepared to have a layout broken than I am to have code break onto two lines, since an awful lot of languages are intolerant of that sort of thing. My solution to this when I post code blocks is <pre><code>...</code></pre>. I’ve seen people set \<code> to display: block in stylesheets, but that breaks if you want to write some code inline (as with that little CSS snippet just there).


I'm currently available for hire, to help you plan, architect, and build new systems, and for technical writing and articles. You can take a look at some projects I've worked on and some of my writing. If you'd like to talk about your upcoming project, do get in touch.

More in the discussion (powered by webmentions)

  • (no mentions, yet.)