HTMX Crash Course
HTMX is a library that allows you to create dynamic web pages without writing any JavaScript. It is a game-changer for web developers who want to improve user experience by making their websites more interactive and responsive.
Getting Started with HTMX
To get started with HTMX, you need to include the HTMX library in your HTML file. You can do this by adding the following script tag to your document’s head:
<script src="https://unpkg.com/htmx.org@1.4.0/dist/htmx.min.js"></script>
Creating Dynamic Pages
Once you have included the HTMX library, you can start making your web pages dynamic. HTMX uses HTML attributes to define the behavior of your elements, so you don’t need to write any JavaScript code. For example, you can use the hx-get
attribute to dynamically load content from a server without refreshing the entire page:
<div hx-get="/api/posts">Click here to load posts</div>
When the user clicks on the above <div>
element, HTMX will send a request to the specified URL and replace the content of the <div>
with the response from the server.
Handling Form Submissions
HTMX also makes it easy to handle form submissions without writing any JavaScript. You can use the hx-post
attribute to send form data to a server and update the page with the response. For example:
<form hx-post="/api/submit-form" method="post">
<input type="text" name="username" placeholder="Enter your username" />
<input type="submit" value="Submit" />
</form>
When the user submits the form, HTMX will send the form data to the specified URL using a POST request and update the page with the response from the server.
Conclusion
HTMX is a powerful library that allows you to create dynamic web pages without writing any JavaScript. It simplifies the process of making your websites more interactive and responsive, and it is a great tool for improving user experience. If you want to learn more about HTMX, be sure to check out the official documentation and start experimenting with it in your projects!
hey brad, is your laravel course will be soon available?
I'd rather use no server than no JavaScript every single time
I was waiting for an HTMX video from you. Thanks for posting!
YouTube Intro Tutorials are a requirement nowadays for people who cant even understand the documentation.
Videos like this actually explain what you should/and should not do and I appreciate that. ❤
If more tutorials are done like this first, developers will understand the documentation better. Then they will he able to use these "steel lego bricks" to build "tools" to build components that (feel) very easy to reuse.
You are the first best teacher on these things and I appreciate that. ❤ Thank you. ❤️
Thanks Brad!
Great content! Thank you for this tutorial. Happy New Year. Do you have tutorials for framework agnostic components ? Like say LitElement or Adobe Spectrum ?
Wow, what a treat! I've been looking for a quick and simple tutorial for HTMX. Thank you!
I was searching for an HTMX guide to start my next project, this came up right on time. This was a great tutorial, thank you!
This course is amazing. But a question, how viable is it for big projects (100+ pages) with 150+ API endpoints/ rest and graphql etc.
Because this looks like we are merging Backend and Frontend together. So an existing API can't be used if there is one, and even for new projects HTMX makes it so we have to create a specific API tailoring to HTMX which then can't be used for other projects which need to use the same API?
What are the main use cases for this?
Thank you
It is a good tutorial, but for me, one point is misleading: calling no javascript is not the truth. It's still JavaScript, but you don't need to write JS code deliberately. Under the hood, htmx is a javascript library that binds HTML attributes.
Very nice tutorial Brad. Lord bless you. HTMX is cool but one thing I can’t help but notice is that even for the simplest of things like email validation or checking for an empty search value we have to make a separate API request, wouldn’t it be better if these things are somehow provided by HTMX. Would love to know your take on this?
Hi Brad and hello community. Thank you for this intro to HTMX. I like the simplicity and the low footprint of HTMX. I want to use it with Rust and now need to figure out how. Overall it looks very nice. May you all have a great 2024!
Thank you Brad, the best and award-winning programming instructor in the world. Keep up the good work. May the good Lord bless you and water your garden as you water ours. Happy new prosperous year.
I have been exploring HTMX for the past few days and trying to build a todo app using the BETH Stack, which includes Bun, Elysia, Turso, and HTMX. This video has come in handy! Thank you!
Thanks Brad, been curious about HTMX.
wtf ? when did you hit millions ?
2024 === HTMX
Great video. It's what I needed to get on with HTMX. Thanks.
Excellent video! Thanks for sharing it!
When picking a server-side stack, I think it’s a good idea to choose one that has good support for generating HTML (not just string concatenation) and has tooling support that gives syntax highlighting and understands what is valid in HTML.
htmx, finally 😉 You've just scratched the surface… Hope you will continue on this path as, IMO, you are probably the only YT coding instructor that is clear and devoid of fast-edit/fast-speak. Thanks!