CSS Subgrid Layout Builder - Online Align Nested Grids
Design a layout where nested grids share track sizes with their parent via subgrid. Copy the complete CSS.
UD5 Toolkit
Test and compare :focus-visible vs :focus pseudo-classes in real time. Discover how browsers intelligently show focus rings only when you need them — for keyboard navigation, not mouse clicks.
tabindex="0"
tabindex="0"
—
<input>, <textarea>, <select>), most browsers also match :focus-visible on mouse click — because showing a focus indicator on text fields is always helpful for usability. Buttons and links typically only match :focus-visible via keyboard navigation.
/* ✅ Best Practice: Hide default focus, show only for keyboard */
:focus {
outline: none;
}
:focus-visible {
outline: 3px solid #3b82f6;
outline-offset: 2px;
box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.25);
border-radius: 4px;
}
/* For older browsers, use the polyfill: */
/* npm install focus-visible */
/* import 'focus-visible'; */
:focus-visible is a CSS pseudo-class that applies styles only when the browser determines that a focus indicator should be visible. It represents the browser's best guess about when the user really needs to see a focus ring — typically when navigating via keyboard (Tab, arrow keys) rather than mouse click or touch.
Introduced by the CSS Selectors Level 4 specification, it helps solve a long-standing UX problem: focus rings are essential for keyboard users but visually annoying for mouse users.
:focus — matches any element receiving focus, regardless of input modality (mouse, keyboard, touch, or programmatic). The focus ring appears every single time.
:focus-visible — matches only when the browser believes the user needs to see the focus indicator. Typically:
Native support is excellent across all modern browsers:
| Browser | Version | Support |
|---|---|---|
| Chrome | 86+ | ✅ Full |
| Firefox | 85+ | ✅ Full |
| Safari | 15.4+ | ✅ Full |
| Edge | 86+ | ✅ Full |
| Samsung Internet | 16+ | ✅ Full |
| iOS Safari | 15.4+ | ⚠️ Partial |
For older browser support, use the official focus-visible polyfill from WICG.
The polyfill adds a .focus-visible class to focused elements when the browser would have matched :focus-visible. Here's how to use it:
npm install focus-visible
// In your JS entry file:
import 'focus-visible';
/* In your CSS, use both to cover all browsers: */
:focus { outline: none; }
:focus-visible,
.focus-visible {
outline: 3px solid #3b82f6;
outline-offset: 2px;
}
The polyfill is lightweight (~2KB) and works by simulating the browser's heuristic using JavaScript event listeners for keyboard and mouse input.
This is expected browser behavior and part of the specification's heuristic. Browsers determine when to match :focus-visible based on element type and context:
You cannot override this heuristic with CSS alone. If you truly need to suppress focus indicators on text inputs for mouse users, you'd need JavaScript-based solutions (though this is generally not recommended for accessibility reasons).
The recommended best practice combines both pseudo-classes for maximum compatibility and usability:
:focus { outline: none; }:focus-visibleoutline-offset to prevent the focus ring from touching the element edge.focus-visible class with the polyfill for older browsers❌ Avoid: :focus { outline: none; } without providing an alternative — this breaks keyboard accessibility entirely.
Absolutely! You're not limited to the browser's default outline. Here are some creative approaches:
/* Glowing ring */
:focus-visible {
outline: none;
box-shadow: 0 0 0 3px #fff, 0 0 0 6px #3b82f6;
border-radius: 6px;
}
/* Underline indicator */
:focus-visible {
outline: none;
border-bottom: 3px solid #3b82f6;
padding-bottom: 2px;
}
/* Inset ring */
:focus-visible {
outline: none;
box-shadow: inset 0 0 0 3px #3b82f6;
}
Just ensure the indicator is clearly visible and meets contrast requirements. The demo on this page uses a blue box-shadow ring for :focus-visible and a red one for :focus to clearly differentiate them.
:focus-visible is a crucial tool for accessibility because it:
Never use :focus { outline: none; } alone without providing a :focus-visible alternative — this creates an accessibility barrier for keyboard-only users.
Design a layout where nested grids share track sizes with their parent via subgrid. Copy the complete CSS.
Create a pure CSS scroll progress indicator using animation‑timeline: scroll(). No JavaScript. Copy the complete code.
Paste your CSS and see warnings for properties that have limited browser support. Links to CanIUse. Modernize safely.
Limit browser gestures on an element: pan‑x, pinch‑zoom, manipulation. Draw on a canvas to test. Mobile dev helper.
Press any key to see the complete KeyboardEvent properties: key, code, keyCode, modifiers. Indispensable for game & shortcut developers.
Create complex linear gradients with any number of color stops, exact angles, and length units. Live preview and CSS code.
Style underlines, overlines, and strike-throughs with colors, wavy styles, and thickness. Modern CSS text‑decoration.
Design a button or card that glows on hover. Adjust shadow color, spread, and transition. Copy the CSS. Rich UI.
Create a realistic letterpress (debossed) text effect using CSS text‑shadow and background. Adjust depth and light direction. Copy code.
Generate a subtle noise/grain texture as a CSS background pattern. Adjust opacity and size. For that film look.
Create a customizable checkerboard or grid background using pure CSS gradients. Adjust cell size and colors. Copy the code.
Upload two images and apply CSS blend modes (multiply, screen, overlay, etc.). See the result and copy the filter CSS. Pure frontend.
Add print styles like removing backgrounds, adding page breaks, setting margins. See print preview instantly.
Create a pure CSS countdown timer with a flipping number effect. Adjust duration and style. No JavaScript needed for display.
Create a glowing or rotating border animation around an element. Copy the CSS keyframes. Pure CSS magic.
Create a custom HTML/CSS progress bar with percentage, colors, and animation. Copy the code. Modern UI element.
Press any key and see it light up on a standard QWERTY layout. Check functionality or demonstrate shortcuts.
Design a realistic neon sign text with multiple layers of glow. Copy the CSS and HTML. Perfect for headers.
A replica of the famous Flexbox Froggy game: solve alignment puzzles by writing CSS. Progress saved locally. Fun frontend learning.
Fetch a website's CSS and extract :root custom properties (‑‑color) to reveal its design token palette. For learning and inspiration.
Enter a URL and extract tab‐index order violations and focusable elements. Quick accessibility audit. Client‑side fetch.
Recreate the target CSS linear gradient by adjusting stops and colors. A unique game for front‑end developers to master gradients.
Play a virtual piano keyboard using mouse or computer keys. Sustain and octave control. Record and play back your tune.
Browse and search all Font Awesome 6 icons with preview, class name, and unicode. Copy the HTML snippet. Perfect for web developers.
Create text with a gradient fill using CSS background-clip. Configure colors and direction. Copy the code. Works in modern browsers.
A complete, searchable list of all 140+ named HTML/CSS colors with their hex codes and color previews. Click to copy code. Essential web reference.
Visually experiment with Flexbox container and item properties. See the layout update in real time and copy the CSS. Learn by doing, fully interactive.
Minify JavaScript and CSS code to reduce file size for production. Remove whitespace and comments instantly. Run locally, your code stays private.
Easily create asymmetric border radius values and preview the result. Copy the generated CSS instantly. All interactively and browser-based.
Beautify and format your CSS stylesheets instantly. Organize, minify, or prettify CSS code for better readability. Processed securely on client-side.