Fireship · @fireship

htmx in 100 seconds

Uploaded July 7, 2023 · Length 2:27

htmx in 100 seconds

Summary

htmx explained as a UI library for web development that simplifies HTML and replaces JavaScript frameworks.

  • htmx
  • ui library
  • web development
  • html
  • javascript framework
  • hypermedia

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    htmx a UI library for the web that can

  2. 0:03

    replace your JavaScript framework with

  3. 0:05

    the Simplicity of HTML playing HTML is

  4. 0:07

    more capable than you think every time

  5. 0:09

    you click on a link or submit a form it

  6. 0:11

    automatically sends an HTTP request to

  7. 0:13

    the server and renders the response in

  8. 0:15

    the UI it's so easy but why stop there

  9. 0:17

    HDMX Embraces an architectural

  10. 0:19

    constraint known as Hyper media as the

  11. 0:21

    engine of application state by adding

  12. 0:23

    new attributes to HTML that can handle

  13. 0:25

    the complex requirements of modern uis

  14. 0:27

    it gives you the ability to make a

  15. 0:29

    request to the server from any element

  16. 0:31

    by providing an attribute with an HTTP

  17. 0:33

    verb and the URL endpoint on the server

  18. 0:35

    it'll take the response from the server

  19. 0:37

    and replace this element asynchronously

  20. 0:39

    or it can specify a Target to replace a

  21. 0:41

    different element on the page it can

  22. 0:43

    also customize the event on which it's

  23. 0:44

    triggered along with modifiers like

  24. 0:46

    delay and throttle to control the way

  25. 0:48

    the request is sent it keeps track of

  26. 0:49

    the loading state so you can show a

  27. 0:51

    spinner apply CSS transitions for

  28. 0:53

    animation and builds on the HTML

  29. 0:55

    validation API to validate forms it even

  30. 0:57

    has a client-side router called boost

  31. 0:59

    that can make any traditional web

  32. 1:01

    application feel like a faster single

  33. 1:03

    page application and it also includes

  34. 1:04

    extensions for more advanced features

  35. 1:06

    like websockets and Integrations with

  36. 1:08

    other HTML Frameworks like Alpine to

  37. 1:11

    install it simply Import htmx in a

  38. 1:13

    script tag from the head of an HTML

  39. 1:15

    document you just put the hyper back

  40. 1:16

    into hypertext now all you need is a

  41. 1:18

    server in your favorite programming

  42. 1:20

    language that returns html text as a

  43. 1:22

    response now we can use the HX get

  44. 1:24

    attribute to make a request to this

  45. 1:26

    endpoint along with HX swap to replace

  46. 1:28

    this element with the HTML on the

  47. 1:30

    response when swapping though we don't

  48. 1:32

    only have the option to replace the

  49. 1:34

    outer HTML but we could also append or

  50. 1:36

    prepend the response to the existing UI

  51. 1:38

    or the HX Target attribute allows us to

  52. 1:40

    move the UI to a completely different

  53. 1:42

    element it finds that element with a CSS

  54. 1:44

    selector but has additional syntax like

  55. 1:47

    next and closest allowing you to easily

  56. 1:49

    find the proper element without a bunch

  57. 1:51

    of custom IDs we might also use HDMX

  58. 1:53

    indicator to show a loading spinner and

  59. 1:55

    write a CSS transition animation for the

  60. 1:58

    incoming element behind the scenes a