Replacing JavaScript with Just HTML

(htmhell.dev)

261 points | by soheilpro 6 hours ago

27 comments

  • subdavis 5 hours ago
    The details / summary thing absolutely kills me. There’s basically nothing you can’t do with them. Hiding and replacing markers is easy. But every component library just pretends they don’t exist.

    It even saves you the effort of all the aria control and expanded tags: these tags don’t need them.

    • maxloh 3 hours ago
      > The details / summary thing absolutely kills me. There’s basically nothing you can’t do with them.

      Animating the details element is tricky. By the spec, browsers don’t natively support transitions between display: none and display: block.

      • jakelazaroff 2 hours ago
        That is no longer true! You can do it in CSS with a combination of `@starting-style` and `transition-behavior: allow-discrete`. [1]

        Another gotcha you'll run into is animating the height. A couple other new features (`interpolate-size: allow-keywords` and `::details-content`) will let you get around that. [2]

        Modern CSS is awesome.

        [1] https://developer.chrome.com/blog/entry-exit-animations

        [2] https://nerdy.dev/open-and-close-transitions-for-the-details...

        • llmslave2 39 minutes ago
          @starting-style Has less than 90% browser support making it a non-starter for the time being at least.
      • qudat 3 hours ago
        Animating accordions is almost always a bad idea because the content length can make it unbearable.

        In general I find animations on the web overused and unnecessary

        • xp84 1 hour ago
          Seriously. As a user I can count on zero hands the number of times I’ve said “Oh great, I’m sure glad this UI is animated!” - and likewise zero times have I missed it when animation isn’t used. Animation is a way to light small units of your users’ precious time on fire, for zero benefit.
          • normie3000 15 minutes ago
            Animations are also a way to explain causal relationships between interactions and their results, and to help build mental models of software behaviour.
      • computerfriend 2 hours ago
        You can put a transition on details > summary.
    • webstrand 5 hours ago
      Details works even when it's set display:contents too, for even more flexibility. Can't animate from open›close, yet, though. That's pretty much my last frustration with it.
      • shakna 5 hours ago
        I think the CSS support for that has finally landed, though it means targetting a pseudo element instead. Its been a year, so support is probably good enough you don't care if just the animation doesn't happen.

        https://developer.chrome.com/blog/styling-details

        • lelandfe 2 hours ago
          Note that the transition to `auto` in that post relies on `interpolate-size` which has yet to land on Firefox or Safari, and neither have movement right now.
    • raybb 4 hours ago
      Do they work well for when you want to preview text? Like show the first 100 characters of a paragraph and then click to expand?
      • zahlman 3 hours ago
        Yes. For example, on Codidact (https://codidact.com), limited HTML access is offered along with Markdown when making posts, and the details and summary tags in particular are whitelisted. I've made extensive use of this in some of my content, for example https://software.codidact.com/posts/289251/289252#answer-289... . If you have NoScript you can easily verify that the expanding sections work perfectly well without JavaScript. They can even be nested, as they are here; and the summary text can contain some other forms of markup without issue. (When crafting the post, however, I had to do some tricky things with whitespace to avoid confusing the Markdown parser.)
      • veqq 3 hours ago
        Of course. That's the summary part
    • rado 41 minutes ago
      You can’t force it to be always open on desktop and collapsible on mobile. That was a deal breaker for me.
    • crooked-v 4 hours ago
      You can't actually control the open state properly from markup (the `open` attribute only sets the default state), which is why I haven't bothered with them.
  • Izkata 3 hours ago
    Does it bother anyone else that it links to Codepen instead of just putting them on the page?

    Like I get this is a blog system but it still feels odd, especially for a "use this plain HTML"-style post...

    • acomjean 2 hours ago
      It doesn’t really bother me.

      It seems to link to the authors codepen. If you us code pen you can bookmark the snippets. Codepen colorizes the html/css etc.

      Link rot is a thing though, so it’s not always ideal to have dependencies on third party urls staying the same.

  • montroser 4 hours ago
    Most of this is great, except for the input/datalist bits, which are not sufficiently functional to be used in any real scenario. Users expect these interfaces to be tolerant of misspellings, optional sub text under each option, mobile ux niceties, etc -- and so everyone builds this with js...
    • kmoser 3 hours ago
      My main beef with datalist is that there's no easy way to show and allow only text (e.g. Beverly Hills), but have the actual value selected be a number (e.g. 90210). In other words there's no analogy to <option value="90210">Beverly Hills</option>.
  • ronbenton 5 hours ago
    One thing I am quite hopeful for is customizable selects! It's in WHATWG stage 3 right now. I have seen so many horrors with javascript-based custom dropdowns components. https://developer.chrome.com/blog/a-customizable-select
  • troad 2 hours ago
    Plain HTML is very cozy to me - I came of age in that era. Marquee tags 4eva.

    But as much as I hate to admit it, it is very difficult to build something functional today with plain HTML and no/minimal JS. If you want, say, a model form that manages its children as well, you're basically going to end up with a 2003-era ASP-feeling application with way too many views and forms (as seen on your employer's current HR system). Or you use HTMX... and you still end up with just as many (partial) views, but now with so much implicit state that you're veering into write-only code.

    I dislike modern JS to the extent that I opted for Phoenix LiveView, just so I could achieve interactivity without ever having to touch JS, but in truth it's not a comprehensive solution. Still had to write a web worker, a bridge to handle things like notifications, etc. Plus the future direction of Phoenix, all in on AI, is worrying.

    Honestly, I should probably just swallow my disdain and learn to appreciate and use modern JS, as painful as that sounds. I want to write and release cool things, not get caught up in navel-gazing language wars.

    • bigstrat2003 1 hour ago
      > But as much as I hate to admit it, it is very difficult to build something functional today with plain HTML and no/minimal JS.

      I would certainly agree that using a little JS can get you further than just HTML. But I think that a plain HTML page is far more pleasant to use (and thus, functional) than the JS monstrosities that dominate the Web today. There's a reason people use the NoScript addon: because a whole lot of website designers use JS in ways that make the experience a ton worse for the user.

      • llmslave2 31 minutes ago
        It's not an either/or. Modern Javascript is actually really nice to write and use, and you can write it in a tight, minimal way that doesn't bloat the page or slow it down.
    • wild_egg 2 hours ago
      > Or you use HTMX... and you still end up with just as many (partial) views, but now with so much implicit state that you're veering into write-only code.

      You're overthinking htmx then. I do some fairly complex stuff with no extra partials. Trick is just always rerender and use hx-select and hx-target to slice out the bits you want to update on the current page.

      Server always has authoritative state and code is dead simple to reason about.

    • faitswulff 2 hours ago
      I haven't used it in anger myself, but if you know Elixir and Phoenix you might like Gleam, which compiles to Javascript.
      • troad 2 hours ago
        I appreciate the helpful reply, but I think this is precisely the kind of indirection I need to avoid. I'm a sucker for elegance. If left entirely to my own devices I'd probably design a language / write a transpiler of my own, and wind up with exceedingly elegant tooling for websites, and no websites. :)
        • llmslave2 30 minutes ago
          This is why I don't use Typescript or frameworks in my own projects, I just constantly seek the cleanest abstraction and never get anything done. Using a deliberately messy solution is annoying but at least I accomplish stuff.
  • overflowy 4 hours ago
    HTML and JavaScript serve distinct purposes, making better or worse comparisons logically flawed. Complex/interactive web apps requires JavaScript, period. Attempting to build sophisticated apps solely through HTML (looking at you HTMLX) eventually hits a functional ceiling.
    • ksec 1 hour ago
      I dont think anyone is arguing Google Earth should be pure HTML. But it is equally false you cant do Gmail with HTML only.

      There are things that HTML could do, and should be doing, that is not done or not yet possible simply due to hype and trend from browser vendors. We could continue to polish HTML + sprinkle of Javascript to its absolute maximum before hitting JS Apps. Right now this is far from the case.

      • llmslave2 29 minutes ago
        Gmail with html only would not be a nice experience. Modern gmail is really bloated but it's actually one of the few web apps I have no problems with.
    • imbusy111 4 hours ago
      I assume you mean htmx. It doesn't have to be either/or. You can supplement htmx with Javascript.

      The core idea with htmx is that you transfer hypertext with controls and structure built in, not just a JSON blob that requires additional context to be useful.

      I have just shipped a very useful and interactive app surprisingly quickly for my customer using just htmx with a little Javascript.

    • mcny 4 hours ago
      It shouldn't have to be this way though. There is no reason html can't do things it needs to do to build complete apps. We could use reasonable defaults to allow a new type of html markup without JavaScript.

      All the http verbs. Decent html input controls What else?

  • hn111 1 hour ago
    I’ve tried replacing my modal components with the <dialog> element, but had to reverse everything due to this issue: https://github.com/whatwg/html/issues/9936

    In short: you can’t have an interactive popover (e.g. a toast notification) on top of a dialog modal.

    I’d love to use the new native elements but we’re sadly not quite there yet.

  • shahzaibmushtaq 27 minutes ago
    This is helpful when development revolves around static environment.
  • smlavine 5 hours ago
    The Pentagram at the top of the page does not load without JS enabled.
    • bitbasher 5 hours ago
      So it's.. fitting, how meta.
  • prisenco 5 hours ago
    When building out a new app or site, start with the simplest solution like the html-only autofilters first, then add complex behavior later.

    It's good to know these things exist so there are alternatives to reaching for a fat react component as the first step.

    • zdragnar 5 hours ago
      Until your client tells you that it doesn't work in Edge and you find out it's because every browser has its own styling and they are impossible to change enough to get the really long options to show up correctly.

      Then you're stuck with a bugfix's allotment of time to implement an accessible, correctly themed combo box that you should have reached for in the first place, just like what you had to do last week with the native date pickers.

      • prisenco 2 hours ago
        Right, don't add complexity until you have to.
    • willparks 5 hours ago
      It’s great to see practical examples that push us to consider what the platform already offers before adding more layers of complexity.
  • iammrpayments 3 hours ago
    I was trying to rewrite some UI library with html sometime ago following the W3C accessibility specs and found out a lot of patterns can’t be done with pure html and require javascript unfortunately.
    • scrame 2 hours ago
      like what?
      • iammrpayments 2 hours ago
        Tabs, accordion, combobox. There is a whole lot more, these are just the ones I can remember now.
        • paulhebert 1 hour ago
          Yeah this is true at this point. A lot of more complex patterns require JS to be accessible to screen readers.

          We still should do more with HTML and CSS! And reach for leaner solutions than React everywhere.

          But be careful going for a pure CSS solution for things like tabs if you don’t understand the accessibility requirements.

          (I wish the HTML spec would move faster on these common patterns!)

        • zepolen 38 minutes ago
          All of those can be done with pure html/css, eg. https://codepen.io/mikestreety/pen/yVNNNm
  • Sephr 3 hours ago
    I don't see any mention of HTTP 204 or multipart/x-mixed-replace. Those are both very helpful for implementing rich JavaScript-free HTML applications with advanced interactivity.
  • theandrewbailey 5 hours ago
    > Input with Autofilter Suggestions Dropdown

    It's great until you have a typo in the field, or want to show options that don't start with what you typed in but appear near the end of an option (think Google search's autocomplete). There's no way to filter in Javascript and force it to show certain options with <datalist>. I've resorted to <ol> for search suggestions.

  • dpedu 4 hours ago
    I didn't know about <datalist>, but how are you supposed to use it with a non-trivial amount of items in the list? I don't see how this can be a replacement for javascript/XHR based autocomplete.
    • lelandfe 2 hours ago
      Don't use it, it totally blows. For another oddity to not use, check out the multiple select: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/...

      Expecting users to press modifiers when clicking on these is so funny.

    • reed1234 4 hours ago
      > If we can hand-off any JS functionality to native HTML or CSS, then users can download less stuff, and the remaining JS can pay attention to more important tasks that HTML and CSS can't handle (yet).
    • psnehanshu 4 hours ago
      You can't. It's only supposed to be used for a limited list.
  • Dwedit 2 hours ago
    Nobody tell them about how much stuff can go into SVG. That can even be inlined within HTML source code.
  • avodonosov 1 hour ago
    I am reading the CodePen example for summary/details. Especially the CSS part.

    Its so easy, like a breeze!

  • anidsiam 4 hours ago
    Your blogs have very small amount solution, but the JS use cases are very large. How this little replacement can do more thing? I usually like the idea of being using as lean as possible, if it's can be possible to do more thing just with HTML and CSS that's obviously cool. Is it really possible to replace JS with HTML in near future?

    BTW the toggle solution (expanding content) is good.

  • suprjami 5 hours ago
    Gimme a dark/light mode switch. CSS is allowed.
  • only-one1701 5 hours ago
    Something I keep thinking about when I consider the trade-offs between building a site with HTML/CSS wherever possible vs JS is what the actual _experience_ of writing and maintaining HTML/CSS is vs JS. JS gets knocked around a bunch compared to "real" languages (although less so in recent years), but at the end of the day, it's a programming language. You can write a loop in it.

    Writing a web server in C++ is a way to get excellent performance. So why don't most people do it?

    • breve 3 hours ago
      > Writing a web server in C++ is a way to get excellent performance. So why don't most people do it?

      Because they already wrote it in C.

      Apache and Nginx are both written in C. Together they run 57.7% of all web servers:

      https://w3techs.com/technologies/overview/web_server

  • odie5533 4 hours ago
    The Popover API looks really cool. Could see it for tooltips or lightboxes.
  • 65 3 hours ago
    It feels like some variation of this post gets submitted here every week.
  • superkuh 5 hours ago
    Some of these new HTML features don't fully work in my "ancient" browser. But all of them partially work (ie opening the accordion element doesn't close others but it still opens and closes) and they still remain functional elements I can read and interact with. This puts them far ahead of any javascript implementation which almost universally fail to nothing.
    • ravenstine 5 hours ago
      What "ancient" browser are you using?
      • vpShane 4 hours ago
        Probably something 300 CVEs ago.
  • fnord77 2 hours ago
    <blink>
  • econ 4 hours ago
    I'm so not impressed by the toggle implementation... How nice it could have been.

    Nesting the elements is a truly hideous choice. The summary is part of the details?? I thought they were opposites.

    Should we also put the headings in the <p> from now on?

    Identifying a target should be done by id or by name. That it does use a name because js can't target it without makes it even more stupid.

    We already had labels for form fields. Inventing a completely different method for something very similar is a dumb idea. The old checkbox hack is more flexible and less ugly for some implementations.

    Why force the hidden content to be below or above the toggle? We aren't gaining anything with this.

    What is this nonsense for an element to not just be hidden or displayed but to have some weird 3rd state where only one of its children is shown?

    How should styling it even work for this new state? If I apply a style to the hidden content it must also apply to the link? The text is hidden but the style is visible??? Preposterous!

    Don't try style <details> to avoid unexpected behavior. Try wrapping the hidden content in a new element to make it behave normally.

    What is this ugly arrow? If you find 1000 websites using a toggle I doubt there is one using an ugly arrow like that.

    The default styling gives no clue about it being clickable?

    The pointer (awkwardly called the cursor) choice is the text selection?????

    Blue underlined "more" is what everyone does and everyone is used to. The cursor should be pointer. (This is css speak for "the pointer should be a hand")

    The number of js toggles you can find online where the button lives inside the hidden text is guaranteed to be zero. Forget about drop in replacement, you will have to reinvent your css.

    Maybe I'm dense but I also want my url to reflect the state of the page. I would have been impressed if that was supported. Personally I use actual links and disable default action in the listener if js is enabled/working or modify the state on the server if js isn't available/working.

    It would have been great if the toggle action was implemented as a simple attribute something like toggle="element name" so that anything can be clickable and anything can be toggleable. Have a "closed" as well as an "open" attribute for the target.

    Doesn't seem very hard. An open/closed attribute would be useful for other things too. Using display:none is terrible as display: is used for many things.

    • zahlman 3 hours ago
      > Nesting the elements is a truly hideous choice. The summary is part of the details?? I thought they were opposites.

      It gives them a semantic connection. Last I checked, HTML isn't really based on giving special meaning to combinations of sibling tags. A summary is part of the thing that conceptually requires detailing.

      > If you find 1000 websites using a toggle I doubt there is one using an ugly arrow like that.

      I think the default looks fine. But TFA clearly explains right there that it can be styled. (Specifically, by styling ::before on the summary tag.)

      > The default styling gives no clue about it being clickable?

      You asked what the arrow is, and then asked about the lack of indication that the summary header is clickable. The arrow is exactly that indication.

      > Maybe I'm dense but I also want my url to reflect the state of the page.

      If you scroll, should the fragment automatically update as you scroll past anchors? I think I'd find that quite annoying.

  • FormerlyEL 4 hours ago
    [dead]
  • cantalopes 4 hours ago
    The problem is that it's difficukt to style or animate those things. Unless you're builsing something for dun or technical where it's not important it's fine but i doubt any real world commercial project would be satisfied with just this