Chapter 28 | cite
, q
, dfn
, abbr
, s
, ins
, and del
Continuing with the text-level semantics journey, today we look at cite
, q
, dfn
, abbr
, s
, ins
, and del
.
cite
The cite
element represents the name of a piece of work. This covers a wide variety of topics. From the docs:
e.g. a book, a paper, an essay, a poem, a score, a song, a script, a film, a TV show, a game, a sculpture, a painting, a theatre production, a play, an opera, a musical, an exhibition, a legal case report, a computer program, etc
The element can be used when the work is mentioned, referenced in detail, or even just in passing. What is important to remember is that only the title of the work is wrapped with the cite
element, not the entire reference. The text that is wrapped also does not have to link to the work being referenced. For example:
|
|
Live Codepen - Using the cite
element
The following example would be an incorrect usage of the element:
|
|
Instead, you would do:
|
|
And you could of course also do:
|
|
q
The q
or quote element represents content quoted from a different source. For example:
|
|
Because the content contained by a quotation element is meant to be phrasing content(part of a larger sentence perhaps), the element is rendered inline and is not a block-level element like the blockquote
. Also, unlike the blockquote
element you do not include your own quotation marks but instead, let the user agent automatically add these.
Live Codepen - Using the q
element
If you know the URL of the source of the quoted text, you can provide the URL to the source via the cite
attribute:
|
|
As mentioned when I covered the cite
attribute previously, a user agent can provide a mechanism by which the user can navigate to the destination specified via the cite
attribute. Currently, however, I am not aware of any that do and the cite
attribute is mainly used for private use(“e.g., by server-side scripts collecting statistics about a site’s use of quotations”).
dfn
The dfn
or definition element represents the first or initial definition of a term. That in itself is a bit vague, so let’s dig in a little more. What is meant by a term here is for example something like the abbreviation HTML. Using the dfn
element we can represent the first definition of this term in a couple of ways. Firstly, in the context of a larger phrase, for example.
|
|
In the above example, the definition element is used to indicate the term being defined by its ancestor paragraph element. Another way the above can be written as follows:
|
|
In this example, the title
attribute is used to provide the definition of the term that is being introduced. It is important to note that when a title
attribute is present, it must only contain the definition of the term. You can also couple the dfn
element with the abbr
element, for example, let’s rewrite the above again slightly:
|
|
Live Codepen - Using the dfn
element
Now the definition element represents the initial definition of the term and the definition is provided by the title
attribute of the abbr
element.
NOTE: If you look at the live example and hover your mouse pointer over the term HTML for the last two examples, you will notice that the browser shows a tooltip with the full definition. However, notice that the
abbr
element also receive special styling by the browser. In most cases, the second example makes the most semantic sense and is the preferred method.
Let’s consider another example. Say we introduce the term HTML as we did above. Several paragraphs later, we use the term again. This is clearly not the initial definition so, we will not use the dfn
element.
|
|
In the above example, this is most likely more than enough but, should you wish to give a user an easy way to get to the initial definition within its larger context, you can use an anchor link with a fragment identifier as we have discussed before. Let rewrite the last example to demonstrate this use case.
|
|
Clicking the link inside the h4
element will take the user to the initial definition of the term within its larger context.
Live Codepen - Using the dfn
element in a larger context
abbr
After the previous section, this element needs no introduction. 🤪 The abbr
element represents an abbreviation or acronym. While not common, you do not have to provide an expansion of the abbreviation via the title
attribute. Both of the abbreviations in the following example are valid ways to markup an abbreviation or an acronym.
|
|
Live Codepen - Using the abbr
element
Generally though, if you do not intend to provide an expansion for the abbreviation or acronym, there is no need to mark it up using this element.
s
aka strikethrough element
The s
element represents content that is no longer relevant or accurate. While its contents are rendered with a strike through, it’s not meant to be used to indicate document edits. There are specific elements for those use cases which we will discuss next. This element is more appropriate for instances such as the following:
|
|
Live Codepen - Using the strikethrough element
del
and ins
While not under the heading of text-level semantics but under the sub-heading “Edits”, I thought it an opportune time to discuss these two elements here. The basics around these two elements are self-explanatory. You use the del
element to represent a deletion and the ins
element to represent an addition. For example:
|
|
In the example, we indicate that the var
keyword was removed(visually indicated with a strikethrough) and replaced by the const
keyword(visually indicated by an underline). For both elements, you can go a step further.
|
|
Live Codepen - Using the del
and ins
elements
Here we are using the two common attributes for both elements to:
- Provide a link to a document(pull request in this case), that explains the reason for the change. As with other elements that support the
cite
attribute, user agents can provide a means for the user to navigate to the URL but none currently do. - Provide a date and optional time on which the changes were made. The value of the
datetime
attribute needs to be a valid date, or date and time string. as with thecite
attribute, the information is not exposed by the user agent in a meaningful way. It would be up to the developer to extract and display the information if relevant.
Due to the way implied paragraphs are defined, always explicitly mark up paragraphs using the paragraph tag. This allows you to indicate the removal and/or addition of multiple paragraphs without creating confusion.
|
|
You can read additional information regarding the above on the specification page.
When it comes to lists, you cannot wrap a list item or multiple list items with either of these elements as they are not allowed to be children of the ordered or unordered list parent elements. For lists then, you need to wrap the contents of each list item. For example:
|
|
Live Codepen - Using the del
and ins
elements with lists
That was a lot to cover, and it leaves us with only 4 remaining text-level elements which we will cover in the next chapter.