- Part I - Web Components without a Framework
- 1. Why Web Components, Why Lit
- 2. Custom Elements: Definition and Lifecycle
- 3. Attributes, Properties, and Reflection
- 4. Shadow DOM and Encapsulation
- 5. Slots, Composition, and the Template Problem
- Part II - Getting Started with Lit
- 6. Your First Lit Component
- 7. Project Setup and Tooling
- Part III - Core Lit
- 8. How Lit Renders
- 9. Reactive Properties and Attributes
- 10. The Update Lifecycle
- 11. Expressions and Bindings
- 12. Composing Templates and Template Safety
- 13. Built-in Directives
- 14. Writing Custom Directives
- Part IV - Styling and Theming
- 15. Styling Components
- 16. Theming: Custom Properties and Parts
- 17. Design Tokens and Multi-Theme Systems
- Part V - Architecture and Patterns
- 18. Events and Component Communication
- 19. Reactive Controllers
- 20. Async Data and the Task Controller
- 21. Context and Dependency Injection
- 22. State Management, Stores, and Signals
- 23. Forms and Form-Associated Custom Elements
- Part VI - Building the Design System
- 24. Designing a Component API
- 25. Accessibility Fundamentals
- 26. Focus Management and Overlay Components
- 27. Animation and Transitions
- 28. Documenting Components and the Manifest
- Part VII - Delivery
- 29. Routing and the App Shell
- 30. Testing Components
- 31. Visual Regression, E2E, and CI
- 32. Performance and Rendering Cost
- 33. Localization and i18n
- 34. Server-Side Rendering and Hydration
- 35. Publishing the Library
- 36. Framework Interop
- Appendices
- Appendix A: TypeScript with Lit
- Appendix B: Browser Support and the Baseline
- Appendix C: Migrating to Lit
- Appendix D: Tooling and Build Reference
- Appendix E: Quick Reference
Web Components with Lit
A hands-on guide to building web components and design systems
Frameworks come and go; components built on the browser's own element model don't have to. This book teaches the platform first, then Lit on top of it, and builds one real design system the whole way through: from a bare button to a versioned, documented, server-renderable npm package.
Minimum price
$19.00
$29.00
You pay
Buying multiple copies for your team? See below for a discount!
About
About the Book
Frameworks come and go. The components you build on the browser's own element model don't have to.
Web Components with Lit teaches the platform first — custom elements, shadow DOM, slots, the upgrade problem, retargeted events — with no framework in sight, because Lit is a thin layer over those primitives and the layer makes more sense once you've felt the bare platform. Then it builds up Lit itself: reactive properties, the update lifecycle, templates and directives, reactive controllers, context, state management, and forms that work inside a native <form>.
One project runs through the whole book. Cinder is a small design system, published as cinder-ui. It starts in Chapter 6 as a button that does almost nothing and ends as a versioned, documented, server-renderable npm package with a React wrapper and written guidance for every other framework. Along the way you build an icon, a text field and checkbox that participate in form validation, an accessible dialog, a toast system, and a theming layer driven by design tokens.
The book is written to be read four ways. If you're new to web components, Part I teaches the platform from zero. If you're coming from React, Vue, or Angular, it shows you the parts of the browser your framework hides and where Lit's reactivity diverges from what you know. If you already ship Lit, it starts you at the patterns most Lit codebases get wrong — controllers, context, state, forms — and the delivery material that's hardest to find written down: accessibility, testing, visual regression, localization, server-side rendering, and publishing.
Every example is plain JavaScript. Lit needs no compiler and no build step to start, and the standards-only syntax — static properties, no decorators — is the version that will still run unchanged years from now. Where TypeScript changes the picture, a short callout shows the decorator equivalent, and an appendix collects all of it.
Every runnable listing in the book was actually run, in a real browser or a real terminal, before the text described what it does — including the listings that are meant to fail. Every cross-reference was checked. Every version number was verified against the live source. Where checking the code caught the first draft being wrong, the correction was left in the text.
Targets Lit 3.3.3. 36 chapters, 5 appendices, 102 figures.
You'll learn how to:
• Define custom elements and manage their lifecycle without a framework
• Use shadow DOM, slots, and CSS encapsulation deliberately
• Model reactive state with Lit's properties and update lifecycle
• Write templates, use built-in directives, and build your own
• Style and theme components with custom properties, parts, and design tokens
• Extract behavior into reactive controllers and share state with context and stores
• Build form-associated components that validate inside a native <form>
• Make components accessible: focus management, overlays, ARIA across the shadow boundary
• Test components, add visual-regression and end-to-end coverage, and wire up CI
• Localize, server-render and hydrate, and publish a component library to npm
• Consume the library from React and other frameworks
Who it's for: developers who can write modern JavaScript and have touched the DOM directly at least once. No TypeScript, no build tool, and no prior component-library experience required.
Feedback
Team Discounts
Team Discounts
Get a team discount on this book!
Up to 3 members
- Minimum price
- $47.00
- Suggested price
- $72.00
Up to 5 members
- Minimum price
- $76.00
- Suggested price
- $116
Up to 10 members
- Minimum price
- $133
- Suggested price
- $203
Up to 15 members
- Minimum price
- $190
- Suggested price
- $290
Up to 25 members
- Minimum price
- $285
- Suggested price
- $435
Author
About the Author
Sandeep Kumar Patel is a senior web developer and founder of
, a widely- read programming blog since 2012. He has more than six years of experience in object-oriented JavaScript and JSON-based web applications development. He is GATE-2005 Information Technology (IT) qualified and has a Masters degree from VIT University, Vellore
Contents
Table of Contents
Get the free sample chapters
Click the buttons to get the free sample in PDF or EPUB, or read the sample online here
About the Publisher
About the Publisher
This book is published on Leanpub by Tutorial Savvy
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Write and Publish on Leanpub
You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!
Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.
Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.