Replacing JavaScript with Just HTML

102 points | by soheilpro 2 hours ago

25 comments

  • subdavis an hour 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.

      webstrand an hour 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 an hour 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

  • dpedu 5 minutes 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.

      reed1234 2 minutes 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 2 minutes ago

      You can't. It's only supposed to be used for a limited list.

  • ronbenton an hour 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

  • overflowy 18 minutes 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.

      imbusy111 a few seconds 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 2 minutes 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?

  • prisenco an hour 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 an hour 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.

      willparks an hour ago

      It’s great to see practical examples that push us to consider what the platform already offers before adding more layers of complexity.

  • smlavine an hour ago

    The Pentagram at the top of the page does not load without JS enabled.

      bitbasher an hour ago

      So it's.. fitting, how meta.

  • cantalopes 30 minutes 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

  • theandrewbailey 2 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.

  • only-one1701 an hour 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?

  • suprjami an hour ago

    Gimme a dark/light mode switch. CSS is allowed.

      adzm an hour ago

      Use a checkbox, d. Define vars for light mode. Override when checked for dark mode with body:has(#d:checked) and can include the dark mode media query too

      johnisgood an hour ago

      Checkbox and :checked are your friends.

  • odie5533 41 minutes ago

    The Popover API looks really cool. Could see it for tooltips or lightboxes.

  • superkuh an hour 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 an hour ago

      What "ancient" browser are you using?

        vpShane 26 minutes ago

        Probably something 300 CVEs ago.