Writing Dialogue/Dialog on the Web
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.
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.
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…
Mike Cherim responds:
Posted: December 4th, 2006 at 6:08 pm →
Good question, Blair. I “Googled” it but I couldn’t find anything that could answer that. I guess it would be useful, but with my last attempt to make an official recommendation and feeling like an outsider in a big way I’m afraid to bring it up.
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!
Mike Cherim responds:
Posted: December 5th, 2006 at 7:04 pm →
Thanks Elliott. Concerning the suggestion for shorter shorthand: Wouldn’t that be the same as 10px on top and 0px in all other directions? I also wanted to have 10px on the bottom. Maybe I’m wrong on that, though. I’ve never been real good at using shorthand CSS. It’s something I need to brush up on more.
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.:
You may find these helpful as well:
Efficient CSS with shorthand properties
CSS Shorthand
Mike Cherim responds:
Posted: December 8th, 2006 at 12:26 am →
Thanks Kravvitz. I just learned something!
I do know some shorthand. I use the techniques for backgrounds, colors, and sometimes font property values, but I didn’t know the rule you quoted that when there is only two margin/padding values the margin-right was skipped in favor of the top and then bottom first. I always thought it was first is top and the second is the rest. That’s good stuff and I appreciate you pointing it out and providing the reference links.
So much to know, so little time