Video summary
Use these CSS features instead of JavaScript
Main summary
Key takeaways
Summary of CSS features replacing (or reducing) JavaScript
1) Smooth scrolling without manual offsets
- Problem:
scroll-behavior: smoothplus anchor/section jumping can cause the target to be hidden/overlapped by a fixed header. - CSS solution: use
scroll-marginon the target (e.g., thesectionor the header element that corresponds to the target ID) so the browser accounts for spacing automatically. - Demo detail: using a viewport-relative
scroll-margin(e.g.,vw/vh) helps illustrate spacing differences when scrolling to “middle” vs “bottom”. - Accessibility: coordinate smooth scrolling with
prefers-reduced-motionso users who prefer reduced motion get instant jumps (while still benefiting fromscroll-margin). - Support note: described as having solid browser support for
scroll-behavior, and “around forever” / widely available support forscroll-margin.
2) Horizontal scrolling + CSS scroll snapping
- Approach: create a horizontal scroller (shown using CSS Grid, though flexbox also works) and rely on CSS scroll snapping.
- Key CSS requirements for snap:
- Parent: define
scroll-snap-type(axis + snapping mode). - Child: define
scroll-snap-align(the snap alignment target likecenter,left,right, etc.).
- Parent: define
scroll-snap-typevalues:- Axis:
inline/block(orx/y) - Mode:
mandatoryvsproximity(recommended to test based on your use case)
- Axis:
- UX notes:
- Desktop: snapping can feel less ideal during scrolling, but it still snaps reliably to the next element.
- Mobile: described as feeling “just great” for web app-like horizontal content.
- Support note: described as excellent.
3) Form validation: prefer CSS :user-valid / :user-invalid over JS blur logic
- Motivation: common JS patterns (listening to
blur, toggling “touched”, then applyingvalid/invalidstyles) can become complex. - Why CSS-only
:valid/:invalidcan be a poor UX:- Fields may be marked invalid immediately based on constraints, even before the user interacts (e.g., required fields appear invalid on load).
- CSS solution: use
:user-validand:user-invalidso validation styling changes only after user interaction (e.g., after focus/blur). - Examples mentioned:
- Required fields can become invalid once constraints apply, but remain neutral until the user types.
- Use built-in constraints like minimum length to trigger valid/invalid states automatically.
- Use
patternwith regular expressions to validate formats (e.g., requiring a number).
- Messages:
- Browser-native validation messages can be customized/extended (customization typically requires JS), but the base validity marking can work without it.
- Recommendation / best practice:
- Use CSS as the first line of defense for user feedback.
- Still perform server-side validation on submit.
- Support note: discussed as broadly available for a couple of years; “safe at this stage,” with the reminder to re-check depending on the audience.
4) Better focus styling: use :focus-visible instead of removing outlines
- Issue: removing focus outlines (e.g.,
outline: none/focus: 0) hurts accessibility for keyboard users. - CSS solution: use
:focus-visibleso the focus ring appears only when appropriate (e.g., keyboard/tab navigation), but not for mouse clicks. - Support note: described as standard browser behavior with strong support.
5) Textarea sizing without “magic numbers”: lh unit + min height
- Problem: “make it 3 lines tall” often becomes fragile when fonts change—hard-coded heights break.
- CSS solution:
- Use the
lhunit to size textarea height in terms of “number of lines” (e.g.,min-height: 3lh). - Prefer
min-height(and possibly logical property variants likemin-block-size) over fixedheight.
- Use the
- Result: textarea height adjusts automatically when the font size changes, maintaining the intended line count.
6) Auto-growing fields/textarea: field-sizing
- Previous pain: expanding textarea as the user types typically required JS measuring.
- CSS solution:
field-sizingenables auto-growing behavior via a single CSS property. - Progressive enhancement:
- Described as broadly available, with full support for most browsers after it was added “recently”.
- Used as a strong example of progressive enhancement for chat bubbles and other content-dependent sizing.
Main speakers / sources
- Kevin Powell (the channel host referenced throughout: “Kevin Powell” / “I’ll leave a link in the description” / “I have to talk about… it might be worth…”).
- Mentions of inspiration/support: Johnny (credited as inspiration), plus “patrons and sponsors” supporting the channel.
Rate this summary
Your feedback will help improve summaries.
Improve this summary
Reprocess with a stronger model when the summary feels incomplete or inaccurate.
Translate summary in another language
Ask questions to this video
Chat for follow-up questions, clarifications, and source-backed answers.