Button types

I’ve been banging the drum for a button type="share" for a while now.

I’ve also written about other potential button types. The pattern I noticed was that, if a JavaScript API first requires a user interaction—like the Web Share API—then that’s a good hint that a declarative option would be useful:

The Fullscreen API has the same restriction. You can’t make the browser go fullscreen unless you’re responding to user gesture, like a click. So why not have button type=”fullscreen” in HTML to encapsulate that? And again, the fallback in non-supporting browsers is predictable—it behaves like a regular button—so this is trivial to polyfill.

There’s another “smell” that points to some potential button types: what functionality do browsers provide in their interfaces?

Some browsers provide a print button. So how about button type="print"? The functionality is currently doable with button onclick="window.print()" so this would be a nicer, more declarative way of doing something that’s already possible.

It’s the same with back buttons, forward buttons, and refresh buttons. The functionality is available through a browser interface, and it’s also scriptable, so why not have a declarative equivalent?

How about bookmarking?

And remember, the browser interface isn’t always visible: progressive web apps that launch with minimal browser UI need to provide this functionality.

Šime Vidas was wondering about button type="copy” for copying to clipboard. Again, it’s something that’s currently scriptable and requires a user gesture. It’s a little more complex than the other actions because there needs to be some way of providing the text to be copied, but it’s definitely a valid use case.

  • button type="share"
  • button type="fullscreen"
  • button type="print"
  • button type="bookmark"
  • button type="back"
  • button type="forward"
  • button type="refresh"
  • button type="copy"

Any more?

Have you published a response to this? :

Responses

Dave 🧱

@adactio someone needs to dare me to make a web component for all these 😅(Ps. Typo for “interfa es” on the 4th paragraph, after the quote)

# Posted by Dave 🧱 on Monday, June 19th, 2023 at 3:02pm

Jim Nielsen

@adactio I would love a “Find” functionality that triggers the browsers on-page find functionality

Patrick Smith

@adactio <button type=“cookies-accept”><button type=“cookies-decline”>

Having a standard like that would mean it’s trivial for browsers to auto accept or decline.

Taylor “Tigt” Hunt

@adactio Any JS API that requires a user activation!

Far better to have a button JS can try to `.click()` than vendors having to figure out which which user gestures are allowed to transiently/stickily activate a delegated browsing context’s capability to request for permission with some bespoke permission UI during the next cycle of the event loop/macrotask queue/microtask merry-go-round, because the latest httparchive just dropped and 93% of the new API’s usage was for scamming people.

Darryl Pogue

@adactio In a perfect world, you could polyfill these with `<button is=”share-button”>` and web components, but WebKit is opposed to extending built-in elements so we can’t have nice things 🙁

Darryl Pogue

@adactio I am also maybe still just a little bit bitter about `<button type=”menu”>` getting promised and then axed from the HTML5 specification

Amelia Bellamy-Royds

@adactio Media control (play/pause/volume) buttons have been proposed before; not sure why they didn’t happen. A declarative approach would both clarify the user-interaction permissions and allow devices to map their own special keys or gestures to the button action.

I think a `for` attribute (pointing to another element’s ID) should be sufficient for media control, fullscreen, and probably even `copy`. Maybe also `share`, to share an image or text quote instead of, or in addition to, the URL.

Asbjørn Ulsberg

@stubbornella @brianleroux @adactio Most things that can be done declaratively, especially with HTML, is objectively better than an imperative alternative.

I’m a proud member of the Anti-JavaScript JavaScript Club and share @slightlyoff’s opinion of imperative having gone too far with modern JS frameworks.

So, I agree: Bring the floodgates down and let the declarative juices flow!

https://anti-javascript-javascript.club

Anti-JavaScript JavaScript Club

paulfosterdesign.wordpress.com

In response to Button types on Adactio, about useful everyday JavaScript APIs which should have a declarative equivalent.

 button type="share" button type="fullscreen" button type="print" button type="bookmark" button type="back" button type="forward" button type="refresh" button type="copy"

I agree with this list. If they are common functionality with buttons that could be included in any web page, by anyone of any ability, why should someone have to reach for JavaScript?

Thinking of these things as native features could help during the standards phase, rather than a vaguer concept in JS.

Now we just need a `what` attribute to declare what content ID will be fullscreened, shared, printed, copied etc.

AdvertisementPrivacy Settingswasmart.cmd.push(function() {sas.render(“sas110354”);});window.stq = window.stq || [];window.stq.push( [‘extra’,{xwordadssmart: ‘rendersas_110354’,},] ); Related

# Monday, June 19th, 2023 at 8:27pm

Nicole Sullivan

@brianleroux @adactio I will say, I have some hesitation about spending limited time on things that *don’t do anything*. Ex. Imagine today I had to choose between prioritizing an <accordion> vs <section>. They are both semantic, but only the first one has user interactions and eliminates JS.

O Óscar

@adactio I propose a `<button type=”close”>` to close dialogs, details or any other closeable element

# Posted by O Óscar on Tuesday, June 20th, 2023 at 10:05am

Erik Kroes ✅

@adactio It feels like such a logical suggestion that doesn’t make me think about -if-. It makes me think about what use cases would be a good match. Open? Expand? Close? Cancel? Deny? Update?

adactio.com

I’ve been banging on for a while now about how much I’d like a declarative option for the Web Share API. I was thinking that the type attribute on the button element would be a good candidate for this (there’s prior art in the way we extended the type attribute on the input element for HTML5).

I wrote about the reason for a share button type as well as creating a polyfill. I also wrote about how this idea would work for other button types: fullscreen, print, copy to clipboard, that sort of thing.

Since then, I’ve been very interested in the idea of “invokers” being pursued by the Open UI group. Rather than extending the type attribute, they’ve been looking at adding a new attribute. Initially it was called invoketarget (so something like button invoketarget="share").

Things have been rolling along and invoketarget has now become the command attribute (there’s also a new commandfor attribute that you can point to an element with an ID). Here’s a list of potential values for the command attribute on a button element.

Right now they’re focusing on providing declarative options for launching dialogs and other popovers. That’s already shipping.

The next step is to use command and commandfor for controlling audio and video, as well as some form controls. I very much approve! I love the idea of being able to build and style a fully-featured media player without any JavaScript.

I’m hoping that after that we’ll see the command attribute get expanded to cover JavaScript APIs that require a user interaction. These seem like the ideal candidates:

There’s also scope for declarative options for navigating the browser’s history stack:

  • button command="back"
  • button command="forward"
  • button command="refresh"

Whatever happens next, I’m very glad to see that so much thinking is being applied to declarative solutions for common interface patterns.

# Thursday, March 20th, 2025 at 3:23pm

25 Shares

# Shared by Curtis Wilcox on Monday, June 19th, 2023 at 3:15pm

# Shared by Jeff Posnick on Monday, June 19th, 2023 at 3:15pm

# Shared by Tyler Sticka on Monday, June 19th, 2023 at 3:15pm

# Shared by Dave 🧱 on Monday, June 19th, 2023 at 3:15pm

# Shared by Josh Tumath on Monday, June 19th, 2023 at 3:15pm

# Shared by westbrook on Monday, June 19th, 2023 at 3:15pm

# Shared by Clayton Dewey on Monday, June 19th, 2023 at 3:15pm

# Shared by Johannes Odland on Monday, June 19th, 2023 at 3:41pm

# Shared by Paul Robert Lloyd 🐢 on Monday, June 19th, 2023 at 4:09pm

# Shared by Thain on Monday, June 19th, 2023 at 4:44pm

# Shared by Eric on Monday, June 19th, 2023 at 4:44pm

# Shared by Brian LeRoux 💚 on Monday, June 19th, 2023 at 4:44pm

# Shared by Sean Boots on Monday, June 19th, 2023 at 5:18pm

# Shared by Evert Pot on Monday, June 19th, 2023 at 5:18pm

# Shared by Cédric Belin on Monday, June 19th, 2023 at 6:27pm

# Shared by Matt Round on Monday, June 19th, 2023 at 7:38pm

# Shared by Felix Niklas on Monday, June 19th, 2023 at 7:38pm

# Shared by Šime Vidas on Monday, June 19th, 2023 at 7:38pm

# Shared by Vladimir Shamsheev on Monday, June 19th, 2023 at 8:36pm

# Shared by Antonio Sarcevic on Monday, June 19th, 2023 at 9:19pm

# Shared by Jeffrey Lembeck on Monday, June 19th, 2023 at 9:19pm

# Shared by Paul Hebert on Monday, June 19th, 2023 at 9:55pm

# Shared by Pez Pengelly on Monday, June 19th, 2023 at 11:49pm

# Shared by Chris Taylor on Tuesday, June 20th, 2023 at 6:11am

# Shared by ambrwlsn on Thursday, June 29th, 2023 at 9:41am

29 Likes

# Liked by Michelle Barker on Monday, June 19th, 2023 at 3:15pm

# Liked by Tyler Sticka on Monday, June 19th, 2023 at 3:15pm

# Liked by Dave 🧱 on Monday, June 19th, 2023 at 3:15pm

# Liked by Josh Tumath on Monday, June 19th, 2023 at 3:15pm

# Liked by westbrook on Monday, June 19th, 2023 at 3:15pm

# Liked by Francis Rubio :verified: on Monday, June 19th, 2023 at 3:15pm

# Liked by Johannes Odland on Monday, June 19th, 2023 at 3:41pm

# Liked by Ashur Cabrera on Monday, June 19th, 2023 at 3:41pm

# Liked by Jared White on Monday, June 19th, 2023 at 4:09pm

# Liked by Paul Foster on Monday, June 19th, 2023 at 4:09pm

# Liked by Jonathan E Cowperthwait on Monday, June 19th, 2023 at 4:44pm

# Liked by greg on Monday, June 19th, 2023 at 4:44pm

# Liked by Sean Boots on Monday, June 19th, 2023 at 5:18pm

# Liked by John P. Green on Monday, June 19th, 2023 at 5:18pm

# Liked by Matthias Ott on Monday, June 19th, 2023 at 5:18pm

# Liked by Cole Peters on Monday, June 19th, 2023 at 6:27pm

# Liked by Asbjørn Ulsberg on Monday, June 19th, 2023 at 6:27pm

# Liked by Pauxlll Kruczynski on Monday, June 19th, 2023 at 7:04pm

# Liked by Chris Price on Monday, June 19th, 2023 at 7:04pm

# Liked by Stefan Grund :eay: on Monday, June 19th, 2023 at 7:38pm

# Liked by Antonio Sarcevic on Monday, June 19th, 2023 at 9:19pm

# Liked by Paul Hebert on Monday, June 19th, 2023 at 9:55pm

# Liked by Troels Thomsen on Monday, June 19th, 2023 at 10:25pm

# Liked by Chris Taylor on Tuesday, June 20th, 2023 at 6:10am

# Liked by Dave Rupert on Tuesday, June 20th, 2023 at 8:19am

# Liked by Erik Kroes ✅ on Tuesday, June 20th, 2023 at 11:15am

# Liked by Valtteri Laitinen on Tuesday, June 20th, 2023 at 8:46pm

# Liked by Ben Spaulding on Wednesday, June 21st, 2023 at 4:16am

# Liked by Simeon.__proto__ on Friday, June 23rd, 2023 at 3:49pm

Related posts

The datalist element on iOS 26

Once again, Safari has fucked up its implementation.

Awareness

Turning accessibility awareness into action with HTML.

Making the website for Research By The Sea

Having fun with view transitions and scroll-driven animations.

Pickin’ dates on iOS

Mobile Safari doesn’t support the min and max attributes on date inputs.

Progressive disclosure with HTML

The `details` element is like the TL;DR of markup.

Related links

Performance-Optimized Video Embeds with Zero JavaScript – Frontend Masters Blog

This is a clever technique for a CSS/HTML only way of just-in-time loading of iframes using details and summary.

Tagged with

Cool native HTML elements you should already be using · Harrison Broadbent

dialog, details, datalist, progress, optgroup, and more:

If this article helps just a single developer avoid an unnecessary Javascript dependency, I’ll be happy. Native HTML can handle plenty of features that people typically jump straight to JS for (or otherwise over-complicate).

Tagged with

Building WebSites With LLMS - Jim Nielsen’s Blog

And by LLMS I mean: (L)ots of (L)ittle ht(M)l page(S).

I really like this approach: using separate pages instead of in-page interactions. I remember Simon talking about how great this works, and that was a few years back, before we had view transitions.

I build separate, small HTML pages for each “interaction” I want, then I let CSS transitions take over and I get something that feels better than its JS counterpart for way less work.

Tagged with

una.im | Updates to the customizable select API

It’s great to see the evolution of HTML happening in response to real use-cases—the turbo-charging of the select element just gets better and better!

Tagged with

CSS { In Real Life } | I’ve Been Doing Blockquotes Wrong

It’s pretty easy to write bad HTML, because for most developers there are no consequences. If you write some bad Javascript, your application will probably crash and you or your users will get a horrible error message. It’s like a flashing light above your head telling the world you’ve done something bad. At the very least you’ll feel like a prize chump. HTML fails silently. Write bad HTML and maybe it means someone who doesn’t browse the web in exactly the same way as you do doesn’t get access to the information they need. But maybe you still get your pay rise and bonus.

So it’s frustrating to see the importance of learning HTML dismissed time and time again.

Tagged with

Previously on this day

4 years ago I wrote Backup

Making Keynote files with no fonts.

7 years ago I wrote Toast

Jeremy is not eating toast.

11 years ago I wrote 100 words 089

Day eighty nine.

19 years ago I wrote Hackfight

How a vague idea turned into reality thanks to an amazing team of hackers.

20 years ago I wrote Ajax workshop in NYC

Learn DOM Scripting and Ajax in the Big Apple.

23 years ago I wrote A source of beauty

Sometimes I come across a website that’s so beautifully designed and elegantly executed that I don’t know whether to be inspired or depressed by it.