Custom UI Components with Radix UI: Accessibility & Styling
We often face the task: create custom UI components that work with a keyboard, are correctly announced to screen readers, and still look unique. Ready-made UI libraries (Material UI, Ant Design) impose their own styles, while writing everything from scratch is time-consuming and prone to accessibility errors. Radix UI solves this problem: headless primitives with correct semantics, focus, and ARIA, while the appearance remains with the developer. Our experience of over 5 years in creating React interfaces confirms: Radix UI is the best choice for projects where accessibility and customization matter.
Why Radix UI is the Best Choice for Accessible Interfaces
Unlike traditional UI libraries, Radix UI does not impose styles. You get ready-made logic: focus management, keyboard navigation, ARIA attributes, and states. For example, Dialog automatically traps focus inside, closes on Escape, and blocks page scrolling — all without a single line of JavaScript. Compare that to a typical modal implementation: you need to manually handle focus trap, scroll lock, and animations. Radix UI reduces development time for such components by 3–5 times.
How Radix UI Simplifies Component Customization
Each Radix primitive consists of parts (Anatomy). You style each part independently via CSS classes or Tailwind. For example, <Dialog.Content> can have custom padding, background, and animation — without overriding built-in styles because there are none. This gives complete design freedom and speeds up layout.
What are Headless Primitives and Why Use Them?
Headless primitives are components without built-in styles that provide only logic (states, events, accessibility). This allows the developer to fully control the appearance without sacrificing correct semantics. Radix UI implements WAI-ARIA patterns, so your interfaces will be accessible to people with disabilities without extra effort. For example, when using Select from Radix, the screen reader automatically announces the selected item and the number of options.
Installation and Usage
npm install @radix-ui/react-dialog @radix-ui/react-select @radix-ui/react-dropdown-menu
import * as Dialog from '@radix-ui/react-dialog';
function Modal() {
return (
<Dialog.Root>
<Dialog.Trigger asChild>
<button className="btn-primary">Open</button>
</Dialog.Trigger>
<Dialog.Portal>
<Dialog.Overlay className="fixed inset-0 bg-black/50 backdrop-blur-sm" />
<Dialog.Content className="fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 bg-white rounded-lg p-6 w-full max-w-md shadow-xl focus:outline-none">
<Dialog.Title className="text-xl font-semibold">Title</Dialog.Title>
<Dialog.Description className="mt-2 text-gray-600">
Dialog description.
</Dialog.Description>
<Dialog.Close asChild>
<button className="absolute top-4 right-4" aria-label="Close">
✕
</button>
</Dialog.Close>
</Dialog.Content>
</Dialog.Portal>
</Dialog.Root>
);
}
Styling States via data-attributes
Radix sets data-state attributes to manage states: open/closed, active/inactive, etc. They can be used in CSS for animation or via the tailwindcss-radix plugin in Tailwind.
[data-state="open"] .dialog-overlay {
animation: fadeIn 150ms ease;
}
[data-state="closed"] .dialog-overlay {
animation: fadeOut 150ms ease;
}
[data-state="open"] .select-trigger {
border-color: #2563eb;
}
With Tailwind — via plugin:
<Select.Trigger className="data-[state=open]:border-blue-500 data-[placeholder]:text-gray-400" />
Accessibility - What You Get for Free
- Focus trap: in Dialog and Popover, focus automatically moves inside and does not escape.
- Escape to close: Dialog, Popover, Select close on Escape.
- Scroll lock: when Dialog is open, the page does not scroll.
- ARIA: automatic
aria-haspopup, aria-expanded, aria-controls, role.
- Keyboard navigation: in Select, Menu, RadioGroup — arrows + Home/End.
Radix Primitives Components
| Category |
Components |
| Overlay |
Dialog, AlertDialog, Sheet |
| Menu |
Select, DropdownMenu, ContextMenu, NavigationMenu |
| Popover |
Tooltip, Popover, HoverCard |
| Layout |
Accordion, Tabs, Collapsible |
| Form |
Checkbox, RadioGroup, Switch, Slider |
| Other |
Progress, ScrollArea, Separator, Avatar, AspectRatio |
Comparison: Radix UI vs Material UI
| Parameter |
Radix UI |
Material UI |
| Customization |
Full (no styles) |
Limited (theming) |
| Bundle size |
~5 kB (tree-shaked) |
~100 kB (with theming) |
| Accessibility |
WAI-ARIA by default |
Requires manual setup |
| Modal development time |
2–3 hours |
4–6 hours (with customization) |
| SSR/Next.js support |
Full |
Full |
Shadcn/ui - An Overlay on Radix
Shadcn/ui provides ready-made styled components based on Radix + Tailwind. Unlike regular UI libraries — components are copied into the project (npx shadcn-ui add button), not imported as a dependency. Full freedom to modify. This saves up to 40% additional time on initial setup.
Additional info: how to choose between Radix and Shadcn/ui
If you need full control over every line of code — choose Radix. If you want to get a ready but easily customizable UI right away — use Shadcn/ui. Both options provide excellent accessibility and performance.
Project Workflow with Radix UI
- Analysis of accessibility and design requirements.
- Selection of Radix primitives set.
- Custom styling (Tailwind/CSS).
- Integration with form or routing.
- Keyboard and screen reader testing.
- Deployment and Core Web Vitals optimization.
Estimated Timelines
Implementation of a UI component set (modal, dropdown, select, tabs, form) using Radix UI + custom styles: from 3 to 5 days depending on the number and complexity of components. The cost is calculated individually. We will evaluate your project for free — just write to us.
We guarantee full accessibility according to WCAG 2.1 standards and support for all modern browsers. Our team of certified React developers has over 5 years of experience and has completed more than 100 projects with Radix UI. Order Radix UI interface development today — get a consultation from our specialist. Contact us to discuss details.
Website Accessibility: WCAG, Screen Readers, Keyboard Navigation
On a major bank's website, the "Submit Application" button was marked up as <div class="btn" onclick="...">. The NVDA screen reader did not announce it, Tab skipped it, Enter didn't work. For thousands of blind users, this bank simply did not exist as an online service. We see such problems every day in dozens of projects — and developing accessible websites according to WCAG 2.2 AA has become the only way to avoid discrimination and legal risks. Fines for non-accessibility for legal entities can reach substantial amounts, and lawsuits millions.
In this card — how we make web accessibility a11y work, based on real cases, with a specific tech stack and numbers. No generic phrases.
Why is Semantic Markup the Foundation of Web Accessibility (a11y)?
Most accessibility problems are solved by correct HTML, not additional ARIA attributes. <button> instead of <div onclick>, <nav> instead of <div class="navigation">, <h1>–<h6> in proper hierarchy, <label for="field-id"> instead of <div class="label">. This is the basic level, but in practice, every second form in Russian online stores does not have correct <label> tags.
ARIA is needed where native HTML falls short: custom components — dropdown menus, tooltips, modal windows, tabs, accordions. And here the complexity begins.
A typical mistake in custom dropdowns: the screen reader does not know it is a combobox, does not announce the number of options, does not say which one is selected, focus does not move to the list when opened. Proper implementation:
-
role="combobox" on the input
-
aria-expanded="true/false" when opened/closed
-
aria-controls="listbox-id" points to the list
-
aria-activedescendant — ID of the currently selected item
-
role="option" and aria-selected on each option
This is not theory; it is tested with a screen reader. NVDA + Chrome or VoiceOver + Safari is a mandatory part of QA.
Example implementation of custom combobox with ARIA
<div role="combobox" aria-expanded="false" aria-controls="listbox-1" aria-activedescendant="" tabindex="0">
<label for="input-1">Select city</label>
<input id="input-1" type="text" role="combobox" aria-autocomplete="list" />
<ul id="listbox-1" role="listbox" aria-label="Cities">
<li role="option" aria-selected="false" id="opt-1">Moscow</li>
<li role="option" aria-selected="false" id="opt-2">St. Petersburg</li>
</ul>
</div>
The cost of fixing a single Level A violation varies depending on complexity. Implementing a11y from the design stage reduces the refactoring budget by 2–3 times compared to retrofitting a finished site.
How to Properly Build Keyboard Navigation?
Tab order should match the visual order of elements. If in HTML the "Cancel" button comes before "Confirm", but CSS swaps them — the keyboard user is confused.
Focus trap in modal windows. When a modal opens, Tab should cycle only within it. When closing, return focus to the element that opened the modal. Without this, the user ends up at the top of the page after closing.
tabindex="-1" — element does not enter Tab sequence but can receive focus programmatically. Used for elements that receive focus via JavaScript (section headings after anchor navigation).
tabindex="1" and above is almost always an error. Explicit order breaks natural order and creates unpredictable behavior. Control order via DOM, not tabindex.
Skip links — a "Skip to content" link, hidden visually, visible on Tab. Allows screen reader users to skip repetitive navigation.
Color and Contrast: Requirements and Common Violations
WCAG 2.2 AA requires contrast 4.5:1 for normal text, 3:1 for large text (18px+ or 14px+ bold). AAA requires 7:1 and 4.5:1.
The most common violations: gray placeholder in inputs (#999 on white = 2.9:1), light gray secondary text, white text on pastel backgrounds.
Color should not be the sole indicator: "required fields are red" without an asterisk — violation for color blind users.
Testing tools: axe DevTools, WAVE, Accessibility Inspector in Chrome DevTools. axe-core integrates into Playwright tests: automatic check of 80+ rules on every deployment. Manual testing finds about 60% more errors than automated.
What Is Important About Media Content and Dynamics?
Images without alt — a common basic failure. alt should be meaningful: not alt="image_123.jpg", but a description of content relevant to context. Decorative images — alt="" (empty, not missing attribute).
Video should have captions. YouTube auto-captions are not a standard; they make mistakes. WebVTT files with correct captions for all educational and marketing video content.
Animations — a problem for users with vestibular disorders. @media (prefers-reduced-motion: reduce) — media query that disables or slows animations for users with that OS setting.
What Changed in WCAG 2.2?
Version 2.2 came into effect with new criteria:
| Criterion |
Level |
Essence |
| 2.5.7 Dragging Movements |
AA |
All drag operations must have a keyboard alternative |
| 2.5.8 Target Size |
AA |
Minimum interactive element size 24×24 px |
| 3.2.6 Consistent Help |
A |
Contact/chat location should be same on all pages |
| 3.3.7 Redundant Entry |
A |
Do not force re-entry of same information in one session |
These criteria raise the entry bar, but we already include them in our standard checklist.
| Level |
Minimum text contrast |
Large text contrast |
| AA |
4.5:1 |
3:1 |
| AAA |
7:1 |
4.5:1 |
Audit and Remediation
Automated tools find about 30–40% of violations. The rest is only manual testing. Minimum scenario: go through the entire critical user flow (registration, purchase, form) using only keyboard and screen reader.
Process
-
Automated audit — axe-core, Lighthouse, WAVE — outputs 80+ rules.
-
Manual testing — NVDA, VoiceOver, keyboard — 2–3 days for a typical site.
-
Violation prioritization — P1 (blocks usage), P2 (creates difficulties), P3 (enhancements).
-
Fixing — iteratively, integrate checks into CI via Playwright + axe.
-
Re-audit — close all P1/P2 before release.
-
Documentation and handover — report with results, maintenance recommendations, team training.
Results and Scope
- Full audit report with violation prioritization (PDF/HTML)
- Fixed code: semantic markup, ARIA, keyboard navigation
- Integration of axe-core into CI/CD for regression control
- Training for client developers on a11y (2-hour session)
- Access to repository with correct component examples
- Guarantee of WCAG 2.2 AA compliance at time of delivery
Timeline
| Stage |
Duration |
| Site audit (up to 50 pages) |
3–7 days |
| Remediation of A/AA violations on existing project |
3–8 weeks |
| Development of new project adhering to WCAG 2.2 AA |
from 6 weeks |
Budget is calculated individually after the audit. Contact us — we will evaluate your project in 1 day. Get a consultation and free checklist when ordering an audit.
Experience and Guarantees
We have been working in web accessibility a11y for over 8 years. Completed more than 50 projects for banks, retail, and government. Certified specialists (IAAP CPACC, WAS). We guarantee passing a third-party audit or will fix for free.
WCAG 2.2 Standard — official W3C recommendation defining web content accessibility requirements.
Wikipedia: Web Content Accessibility Guidelines
Wikipedia: ARIA
— web accessibility levels a11y per version 2.2.
Order an audit now — get a checklist and preliminary estimate for free. Contact us – we will respond within an hour.