The reason for a share button type
Tags: html, markup, declarative, webshare
Published: 2020-10-09 16:20:26

---
title: The reason for a share button type
published: true
date: 2020-10-05 16:45:17 UTC
tags: html,markup,declarative,webshare
canonical_url: https://adactio.com/journal/17493
---

If you’re at all interested in what I wrote about [a declarative Web Share API](https://adactio.com/journal/17398)—and its sequel, [a polyfill for button type=”share”](https://adactio.com/journal/17405)—then you might be interested in [an explainer document I’ve put together](https://github.com/adactio/share-button-type/blob/gh-pages/explainer.md).

It’s a useful exercise for me to enumerate the reasoning for `button type=“share”` in one place. If you have any feedback, feel free to fork it or [create an issue](https://github.com/adactio/share-button-type/issues).

The document is based on my initial blog posts and the discussion that followed in [this issue on the repo for the Web Share API](https://github.com/w3c/web-share/issues/176). In that thread I got some pushback from [Marcos](https://marcosc.com/). There are three points he makes. I think that two of them lack merit, but the third one is actually spot on.

[Here’s the first bit of pushback](https://github.com/w3c/web-share/issues/176#issuecomment-694089279):

> Apart from placing a button in the content, I’m not sure what the proposal offers over what (at least one) browser already provides? For instance, Safari UI already provides a share button by default on every page

But that is addressed in [the explainer document](https://github.com/w3c/web-share/blob/master/docs/explainer.md) for the Web Share API itself:

> The browser UI may not always be available, e.g., when a web app has been installed as a [standalone/fullscreen app](https://www.w3.org/TR/appmanifest/#display-modes).

That’s exactly what I wanted to address. Browser UI is not always available and as progressive web apps become more popular, authors will need to provide a way for users to share the current URL—something that previously was handled by browsers.

That use-case of sharing the current page leads nicely into [the second bit of pushback](https://github.com/w3c/web-share/issues/176#issuecomment-694760476):

> The API is specialized… using it to share the same page is kinda pointless.

But again, [the explainer document](https://github.com/w3c/web-share/blob/master/docs/explainer.md) for the Web Share API directly contradicts this:

> Sharing the page’s own URL (a very common case)…

Rather than being a difference of opinion, this is something that could be resolved with data. I’d really like to find out how people are currently using the Web Share API. How much of the current usage falls into the category of “share the current page”? I don’t know the best way to gather this data though. If you have any ideas, let me know. [I’ve started an issue](https://github.com/adactio/share-button-type/issues/1) where you can share how you’re using the Web Share API. Or if you’re not using the Web Share API, but you know someone who is, please let them know.

Okay, so those first two bits of pushback directly contradict what’s in [the explainer document](https://github.com/w3c/web-share/blob/master/docs/explainer.md) for the Web Share API. The third bit of pushback is more philosophical and, I think, more interesting.

The Web Share API explainer document does a good job of explaining [why a declarative solution is desirable](https://github.com/w3c/web-share/blob/master/docs/explainer.md#why-not-make-a-share-uri-scheme-like-mailto-instead-of-a-javascript-api):

> The link can be placed declaratively on the page, with no need for a JavaScript click event handler.

That’s also my justification for having a declarative alternative: it would be easier for more people to use. [I said](https://github.com/w3c/web-share/issues/176#issuecomment-695340503):

> At a fundamental level, declarative technologies have a lower barrier to entry than imperative technologies.

[But Marcos wrote](https://github.com/w3c/web-share/issues/176#issuecomment-697232255):

> That’s demonstrably false and a common misconception: See OWL, XForms, SVG, or any XML+namespace spec. Even HTML is poorly understood, but it just happens to have extremely robust error recovery (giving the illusion of it being easy). However, that’s not a function of it being “declarative”.

He’s absolutely right.

It’s not so much that I want a declarative option—I want an option that has robust error recovery. After all, XML is a declarative language but its error handling is as strict as an imperative language like JavaScript: make one syntactical error and nothing works. XML has a brittle error-handling model by design. HTML and CSS have extremely robust error recovery by design. It’s that error-handling model that gives HTML and CSS their robustness.

I’ve been using the word “declarative” when I actually meant “robust in handling errors”.

I guess that when I’ve been talking about “a declarative solution”, I’ve been thinking in terms of the three languages parsed by browsers: HTML, CSS, and JavaScript. Two of those languages are declarative, and those two also happen to have much more forgiving error-handling than the third language. That’s the important part—the error handling—not the fact that they’re declarative.

I’ve been using “declarative” as a shorthand for “either HTML or CSS”, but really I should try to be more precise in my language. The word “declarative” covers a wide range of possible languages, and not all of them lower the barrier to entry. A declarative language with a brittle error-handling model is as daunting as an imperative language.

I should try to use a more descriptive word than “declarative” when I’m describing HTML or CSS. [Resilient](https://resilientwebdesign.com/)? [Robust](https://en.wikipedia.org/wiki/Robustness_principle)?

With that in mind, [`button type=“share”`](https://github.com/adactio/share-button-type/blob/gh-pages/explainer.md) is worth pursuing. Yes, it’s a declarative option for using the Web Share API, but more important, it’s a _robust_ option for using the Web Share API.

I invite you to [read the explainer document for a share button type](https://github.com/adactio/share-button-type/blob/gh-pages/explainer.md) and I welcome your feedback …especially if [you’re currently using the Web Share API](https://github.com/adactio/share-button-type/issues/1)!