When writing my own posts I have been using <element> (using <> and inline code quotes) to refer to elements inline. I will sometimes add element after it as well (e.g. <div> element). I think it makes it easier to read and stands out in titles better. If I'm just referring to what the element is, and it has an English word associated with it, I'll use that instead. Here's an example from a recent answer of mine:

If the image is just a way to make a button visually pleasing, use CSS background-image to style the <button> (and don't use an <img>).

Here I referred to the image and the button, but when I got the the code part of it (assigning styles), I used the <element> format. If it doesn't have a common English equivalent, like <div>, I will always use the <element> format. Pluralization can be awkward and I vary between: <divs>, <div>s, and <div> elements.

My question is about editing other's posts. I don't usually edit posts just for formatting unless it's really bad, but when I do edit a post I try to fix all the formatting to at least be consistent across the post. I don't really want to impose my formatting preferences on posts I edit and would rather use a more standard and accepted method (which I'll happily adopt for my own posts) if one exists. I currently try to use what the OP used most often and format the rest to match.

I always want to change these (especially in titles):

  • First letter capped (Div, Img)
  • All caps (DIV, SPAN, P)
  • Non-word elements with no <> or code quotes (div, p)

Is there a preferred format for inline HTML?

  • <div> is a division, no? That's what I call them. – animuson Dec 31 '11 at 0:27
  • @animuson You say (in a post), "You might want to add width: 100px to all your divisions."? That's a pretty uncommon way to refer to a <div>. – ThinkingStiff Dec 31 '11 at 0:29
  • @animuson Either way, if you were editing a post and someone wrote div in a sentence, with no other formatting, would you change it to division? – ThinkingStiff Dec 31 '11 at 0:35

I'd say it completely depends on the context of the post, and whether the "div" is the emphasis or just a reference. If I'm just using a division (yes, I do use the full word frequently) with my code, but that's not the focus of the post, it really doesn't matter. I would definitely just leave that as "div".

Use cases:

  • DIV or Div - Makes it look like an acronym, to be honest. It's not an acronym, it shouldn't be in all uppercase letters. Whenever you're using the shortened form of an element, it really should be in lowercase. Namely, because the HTML standards recommend that all lowercase letters be used, and XHTML demands that all lowercase letters be used. It's very odd to see elements with one or more uppercase letters. However, something like Acronym would be acceptable because the element and full name are equivalent, it doesn't really matter. Although if it were enclosed as <acronym> it should be in lowercase letters.

  • &lt;element&gt; - Change them. The only reason people ever do this is to make the characters work outside of inline code, when they really should just be using the inline codes. Anytime the < and > characters actually appear, they should be enclosed in an inline code. However, you do have a judgement call. Going along with the context I've been talking about, you can change this in one of two ways: making it plain text without the brackets or making it an actual inline code block.

  • Just plain div - This is where you really need to read the context of the post. I don't see anything wrong with people using "div" as a word for the element. In many cases if they didn't include the brackets around it, it's because the context in which the word appears does not place any emphasis on the use of that element. The question could be about JavaScript, wherein the only reason they mentioned "div" was to say that they were trying to edit the content, which happened to be inside a div. In this case, no, it doesn't need to be modified to be an inline code block because it serves no purpose that way. And thus, we have come to the root of the issue. If making it an inline code doesn't serve any purpose to the overall question, don't worry about it. It really only needs to be inline code if the question is about a division in particular.

  • <divs> - Don't edit these. It's clear they're talking about divisions (plural). Editing it to make it "<div>s" or "divisions" will serve absolutely no purpose other than conforming to the personal standards of the editor. As long as they are formatted appropriately for the context of the post, there is nothing wrong with their preference of pluralization, and Jeff might knock at your door for submitting an edit which only addresses a pluralization problem.

Possible exceptions:

  • Elements that are confused with other words, such as <command> should be formatted into inline code or make sure it says "command element" so people aren't confused. In these cases, the inline code serves to show that we're talking about the element, and not the word. If I asked "How do I use command?" no one would know what I was talking about. Again, take it with the context around it. If the context around it specifically emphasizes that they're talking about the <command> element already, then leave it be.

  • Short, one-lettered elements such as <a> and <p> should be inline coded because they're only one letter and are harder to notice within a block of text. I've never seen someone use <a> as just a letter "a" because that would be confusing as hell. I would probably do this for two-letters elements as well, just out of personal preference and only if there were other edits to be made as well.

Questions to ask yourself:

  • Does the way it's currently used make sense to you?
  • Is the element in question important to the overall question at hand, or just a reference?

Also, think about the opposite. If an element has been made into inline code, think about if it needs to be formatted that way.

  • Does (or would) this inline code block draw attention away from more important information in the post?
  • All great points and inline with where my thoughts are on this. I like the last two points best. Clarifying and/or not distracting from the core focus of the post makes the rest of it fall into place. One key thing I noticed from the total lack of interest in this question is that, while I'm a stickler for formatting/consistency, most people don't really care. – ThinkingStiff Dec 31 '11 at 1:41
  • I sometimes complain about edits people make in the comment area for the edit I make over theirs; not that people will ever actually read them though. – animuson Dec 31 '11 at 1:44

You must log in to answer this question.

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