HTML5 Doctor » Elements http://html5doctor.com helping you implement HTML5 today Wed, 02 Mar 2016 08:08:54 +0000 en-US hourly 1 The woes of date input https://stevefaulkner.github.io/html5doctored/the-woes-of-date-input/ https://stevefaulkner.github.io/html5doctored/the-woes-of-date-input/#comments Tue, 19 Jan 2016 14:39:31 +0000 http://html5doctor.com/?p=5961

Related Posts:

]]>
One of the many new input types that HTML5 introduced is the date input type which, in theory, should allow a developer to provide the user with a simple, usable, recognisable method of entering a date on a web page. But sadly, this input type has yet to reach its full potential.

Briefly, the date input type is a form element that allows the capture of a date from a user, usually via a datepicker. The implementation of this datepicker is up to the browser vendor, as the HTML5 specification does not tell vendors how to implement the input’s UI.

The input itself can of course be used without using any of its available attributes:

<label for="when">Date:</label>
<input id="when" name="when" type="date">

Or you can specify minimum and maximum date values via the min and max attributes, ensuring that a user can only choose dates within a specific range:

<label for="when">Date:</label>
<input id="when" name="when" type="date" min="2016-01-01" max="2016-12-01">

You can also use the step attribute to specify, in days, how a date can increment. The default is 1.

This of course is the theory and a fine reality it would be, if it were so but alas it is not.

Features

Rather than talk about browser support for the date input type, I will instead talk about the various features that are part of this input type:

The input field

Neither Firefox nor Safari support this input type; it is treated as a simple text field with no formatting and no special interaction.

Microsoft Edge has no special interactions and in fact the input field appears to be read-only.

Chrome and Opera have the same implementations which display a date placeholder (or date value if the input’s value attribute has been set) using the user’s system settings’ date format. There are also some controls that allow the user to clear the input field, some arrows to cycle up and down between values, and an arrow that will open a datepicker (see Figure 1). There are some WebKit prefixed pseudo selectors available that allow you to change the appearance of the various bits within the input date field.

Screenshot of WebKit's native date input on Chrome

Figure 1. – WebKit’s date input field as seen on Chrome

The min and max attributes

All of those browsers that support the date input type also support the min and max attributes.

Chrome and Opera both work fine if both the min and max attributes are set, but the UI is poor when only one of them is set. In these browsers, the date input displays up and down arrows for the user to change each value (day, month, and year). If a date input has a minimum value set at today’s date, then if the user highlights the year and then clicks the down arrow, the year will change to 275760 as the arrows cycle between the valid values and, since no maximum has been set, the default maximum is used (see Figure 2). This has been reported as a bug but has been marked as “won’t fix” as apparently it is the desired behaviour, I disagree.

Screenshot of WebKit's native date input on Chrome showing the year cycling to 275760

Figure 2. – WebKit’s buggy date input field with a min value set but no max

Something similar happens when only a max value is set in that pressing the up arrow will cycle around to the year 0001, which is the default minimum. Again this leads to a very confusing UX for the user, so please use both min and max where possible.

With Android, the setting of these attributes can cause some weird quirks with the datepicker.

The step attribute

None of the browsers tested support the step attribute.

The datepicker

Firefox and Safari do not support the date input type and therefore do not open a datepicker on desktop. But they do open a device’s native datepicker on mobile devices when the date input field receives focus.

Microsoft Edge opens a datepicker, but its UI is very poor (see Figure 3).

Screenshot of the the Edge's datepicker, which displays a list of selectable dates with one highlighted and two buttons at the bottom, once with a tick and the other with an X

Figure 3. – Microsoft Edge’s native datepicker

Chrome and Opera open a fairly decent datepicker on desktop but you cannot style it at all. It looks how it looks (see Figure 4), and there’s nothing that you can do about it, no matter what your designer says. With these browsers you can disable the native datepicker if you want and implement your own, but this will not work with mobile devices. This gives you the best of both worlds: you can implement a nicer datepicker for desktop and let a device use its own native datepicker.

Screenshot of WebKit's native datepicker and date input on Chrome

Figure 4. – WebKit’s native datepicker and date input field as seen on Chrome

All the native datepickers that I tested on Android displayed some sort of confusing display quirks when valid min and max attribute are set. A user is correctly restricted from selecting a date outside of the specified range, but the visual datepickers often display “previous”, “current”, and “next” values for day, month, and year, and the values displayed for “previous” are either empty (in the case of the month) or set to 9999 (in the case of the year, see Figure 5).

Screenshot of the native datepicker on Android 4.3, with a selected date and the previous year set to 9999

Figure 5. – The native datepicker on Android 4.3

Events

Like most of the other input fields, the date input supports the input and changed events. The input event is fired every time a user interacts with the input field, while the change event is usually only fired when the value is committed, i.e. the input field loses focus.

For those browsers mentioned above that support the native date input field, no specific events are fired that will allow you to determine if the user has done anything “date specific” such as opened or closed the datepicker, or cleared the input field. You can work out if the field has been cleared by listening for the input or change events and then checking the input field’s value.

If you have an event listener set up for the change event and one for the input event, changed will never actually fire as input takes precendence.

Conclusion

So, what can we deduce from all this? Should we use the input date type or not? And as usual the answer is “it depends” as only you know what you’re building and how and where it will be used, so it might fit perfectly for your needs or it might not.

I think in general it’s safe to use the input date type on occasions where a min and max does not need to be set as the quirks when these attributes are used are too irritating to ignore. Since not all browsers support a datepicker and you will have to get one from somewhere else to support these browsers, I would also recommend turning off the datepicker for all desktop browsers (using the method linked to above) as this will still allow devices to use their own.

Have fun!

The woes of date input originally appeared on HTML5 Doctor on January 19, 2016.

]]>
https://stevefaulkner.github.io/html5doctored/the-woes-of-date-input/feed/ 8
HTML Developers: Please Consider https://stevefaulkner.github.io/html5doctored/html-developers-please-consider/ https://stevefaulkner.github.io/html5doctored/html-developers-please-consider/#comments Wed, 09 Dec 2015 14:51:50 +0000 http://html5doctor.com/?p=5930

Related Posts:

]]>
ARIA is an amazing technology, it allows developers to add meaning to meaningless HTML or override meaning on HTML that is being repurposed and sometimes misused, so that users who rely upon the meaning of HTML, as implemented in browsers, can understand and interact with HTML User Interfaces successfully.

ARIA allows developers to re-invent and extend native HTML features in meaningful ways. But like all bolt-on technologies its features are brittle compared to its built-in counterparts.

Whenever you are considering:

By using native HTML features, wherever practical, over custom HTML with bolt-on semantics and interaction behaviours, you will save yourselves and users a lot of grief and ensure that your User Interfaces work robustly across the largest number of devices, operating systems, input devices, browsers and assistive technologies.

Further Reading

HTML Developers: Please Consider originally appeared on HTML5 Doctor on December 9, 2015.

]]>
https://stevefaulkner.github.io/html5doctored/html-developers-please-consider/feed/ 4
On HTML belts and ARIA braces (The Default Implicit ARIA semantics they didn’t want you to know about) https://stevefaulkner.github.io/html5doctored/on-html-belts-and-aria-braces/ https://stevefaulkner.github.io/html5doctored/on-html-belts-and-aria-braces/#comments Tue, 14 Apr 2015 15:26:21 +0000 http://html5doctor.com/?p=5807

Related Posts:

]]>
The question of whether HTML elements need the addition of ARIA role attibutes to expose their semantics, is one that surfaces on a regular basis. The answer is maybe for a subset of elements, but increasingly no.

male torso with belt and braces.

Patrick Lauke modelling last seasons must have; HTML5 casual Polo neck with lumbar support [button] belt and [role] braces combo.

ARIA roles add nothing to default semantics of most elements

In some cases the semantics of a HTML element can be expressed by an ARIA role, state or property. This is fiendishly known as the element’s ‘Default Implicit ARIA semantics‘

None of the elements defined in HTML4 need ARIA roles added to expose their default semantics. Adding an ARIA role is extra work for no gain and could lead to pain for you or somebody else. The new features defined in HTML5 , where implemented, now have their default semantics exposed by most browsers.

The HTML5 Specification includes this note:

In the majority of cases setting an ARIA role and/or aria-* attribute that matches the default implicit ARIA semantics is unnecessary and not recommended as these properties are already set by the browser.

Some examples of  redundant ARIA

Adding default implicit roles to interactive elements listed in the HTML5 Recommendation is a waste of time:

<button role=”button”>press me</button>

Adding ARIA state or property attributes in addition to their native HTML counterparts is a waste of time:

<input type=”text” required aria-required=”true”>

<div hidden aria-hidden=”true”>

Adding ARIA roles and states or properties to long-implemented structural elements is a waste of time:

<h1 role=”heading” aria-level=”1″>heading text</h1>

What about the newish HTML5 structural elements?

HTML5 defined a new set of structural and sectioning elements with default implicit semantics that match ARIA roles (for some, only under certain conditions):

What this means is that, where implemented, the browser will expose the default implicit semantics of the element so you don’t have to.

Although the main element is the newest kid on the block, it no longer needs a role added as its accessibility semantics were implemented at the same time as the other aspects of it’s implementation in browsers (except in IE).

The default implicit semantics implementation story

For the the structural elements newly minted in HTML5, the story is overall a good one. We are at a stage where all modern browsers (that support accessibility) implement the default semantics (except IE and though late to the party, they are finally implementing).

Bottom Line

In general, if it’s defined in the HTML5 Recommendation the  feature does not need ARIA role, state and property attributes. So don’t do it, it’s just another point of code complexity and potential failure for no gain.

For the newish structural elements

Given the more robust support for structural element semantics (sans the outline algorithm aspect, but that’s another orthogonal story) I consider web developers should think about dropping the legacy HTML belt and ARIA braces approach. To that end HTML 5.1 is moving towards making all use of default implicit semantics as a SHOULD NOT normative requirement:

Default Implicit ARIA semantics – SHOULD NOT be used

– ARIA in HTML

This does not mean you can’t continue to, but is meant as a discouragement (think deprecation rather than obsolescence). So in the near future, if you check your HTML using a conformance checker, a warning will be flagged where it finds ARIA roles matching the default implict semantics of HTML elements.

For features defined in HTML 5.1, but not yet interoperably implemented

In some cases there are features absent from HTML5, but re-appear in HTML 5.1 (they were removed from HTML5 due to lack of implementations); details and summary or dialog elements are examples. For these elements it’s both fine and useful to add default semantics via ARIA as appropriate when using polyfils.

On HTML belts and ARIA braces (The Default Implicit ARIA semantics they didn’t want you to know about) originally appeared on HTML5 Doctor on April 14, 2015.

]]>
https://stevefaulkner.github.io/html5doctored/on-html-belts-and-aria-braces/feed/ 30
The ride to 5 https://stevefaulkner.github.io/html5doctored/the-ride-to-5/ https://stevefaulkner.github.io/html5doctored/the-ride-to-5/#comments Tue, 28 Oct 2014 17:06:48 +0000 http://html5doctor.com/?p=5548

Related Posts:

]]>
W3C HTML5 Recommendation

Forwards

In recent weeks I contacted around 40 people, a cross section of those who have banged away at, or banged on about, HTML5. I asked them for their perspectives on HTML5 becoming a W3C Recommendation. Below are the words of the 28 people who responded, pretty much in the order they hit my inbox:

HTML5 is a W3C Recommendation, what do you think?

Tim Berners-Lee
– Director of the World Wide Web Consortium (W3C), the place to agree on web standards.

HTML began 25 years ago to provide content and links, the initial flesh and bones of the web. HTML5 is still the basis of a web of links and content, but it is now also the user interface part of an entire computing platorm. Now every web page can be programmed like a computer. That is a huge change, and we can only imagine what will be deployed in the future on top of the Open Web Platform.

I showed up at the W3C in 2007 to do three things: chew bubblegum, help get a new HTML spec to Recommendation, and kick ass. We’re now near the end of 2014, HTML5 has finally reached Rec, and I’m all out of bubblegum.

The publication of the spec reflects a formidable success at finally gaining consensus. This is always difficult, but made more so in a group that could not move forward and at one point due to to infighting and the inability to do exactly what Tim Berners-Lee suggested we do in his remarks at yesterday’s W3C 20th Anniversary: “Sacrifice your own way of thinking.” So we’ve made big progress on that front. Insofar as the spec itself – as with all specifications – some good, some bad, some intolerable, some ridiculous. In the end it doesn’t matter, really, because it is not always what is specified that is pragmatic. That which is implemented and understood first become the languages, tools and techniques we actually put to use.

Again, my most sincere thanks for including me – each step forward in my work is a step forward in my enjoyment of life no matter my personal circumstance.

The path to HTML5 has been more than a little rocky, and if the road to get to this point isn’t littered with dead bodies, there are some walking wounded among the specification participants.

But none of the interesting times spent working on this spec matters once HTML5 is officially done, and launched. All that matters is we have something we can all live with, being implemented in all our favorite tools, and providing us so much more than what we had before the effort started. That’s the win, the gold star, and the only reward so many hard working people will get for their effort with this spec: the web is a better, richer place.

So thank you hard working people, in the W3C and out. Thank you for not giving up, and seeing it to the end.

All systems that are going to improve must “breathe”; they must undergo periods of expansion and consolidation. HTML5 represents important consolidation for the web platform and I’m glad that the W3C is putting a bow on it and getting broad agreement about what it “is”.

This isn’t to say we’re done; the reason I’ve worked on Web Components in the recent past is to help ensure that the next breath won’t need to be so deep or long. The driver of nearly all progress is iterative improvement. That HTML5’s parsing includes support for custom-element definitions helps ensure that we can democratize the evolution of our shared platform so that when we get around to it, HTML6 can be informed by a vibrant community of extensions that pave a path for new semantics without fighting the language in the interim.

Finally a stable HTML5 specification that authors can develop against, knowing it will not change from one day to the next. And a lot sooner than the 2022 date that was previously mentioned.

There are some really good things in HTML5. The re-think of how the spec works, as a way to take more or less anything that claims to be HTML and produce a DOM is a big step forward. And of course it is aligned with reality, and browsers have worked much harder to align with it than they ever did with HTML4 or 3.2, which makes everyone a winner.

There are things that are not that great. Writing a huge pile of algorithms makes the document very hard to read, and it is *very* big, which in itself is a drawback. Similarly, there are some steps forward for accessibility, and the inclusion of SVG and MathML is a step forward accessibility that should bring other advantages, although there are some problems in the real world that make this less valuable than one could hope.

But the disadvantages are minor compared with the advantage of having a modern spec that is pretty close to what browsers, web pages, and other tools actually work with. It’s high time to publish what is there, although it is important to keep working – the web is a living platform, and while different bits move at very different speeds we have been a bit slow in offering a stable target since XHTML 1.0 was published as the last significant revision of HTML.

I’ve been experimenting with Meteor, recently; a javascript application framework. It returned a curious error just yesterday, when I started the application after editing the master HTML file: ‘Can’t set DOCTYPE here. (Meteor sets for you)’. Five, maybe four years ago this would have been considered highly dictatorial – irresponsible even.

The fact is, HTML5 is now the de facto language of the web. We know that already, so arguably a ‘recommendation’ from on high feels somewhat irrelevant. I see it like this: Together we – the implementers and authors – have embraced and advanced HTML5. We are the tide and the recommendation is the high water mark. It’s nice to see how far we’ve come.

Developing standards is not unlike developing software: you can’t just continue to develop new features – you have to stop from time to time, assess the features that you have, remove those that aren’t working, fix those that have bugs, and release a new version. HTML is such a beast and while it is important to continue its development, it’s also good to have a fixed feature set that people can reference and rely on. So: congratulations to the W3C for getting HTML5 to Recommendation status.

But what does it mean? HTML5 is the basis for a new stable and fully interoperable Web. It lists a feature set that Web developers should be able to rely on in all browsers. Thus, HTML5 is a Recommendation to browser developers to make that interoperability uniform. Find those features that your browser isn’t supporting yet in the list of HTML5 features and implement them (well, yeah: by also looking at the version of that feature in the WHATWG spec, where bugs are fixed and features continue to evolve).

This means, to everyone else: HTML5 is a Recommendation to develop more benchmarks that test the interoperability of the features. There are places like http://html5test.com/ , http://caniuse.com/ , or the W3C’s own test suite, already, but HTML5 is big, so find your favorite features and help make the Recommendation become a real standard.

It’s marvellous that HTML5 has reached this point of maturity, and that accessibility has truly emerged as a core design principle. The inclusion of ARIA puts critical semantic information right where developers need it – at the heart of the HTML specification. Coupled with features that were introduced in HTML5 (like native controls and new structural elements), we’re now in a position to design and build innovative interfaces that are usable by everyone.

This milestone is a time to look to the future as much as to past accomplishments though. As HTML development continues, we need to achieve and maintain a faster and more flexible way of working, without sacrificing the inherent stability and resilience of this open W3C standard.

People hardly remember in what limbo state was (X)HTML in 2007. At the time, I was part of W3C staff. We were struggling and discussing about the best outcome for the future of HTML. WhatWG had started since 2004 to rewrite the lingua franca MarkUp language with a much more implementers oriented specification. Finally W3C rebooted the HTML WG on March 2007.

To see HTML5 being finally released is a huge step for all people of good will participating into this effort. Imagine that. For the first time, we defined a precise algorithm for parsing HTML as it is written on the Web. It means less ambiguity. We got an enriched semantics for authors with a lot better support by browsers than in the past. It means better accessibility. And so many other things.

There will be more struggles in the future. How do we, the Web community altogether, decide to evolve the Web? But, we now have a solid foundation where we can build upon and explore new areas. This is HTML5. Let’s celebrate.

HTML 5.0 isn’t a destination, but rather a long-overdue step on a long journey.

I have mixed feelings about the process, but I’m delighted that HTML5 will be “finished” in 2014. Sure beats 2022. As for the idea that there will be subsequent updates (HTML5.1, HTML5.2, etc.), well, of course there will be. Specifications make more sense to me than the idealistic but somewhat vague idea of HTML as a “living standard.” Living standards are nice, but it’s also nice to be able to say that Browser X fully supports HTML 5.0 (or HTML 5.1, and so on).

Prior to HTML5, HTML did little to ensure consistent implementation across browsers and accessibility features were added late in the cycle without a comprehensive look at accessibility and how accessibility could be added in a way that made it easier for the developer to produce custom accessible applications. The release of HTML5 to recommendation status by the W3C specifies how HTML must be implemented across browsers to ensure consistency.

HTML5 is also the first host language to give authors a comprehensive set of tools to produce accessible custom rich internet applications, through its integration of WAI-ARIA, and accessible rich media to support the blind and visually impaired. These changes leverage the browser to produce cross-platform accessible applications at a dramatically reduced cost over native platforms as the cost of mapping the accessibility information to platform accessibility API services layers is pushed off to the user agent.

In short, HTML5 has established the core plumbing needed for accessibility and browser consistency and the work here can now be carried over and built upon for electronic books, Scalable Vector Graphics, and CSS – the bar has been raised. With the core plumbing in place the greater areas of innovation will now be in accessible graphics, device independent interaction, enhance web application functionality, CSS driven content and navigation, and context aware application infrastructure development.

Finally! w00t!

On the one hand, it doesn’t really matter whether HTML5 is W3C recommendation or not. After all, what really matters to developers is what they can use in browsers today. So, from that perspective, the way the WHATWG views HTML as a “Living Standard” makes a lot of sense.

On the other hand, it’s awfully nice to have some stability in the ever-changing world of web standards and browsers. That’s where the W3C provides balance. They are the yin to the WHATWG’s yang.

HTML5 reaching recommendation status provides a welcome punctuation in the ongoing story of the most important format ever created.

Gosh! It’s not 2022, yet we’re getting HTML5 early! Of course, many web developers know that much of “HTML5” has been ready for a long time in browsers, but it’s important that IT Directors, compliance people and clients know that this is a *stable* standard that reflects what’s in browsers now. With an incredibly active community of developers, browser vendors and spec authors, this is a milestone but emphatically *not* the destination. Onwards, and vive le web!

Many people do not realize that agreement and adoption happens on a continuum: Early adopters pay a price to do it. As things settle down, waves of increasingly less knowledgeable or risk-averse adopters join in, and all the while we are honing the proposal, and implementations. Given this, for many of us, promotion of HTML 5 to REC will seem like a non-event – a kind of statement of the obvious. At some level, it is: A recommendation, at its best, is a statement of agreement about already at that point *is* standard, not what should be. The value in REC is setting of a goal more than the eventual arrival. It’s true that there is a long tail of developers who are unwilling (or even unable) adopt until something reaches this level of maturity officially, and for them, this move will be a very big deal indeed. For the rest of us, I’d suggest that this is the time to appreciate the many hurdles crossed and the long struggles to arrive to this point – step back, assess and examine the things that made it much harder and more frustrating than it should have been at times and the ways that we can improve it all dramatically by changing the model, involving developers, building up and letting us #extendthewebforward.

 

I am very pleased to see the World Wide Web Consortium release a new version of html in a specification that is not going to change overnight. Even if a frozen state implies imperfections, I don’t see that as a problem if errata are correctly and timely dealt with. That’s the mistake the W3C made years ago not maintaining HTML4 and I think they got the message. A frozen html5 was needed by some industries out there that just cannot cope with living standards. Some of our partners in Standardization, like IDPF or ISO, also need to refer to a given version of our specifications. The world of our users is very different from the world of our implementers and we neglected some of them. The W3C has implemented considerable changes to its process to achieve that html5 release. Some came easily, some were heavily discussed and triggered a lot of noise. After a start based on a rather heavy process, the HTML WG came back to more pragmatism. I see that as a mark of maturity. I now look forward to the modularization of html, the specification looking too heavy to me to remain as is in the future.

 

The relatively popular opposition between living standards and snapshots is a false dichotomy. More importantly, we don’t need to choose: as a community we have vast amounts of experience with a processes that marry continuous updates, testing, and periodic releases as that is a common and proven way of producing software.

Standards are similar to software in more ways than one, yet we have long been remiss in applying our knowledge of the latter to the former. This needs to change.

HTML5 exhibits many of the travails of large software projects. Is it perfect? No. Is it complete? Not in the least. But we’re now in a good place to move on to a new phase in which we push open standards towards a saner, happier open source-like model. I for one welcome this bright future.

Milestones are an important part of any journey, and this is a significant milestone. I’m glad to see us reach this one, and I’m looking forward to seeing what comes as we approach the next.

It will be great to finally have a version of HTML that can be used as a standard to work from. Although some of us are lucky enough to work in an environment where we can happily use experimental and non-standard HTML features, there are others for whom standards are very important – perhaps even mandatory – and having one for HTML allows them to move up a step to something stable. This can only be a good thing.

In the beginning it was said that HTML5 would not be “ready” until 2022, but here we are at the end of 2014 and we’re nearly there. A lot of hard work by a lot of different people – in the W3C, WHATWG, and outside – has gone into getting the specification this far, and long may it continue to evolve.

HTML5 going to Rec is a significant milestone and something of significant value for society. It will be the first time we have an actual (royalty) free and open standard that describes how core parts of the Web Platform *actually work*. Despite the success of the Web, previous attempts to standardize HTML were not very successful, forcing browser vendors to reverse engineer each others browsers. This led to many years of stagnation in the platforms.

With HTML, we actually have a more realistic understanding of how the platform works. And with the IPR assurance that comes from HTML5 going to Rec, it means that everyone will be free to implement what is in the HTML5 specification without fear of legal repercussion from other W3C members who were part of the HTML WG. We are talking about big big big companies with large patent portfolios potentially worth millions, which they are essentially giving to the commons. Thanks, Apple, Google, Microsoft, IBM, etc.! you is good peoples.

It is time for HTML5 to graduate. It seems to me that we’ve done a too good job hyping HTML5 whilst we created and implemented it in browsers and we moved fast and broke a lot of things. You’d be hard pushed to find “HTML5 solutions” out there using plain vanilla code and not rely on many abstractions, polyfills and libraries. Even worse, many tell you flat out to use a certain browser – a massive mistake we already made with IE6 in the past. In the enterprise world, none of these “fixes” are applicable without certification or auditing and even HTML5 wasn’t really an option until it is a recommendation.

It will be an interesting talk to convince people to upgrade all the old systems that rely on bespoke browser technology of 1999 and move towards a multi-browser world. Having a recommendation sanctified by the W3C is a great stake in the ground to work from.

I think the W3C HTML5 Recommendation is important in the sense that some very big companies have committed (or are about to commit) to exclude the important Web functionality described by the W3C HTML5 Recommendation (which is a modified snapshot of WHATWG HTML) from patent aggression. However, I think the W3C HTML5 Recommendation should not be oversold as being useful for purposes other than a reference point under the W3C Patent Policy. In particular, the “Plan 2014” process arrangement that allowed HTML5 to proceed to Recommendation with relatively sparse test coverage means that it’s quite possible that there are areas of the specification that developers shouldn’t be relying on in case those areas of the specification turn out to be wrong due to inadequate test coverage.

In general, it’s a bad idea for both browser developers and Web developers to read old specification snapshots. Browser developers should generally read Editor’s Drafts instead of Recommendation snapshots and test suites should also track the most recent spec edits instead of reflecting snapshots whose bugs may already have been fixed in more recent edits. For Web developers it often makes sense to refer to Web developer-targeted documentation such as Mozilla Developer Network or Can I Use and, when those fail, also refer to Editor’s Drafts of the relevant specifications.

The cost of getting to this snapshot has been very high, unfortunately. It’s very sad that the HTML WG ended up driving away many of the people who had contributed to the HTML5 effort at the WHATWG and had come over to the HTML WG when the new HTML WG was established in 2007 to bring the WHATWG’s work on HTML5 into the W3C. I hope the divergence between WHATWG HTML and W3C HTML won’t be permanent.

One of the most pleasing aspects of the W3C’s work on HTML 5 has been the renewed commitment to testing, through initiatives such as Test the Web Forward and the web-platform-tests open source project. Implementation differences have long been a source of frustration for  web developers, and the creation of cross-browser testsuites for the web platform is the best way to eliminate them in the future.

Just because HTML 5 has now reached Recommendation status, this testing work does not stop. Although HTML now has a more substantial testsuite than at any time in the past, we know that there are large areas that still have poor test coverage. Rectifying this is an ongoing project, and one where all web developers can make an invaluable contribution by submitting tests to web-platform-tests whenever they encounter incompatibilities between different browsers.

HTML5 is an important step forward for browser interoperability. When HTML 4.01 was published back in 1999, it said “Since user agents may vary in how they handle error conditions, authors and users must not rely on specific error recovery behavior.” This meant that the behaviour of malformed HTML was undefined despite a huge percentage of pages being malformed (some deliberately for better performance in some browsers). Back them, few would have believed that it was possible to write down a common algorithm for parsing HTML and then get all the popular browser engines to adopt and implement it. But HTML5 did that. And it did so much more. The HTML5 Recommendation brought a level of preciseness to the core pieces of the web that we didn’t have before.

Is HTML5 finished? Is it perfect? No, it’s a software project and it is a work in progress as is the whole web. The web keeps growing, keeps adding new capabilities, and keeps getting better. But shipping is a feature and the web community has spent the last couple of years stabilising and scoping the HTML5 specification. This is an important stabilisation milestone on the way to an even better future.

The HTML5 parsing steps and I become acquainted long before I joined the editor team; I ran the spec algorithm on a particular input that was exploiting a defect in IE to confirm both that 1) if IE had only implemented the spec this wouldn’t be a problem and that 2) the HTML5 spec was going to take more than a mild investment to fully understand. Boy, was that an understatement.

HTML5 changed a lot of things. It redefined the expectations of what degree of detail is necessary to achieve broad interop. It brought together and standardized diverse new capabilities like media and canvas. It demystified name lookup on the window. It even provided all those who had the pleasure of working with it a great deal of </sarcasm>. Literally.

Getting this spec to Rec is a major accomplishment for so many people. While HTML’s journey will surely continue on, it’s great to pause and appreciate this significant milestone. I’ve had a wonderful time getting to know the many amazing, talented, and persistent people behind the scenes making it all happen. Thanks and congratulations!

To keep the web truly open we need to protect our multi-browser supported web. This is an epic milestone in the hard work for an interoperable web platform. To be continued!

Afterwards

Mike[tm] Smith, – W3C HTML Working Group Assistant Remedy Engineer, relaxing (off duty) in front of the HTML World Standard sign.

Work continues apace on HTML at the W3C and WHATWG and any place where people are working on HTML and the Open Web Platform.  HTML5 to REC is a promise to the Open Web Platform. Now there is no excuse, we can all officially say goodbye to HTML 4 and XHTML 1.1.

…and right now, RIGHT NOW, its time to KICK OUT THE JAMS MOTHERFUCKER!

– MC5

The ride to 5 originally appeared on HTML5 Doctor on October 28, 2014.

]]>
https://stevefaulkner.github.io/html5doctored/the-ride-to-5/feed/ 10
The Web Manifest specification https://stevefaulkner.github.io/html5doctored/web-manifest-specification/ https://stevefaulkner.github.io/html5doctored/web-manifest-specification/#comments Tue, 29 Jul 2014 09:51:22 +0000 http://html5doctor.com/?p=5515

Related Posts:

]]>
By Marcos Cáceres and Bruce Lawson.

Update 26 September 2014 The initial work for Manifest in Chromium M39 is done, and Marcos (more or less) finished coding the processor a few months ago. “I’m hoping to see it in fxos 2.2“, he said from the pool of his gorgeous Malibu home.)

Update 11 November 2014 Web Application Manifest is in Chrome 38.

Update 9 April 2015 Updated implementation status to note App Install banners in Chrome, Opera Android implementation underway. Also show how to link to the manifest (thanks @mathias!) and remove some scary “this may all change” warnings.

Update 18 August 2015 François Beaufort pointed out that “According to the spec https://w3c.github.io/manifest/#h-density-member, the density should actually be a number (not a string)” – amended accordingly.

Update 7 December 2015 Link to my blogpost declaring Progressive Web Apps “ready for primetime”; remove stuff about service_worker manifest member, as it’s gone now because it was useless

Manifest? Eh? What? Why?

Many of us who work on the web are actively working to narrow “the gap” between native applications and web applications. (Disclosure: your humble authors, Marcos Caceres and Bruce Lawson work for browser vendors – Mozilla and Opera respectively – and therefore have mortgage-related reasons to convince you this stuff is a good idea.)

But what is that gap? Just a few years ago, that gap was largely technological. If you wanted access to a device’s GPS, you had to write a native app. Nowadays, the situation is improving somewhat: we can now access devices sensors like GPS, camera, and orientation sensors – though we still have a long way to go. Thanks to recent advances in the web platform we now have a platform that can compete with native applications on a more equal footing.

Nowadays, the primary gaps between native and web is not so much technological. It’s user experience. Users simply love installing apps, which live snugly on the homescreen (or the desktop) waiting to be tickled into life with the tap of a finger or the click of a mouse.

Furthermore, native apps work offline by default, and integrate with the facilities provided by the underlying operating system: consider being able to see installed applications in the task switcher. Or being able to control an app’s privacy settings in the same place as apps installed from an app store. In browser land, we are still fumbling around trying to find opened tabs and having to type long and boring URLs to get anything done.

What we need is a method of “installing” web apps so they are indistinguishable from any other app installed on a user’s device. But at the same time, we don’t want to lose the powerful features that are central to the web platform: linkability, view source, and the ability to host our own stuff.

What is “installation”?

At its most basic, “installation” of a web app means “bookmarking” the web application to the homescreen or adding it to an application launcher. There are some pretty obvious things that you, as a developer, would need to provide to the browser so that it can treat your website as an app: the name, icons, etc. There are then more advanced features that you would need, like being able to indicate the preferred orientation and if you want your app to be fullscreen.

The Manifest specification aims to give you a standardised way to do this using JSON. In the HTML page to be “installed”, simply link to a manifest file, thus:

<link rel="manifest" href="/manifest.json">

But what’s in this mysterious manifest file? Glad you asked!

Application name

The application needs a real name or set of names (which is usually not the same as the title element of a document). For this you use the name and the short_name properties.

{
name: “My totally awesome photo app”
short_name: “Photos”
}

The short_name serves as the name for the application when displayed in contexts with constrained space (e.g., under an icon on the homescreen of a phone). The name can then be a bit longer, fully capturing the name of the application. This also provides an alternative way for users to search your app on their phone. So, typing ‘awesome’ or ‘photo’ would find the application on a user’s device.

If you omit the name, the browser just falls back to using <meta name=”application-name”>, and failing that, the <title> element.

Icons

There needs to be an icon associated with a web app, rather than the browser’s icon. To handle this, the manifest has an icons property. This takes a list of icons and their sizes, format, and target screen density. Having these optional properties makes icon selection really powerful, because it provides a responsive image solution for icons – which can help avoid unnecessary downloads and helps to make sure your icons always look great across a range of devices and screen densities.

{
   "icons": [{
        "src": "icon/lowres",
        "sizes": "64x64",
        "type": "image/webp"
      }, {
        "src": "icon/hd_small",
        "sizes": "64x64"
      }, {
        "src": "icon/hd_hi",
        "sizes": "128x128",
        "density": 2
      }]
}

If you omit the icons, the browser just falls back to looking for <link rel=”icon”>, the favicon.ico or, failing that, may even use a screenshot of your website.

Display modes and orientation

Apps need to be able to control how they are to be displayed when they starts-up. If it’s a game, it might need to be in full-screen and possibly in landscape mode. In order to do this, the manifest format provides you with two properties.

{
 "display": "fullscreen",
 "orientation": "landscape"
}

For the display modes, the options that you have are:

  • fullscreen: take over the whole screen.
  • standalone: opens the app with a status bar.
  • minimal-ui: like on iOS, the app is fullscreen, but certain actions can cause the navigation bar and back/forward buttons to reappear.
  • browser: opens your app with normal browser toolbars and buttons.

The nice thing with orientation is that it serves as the “default orientation” for the scope of the application. So, as you navigate from one page to another, your app stays in the correct orientation. You can override the default orientation using the Screen Lock API.

Start URL

Sometimes you want to make sure that when the user starts up an app, they always go to a particular page first. The start_url property gives you a way of indicating this.

{
 start_url: “/start_screen.html”
}

“Scope” of the app

Native applications have clear “boundaries”: as a user, you know when you open a native application that it won’t suddenly open a different application without you noticing. When switching from one native application to another is often pretty clear that you’ve switched applications. These visual cues are often provided by the underlying operating system (think of bringing up the task manager and picking a different application – or pressing “command/alt-tab” on your desktop machine).

The web is very different: it’s a huge hypertextual system where web applications can span multiple domains: you can seamlessly jump from “gmail.com” to “docs.google.com” and as a user have no idea that you’ve jumped form one “origin” to another. In fact, the whole idea that there are boundaries to an application is totally foreign on the Web as, in reality, a web application is just a series of HTML documents (think, “a series of tubes”… no, don’t think that!).

On the web, the only reason we know that we’ve left the scope of one application and entered into another application is because the web designers have been kind enough to make their websites look uniquely different. In case where they haven’t, a lot of users have also been tricked by sites masquerading as another site (the ol’ “phishing attack”).

The manifest format assist with this problem by allowing you to specify a “URL scope” for your application. This scope sets a boundary for an app. It can either be a domain or a directory within that domain.

{
    “scope”: “/myapp”
}

How can I detect if the user “installed” my app?

As a developer, you really should not have to worry about this – the browser will take care of it for you. Firstly, bugging users to install your app is annoying. We’ve all seen this happen in iOS with sites asking users to “add my app to the homescreen”.

Instead, the approach that we take with the manifest is that “installing” is a progressive enhancement. Focus on creating the optimum experience based on what “display mode” the application is in. You will be able to detect and style this with CSS.

@media all and (display-mode: standalone){ ...}

You can use JavaScript matchMedia to test that media query in JavaScript.

Addendum June 2015: In Chromium, you can detect whether a user accepted or dismissed an install banner.

What’s wrong with <meta> tags?

During the specification discussions, it was hotly debated whether to use <meta> tags in HTML rather than make a new format. After all, the Chrome implementation of Add to Homescreen uses <meta> tags, and this has been the natural home for proprietary flimflam since the web began.

The reasons for including a separate file are

  • it saves loading every page of an installable app/site with tons of header info
  • once downloaded, the file sits in the browsers’s HTTP cache.
  • Marcos loves JSON because he’s totally rad

Who is implementing this

The manifest, and Progressive Web Apps are implemented in Chrome and Opera for Android. Implementation is underway in Firefox. You can kinda-sorta do this is a non-standard way in Safari/iOS, too.

Progressive Web Apps are ready for primetime, I believe.

The Web Manifest specification originally appeared on HTML5 Doctor on July 29, 2014.

]]>
https://stevefaulkner.github.io/html5doctored/web-manifest-specification/feed/ 6
Using ARIA in HTML https://stevefaulkner.github.io/html5doctored/using-aria-in-html/ https://stevefaulkner.github.io/html5doctored/using-aria-in-html/#comments Sat, 21 Jun 2014 14:43:14 +0000 http://html5doctor.com/?p=5472

Related Posts:

]]>
ARIA (WAI-ARIA if you want to be formal) is a set of attributes that you can add to HTML elements.

These attributes communicate role, state and property semantics to assistive technologies via the accessibility APIs implemented in browsers. The W3C HTML specification provides information about which ARIA attributes are allowed to be used on each HTML element in section 3.2.7 WAI-ARIA.

Developer (un)friendly information

The requirements specified in section 3.2.7 WAI-ARIA are not in a form which could be considered web developer friendly. They are presented in 2 large tables and only include features that have constraints. i.e. if you can use any ARIA attribute, the element is not listed, this is because the primary purpose of this information is for browser and conformance checker implementers, not developers like you and I. Furthermore to find out what ARIA attributes can be used on a particular element, in the past would involve navigating away from an element definition to the ARIA section then going through the tables to find the desired element or attribute, to locate its ARIA rules.

Developer friendly information

Over the past few months the W3C HTML specification has been updated to include the ARIA information, formerly tucked away or absent, now presented in your face, in the introductory section of each element definition.

In the example below, the introductory section of the picture element definition now includes information about allowed ARIA roles and property attributes, so developers can quickly find the info without having to hunt about in the spec. In the case of the (newly added) picture element, the role attribute cannot be used and only global ARIA attributes are allowed. The same ARIA information can be found in the introductory section of every element in the HTML specification.

picture element definition

If an element can have roles set it is stated in the intro, for example the button element intro includes all allowed ARIA role values and indicates the default role for the element, which in most circumstances does not need to be set. Each role is linked to a description, within the ARIA reference section, of the HTML spec, which also includes a list of allowed aria-* attributes for each role value, with additional links to the ARIA specification information for all role, states and properties.

button

The intent of these additions to the HTML specification is to make it easier for developers to get at the information they need to make accessible things with HTML. Feedback welcome!

Further Reading

Using ARIA in HTML originally appeared on HTML5 Doctor on June 21, 2014.

]]>
https://stevefaulkner.github.io/html5doctored/using-aria-in-html/feed/ 5
Responsive images – end of year report https://stevefaulkner.github.io/html5doctored/responsive-images-end-of-year-report/ https://stevefaulkner.github.io/html5doctored/responsive-images-end-of-year-report/#comments Tue, 12 Nov 2013 17:12:26 +0000 http://html5doctor.com/?p=5352

Related Posts:

]]>
It’s nearly two years since I suggested a <picture> element as a strawman proposal as a way to solve the problem of responsive images, so let’s have a look at how we’re doing.

In September there was a big meetup at Mozilla’s Paris office organised by Mozilla’s Marvellous Mr Marcos who’s been very active in the Responsive Images Community Group and did the hard work of actually turning the <picture> strawman into a spec. Such is the combined allure of Marcos and Paris that a rep from Apple showed up – kudos to Edward O’Connor.

The outcome of the meeting was that <picture> isn’t a viable option. Browser makers don’t like the fact that it’s a new element that does the same as <img> (or what <img> should do if we were speccing it today), and that it depends on multiple nested children. I’d based this on the HTML5 <video> and <source> pattern, but Ian Hickson already said “we learnt with <video> and <source> that having multiple elements for selecting a resource is a huge design pitfall”.

The Paris meetup’s most immediate outcome was agreement that srcset + DPR-switching is the right initial step forward (i.e., the 2x, 3x, etc. syntax). (See Marcos’ full write-up for more fun.)

srcset was specified as part of the WHATWG specification and a draft extension to HTML5, based on Edward O’Connor’s imgset in CSS that’s already implemented in WebKit. It’s fair to say that the syntax hasn’t been received with enthusiasm by developers, as it is ugly and unintuitive. But for the simple case of sending a large image to high-dpi displays and not to 1x dpi displays, it’s simple:

<img src="normal.png" srcset="retina.png 2x" alt="otter vomiting">

Browsers with two or more device pixels per CSS pixels (“retina”) get the 2x image; other browsers, including those that don’t understand srcset get normal.png as specified in the traditional src attribute. Hurrah!

This limited version of srcset is already implemented in WebKit nightly, but not shipping, and was about to be implemented in Gecko and Blink when a proposal from Tab Atkins and John Mellor of Google called src-N made a fashionably late entrance.

It’s not the easiest syntax in the world, either, but src-N does address the three main usecases:

  • devicePixelRatio based resolution switching
  • viewport-size based resolution switching
  • art direction

The simplest incarnation – serving high-dpi images only to browsers that can deal with them is

<img src="normal.png" src-1="normal.png 1x picHigh.png 2x" alt="narwhal regurgitating">

An explainer email shows how verbose <picture> can be for a real sites, while a blog post from Tab Explaining The Last Clause of the src-n Grammar shows a more verbose example of src-N while comparing it with its srcset analogue which is, Tab says, “fucking terrible” – much longer and harder to maintain, requiring non-trivial maths.

All the proposals are verbose and tricky. I suspect that this is simply because it’s a really hard problem, but it is one that needs solving. Tim Kadlec’s posts on Why We Need Responsive Images quantify the bandwidth that we currently waste, and wasted bandwidth costs money and slows down the site for users which has a measurable and significant impact on your sales.

Since src-N has been proposed, both Blink and Gecko have decided not to implement srcset which is currently not yet shipping in WebKit. A representative of Apple called src-N‘s use of multiple attribute “a grotesque perversion of the HTML language“, which implies they’re not eager to implement it. (We’ll ignore the irony that the company which gave us a meta tag in HTML to control presentation is accusing others of perverting HTML).

Meanwhile, the src-N explainer says “Ideally, browsers that have already implemented the basic srcset syntax would remove that as soon as possible before sites start to depend on it”, but goes on to note “it would be possible for such browsers to integrate srcset, just like src acts as a fallback”.

Adam Barth, a Blink rep, writes “I’d rather ship something that’s useful today and iterate to improve it in the future than not ship anything for a long time”, which is fair enough – but Henri Sivonen of Mozilla counters “I think srcset should be taken out of the spec ASAP before WebKit ships it and we get stuck with something that doesn’t allow iteration”. The bone of contention – is srcset subsequently extensible?

Given that src-N addresses more usecases than WebKit’s proposed dpi-switching srcset and the similarity of syntax, I wish WebKit would simply alias their nightly code and ship the minimal dpi-switching src-N given above (so src-1 instead of srcset) and argue about discuss extending it later.

But no. So, once again, impasse. Our doctors’ report: must try harder.

Added 13 November 2013: It’s been pointed out to me that srcset is also implemented in Blink, behind the “experimental features” flag. Demo. The point, however, is that it’s not shipping anywhere so no websites rely in it, and it’s not in Firefox or IE.

Added 2 January 2014: Given the impasse described above, the proposed <picture> element has been revived again and new <picture> specification is under development that combines the best features of all proposals. The most important difference from “old” <picture> is that the <source> elements control the src of the <img> element; thus, <img> is an integral part of the construct rather than simply fallback (and thus is unlikely to be omitted by authors, so “old” browsers won’t be left out.)

Responsive images – end of year report originally appeared on HTML5 Doctor on November 12, 2013.

]]>
https://stevefaulkner.github.io/html5doctored/responsive-images-end-of-year-report/feed/ 76
cite and blockquote – reloaded https://stevefaulkner.github.io/html5doctored/cite-and-blockquote-reloaded/ https://stevefaulkner.github.io/html5doctored/cite-and-blockquote-reloaded/#comments Mon, 04 Nov 2013 17:20:54 +0000 http://html5doctor.com/?p=5283

Related Posts:

]]>
The definitions of the blockquote and cite elements in the HTML specification have recently been updated. This article explains what the changes mean for developers.

Russian translation: Сite и blockquote: перезагрузка

blockquote definition updated

The blockquote element represents content that  is quoted from another source, optionally with a citation which must be within a footer or cite element, and optionally with in-line changes such as annotations and abbreviations.
Content inside a blockquote other than citations and in-line changes must be quoted from another source, whose address, if it has one, may be cited in the cite attribute. [emphasis mine]
– 4.51 the Blockquote element , Berjon et al. 2013

Note the added emphasis indicated via an inline note using square brackets “[emphasis mine]”

What the changes to blockquote mean for developers

Previously in HTML5 it is was not conforming to include citations within blockquote elements. Now it is, as long as the citation content is within a cite or footer element. Citations inside blockquote elements are a common markup pattern (data indicates approximately 60% of blockquote elements include citations), the change to the HTML spec acknowledges this and provides semantic mechanisms to differentiate quoted content from citations.

Example of footer and cite used inside a blockquote:

<blockquote>
<p>As my fellow HTML5 Doctor, Oli Studholme has showed, people seldom quote exactly 
– so sacrosanctity of the quoted text isn’t a useful ideal – and in print etc, 
citations almost always appear as part of the quotation – it’s highly conventional.</p>
<footer>
— <cite><a href="http://www.brucelawson.co.uk/2013/on-citing-quotations-again/">Bruce Lawson</a></cite>
</footer>
</blockquote>

The above example is indicative of what authors are doing anyway, so rather than maintain a theoretical purity which serves no one, the definition has been modified to solve a real problem using existing HTML features, rather than re-inventing the wheel.

An edge case

One of the arguments against allowing use of cite and footer in blockquote to identify citation content is that the quoted content itself may contain these elements. The simple reason for dismissing this argument is that the vast majority of instances of quotations in blockquote elements this will not be the case. Denying the utility of cite and footer for an edge case is another example of theoretical purity that serves  minimal practical purpose.

If the case does arise for you, one method the HTML speccurrently suggests is you comment out the elements from the source (This is still an open issue and advice may change):

(added 20/11/13) In response to feedback the suggestion in the HTML spec is to use a class attribute (a defined extensibility mechanism) on the cite element to identify it as an inclusion from the quoted source:

  <blockquote>
  <p>My favorite book is <cite class="from-quote">At Swim-Two-Birds</cite></p>
  <footer>- <cite>Mike[tm]Smith</cite></footer>
  </blockquote>

cite definition updated

The cite element represents a reference to a creative work. It must include the title of the work or the name of the author (person, people or organization) or an URL reference, which may be in an abbreviated form as per the conventions used for the addition of citation metadata. [emphasis mine]
– 4.51 the Cite element , Berjon et al. 2013

What the changes to cite mean for developers

Previously in HTML5 it is was not conforming to cite an author by name or include other reference information for a creative work in a cite element, the use of cite was reserved (theoretically) to identify the title of a creative work. This was an attempt to rip up a cow path, that authors had created over the last 14 years of the cite elements existence.

Authors railed against the change in definition:

Join me in a campaign of civil disobedience against the unnecessarily restrictive, backwards-incompatible change to the cite element. Start using HTML5 but start using it sensibly. Let’s ensure that bad advice remains fictitious.

Jeremy Keith, 2009

They also provided use cases and real world examples of citation usage. As a result of research, data analysis and discussion, authors can now, again, use the cite element to identify a wider range of references to a creative work; the title of the work or the name of the author (person, people or organization) or an URL reference. What we lose in theoretical purity we gain in utility:

What do you think?

Please read the definitions in HTML 5.1, your feedback as always is welcome!

Big up! to Doctor Oli whose research helped mold the changes made to the cite and blockquote elements. And to Doctor Bruce for insisting that it his right to cite his mum.

cite and blockquote – reloaded originally appeared on HTML5 Doctor on November 4, 2013.

]]>
https://stevefaulkner.github.io/html5doctored/cite-and-blockquote-reloaded/feed/ 35
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
The main element https://stevefaulkner.github.io/html5doctored/the-main-element/ https://stevefaulkner.github.io/html5doctored/the-main-element/#comments Wed, 26 Jun 2013 08:33:59 +0000 http://html5doctor.com/?p=5081 Recently, main was formally added to the W3C HTML specification. Now that the dust has settled, it's about time we dive in to find out where and when it's appropriate to use main. Let's get started.

]]>
Recently, <main> was formally added to the W3C HTML specification. Now that the dust has settled, it’s about time we dive in to find out where and when it’s appropriate to use <main>. Let’s get started.

History

The inclusion of a main element (or similar) has long been debated in the working groups with authors and others often questioning why we had new elements such as <header>, <article>, and <footer> but no element to accurately describe the primary content of a page.

Steve Faulkner, an accessibility consultant and new doctor in residence, undertook the hard graft of carrying out research, gathering data and use cases, and speaking to implementers to get them interested. As Steve explains, he talked to:

as many implementers (both general browser implementers and accessibility implementers), developers, authors and users as I could and got advice and input from them. I went where the various people hung out; on IRC, mailing lists, twitter, blogs, conferences — anywhere.

This led to his writing an extension specification for <main> and a thorough use case rationale.

The proposal was accepted in November 2012, and <main> was then rolled into the HTML5.1 specification. Recently, it was added to the HTML5 specification following no objections. Lets have a look at how the spec describes <main>.

W3C Specification

The primary purpose of <main> is to map ARIA’s landmark role main to an element in HTML. This will help screen readers and other assistive technologies understand where the main content begins. The W3C spec describes <main> as representing:

The main content of the body of a document or application. The main content area consists of content that is directly related to or expands upon the central topic of a document or central functionality of an application.

Since the <main> element is now included in the HTML specification, the <body> element has reverted to its HTML4 definition:

The body element represents the content of the document.

More Details

One important facet of <main> is that it can only be used once per page. Jeremy Keith wrote to the working group to understand why this is the case (rather than allowing multiple <main>s). Although I won’t go into detail, the discussion is an interesting read.

As per the spec, the W3C validator throws an error if you attempt to use multiple <main> elements per document.

Another stipulation of <main> is that it can’t be used as a descendant of an <article>, <aside>, <footer>, <header>, or <nav> element.

Because <main> isn’t sectioning content, it doesn’t affect the document outline in the same way <article>, <nav>, or <section> do.

Getting Going

Just as with the introduction of many other new HTML5 elements, not all browsers recognise <main> or have preset styles for it. You’ll need to ensure it displays as a block level element in your CSS:

main {display:block;}

For the time being, you'll also need to use JavaScript to create the element for older versions of IE:

<script>document.createElement('main');</script>

Of course, if you use the html5shiv, <main> is now baked in directly.

Implementing <main> on HTML5 Doctor

The easiest way to implement <main> is to replace that <div> that you've likely got with an id or class of something like main or content.

So what does that look like in practice? Well, here's our pre-<main> markup on HTML5 Doctor:

<body>
<header role="banner">
[...]
</header>

<div id="content" class="group" role="main">
[...]
</div>

<footer role="contentinfo">
    [...]
</footer>
</body>

And here's what it's like now:

<body>
<header role="banner">
[...]
</header>

<main id="content" class="group" role="main">
[...]
</main>

<footer role="contentinfo">
    [...]
</footer>
</body>

Yes, it's really that simple. With any luck, it'll take you less than five minutes to implement.

The WHATWG Version

The WHATWG definition of <main> differs from the W3C version in that the element has no meaning. It's merely a styling hook (like a <div> with a new name) and represents its children.

The main element can be used as a container for the dominant contents of another element. It represents its children.

We recommend using the W3C version of <main> as described above.

Browser Support

Firefox 21, Chrome 26, and a WebKit r140374 have all implemented basic support for <main>.

They have all mapped the ARIA role="main" to the <main> element so assistive technologies can now recognise the <main> element without issue.

Summary

As you've seen, it's super easy to get up and running with <main>. It only takes a few minutes, so now really is the time to start adding it to the sites you're developing.

If you aren't sure when or where to use <main>, be sure to ask us in the comments and one of us will try to help you out.

Further reading

The main element originally appeared on HTML5 Doctor on June 26, 2013.

]]>
https://stevefaulkner.github.io/html5doctored/the-main-element/feed/ 100