CSS – HTML5 Doctor http://html5doctor.com helping you implement HTML5 today Mon, 11 Jul 2016 11:54:15 +0000 en-US hourly 1 Comparing and contrasting ins, del, and s https://stevefaulkner.github.io/html5doctored/ins-del-s/ https://stevefaulkner.github.io/html5doctored/ins-del-s/#comments Tue, 20 Aug 2013 13:30:34 +0000 http://html5doctor.com/?p=5086 Since the mists of HTML 2 we’ve been able to semantically indicate added or removed information using the elements <ins> and <del> respectively. While seemingly simple on the surface these elements have hidden depths. I’ll also compare and contrast <del> with <s>, recently out of font style rehab and back in HTML5. Let’s start with <ins> and <del>…

]]>
Since the mists of HTML 2 we’ve been able to semantically indicate added or removed information using the elements <ins> and <del> respectively. While seemingly simple on the surface these elements have hidden depths. I’ll also compare and contrast <del> with <s>, recently out of font style rehab and back in HTML5. Let’s start with <ins> and <del>…

Using ins and del

These two elements have very simple definitions:

The ins and del elements represent edits to the document.

The ins element represents an addition to the document.

The del element represents a removal from the document.

— WHATWG HTML Living Specification

So what kind of edits are we talking about? You could use these elements to:

  • Record changes to an official document, such as meeting minutes or a law
  • Note changes to an article — in addition to journalistic corrections, this helps to maintain editorial integrity and avoid charges of “rewriting history”
  • Indicate the changes between two versions of a document (a diff), for example to indicate editorial changes
  • Indicate a signficant addition or removal of content that people accessing the document would benefit from knowing about

While some uses require recording changes exactly, when you’re just highlighting a change I think minor editing for clarity or grammar is fine — as long as the meaning isn’t changed. If necessary consider adding a note describing the change, perhaps in a footer or aside. Also, keep in mind that it rapidly becomes impractical (or impossible) to mark up all edits — only use these elements when there’s a benefit in explicitly indicating them.

“Implied paragraph bondaries”

<ins> and <del> are unusual in that they can contain contain phrasing content or flow content (in HTML 4-speak, they can be inline or block-level). For example, here’s an inserted paragraph that contains a phrasing content deletion:

<!-- block-level ins -->
<ins>
  <!-- inline del -->
  <p>Today I saw <del>flying monkeys</del> the doctor. The prognosis was not good.</p>
</ins>

Note that browsers will style these elements as inline by default, and you’ll need to include display: block; if you want to apply block-level styling. We’ll cover this later in the article.

The spec warns that the elements “should not cross implied paragraph boundaries”. These occur when there’s phrasing content (= text or inline elements) without a block-level element wrapper as a sibling of a block-level element. For example:

<div>
  <p>This text is in a block-level element.</p>
  <!-- implied paragraph boundary here -->
  Oh snap! Someone forgot the paragraph tags!
</div>

Of course, we always wrap our text, so this would never happen to us! But still, now you know ^_^

We also need to make sure each <ins> or <del> element is either inline or block-level, but not both. For example, don’t start in the middle of one paragraph and end in the middle of the next.

<!-- This is wrong -->
<p>Flying monkeys are <del>a common hazard.</p>
<p>Protect yourself by</del> screeching loudly.</p>

<!-- del as inline -->
<p>Flying monkeys are <del>a common hazard.</del></p>
<p><del>Protect yourself by</del> screeching loudly.</p>

<!-- del as block-level -->
<del>
  <p>Flying monkeys are a common hazard.</p>
  <p>Protect yourself by screeching loudly.</p>
</del>
<p>Flying monkeys are screeching loudly.</p>

datetime and cite attributes

The <ins> and <del> elements can also take two optional attributes, datetime and cite. You’ll be familiar with datetime from our article on the <time> element, and it works just the same here. Use it to record the date (and optionally the time) of the edit:

<p><del datetime="2012-09-13">Todo: add a datetime example here.</del>  <ins datetime="2012-09-14T10:21:44+09:00">This inserted text has the date and time it was added indicated via the datetime attribute.</ins></p>

cite will also be familiar if you’ve read our article Quoting and citing with blockquote, q, cite, and the cite attribute. It contains a URL linking to more information about the change.

<!-- Reference or in-page links are URLs too -->
<ins cite="#ins-1">This inserted text has a cite attribute, with a link to more information.</ins>

As this is generally hidden data, there’s a strong chance of it becoming metacrap. You can help avoid this by exposing cite with CSS:

<style>
ins[cite]:after,
del[cite]:after {
  content: " (" attr(cite) ")";
  font-size: 75%;
  line-height: 0;
  color: #888;
}
</style>
…
<ins cite="https://stevefaulkner.github.io/html5doctored/more-info/123">[Inserted text…] More information is available about this addition.</ins>

[Inserted text…] More information is available about this insertion.

Example CSS to append the cite attribute’s value as generated content.

Even better, consider adding this link as content, for example:

<ins>This is an article update<a href="#ins-1">¹</a>.</ins>
…
<footer>
  <h2>Article changes</h2>
  <ol>
    <li id="ins-1">This addition was added on <time datetime="2012-09-14T10:21:44+09:00">14th September 2012</time> by Oli Studholme.</li>
  </ol>
</footer>

Finally, make sure when using <del> that this is a removal from the document you want/need to indicate. Other options include commenting the content out using <!-- -->, or deleting it from the HTML source.

The s element

The specification describes the <s> thus:

The s element represents contents that are no longer accurate or no longer relevant.

— WHATWG HTML Living Specification

Historically <s> (and the obsolete <strike>) were font style elements, and they were deprecated in HTML 4, then dropped in HTML5. However, a couple of semantic use cases have seen <s> return. These include marking up the original price when something is on sale, and indicating a time limit that has passed, such as early bird tickets for an event. This is content that provides useful information so we don’t want to delete it, but it’s not accurate and we want to indicate this. Other uses include any outdated but still relevant information that isn’t the result of an edit. The <s> element could even arguably be used for indicating sarcasm, or for marking up examples of Sous rature for all you Jacques Derrida fans out there. Well… maybe ;-).

As an example, if Kickstarter used <s>, it might look like this:

Using the <s> element to semantically indicate when a limited pledge is full

s vs del: fight!

The <s> element seems dangerously close to stepping on the semantic toes of <del>, as I’m sure someone will helpfully point out in the comments :) However, there is a subtle but significant difference. <ins> and <del> are for showing editorial changes, generally to an already published page. The <s> element is for indicating information that is no longer relevant or accurate, but still provides some value, and is generally used to create a document with both old and new information at the same time.

Hixie describes the difference in this way:

[T]o put it another way, with <del> there is usually a view of the document that doesn’t include the <del> text. But with <s> there is no version of the document without the <s> text, because the <s> text is part of the document still, it’s just that it’s marked as old.

— Ian Hickson in the WHATWG IRC channel

Styling ins, del, and s

The browser default styles are:

  • <ins>: text-decoration: underline (default inserted content)
  • <del>: text-decoration: line-through (default deleted content)
  • <s>: text-decoration: line-through (default strikethrough content)

By using underline, the default <ins> styling is very similar to a visited link, a classic usability blunder. Worse, the default <del> and <s> styles are identical (although it’s rare that you’ll use them together). However, as long as <s> is visually distinct from <del>, I’ve found the default text-decoration: strikethrough; style of <s> ends up being what you generally want.

Phrasing ins and del styling

Here are some styles I’ve used for <ins> and <del> in the past:

ins styling

  • Normal text with green underline (example inserted content)

    ins {
      border-bottom: 1px solid #47ad09;
      text-decoration: none;
    }
  • Green text with faint underline (example inserted content)

    ins {
      border-bottom: 1px solid #ccc;
      text-decoration: none;
      color: #388807;
    }
  • Normal text with a light green background color (example inserted content)

    ins {
      text-decoration: none;
      background-color: #d4fcbc;
    }

del styling

  • Gray text (example deleted content)

    del {
      text-decoration: none;
      color: #777;
    }
  • Red text (example deleted content)

    del {
      text-decoration: none;
      color: #91081f;
    }
  • Normal or gray text with a light red background color (example deleted content)

    del {
      text-decoration: none;
      background-color: #fbb6c2;
      color: #555;
    }

Check your <ins> styling can’t be mistaken for a link. Make sure that if you only use color to differentiate, that these are easily distinguished, even for the colorblind. Avoid hiding <del> content with display: none; — if it’s no longer content remove it or comment it out. Differentiate <del> from <s> if you use both elements.

Finally, I prefer to avoid using text-decoration: line-through; for <del>, as it makes the text hard to read. When it comes to <s> however, this default style seems to be the best fit, which is just as well because nothing else seems appropriate.

Flow ins and del styling

By default, <ins> and <del> are treated as inline elements by browsers, and styled as such. If you want to use block-level CSS, you’ll need to apply display: block;. Also, even the nicer styles above can be a little strong for whole paragraphs of text, not to mention useless for e.g. a block-level image. I style <ins> and <del> for phrasing use, and use classes with overrides for block-level use:

  • Block-level <ins> with green left border
.ins-block {
  display: block;
  margin-left: -1em;
  border-left: 0.5em solid #47ad09;
  /* styles to override inline ins style, e.g.
  text-decoration: none; */
  padding-left: 0.5em;
}

Alice was beginning to get very tired of sitting by her sister on the bank and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, “and what is the use of a book,” thought Alice, “without pictures or conversations?”

  • Block-level <del> with red left border and faded text
.del-block {
  display: block;
  margin-left: -1em;
  border-left: 0.5em solid #91081f;
  /* styles to override inline del style, e.g.
  text-decoration: none; */
  padding-left: 0.5em;
  color: #777;
}

So she was considering, in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her.

You could also append a label:

  • Block-level <ins>: Green border with generated content label
.labeled-ins-block {
  display: block;
  margin-left: -1.25em;
  border-left: 0.75em solid #47ad09;
  padding-left: 0.5em;
}
.labeled-ins-block:before {
  position: relative;
  display: block;
  content: "Addition";
  left: -1.55em; /* adjust to fit */
  top: 5em; /* adjust to fit */
  width: 0;
  height: 0;
  font: 0.6em/0 "Helvetica Neue", Arial, Helvetica, sans-serif;
  letter-spacing: 1px;
  color: #fff;
  -webkit-transform: rotate(270deg);
  -moz-transform: rotate(270deg);
  -ms-transform: rotate(270deg);
  -o-transform: rotate(270deg);
  transform: rotate(270deg);
}

The rabbit-hole went straight on like a tunnel for some way, and then dipped suddenly down, so suddenly that Alice had not a moment to think about stopping herself before she found herself falling down what seemed to be a very deep well.

Finally, WordPress users should note that my nemesis wpautop will laugh at your attempts to use block-level <ins> and <del>. Make sure you use “Format this post with: No Formatting”.

Conclusion

So to sum up, we recommend you use <ins> and <del> for edits to an existing document, but only when indicating these changes is beneficial for those using the page. Use <s> to indicate information that is no longer relevant or accurate, but removing that information would negatively affect the meaning. Make sure to carefully style these elements to avoid confusion with links (for <ins>), and each other (for <del> and <s>). Finally note that <ins> and <del> can be ued for inline or block-level content (although not both at the same time), but <s> can only be used for inline content.

I’ve noticed a trend towards not having dates as part of the article’s URL, with authors then making a concious effort to keep articles up-to-date. If you do this, <del> and <ins> change from being rarely used to quite useful for indicating your edits. On the other hand, <s> seems destined to remain one of those obscure but useful elements that you’ll hardly ever need, but will be glad to have available when you do.

So what do you think? Do you use these elements? Will you use them now? Do you have any other ways you like to style them? Let us know in the comments!

Comparing and contrasting ins, del, and s originally appeared on HTML5 Doctor on August 20, 2013.

]]>
https://stevefaulkner.github.io/html5doctored/ins-del-s/feed/ 12
CSS3 Pseudo-Classes and HTML5 Forms https://stevefaulkner.github.io/html5doctored/css3-pseudo-classes-and-html5-forms/ https://stevefaulkner.github.io/html5doctored/css3-pseudo-classes-and-html5-forms/#comments Tue, 28 Feb 2012 14:30:47 +0000 http://html5doctor.com/?p=4483 Guest Doctor Peter Gasston takes a look at how new CSS3 Pseudo-classes align perfectly with HTML5 Forms.

]]>
Hello! I’m Doctor Peter and I’m here to treat you with a dose of complementary CSS3. Don’t worry, this won’t hurt a bit.

Contrary to what HTML5 Please and the W3C would have you believe, CSS3 is not part of HTML5. “But this is HTML5 Doctor,” I imagine you saying. “Why are you talking about CSS3 here?” Well, I want to talk about a very specific part of CSS3, one that works in perfect tandem with HTML5, specifically with the new form functions that are available.

One of the killer features that HTML5 introduces is client-side form validation without using JavaScript. Now, I know the other doctors haven’t discussed this yet, and as I’m just a locum, you might feel as if I’m putting the cart before the horse (#mixedmetaphors), but I’m hoping to explain just enough to let you know how it works, and then your regular doctors can provide the details at a later date.

A Recap of Pseudo-Classes

A pseudo-class is information about an element that’s in the document tree but not available through any specified attributes. For example, the :first-child pseudo-class applies to elements which are the first child of their parents. You can get that information from the DOM tree, but there’s no first-child attribute.

In CSS2.1, there were a handful of pseudo-classes available, notably the link states (:link, :visited) and those of user actions (:active, :hover). In CSS3, that handful becomes a basketful, with pseudo-classes of structure (:nth-child, :nth-of-type), UI element (:enabled, :checked), and the ones we’ll look at now, of form validation.

Form Validation without JavaScript

So as I mentioned at the beginning, HTML5 introduces client-side form validation without the need for JavaScript. When you attempt to submit a form, your browser will validate all of the fields and return an error if any of the fields is incorrect. This will happen mostly automagically — provided your browser has the capability — and will look something like what’s shown in Figure 1:

Form with an invalid field and associated error message
Figure 1: A form validation error message

Those error messages are browser and OS specific, and hard to modify (which I documented on my blog), but you can change the way the errors appear on the elements themselves with the new validation pseudo-classes, which are part of the CSS3 Basic UI module.

I’ll cover current browser support as we go through the article, but in a nutshell:

  • Firefox and IE10 support some of it.
  • Opera and Chrome support all of it.
  • Safari supports all of it too, but form validation is disabled by default.

That being the case, I’d recommend using Chrome, Opera, or Safari to view the examples I’ll be showing you.

If you want to keep up to date with browser support for form validation, I suggest keeping an eye on When can I use.

So with all of the boring technical guff out of the way, let’s get on with the interesting technical guff and take a look at some examples of form validation.

Required and Optional Elements

One of the most common patterns of validation is that of mandatory (that is, required) values — the fields that the user must complete in order to progress. To mark a form element as mandatory, you need only add the required attribute to it:

<input type="text" required>

If you want to apply styles to this in order to show that requirement, you can use the new :required pseudo-class, which applies rules to any matched element which has the required attribute. For example, you may want to put an asterisk after the text of the label:

input:required + label::after { content: "*"; }

The exact rules you use depends on how you’ve marked up your document. The rule in this example is based on the markup having this structure:

<input type="text" required id="foo">
<label for="foo">Foo</label>

The opposite of required is, of course, optional. And wouldn’t you know it, we have a pseudo-class for that too, logically named :optional. It affects any form element that doesn’t have a required attribute. For example, you may want to make those have a lighter border:

input:optional { border-color: silver; }

You can see this in action in Figure 2, or take a look at a live example.

Required and optional form fields
Figure 2: Input fields styled with :required (top) and :optional (bottom)

Valid and Invalid Elements

There are other types of validation besides simply “required” or “optional”. You can use pattern matching, such as email address validation:

<input type="email">

If the user enters anything into the field, it has to match the pattern of an email address, or else it will be marked as invalid. (Of course, if it’s not required, then it can be left blank.)

You can style valid or invalid form elements using pseudo-classes called — wait for it — :valid and :invalid. Maybe you want add a symbol depending on the validation status:

input:invalid + label::after { content: ' ⨉'; }
input:valid + label::after { content: ' ✓'; }

Note that these will take effect as soon as the page loads, so you’ll probably want to use JavaScript to apply them only after submission, perhaps by adding a class to the form with JavaScript:

document.forms[].addEventListener('submit', function(e) {
  e.currentTarget.classList.add('submitted');
  // Your fallback form validation function
});

The exact script you use will vary, but however you do it, you can use that class to style the form elements, like so:

.submitted input:invalid + label::after { content: ' ⨉'; }

Figure 3 shows the output of this, and you can also see the live example.

Valid and invalid form fields
Figure 3: Showing the use of the :valid (top) and :invalid (bottom) pseudo-classes

Two extra things to note about this example: first, in order to use my own JavaScript, I’ve prevented the form from automatically validating by using the novalidate attribute on the submit button; and second, Firefox puts a coloured glow around elements depending on their validation state, which I’ve over-ruled by using their proprietary :-moz-ui-invalid selector. View the source of the demo to see how these are used.

Number Ranges

Some of the new input types, such as number, allow a range of values using the min and max attributes, like so:

<input type="number" max="10" min="1">

Although form controls will usually prevent the user from entering a value outside of this range, there may be occasions (such as when JavaScript is used to provide values) where the value provided to the input does exceed the range:

<input type="number" max="10" min="1" value="11">

When this happens, you can use the :out-of-range pseudo-class for your styling:

input[type='number']:out-of-range { border-color: red; }

And, as you’d expect, there’s a counterpart known by the name of :in-range:

input[type='number']:in-range { border-color: green; }

In Figure 4 you can see these two pseudo-classes at work, and once more there’s also a live example to view.

Out-of-range and in-range form fields
Figure 4: The :out-of-range (top) and :in-range (bottom) pseudo-classes applied to a range input

Reading and Writing

You may have a form field that’s pre-filled with a value that you don’t want the user to be able to edit, such as terms and conditions in a textarea. If that’s the case, you can add the readonly attribute:

<textarea readonly>Lorem ipsum</textarea>

You can style elements which have the readonly attribute applied, using…can you guess? You are correct, imagined reader: the :read-only pseudo-class. You could combine it with the user-select CSS property to prevent the user from being able to select the text (in the example, I’ve also changed the border style to make it more obvious):

textarea:read-only { user-select: none; }

And if you should need it, there is of course a :read-write pseudo-class for elements which don’t have the attribute applied:

textarea:read-write { user-select: text; }

You can see the results in Figure 5, and as before there’s a live example too.

Read-only and read-write form fields
Figure 5: The textarea on the left is styled using :read-write, and the one on the right, with :read-only

Firefox and IE10 have actually implemented the readonly attribute, but don’t yet have support for these pseudo-classes.

Browser Support

This table lists support for HTML5 Form Validation in browsers at the time of writing:

Browser support for HTML5 Form Validation
Browser/Attribute Chrome Firefox IE Opera Safari
:optional / :required 10.0 4.0 10.0 10.0 5.0
:invalid / :valid 10.0 4.0 n/a 10.0 5.0
:in-range / :out-of-range 10.0 n/a n/a 10.0 5.0
:read-only / :read-write 10.0 n/a n/a 10.0 5.0

That’s All from Me

I hope I’ve given you enough to whet your appetite for finding out more about HTML5 Form Validation. There’s plenty more to it, including a full JavaScript API (you can read about this in the HTML5 spec, but ).

Thanks for your time, and thanks to the Doctors for this opportunity.

CSS3 Pseudo-Classes and HTML5 Forms originally appeared on HTML5 Doctor on February 28, 2012.

]]>
https://stevefaulkner.github.io/html5doctored/css3-pseudo-classes-and-html5-forms/feed/ 38
The return of the u element https://stevefaulkner.github.io/html5doctored/u-element/ https://stevefaulkner.github.io/html5doctored/u-element/#comments Tue, 25 Oct 2011 14:00:37 +0000 http://html5doctor.com/?p=3862 The <u> element was deprecated in HTML 4 and non-conforming in HTML5, but a couple of use cases have seen it return from the dead. Are the use cases enough to persuade you that it’s a phoenix not a zombie?

]]>
Presentational elements like <i>, <b>, <small> and <hr> have been redefined in HTML5 with semantic meanings, or, in a couple of cases, made non-conforming. The <u> element had been in the non-conforming camp, but a couple of semantic use cases led it back into the fold. While most of us will never need it (and some will jeer), on the odd occasion, it might be just the element you need.

Before HTML5, <u> was solely for applying a presentational style of underlining to text. HTML 4 discouraged “font-style” or presentational elements, and even deprecated <u>, advising us to use CSS instead. Even before this, <u> was frowned upon as underlines are the browser default for links, and making normal text look like links gives users a bad case of clicky-clicky frustration. <u> was initially non-conforming in HTML5.

There are, however, a couple of non-link places where text is traditionally underlined to convey meaning, as the HTML5 specification’s definition mentions:

The u element represents a span of text with an unarticulated, though explicitly rendered, non-textual annotation, such as labeling the text as being a proper name in Chinese text (a Chinese proper name mark), or labeling the text as being misspelt.

Before we get to them, let’s quickly cover an unarticulated, though explicitly rendered, non-textual annotation. This means <u> is for when you are annotating something, but not explicitly saying what it is (WHATWG IRC, Ian Hickson) — the annotation’s meaning is implied by context.

Chinese proper name marks

And what exactly are those you ask? I had to ask Wikipedia myself:

In Chinese writing, a proper name mark (Simplified Chinese: 专名号, zhuānmínghào; Traditional Chinese: 專名號) is an underline used to mark proper names, such as the names of people, places, dynasties, organizations. … This method of recognizing proper names in text is similar to the English use of a capital letter.

Wikipedia gives the following example, which I’ve formatted using <u>:

<u class="pnm">屈原</u>放逐,乃賦<cite class="bnm">離騒</cite>。<u class="pnm">左丘</u>失明,厥有<cite class="bnm">國語</cite>。(司馬遷 《<cite>報任安書</cite>》)

屈原放逐,乃賦離騒。左丘失明,厥有國語。(司馬遷 《報任安書》)

Qu Yuan was exiled, and thus composed the Li Sao. Zuo Qiu lost his sight, hence there is the Guo Yu. (Sima Qian, “Letter to Ren'an”)

Using <u> for Chinese proper name marks where appropriate

If you’re using Firefox 6+ you’ll also see the appropriate wavy underline for a Chinese book name mark on the quote’s source, courtesy of CSS3’s text-decoration-style: wavy;. I’ve used <cite> for book name marks as it’s more appropriate than <u>. You can find out more about wavy in CSS Text Level 3.

Using <u> for spell-checking feedback

While you’re probably not marking up classical Chinese prose, a more familiar use case is for a spell-checker to indicate incorrect text. The default formatting in word processors is typically a red underline for spelling errors, and a green underline for grammatical errors:

.spelling-error {
  text-decoration: none;
  border-bottom: 1px dashed red;
}
.grammatical-error {
  text-decoration: none;
  border-bottom: 1px dashed green;
}
<p>hello doctor i am having a huge body <u class="spelling-error">oder</u> <u class="grammatical-error">it is smell really bad</u></p>

hello doctor i am having a huge body oder it is smell really bad

Using <u> for annotating spell checker feedback

While we’ve turned off the default text-decoration style, <u> will back us up if CSS is disabled, and potentially provide more information for assistive technology. After all, if it’s semantic it should be in HTML, not CSS.

Some word processors use wavy underlines. This CSS would have the same effect in a supporting browser:

.spelling-error {
  text-decoration-line: underline;
  text-decoration-style: wavy;
  text-decoration-color: red;
}
.grammatical-error {
  text-decoration-line: underline;
  text-decoration-style: wavy;
  text-decoration-color: green;
}

Or, using text-decoration as a shorthand property, and adding a default declaration for non-supporting browsers:

.spelling-error {
  text-decoration: underline; /* for backwards compatibility */
  text-decoration: underline wavy red;
}
.grammatical-error {
  text-decoration: underline; /* for backwards compatibility */
  text-decoration: underline wavy green;
}

Again, you can read more about the upgraded text-decoration properties in CSS Text Level 3.

Using <u> for indicating family names

Another use for <u> is to annotate a family name when this might be confusing — Chinese, Japanese, Korean and Vietnamese (among others) all traditionally write names in a different order than the western-centric “given-name family-name”. While applying a blanket western ordering is fairly common (especially when publishing in English), it’s good form to use culturally appropriate ordering. If the audience might misunderstand, the family name can be underlined, capitalised, or otherwise annotated to make the name order explicit. For example, the CIA’s World Fact Book capitalises the family name:

After World War II, the Communists under MAO Zedong established an autocratic socialist system …

This ties in nicely with the hCard microformat, as the “implied n optimisation” doesn’t work with these non-western ordered names, and we need a wrapper element to indicate each part of the name anyhow.

<style>
  .family-name {text-decoration: underline;}
</style>
<p>
  <span class="vcard" lang="ja-latn">
    <span class="fn n">
      <u class="family-name">Son</u> <span class="given-name">Goku</span>
    </span>
  </span>
   is the main protagonist in 
  <span class="vcard" lang="ja-latn">
    <span class="fn n">
      <span class="given-name">Akira</span> <u class="family-name">Toriyama</u>
    </span>
  </span>’s <i lang="ja-latn">manga</i> “Dragon Ball”.
</p>

Son Goku is the main protagonist in Akira Toriyama’s manga “Dragon Ball”.

Using <u> to indicate the family name in non-western names via underlining

Of course you can then change the style via CSS, for example

.family-name {
  text-decoration: none;
  text-transform: uppercase;
}

Son Goku is the main protagonist in Akira Toriyama’s manga “Dragon Ball”.

Using <u> to indicate the family name in non-western names via capitalisation

The benefit of using <u> for this is the family name will be indicated even when CSS is disabled, ensuring the annotation isn’t lost. Assistive technology may also be able to inform the user of this in the future.

But do we need <u>?

A lot of people bitten by the web standardista bug have somewhat of an allergic reaction to ex-presentational elements in HTML5, after influential articles like Tantek Çelik’s “<b>ed and <br>eakfast markup”. Given <u>’s ignoble past, I expect the reaction to its return will also lead to some poo-pooing. As we already mentioned, however, if it imparts meaning, it should be in HTML. These use cases involve semantic meaning, and even without assistive technology support, <u> conveys some meaning to sighted users via the browser-default style text-decoration: underline;.

Regardless of whether an element is deprecated (HTML 4, XHTML 1) or non-conforming (HTML5) or just plain uncool, browser makers still have to support it for backward compatibility with all those awesome web pages from the days when <blink> was hawt. Because of this, if there’s a semantic use case for an ex-presentational element, it’s definitely better to reform it rather than minting a new element with no backward compatibility. You might think <mark> sounds pretty similar, but the default browser styling would be completely wrong for proper name marks, and semantically less appropriate for spelling errors too.

As Ian Hickson explains:

The presentational markup that was <u>, <i>, <b>, <font>, <small>, etc, is gone. However, there are certain use cases that did not yet have elements yet were important enough to warrant us supporting them. By reusing existing elements, we are able to support them without having to wait for new elements to be implemented. By doing so in a way that closely matches how those elements were actually used in practice (at least to the same extent as other elements have been correctly used in practice) we can not only have older UAs support these new elements automatically, but we can do so in a way that does not introduce an undue volume of invalid pages.

Conclusion

Given the potential to confuse underlined text with links, using text-decoration: underline; on anything other than <a> is bad pretty much all the time. Generally <u> is not the element you’re looking for, even for Chinese book name marks (<cite> would be more appropriate). However, for at least these three use cases, it’s good to have a semantic option, something better than <span>.

So…in a hypothetical world where you did need to code for one of these situations, would you use <u> or something else like <span>? Let us know in the comments!

The return of the u element originally appeared on HTML5 Doctor on October 25, 2011.

]]>
https://stevefaulkner.github.io/html5doctored/u-element/feed/ 37
The scoped attribute https://stevefaulkner.github.io/html5doctored/the-scoped-attribute/ https://stevefaulkner.github.io/html5doctored/the-scoped-attribute/#comments Tue, 13 Sep 2011 13:30:57 +0000 http://html5doctor.com/?p=3634 The scoped attribute for the style element allows you to include styles mid-document that targets a specific element and its children. Depending upon how you look at this, it’ll either be a godsend or a curse. Once you’ve reached the end of this article, I hope you can form your own opinion.

]]>
The scoped attribute for the <style> element allows you to include styles mid-document that targets a specific element and its children. Depending upon how you look at this, it’ll either be a godsend or a curse. Once you’ve reached the end of this article, I hope you can form your own opinion.

Let’s take a quick look at the spec:

The scoped attribute is a boolean attribute. If set, it indicates that the styles are intended just for the subtree rooted at the style element’s parent element, as opposed to the whole Document.

Isn’t this bad practice?

For years, we’ve been told (and have actively told others) to separate content and presentation layers. So why would we introduce something that seems to go against everything we’ve been preaching?

The separation of these layers is still vitally important, but let’s look at a few use cases to shed some light on why this attribute has been introduced. Scoped style provides a W3C-approved way to:

  • Add one-off CSS styles.
  • Add user-defined styles to wiki or CMS content.
  • Add theme-defined styles via CMS plugins.
  • Keep syndicated content together (e.g., keeping example code together with the example).

How does it work?

In this section, I’ll show you how this new attribute will work when it gets rolled out to browsers.

Our starting point

We’ll be using the following code sample as a starting point:

<article>
  <h1>Style Scoped</h1>
  <p>The scoped attribute for the style element will eventually allow for you to include style elements mid-document. To do this, you must mark up your style element with the scoped attribute.</p>
  <section>
    <h2>How does it work?</h2>
    <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
  </section>
</article>

This is a basic example, with two headings and two paragraphs set within the article element.

Adding the scoped attribute

In the next example, we’ll change the foreground color of the second paragraph to red (from whatever was defined in the master CSS file):

<article>
  <h1>Style Scoped</h1>
  <p>The scoped attribute for the style element will eventually allow for you to include style elements mid-document. To do this, you must mark up your style element with the scoped attribute.</p>
  <section>
    <style scoped>
      p { color: red; }
    </style>
    <h2>How does it work?</h2>
    <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
  </section>
</article>

This screenshot shows how things might render in the browser:

How the scoped attribute will render

Backwards compatibility

Unfortunately, scoped style isn’t all puppy dogs and kittens.

Since this newly introduced attribute isn’t understood by current browsers, CSS rules in <style scoped> are just added to the page’s CSS. Therefore, if you were to include a scoped style block mid-page, its declarations would be applied to every matching element in the document, regardless of whether the element were inside or outside of the scope’s range.

For the sake of backwards compatibility, Louis Lazaris has suggested a brand new element called <scopedstyle>. This new element would only be recognised by supporting browsers and ignored by everything else. This way, scoped styles wouldn’t be added to the whole document. Instead, the browser would just throw away the unrecognised <scopedstyle> element and move on.

Browser support

Browser support for <style scoped> (as of )
Browser Support
Chrome 13 No
Safari 5 No
Firefox 6 No
Opera 11.51 No
Internet Explorer 9 No

Currently, the scoped attribute isn’t working in any of the browser alpha versions (Opera.Next, Mozilla Aurora, or WebKit nightly builds). There’s work in progress by Roland Steiner for support in WebKit.

Using <style scoped> today

So you’ve read this article and decided that you need scoped style in your life. What now? Well, just like every other new HTML5 thing, we have a polyfill for it. Simon Madine has created a jQuery scoped CSS plugin on GitHub.

You could also assign a CSS prefix to target the section of your document you want to style. You’d still be able to stick your styles inline, but you’ve also provided a fallback for the older browsers. In fact, Dr. Oli has done just that on his latest article. (View source and search for <div class="faint">.)

Opinions

There’s no denying that we’re breaking backwards compatibility by introducing <style scoped>. To me, this just doesn’t make any sense. I feel this needs to be addressed by either creating a new element like <scopedstyle> or using some protective mechanism like the <!-- and --> delimiters that have been used within <style> and <script> elements.

Let’s not end this article with negative sentiment, though. As with anything, it’s what you make of it. Scoped style is pretty plain vanilla, but if people abuse it, it’ll end up with a bad rap. Dr. Oli has spoken at length about his love for this attribute as it allows him to have live code examples with the CSS in <pre> and also in a <style scoped> within a <figure>.

So now it’s time for you to express your views. What do you think about the new scoped attribute? Do you think it has a future? Should it be fast-tracked into the spec? Or do you think it’s a waste of time that could ultimately end up mixing our content and presentation layers together again? Let us know in the comments!

The scoped attribute originally appeared on HTML5 Doctor on September 13, 2011.

]]>
https://stevefaulkner.github.io/html5doctored/the-scoped-attribute/feed/ 85
Quoting and citing with <blockquote>, <q>, <cite>, and the cite attribute https://stevefaulkner.github.io/html5doctored/blockquote-q-cite/ https://stevefaulkner.github.io/html5doctored/blockquote-q-cite/#comments Tue, 28 Jun 2011 13:30:21 +0000 http://html5doctor.com/?p=3373 Given HTML’s roots in the academic world, it should be no surprise that quoting is well-accomodated in the elements blockquote and q, with their optional cite attribute. In addition, there’s the cite element, which over the last nine years went from ‘semantic orphan element made good’ to one of the more contentious elements in HTML5. Let’s power up the endoscope and examine the scarring, starting with blockquote.

]]>
NOTE: (6/11/2013) The definitions of cite and blockquote in HTML have changed. For the latest advice on using these elements refer to cite and blockquote – reloaded

Given HTML’s roots in the academic world, it should be no surprise that quoting is well-accommodated in the elements <blockquote> and <q>, with their optional cite attribute. In addition, there’s the <cite> element, which over the last nine years went from ‘semantic orphan element made good’ to one of the more contentious elements in HTML5. Let’s power up the endoscope and examine the scarring, starting with <blockquote>.

Quoting with <blockquote>

We’ve become pretty familiar with <blockquote> here, as most of our articles feature excerpts from the HTML5 specification. Look, here’s one right now:
The blockquote element represents a section that is quoted from another source.
Easy peasy, right? Nothing has really changed. Remember that as <blockquote> is a ‘block-level element’ (flow content) we can put most anything in it, including headers, images and tables, in addition to the usual paragraphs of text. There are a couple of slight differences in HTML5 though. <blockquote> is a sectioning root, meaning that any <h1>-<h6> elements it contains don’t become part of the document’s outline. Also, adding a single paragraph of text with no enclosing <p> tags is now completely kosher. Here are some simple <blockquote> examples (apologies for the fake content):
<blockquote>This is a short block quote — look Ma, no paragraph tags!</blockquote>
This is a short block quote — look Ma, no paragraph tags!
<blockquote><p>This is a longer block quote.</p>
  <p>It uses paragraph elements.</p>
</blockquote>
This is a longer block quote. It uses paragraph elements.
<blockquote><h1>OMG a heading!</h1>
  <ul><li>Block quotes can contain more than just paragraphs…</li></ul>
</blockquote>

OMG a heading!

  • Block quotes can contain more than just paragraphs…
Historically, adding the source of a <blockquote> was a semantic conundrum. If you add it as content of the <blockquote>, then semantically it would become part of the quote, right? <blockquote> (and <q>) have a cite attribute for the URL of the quote’s source, to provide context. That’s hidden data, however, and despite the potential for exposing the cite attribute via CSS and/or JS, that’s not as useful as a visible link.
  It seems our long-running convention at HTML5 Doctor of using <footer> for attribution inside a <blockquote> is actually non-conforming. However the phrase in the spec that prevents it also prevents other common block quoting patterns, so the spec will probably change. Read my article <blockquote> problems and solutions, and submit feedback via the WHATWG email list, the comments here or to be via Twitter (@boblet) — your feedback will influence how the spec changes! I’ll update this article after the change, but until then be aware <footer> for attribution in a <blockquote> isn’t strictly valid, and may not be in the future either. The spec currently recommends including attribution in content surrounding the <blockquote>.

Hixie has given his feedback on my email, and it seems like our <footer> citations are still invalid. The official recommendation is to put the blockquote in a figure and add attribution in <figcaption>. Read the whole thread as there are some interesting comments. I’ll wait for the dust to settle a little yet…

HTML5 comes to our rescue with the <footer> element, allowing us to add semantically separate information about the quote. For example:
<blockquote>
  <p>You know the golden rule, don’t you boy? Those who have the gold make the rules.</p>
  <footer>— Crazy hunch-backed old guy from the movie Aladdin</footer>
</blockquote>
You know the golden rule, don’t you boy? Those who have the gold make the rules.
— Crazy hunch-backed old guy from the movie Aladdin
Because of this semantically sound way to show the quote’s source, if you’re going to add a cite attribute on <blockquote>, only do so in addition to visible attribution.
<blockquote cite="http://www.imdb.com/character/ch0000672/quotes">
<p>You know the golden rule, don’t you boy? Those who have the gold make the rules.</p>
<footer>— <a href="http://www.imdb.com/character/ch0000672/quotes">Crazy hunch-backed old guy in Aladdin</a></footer>
</blockquote>
You’ve heard of the golden rule, haven’t you? Whoever has the gold makes the rules.
Even then, the cite attribute is probably only worth it if you can automate it (or you're just crazy OCD ;). We’ll return to <blockquote> in a bit, but let’s first probe into <q>.

Inline quotations with <q>

<q> is for quoting something inline within a section of prose:
The q element represents some phrasing content quoted from another source.
This means we can’t use <q> for sarcasm or other non-quotation uses of quote marks (“”). In those cases, add punctuation manually. The spec continues:
Quotation punctuation (such as quotation marks) that is quoting the contents of the element must not appear immediately before, after, or inside q elements; they will be inserted into the rendering by the user agent.
As with <blockquote>, you can also add a cite attribute with a URL for the quotation’s source (subject to the above caveats against hidden data). If you’re not using these extra features though, it’s a toss-up as to whether <q> is any better than just adding punctuation characters like “” as you type. Okay, let’s see some specimens:
Nested quotations:
<p>Luke continued, <q>And then she called him a <q>scruffy-looking nerf-herder</q>! I think I’ve got a chance!</q> The poor naive fool…</p>
Luke continued, And then she called him a scruffy-looking nerf-herder! I think I’ve got a chance! The poor naive fool…
Language-appropriate quotations (example updated, thanks Zev, Bertil, & Janus):
<ul>
<li lang="ja">彼女は<q>日本語に猫は『にゃん』と鳴く</q>と言った。</li>
<li><i lang="ja-latn">Kanojo wa <q>Nihongo ni neko wa ‘nyan’ to naku</q> to itta.</i></li>
<li>She said <q>In Japanese cats say <i lang="ja-latn">nyan</i></q>.</li>
</ul>
  • 彼女は猫は『にゃん』と鳴くと言った。
  • Kanojo wa Nihongo ni neko wa ‘nyan’ to naku to itta.
  • She said In Japanese cats say nyan.
A quotation using the cite attribute. Note that I’ve also included the cite attribute’s link in content so it’s accessible:
<p><a href="http://www.imdb.com/character/ch0000672/quotes">The Aladdin character Jafar</a> presents an eloquent treatise on the recent global economic meltdown when he states <q cite="http://www.imdb.com/character/ch0000672/quotes">You know the golden rule, don’t you boy? Those who have the gold make the rules.</q></p>
The Aladdin character Jafar presents an eloquent treatise on the recent global economic meltdown when he states You know the golden rule, don’t you boy? Those who have the gold make the rules.
Let’s examine how to style these elements next.

Styling <q> and <blockquote>

Historically, browser support has been patchy for controlling the punctuation used by <q>. Things have settled down now, so we can define nested, language-specific and even author-defined punctuation via CSS.
Browser support for styling quotes
IE Firefox Safari Chrome Opera
Default <q> punctuation¹ 8.0 “” ‘’ 1.5 “” ‘’ 2.0 "" 4.0? "" '' 1.0? "" '' 4.0 “” ‘’
quotes with Unicode escapes 8.0 1.5 5.1² 11.0² 4.0³
quotes with glyphs 8.0 1.5 5.1² 11.0² 4.0³
  1. Default <q> support requires on :before and :after
  2. Webkit support has been weak, with "" and '' hard-coded until Safari 5.1 and Chrome 11. Ref: WebKit bugs 6503 (fixed) and 3234 (new).
  3. Opera is buggy if you nest <q> to a greater depth than quote pairs in your quotes property (test case)
“Correct” punctuation is an intricate topic and varies depending on language, but it generally involves these characters:
Quote punctuation characters
Glyph Description Unicode escape Entity Mac Windows Linux
“ Left double quotation mark \201C &ldquo; Option-[ Alt+0147 AltGr+V
” Right double quotation mark \201D &rdquo; Option-Shift-[ Alt+0148 AltGr+B
‘ Left single quotation mark \2018 &lsquo; Option-] Alt+0145 AltGr+Shift+V
’ Right single quotation mark \2019 &rsquo; Option-Shift-] Alt+0146 AltGr+Shift+B
« Double left-pointing angle quotation mark \00AB &laquo; Option-\ Alt+174 AltGr+[
» Double right-pointing angle quotation mark \00BB &raquo; Option-Shift-\ Alt+175 AltGr+]
‹ Single left-pointing angle quotation mark \2039 &lsaquo; Option-Shift-3 Alt+0139 -
› Single right-pointing angle quotation mark \203A &rsaquo; Option-Shift-4 Alt+0155 -
„ Double low-9 quotation mark \201E &bdquo; Option-Shift-W Alt+0132 -
‚ Single low-9 quotation mark \201A &sbquo; - - -
Narrow no-break space \202F &#8239; - - -

If you’re using the charset UTF-8 (and you should be), we recommend you use the actual characters if possible, rather than the Unicode escapes in CSS or the entities in HTML. You can enter most of these using the keyboard — e.g. “ is Opt-[ on Mac, Alt + 0147 on Windows, and AltGr + V on Linux. Avoid using ", ' or ` in place of “” and ‘’. The “narrow no-break space” is used inside French guillemets.

Most languages alternate between two kinds of punctuation as quotes are nested, such as “” and ‘’ in English. To specify nested quote pairs in CSS, we would write this:
q {quotes: '“' '”' '‘' '’';} /* opening followed by closing quote pairs */
/* The equivalent using Unicode escapes:
  q {quotes: '\201C' '\201D' '\2018' '\2019';} */
q:before {content: open-quote;}
q:after {content: close-quote;}
Unfortunately, browsers use the last quote pair in the quotes property for more deeply nested quotations. In addition, Opera will use the wrong quote characters if you have more nested <q> than your quotes property defines quoting levels for (Opera quotes bug test case). Make sure you have enough levels by repeating quote pairs as necessary:
/* four levels of nested quotes */
q {quotes: '“' '”' '‘' '’' '“' '”' '‘' '’';}
WebKit had "" and '' hard-coded in the browser stylesheet until Safari 5.1 and Chrome 11, which prevented q:before {content: open-quote;} and q:after {content: close-quote;} from working. The workaround is to define opening and closing punctuation manually, then override with open-quote and close-quote. While it’s a little more involved, that’s why we use this CSS on HTML5 Doctor:
/* for two levels of nested quotations */
q {quotes: '“' '”' '‘' '’';}
 /* extra content definitions for pre-2011 WebKit */
q:before {content: '“'; content: open-quote;}
q:after {content: '”'; content: close-quote;}
q q:before {content: '‘'; content: open-quote;}
q q:after {content: '’'; content: close-quote;}
  /* q in blockquote */
blockquote q:before {content: '‘'; content: open-quote;}
blockquote q:after {content: '’'; content: close-quote;}
blockquote q q:before {content: '“'; content: open-quote;}
blockquote q q:after {content: '”'; content: close-quote;}
  /* blockquote hanging opening quote */
blockquote:before {display: block; height: 0; content: "“"; margin-left: -.95em; font: italic 400%/1 Cochin,Georgia,"Times New Roman",serif; color: #999;}
A more traditional English <blockquote> style uses an opening quote character before each paragraph of the quotation and a closing quote character on the last paragraph. You can do that with this CSS, but you’ll need to use <p> for the <blockquote>’s content.
/* alternative blockquote style */
blockquote {quotes: '“' '”';}
blockquote p:before {content: '“'; content: open-quote;}
blockquote p:after {content: ''; content: no-close-quote;}
blockquote p:last-child:after {content: '”'; content: close-quote;}

When quoting a foreign language, we use the quotation marks of the surrounding language, so a Japanese quote in an English sentence still uses English quotation marks:

All he knows how to say in Japanese is 「わかりません」 “わかりません” (I don’t understand).

If you’re dealing with multilingual content, you can specify the quotes property per-language:
/* quotes for French, German (two kinds) and Japanese */
:lang(fr) > q {quotes: '« ' ' »' '“' '”';}
:lang(de) > q {quotes: '„' '“' '‚' '‘';}
:lang(de) > q {quotes: '»' '«' '›' '‹';} /* alternative style */
:lang(ja) > q {quotes: '「' '」' '『' '』';}
You can learn more about this CSS in the specification: CSS Generated Content Module Level 3. Okay, it’s time to put the rubber gloves on: <cite> is up next.

The rise and fall of <cite>

<cite>’s rise to stardom as the semantic super-element

In HTML 2 <cite> was used to indicate the title of a book or other citation. But in HTML 3.2 and HTML 4.01, <cite> was more loosely defined as
Cite: Contains a citation or a reference to other sources
We can define “citation” as:
  • a reference to authority or precedent,
  • a quotation that’s being cited, or
  • a mention of someone or something
And “a reference to other sources” is even less specific [cue Jaws music]. The HTML 4.01 spec’s examples were:
As <CITE>Harry S. Truman</CITE> said… More information can be found in <CITE>[ISO-0000]</CITE>
Sadly, an example of an academic-style citation wasn’t included. Some standardistas enthusiastically adopted <cite> for its semantics, with the high point being Mark Pilgrim’s epic “Posts by citation” (the results of which are now sadly 404’ed). In those heady days, <cite> was used in three main ways:
  1. To refer to a person, generally in connection with some reference or as the source of a quote:
    <!-- Not valid usage of cite in HTML5! -->
    <p>As <cite>George R. R. Martin</cite> wrote in…</p>
  2. To contain the title of a work being referred to or quoted from (what <cite> is now used for in HTML5 — thanks Dylan!):
    <p><cite>A Game of Thrones</cite>, by George R. R. Martin</p>
  3. To contain a full academic-style citation (title plus author, and maybe bibliographic information):
    <!-- Not valid usage of cite in HTML5! -->
    <p><cite>A Game of Thrones, by George R. R. Martin</cite></p>
    • Historically this might also be marked up as:
      <!-- Not valid usage of cite in HTML5! -->
      <p><cite class="book-title">A Game of Thrones</cite>, by <cite class="author">George R. R. Martin</cite></p>
    • or as Wikipedia does (with <cite> set to font-style: normal;):
      <!-- Not valid usage of cite in HTML5! -->
      <p><cite>George R. R. Martin, <i>A Game of Thrones</i></cite></p>
“Wow, what an all-rounder!” I hear you say. “Is there anything <cite> can’t do?” The dirty secret of all this is the <cite> element has historically been semantics for the sake of semantics. So far, the only non-site-specific application of <cite> is browser default stylesheets, which format it with font-style: italic;. This is not a bad thing, as using <cite> consistently on your own site allows you to do all kinds of fun stuff (as Pilgrim demonstrated). But in the past, it’s been used to refer to three related but quite different types of data: titles, full citations, and names. This makes web-wide use, such as by a search engine, tricky.

<cite> snorts too much semantics, checks into rehab

So, in HTML5 this semantic over-achiever has ended up with a more … prosaic definition:
The cite element represents the title of a work (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, etc). This can be a work that is being quoted or referenced in detail (i.e. a citation), or it can just be a work that is mentioned in passing. A person's name is not the title of a work — even if people call that person a piece of work — and the element must therefore not be used to mark up people's names
This restriction has been somewhat … unpopular. Arguments for using <cite> for names (now summarised on the WHATWG wiki) were addressed by Ian Hickson, who decided that historical use wasn’t enough to justify the wooly definition. Jeremy Keith’s 24 Ways article “Incite A Riot” called for civil disobedience and HTML 4.01-style <cite>-ing, but the HTML5 spec has not changed. The in<cite>rs are irate that there are two use cases that <cite>’s new definition leaves semantically unfilled — to mark up speakers in a transcript or dialog, and to indicate the speaker or author of an inline quote (<q>). The HTML5 spec adds semantic insult to injury by saying:
In some cases, the <b> element might be appropriate for names; e.g. in a gossip article … In other cases, if an element is really needed, the <span> element can be used.
By better defining <cite>, we increase the odds of getting usable data from it, though we now need different methods to cover these other uses. For now, it seems that these use cases aren’t specific enough to warrant new elements. Note that <cite> was never a general-purpose element for marking up a person. The still-born HTML 3.0 did try to introduce the <person> element, but if you’ve ever used hCard to semantically mark up a person’s name, you’ll know that we’d need way more than just one element to do names justice. The POSH way of marking up a name is to use hCard (in microformats, microdata or RDFa), or just with a plain old link.

Get ex<cite>d and quote stuff

History and encouraging angry comments aside, let’s suture up and see some examples of HTML5-style <cite> action:
Use <cite> for a movie title:
<p><cite>Aladdin</cite> is a great movie, even after 73 viewings. Aren’t kids great?</p>
Aladdin is a great movie, even after 73 viewings. Aren’t kids great?
Even better, use <cite> with a link:
<p><cite><a href="http://en.wikipedia.org/wiki/Aladdin_(1992_Disney_film)">Aladdin</a></cite> is a great movie, even after 73 viewings. Aren’t kids great?</p>
Aladdin is a great movie, even after 73 viewings. Aren’t kids great?
Use <cite> for the title of a book (but not the author’s name):
<p><cite>A Game of Thrones</cite>, by George R. R. Martin</p>
A Game of Thrones, by George R. R. Martin
If you wanted to semantically indicate the author, you could use microformats, microdata or RDFa:
<p><cite>A Game of Thrones</cite>, by <span class="hcard"><span class="fn n"><span class="given-name">George</span> <span class="additional-name">R. R.</span> <span class="family-name">Martin</span></span></span></p>
A Game of Thrones, by George R. R. Martin
In this example, the author and book title are only connected by proximity. You could connect them more explicitly using the hProduct microformat, RDFa’s GoodRelations, or to really bleed on the edge even Schema.org. Note that you can’t use the now-Google-approved rel="author" attribute here, as George R. R. Martin is being referred to and isn’t writing the article. If you just wanted to style the author’s name, you could use <b class="author"> (gossip column style) or <span class="author"> with whatever CSS you like.

All together now

Oay, let’s start mixing things up on the operating table and show some examples of <cite> with <blockquote> and <q>:
A movie <blockquote> with <cite>:
<blockquote>
<p>You know the golden rule, don’t you boy? Those who have the gold make the rules.</p>
<footer>— Crazy hunch-backed old guy in <cite><a href="http://en.wikipedia.org/wiki/Aladdin_(1992_Disney_film)">Aladdin</a></cite></footer>
</blockquote>
You know the golden rule, don’t you boy? Those who have the gold make the rules.
— Crazy hunch-backed old guy in Aladdin
Adding the cite attribute to a <blockquote> (and its <footer>):
<blockquote cite="http://www.imdb.com/character/ch0000672/quotes">
<p>You know the golden rule, don’t you boy? Those who have the gold make the rules.</p>
<footer>— <a href="http://www.imdb.com/character/ch0000672/quotes">Crazy hunch-backed old guy</a> in <cite><a href="http://en.wikipedia.org/wiki/Aladdin_(1992_Disney_film)">Aladdin</a></cite></footer>
</blockquote>
You know the golden rule, don’t you boy? Those who have the gold make the rules.
A quote from a specification:
<p>I wonder if feedback on <code>&lt;cite&gt;</code> prompted this:</p>
<blockquote><p>A person's name is not the title of a work — even if people call that person a piece of work</p>
<footer><cite><a href="http://developers.whatwg.org/text-level-semantics.html#the-cite-element">HTML5 for Web Developers</a></cite></footer>
</blockquote>
I wonder if feedback on <cite> prompted this:
A person's name is not the title of a work — even if people call that person a piece of work
An academic-style journal citation:
<ol>
<li>The information capacity of the human motor system in controlling the amplitude of movement, Paul M. Fitts (1954). <cite>Journal of Experimental Psychology</cite>, volume 47, number 6, June 1954, pp. 381–391</li>
</ol>
  1. The information capacity of the human motor system in controlling the amplitude of movement, Paul M. Fitts (1954). Journal of Experimental Psychology, volume 47, number 6, June 1954, pp. 381–391
An academic-style book citation:
<blockquote>
<p>Citations … all include the following: author (or editor, compiler, or translator standing in place of the author), title (and usually subtitle), and date of publication.</p>
<footer><cite><a href="http://www.chicagomanualofstyle.org/">The Chicago Manual of Style</a></cite>, 15th Edition (Chicago: University of Chicago Press, 2003), 596</footer>
</blockquote>
Citations … all include the following: author (or editor, compiler, or translator standing in place of the author), title (and usually subtitle), and date of publication.

Conclusion

If you’ve made it this far, congratulations! You’ve now learned more about citing and quoting in HTML5 than you wanted to know ;) But don’t keep the knowledge to yourself — let us know in the comments what you think. We’d also love to hear how you’re using <blockquote>, <q>, and <cite> in HTML5. If you share your code snippets, remember to escape them!

Updates

  1. : It seems our long-running convention at HTML5 Doctor of using <footer> for attribution inside a <blockquote> is in keeping with the <footer> part of the spec, but not with the <blockquote> part. We’re investigating…
  2. : Hixie confirmed that our use of <footer> is currently non-conforming — <footer> can currently only be included in <blockquote> if it’s quoted content. However, the phrase “content inside a blockquote must be quoted from another source” also forbids other common changes and additions to block quotes, so I’m going to see if it can be changed.
  3. : I wrote an article <blockquote> problems and solutions about these problems, and initial feedback from Hixie is that there are legitimate issues, and he’ll review feedback via the WHATWG email list. So, please do that! You can also leave feedback in the comments here or ping me on Twitter (@boblet). Also, don’t miss Jeremy Keith’s excellent commentary “Citation needed” on the issue (watch out for those <cite>s though ;) )
  4. : I’ve added keyboard shortcuts for punctuation characters to the punctuation table, for default (typically US) keyboards.
  5. Added a note about Hixie’s reply to the article.

Quoting and citing with <blockquote>, <q>, <cite>, and the cite attribute originally appeared on HTML5 Doctor on June 28, 2011.

]]>
https://stevefaulkner.github.io/html5doctored/blockquote-q-cite/feed/ 69
HTML5 Reset Stylesheet https://stevefaulkner.github.io/html5doctored/html-5-reset-stylesheet/ https://stevefaulkner.github.io/html5doctored/html-5-reset-stylesheet/#comments Mon, 27 Jul 2009 14:00:42 +0000 http://html5doctor.com/?p=622 HTML 5 so to give you all a helping hand and continue on from those basic building blocks that Remy talked about last week I've created a HTML 5 reset stylesheet for you to take away and use, edit, amend and update in your projects.]]> We’ve had a number of people ask about templates, boilerplates, and styling for HTML 5. Last week, Remy introduced some basic boilerplates for HTML 5, so to keep the momentum going, I’ve modified Eric Meyer’s CSS reset for you to use in your HTML 5 projects.

The code

Let’s start with the complete CSS stylesheet:

/* 
html5doctor.com Reset Stylesheet
v1.6.1
Last Updated: 2010-09-17
Author: Richard Clark - http://richclarkdesign.com 
Twitter: @rich_clark
*/

html, body, div, span, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
abbr, address, cite, code,
del, dfn, em, img, ins, kbd, q, samp,
small, strong, sub, sup, var,
b, i,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section, summary,
time, mark, audio, video {
    margin:0;
    padding:0;
    border:0;
    outline:0;
    font-size:100%;
    vertical-align:baseline;
    background:transparent;
}

body {
    line-height:1;
}

article,aside,details,figcaption,figure,
footer,header,hgroup,menu,nav,section { 
    display:block;
}

nav ul {
    list-style:none;
}

blockquote, q {
    quotes:none;
}

blockquote:before, blockquote:after,
q:before, q:after {
    content:'';
    content:none;
}

a {
    margin:0;
    padding:0;
    font-size:100%;
    vertical-align:baseline;
    background:transparent;
}

/* change colours to suit your needs */
ins {
    background-color:#ff9;
    color:#000;
    text-decoration:none;
}

/* change colours to suit your needs */
mark {
    background-color:#ff9;
    color:#000; 
    font-style:italic;
    font-weight:bold;
}

del {
    text-decoration: line-through;
}

abbr[title], dfn[title] {
    border-bottom:1px dotted;
    cursor:help;
}

table {
    border-collapse:collapse;
    border-spacing:0;
}

/* change border colour to suit your needs */
hr {
    display:block;
    height:1px;
    border:0;   
    border-top:1px solid #cccccc;
    margin:1em 0;
    padding:0;
}

input, select {
    vertical-align:middle;
}

So what’s new?

Quite a bit! The next few sections explain what I changed and why I changed it.

The basics

I started by removing elements that have been deprecated from the HTML 5 specification, like <acronym>, <center> and <big>. (We’ll cover deprecated elements in more detail in another post). I also added new HTML 5 elements, like and, in order to remove any default padding, margin, and borders. I’ve also added an explicit display:block property for elements that are required to render as blocks.

I also removed the explicit unstyling of the :focus pseudo-class. There are two reasons for this. First, by declaring outline:0, you remove the focus identifier for keyboard users. Second, Eric released his stylesheet in good faith that people would explicitly style :focus, but they generally don’t, so it’s safer to leave the default :focus styles in place. (I also set defaults for <ins>, since I don’t think that got updated very often either.)

I’ve left the default list styles in place simply as a personal preference. I tend to add the list style back when using Eric’s reset anyway. I have, however, included nav ul {list-style:none;} to remove those pesky bullets from your navigation.

Using attribute selectors

You’ll notice that I’ve included attribute selectors for <abbr> and <dfn>. This way, the style will only appear if there is a title attribute on the element. This is primarily for accessibility. For example, we use <abbr> regularly on this site but don’t always include a title attribute. We think it’s safe to assume all of our readers (no matter what device they’re using) know what HTML stands for. We do still use the <abbr> element to make sure screen readers read the text as H-T-M-L rather than struggling to pronounce “HTML”.

What’s that bit about mark?

<mark> is a new element introduced in HTML 5 used to (you guessed it) mark text in a document. According to the spec: “The mark element represents a run of text in one document marked or highlighted for reference purposes, due to its relevance in another context.”. I anticipate it will be used for highlighting phrases in search results and other similar purposes. We’ll post more on <mark> soon.

Where are all those application elements?

Application elements is a term I’ve loosely used to describe elements like menu, etc. These elements are more likely found in web apps than web sites. I left these out since, at the time of writing, browsers implement barely any of what was “Web Applications 1.0”. Also, this stylesheet is intended primarily for authors serving their pages as text/html, not XML.

Go grab it

The stylesheet is released under a Creative Commons license in the public domain free of charge under a CC0 Public Domain Dedication and MIT License, so you can use it for both personal and commercial work. Go grab it from Google Code or the Github page and let us know about any improvements you make!

Permission is hereby granted, free of charge, to any person obtaining a copy of any version of this file on Google Code or this file on Github (the “Software”), to deal in the Software under the terms of the CC0 Public Domain Dedication, or,alternatively, to deal in the Software under the terms of the MIT License.

HTML5 Reset Stylesheet originally appeared on HTML5 Doctor on July 27, 2009.

]]>
https://stevefaulkner.github.io/html5doctored/html-5-reset-stylesheet/feed/ 251