Skip to content

This notebook belongs to

Sadat Jubayer

Senior Software Engineer at Premio

If found, please return to hello@jubayer.dev

Vol. 7Seven years of building

Started
January 2020
Everyday tools
TypeScript, Vue, React, Next.js, NestJS, React Native
Education
B.Sc. CSSE, AIUB, 2020
2 min readCSS

Keep focus rings in a Tailwind upgrade

Run the Tailwind v4 upgrade tool and check that renamed utilities preserve the focus treatment from your v3 project.

You ran a dependency update and Tailwind v4 is on the list. Your buttons and inputs already have a focus treatment you want to keep. Move the build and the classes together, then check what a keyboard user sees.

Run the upgrade tool on a clean branch

The Tailwind upgrade guide recommends running the tool in a new branch. The tool requires Node.js 20 or newer. Open a form on v3 and tab to a field so you can compare its focus ring after the upgrade. Check your browser requirements first. Tailwind v4 targets Safari 16.4+, Chrome 111+ and Firefox 128+.

From the root of your v3 project on that branch, run the tool and inspect the changes.

npx @tailwindcss/upgrade
git diff

In a small fixture, the tool updated the dependency, changed the CSS entry to a Tailwind import and rewrote the input's utility classes.

Start with the files that connect Tailwind to your build. If you use PostCSS, Tailwind's plugin is now @tailwindcss/postcss. In the stylesheet, the old three @tailwind directives give way to @import "tailwindcss". Check that the build still includes the same entry stylesheet before debugging class names.

Check the focus classes in the diff

This fixture starts with rounded-sm shadow-sm focus:outline-none focus:ring focus:ring-blue-500. Those names need attention when you want the v3 appearance in v4. Keep the renamed utilities if the tool already migrated them. The input should read like this after the migration.

<input
  aria-label="Search"
  class="rounded-xs shadow-xs focus:outline-hidden focus:ring-3 focus:ring-blue-500"
>

Tab to Search and check for a 3 px blue ring and the same radius and shadow sizes as before. Tailwind v4 refreshed its palette, so the named blue can look different. Keep your exact v3 color as a theme token if you need to preserve it.

The bare ring is 1 px in v4. Use ring-3 where you meant the old width. The old outline-none hid the outline while allowing it to appear in forced colors mode. The v4 name for that behavior is outline-hidden. Check a focus state in forced colors as well as in your default theme.

If a focus ring looks thin in the rebuilt page, inspect its computed box shadow and the utility that set it before editing other rings.