I have a sketch that I want to put up on my website, and I also intend to write a short play at some point which I'd also want to make freely available.
I'm trying to work out the best way of representing this in HTML. I basically need two columns - one for the character speaking, and one for the text. Each speech obviously needs to line up with the speaker though. In other words, something like this:
Jeff This sure is a nice website we've got now. Joel It certainly is. By the way, working at FogCreek rocks. Jeff Of course it does. Have you played Rock Band yet? It's a lot of fun.
(Well it's better than lorem ipsum...)
I know how I could do this with HTML tables (with one table row per speech) but that seems pretty ugly, and everyone certainly seems to be keen on using CSS to represent non-tabular data. I can't see how this really counts a tabular data - my use of "row" and "column" earlier was to do with the layout rather than the fundamental data.
So, any ideas? I think most of the script websites I've seen (not many, admittedly) either use <pre>
like my example above, or don't bother trying to keep the normal script format, instead just prefixing each paragraph with the speaker's name. (See the podcast wiki for an example of this style.) I'm having trouble working out even what HTML elements I should be using to represent this, frankly - a dictionary definition list with the speaker as the term and the speech as the definition is probably the closest I've thought of, but that feels like abuse.
HTML 5.2 recommendation for conversations
Example conversation with minimal markup
CSS for the conversation
I would just use div elements in this case, with nice classes describing the domain. You could argue up and down about using all kinds of HTML elements that give a better semantic meaning of intent, but for instance in the case of the dialog element, that is not intended for writing dialogs between characters in a play, it is however intended to present a dialog box to the user for interacting. But the fact that you can change and style that element to your hearts desire in CSS is nifty - but I would not recommend doing so.
The reason for that is simply that unless you are careful, you override that behavior and appearance for every such element. Let's say this is an interactive application for playwrights, you may want to include dialog boxes in addition to the "dialog" in the play.
I propose this solution:
With the following HTML:
Running JSFiddle: https://jsfiddle.net/quz9cj2f/6/
Now you can actually implement some standard play formatting, that I nicked from this place: http://ptfaculty.gordonstate.edu/lking/CPF_play_formatting2.pdf
With this HTML:
Working JSFiddle: https://jsfiddle.net/quz9cj2f/9/
Or you could go all in and use CSS attribute selectors and create a custom attributes for the meta information:
Now you have gotten rid of the extra elements, and added the meta info as attributes - now you could quite easy transform this from some kind of nice data structure from JSON or XML or other interchange formats into this:
https://jsfiddle.net/quz9cj2f/11/
More proper (semantically) and shorter would be to use definition lists:
IMO that actually is tabular data. First column is speaker, second column is text.
If you want to be fashionable and aggressively eschew tables, though, what I believe is compliant with what the Web mavens are dictating this season is a structure like:
Then you control how that lays out with appropriate CSS.
If it looks like you're basically writing XML and using CSS to specify how it lays out, well, that's because that's what the Web mavens believe you should be doing, AFAICT.
I'd say
as defined in HTML5.
Of course, you'll need a
<script>document.createElement('dialog');</script>
to get IE to do something sensible and adialog { display:block; }
in your CSS to get it to work completely.You're not going to get a definitive answer to this question as HTML has many gaps, one of which is this - there are some very solid articles dotted around the web about his subject and a good place to start would be Bruce Lawson's article from 2006.
Considering that there is no answer to the question, the best we can do is look at what elements that are available to us and make our own compromises based upon our (and the communities) interpretation of the guidelines.
I personally like the
cite
/blockquote
and data list route. I know that data lists smack of none semantic markup, but I truly believe that the intent of data lists isn't to list data definitions purely in a dictionary fashion, but to pair data whereul
s andol
s can't.I've spent a lot of time thinking about semantics, and one thing I (as well as most others in the field) am sure of when looking at all questions of markup is that tables are not the answer to 99.9% of markup questions (if it's not tabular data where you can use
th
,caption
then tables should really be dropped from your inventory). That said, I would also say that exclusively usingdiv
s is also probably not the right answer.I very much doubt that the up-votes in this question will reflect the best approach, but will more likely reflect an agreement to the approach base upon the voters current knowledge and use of HTML.