6

Spurred by this question, which uses code blocks to format a table in a more aesthetically pleasing way than any other formatting option available.

There has been discussion in the past about using code ticks for emphasis, and why it's not a great idea, but nothing about using code blocks or code ticks for reasons other than emphasis. I didn't see a distinction between the two uses, but let's clear it up once and for all.

Backticks and code blocks are both turned into <code></code> tags. Is it okay to use them when not highlighting code, but to make use of the fixed-width formatting in tables and similar constructs?

4
  • About tables -- SE uses markdown, correct? Markdown has tables, so does SE implement that?
    – Restioson
    Nov 5, 2017 at 16:54
  • 1
    @Restioson SE does not implement tables as far as I'm aware. Nov 5, 2017 at 16:57
  • Ah, a shame... many things 'support markdown' but really only support italics, bold, and underline.
    – Restioson
    Nov 5, 2017 at 17:01
  • Yup, only SO used to support tables in some areas
    – dly
    Nov 6, 2017 at 9:45

2 Answers 2

10

If you're really super concerned about semantic markup, you can use <pre></pre> tags, which carry no implication that the preformatted text is code. Personally, I don't care that much.

As for the actual fixed formatting, whether created through <pre>, <code>, backticks, or 4-space indentation, that has never been restricted to code. It's useful for anything that needs exact preservation of spacing and special characters, most notably error messages. There's no reason to restrict it to code.

Note that since the original posting of this question, Stack Exchange has added support for actual table markup, so you don't need to use <pre> to emulate a table.

7
  • 3
    I definitely like the idea of using <pre>, but I disagree with saying they are all meant to be used in the same cases. <pre> is simply preformatted text, while <code> has semantic meaning and should really only be used for code. As the name implies. Nov 1, 2017 at 21:52
  • @DanmakuGrazer: I didn't say they're meant to be used in the same cases. Nov 1, 2017 at 22:09
  • 2
    Then clarify your answer. You said you don't care about the distinction and that there's no reason not to use <code> even though <pre> would be the correct one. Nov 1, 2017 at 22:13
  • 2
    @DanmakuGrazer: I'm not sure how you're getting the "no reason" part of that. I've said that I don't care that much, which is a statement about my own personal level of caring, but I haven't said the other stuff you're attributing to me. (Also, I care somewhat, but I care more about how easy the post is to compose and edit, and <pre> tags make it harder because HTML parsing still applies within them.) Nov 1, 2017 at 22:20
  • 1
    Then, again, clarify your answer. That's how I'm interpreting your second paragraph. Nov 1, 2017 at 22:24
  • 1
    +1, Backticks and indented-blocks are problematic because they convert to <code> under the hood. Explicitly using <pre> prevents that problem while also preserving the formatting. That's probably the best we can do for tabular data until we get a version of markdown that supports tables...
    – Robotnik Mod
    Nov 2, 2017 at 9:38
  • 2
    Personally I don't mind the use of code tags for other preformatted text -- however, I do believe that it is worth noting that semantics matter. They may not matter to you or me, but they may matter to other people, and from an accessibility standpoint -- if you are blind, code tags may be interpreted differently by your reader or whatever you use. That's why html gives use pre tags as well as code tags, as it gives us strong instead of just bold. So yes, semantics do have meaning, and it does actually matter
    – Restioson
    Nov 5, 2017 at 17:00
-1

My answer would be no; code tags have semantic value and using them with content that is not code is clear misuse. Though not part of StackOverflow's aided formatting, the <pre></pre> tags would be a perfect substitute to <code></code>, since they carry no semantic meaning.

Every argument against backticks in the previous meta is just as valid in this case, as both using code tags for their formatting and using code tags for their aesthetics invalidate the semantic value of the tags.

4
  • Bullets could have been used in the case of the question you have linked in your first paragraph of the question. It would make the page considerably longer, but the length of post should not dictate whether or not it's valid.
    – Timmy Jim Mod
    Nov 1, 2017 at 1:07
  • @TimmyJim I agree, I did edit the list to bullet points originally. But the OP argued that it's not a perfect replacement for tables when you need columns to be aligned, and I agree with that too. The table in the question is probably not the best example, but it is the one that started the discussion. Nov 1, 2017 at 9:14
  • 1
    I agree with you. I was unaware of the screen reader issues. I would love to see another formatting/emphasis method that allows the use of a monospaced font that avoids the problems of using code blocks. I can not think of a good alternative to create a table with several columns using the current methods.
    – IronAnvil
    Nov 1, 2017 at 17:04
  • 2
    +1, Using <code>, or anything that converts to <code> under the hood (i.e. backtics and indent blocks), should be reserved for anything that is a precise text input into a computer. Luckily <pre> uses the same monospaced font & formatting without the semantic mismatch.
    – Robotnik Mod
    Nov 2, 2017 at 9:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .