Writing Dialogue/Dialog on the Web

Posted December 1st, 2006 by Mike Cherim

The end is near, but the beginning is clear Is the dialogue (dialog) class semantic? Is it proper? I don’t know, but it’ll look right when writing dialogue on the web. Stories and other works are well served with a dialogue style paragraph. It’s ubiquitous in written works and literature throughout the print world so it serves the reader well to carry this style over to the web. According to William Strunk of Strunk and White’s The Elements of Style fame — which is arguably the authority on proper writing, a paragraph is a “unit of composition,” but when writing dialogue, it’s each unto its own, so to speak.

“In dialogue, each speech, even if only one word, is usually a paragraph by itself; that is, a new paragraph begins with each change of speaker.” The Elements of Style
Fourth Edition, Page 16, 4th Paragraph

How would that look on the web? Let’s see:

“Time is running out; the end is near,” shouted the doomsayer.

“Don’t be a fool, old man,” the businessman replied.

“But I have heard the prophets speaking of—” the doomsayer began.

“Ah, shut up, profits are what I know best! What manner of fool are you out here on the street being a prognosticator of Armageddon? Are you an idiot? Get a job,” the businessman scolded, cutting the old man off.

“But…” the doomsayer said, then stopped.

Pretty spaced out isn’t it? If books were written like that printing costs would go through the roof, especially those with a lot of dialogue. Many trees would needlessly die. In books the “paragraphs” of dialogue contain no spaces — padding or margin — above or below. These are dense paragraphs to save space and add to the readability.

So let’s take that to the web, being sure to add indentation to better mark the beginning of each new dialogue unit or paragraph. Like this:

“Time is running out; the end is near,” shouted the doomsayer.

“Don’t be a fool, old man,” the businessman replied.

“But I have heard the prophets speaking of—” the doomsayer began.

“Ah, shut up, profits are what I know best! What manner of fool are you out here on the street being a prognosticator of Armageddon? Are you an idiot? Get a job,” the businessman scolded, cutting the old man off.

“But…” the doomsayer said, then stopped.

So how was this done? Well aside from the cool box I used this mark-up:


<p class="dialog">"Time is running out; the end is near," shouted the doomsayer.</p>
<p class="dialog">"Don't be a fool, old man," the businessman replied.</p>
<p class="dialog">"But I have heard the prophets speaking of---" the doomsayer began.</p>
<p class="dialog">"Ah, shut up, profits are what I know best! What manner of fool are you out here on the street being a prognosticator of Armageddon? Are you an idiot? Get a job," the businessman scolded, cutting the old man off.</p>
<p class="dialog">"But..." the doomsayer said, then stopped.</p>

And I used this CSS:


p.dialog {
  text-indent : 20px;
  margin : 0;
  padding : 0;
}

This is a fine solution if writing a few lines of dialogue now and then, but if writing a lot of the stuff, it’d be better to containerize it, like so:


<div class="dialog">
 <p>"Time is running out; the end is near," shouted the doomsayer.</p>
 <p>"Don't be a fool, old man," the businessman replied.</p>
 <p>"But I have heard the prophets speaking of---" the doomsayer began.</p>
 <p>"Ah, shut up, profits are what I know best! What manner of fool are you out here on the street being a prognosticator of Armageddon? Are you an idiot? Get a job," the businessman scolded, cutting the old man off.</p>
 <p>"But..." the doomsayer said then, stopped.</p>
</div>

Then add some CSS to style the paragraphs within the .dialog-classed container. Like so:


div.dialog p {
  text-indent : 20px;
  margin : 0;
  padding : 0;
}

It’s a simple solution. Spacing the bodies of dialogue will still be separate from your regular paragraphs because those paragraphs will still offer their default margin and padding. If you have your paragraphs styled differently from the default removing this normal spacing, just be sure to add some margin-top and margin-bottom to the dialog container. Like this:


div.dialog {
  margin : 10px 0 10px 0;  /* Top, Right, Bottom, Left */
}

If styles are unsupported, the user will get the spaced out paragraphs or units, but it will still be proper.

“Happy writing,” Mike said.


7 Responses to: “Writing Dialogue/Dialog on the Web”

  1. Adam H responds:
    Posted: December 1st, 2006 at 2:21 pm

    Huh, so simple yet so markedly interesting. Typography on the web has come a long way and yet is still, at best, terrible. This type of simple semantic advice is much appreciated, Thanks.

  2. Blair Millen responds:
    Posted: December 4th, 2006 at 5:35 pm

    Yeah, it’s a step in the right direction Mike. I’m wondering if (X)HTML5 will have some new tags to accomodate dialogue etc…

  3. Elliott Cross responds:
    Posted: December 5th, 2006 at 6:35 pm

    Great idea! I hadn’t thought much about that before, but you bring out a great point. I will keep it in mind for consideration to clean up some of my sites. One thing though is the last margin you set in the example could use shorthand of margin: 10px 0 to reduce the size. I know it might not add up in a small site, but in a larger site it really helps. I have been reworking my CSS and it does make a difference in the overall size and organization of the elements.

    Great work!

  4. Kravvitz responds:
    Posted: December 7th, 2006 at 11:45 pm

    Mike, I’m surprised you don’t know the shorthand values.

    This is an excerpt from the CSS2 specs.:

    If there is only one value, it applies to all sides. If there are two values, the top and bottom margins are set to the first value and the right and left margins are set to the second. If there are three values, the top is set to the first value, the left and right are set to the second, and the bottom is set to the third. If there are four values, they apply to the top, right, bottom, and left, respectively.

    You may find these helpful as well:
    Efficient CSS with shorthand properties
    CSS Shorthand

Sorry. Comments are closed.




Note: This is the end of the usable page. The image(s) below are preloaded for performance only.