I'm trying to figure out the most semantic way to markup something like this.
John: blah blah
Paul: blah blah
George: blah blah
Ringo: blah blah
or
John: blah blah
Paul: blah blah
George: blah blah
Ringo: blah blah
Ideally there'd be the CSS flexibility to do either or to break it into a paragraph with or without the names visible. I considered using the before:
selector to add the names, but I also want them to be linkable. For example, I'd link to Ringo's twitter profile if he had one. It also should read properly in screenreaders.
We write semantic markup by selecting and using HTML tags properly, and by selecting tags that convey something about the information marked by the tags. There are elements in HTML that are semantic and elements that are non-semantic. Examples of non-semantic elements are div and span .
Semantic Markup refers to marking up documents in ways that provide information about the content itself rather than information about the visual styling of the content. It is critical to ensure that assistive technology users can understand your document.
Semantic markup is a way of writing and structuring your HTML (Hypertext Markup Language) so that it reinforces the semantics, or meaning, of the content rather than its appearance.
The HTML5 spec discusses this, the gist of which is:
Authors are encouraged to mark up conversations using
p
elements and punctuation. Authors who need to mark the speaker for styling purposes are encouraged to usespan
orb
. Paragraphs with their text wrapped in thei
element can be used for marking up stage directions.
So, ultimately, something like this:
<p><span>John:</span> blah blah</p>
<p><span>Paul:</span> blah blah</p>
<p><span>George:</span> blah blah</p>
<p><span>Ringo:</span> blah blah</p>
This would enable styling in the way you describe. You could, of course, also add class
attributes if necessary. Your instinct not to put the names in CSS with the :before
selector is a good one--this information should definitely be in the markup.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With