Asked • 04/21/19

<code> vs <pre> vs <samp> for inline and block code snippets?

My site is going to have some inline code ("when using the `foo()` function...") and some block snippets. These tend to be XML, and have very long lines which I prefer the browser to wrap (i.e., I don't want to use `<pre>`). I'd also like to put CSS formatting on the block snippets.It seems that I can't use `<code>` for both, because if I put CSS block attributes on it (with `display: block;`), it will break the inline snippets.I'm curious what people do. Use `<code>` for blocks, and `<samp>` for inline? Use `<code><blockquote>` or something similar?I'd like to keep the actual HTML as simple as possible, avoiding classes, as other users will be maintaining it.

1 Expert Answer

By:

Jeffrey P. answered • 02/02/21

Tutor
4.9 (81)

Html Tutoring.

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.