#92New: A modal that traps focus

The frontend tricksthe docs leave out.

One short, tested tip for CSS, HTML and JavaScript. Every Tuesday, in five minutes or less.

Join 12,400+ developers · free, every Tuesday

Read by developers at

  • Northwind
  • Lumen
  • Parcel
  • Ostrich
  • Fieldwork
  • Hexagon
  • Quarry
  • Bluebird

Latest issues

Small fixes,explained properly.

Every issue is one problem you have hit, the few lines that fix it, and a demo that proves it works.

New#924 min read

A modal that traps focus. Zero JavaScript libraries.

The native dialog element now handles focus, Escape and the backdrop for you. Here is the five-line version that replaces the 40KB one.

HTMLAccessibility
javascript
const dialog = document.querySelector("dialog");
openButton.addEventListener("click", () => {
  dialog.showModal(); // focus trap + Esc, built in
});
#913 min read

Headlines that never leave one lonely word

One CSS property balances every line of a heading, and its sibling stops orphans in paragraphs. No JavaScript, no manual line breaks.

CSSTypography
css
h1, h2, h3 {
  text-wrap: balance;
}
p {
  text-wrap: pretty;
}
#904 min read

Style the form, not the input, with :has()

Highlight a whole field group when its input is invalid, without a single class toggle. The parent selector finally works everywhere.

CSSForms
css
.field:has(input:user-invalid) {
  border-color: var(--danger);
}
.field:has(input:focus-visible) {
  outline: 2px solid var(--ring);
}
Browse all 12 issues

Readers

Opened first,every Tuesday.

“The only newsletter I read the moment it lands. Every issue has fixed something in production that same week.”
Maya ChenStaff engineer
  • “Finally a newsletter that respects my time. One idea, explained properly, with a demo that works.”

    Jonas WeberDesign engineer
  • “The :has() issue alone deleted two hundred lines of JavaScript from our form library.”

    Aisha BelloTech lead
  • “Clear enough for juniors, sharp enough for seniors. Rare.”

    Ben CarterIndie developer
  • “I unsubscribed from everything else. This one stays because it never wastes a send.”

    Sofia LundProduct designer
  • “Every snippet actually runs. I paste them straight into code review comments.”

    Daniel OkaforSenior developer
  • “It reads like advice from the best engineer on your team, minus the meeting.”

    Hana SatoFrontend lead

Archive

12 issues,all still useful.

Search every tip by name or filter by topic. Each one still works today.

Get the next issueon Tuesday morning.

One tested fix a week. Free, and one click to leave.