Rule
no-hardcoded-radius
Border radius must use radius tokens, not arbitrary values.
- What it catches
- Arbitrary radius (
rounded-[7px],borderRadius: 14) - Why it matters
- Corners are part of the visual language. An arbitrary radius looks almost right next to the components and never quite matches them. A warning by default.
Example
What check_ui returned for this code against the demo design system when the site was built, from version 0.12.1.
<div className="rounded-[7px] border p-4"> <Badge className="rounded-[999px]">New</Badge></div><div className="rounded-sm border p-4"> <Badge className="rounded-full">New</Badge></div>1:17warningno-hardcoded-radiusfix included
Hardcoded radius
rounded-[7px](7px) is off the scale. Nearest:rounded-sm(6px).2:21warningno-hardcoded-radiusfix included
rounded-[999px](999px) is far above the radius scale, so it reads as fully rounded: userounded-full.
How the fix is chosen
Nearest radius token (rounded-sm), including Tailwind's default keys; rounded-full (or a pill token) for values far above the scale (rounded-[999px]).
Every finding in the example carries its fix as text edits, which the agent applies, and so does eslint --fix. The code after the fix is those edits, applied.
- Color matches under ΔE 0.02 count as the same color.
- Under 0.1 the fix is offered, except for a Tailwind palette class: it is fixed only to a token that matches it or that is nearest to the class's own shade (of the shades in its family) and within ΔE 0.037 of it, the most Tailwind v3 and v4 differ on one shade.
- Another close token is suggested without a fix, and the message says why (one shade darker, or closest to another color of the same shade).
- Beyond 0.1 the message names the nearest token but leaves the choice to the agent.
- Opacity is part of the color: a token more than 0.02 apart in opacity is never a fix, so
bg-[#e7000b33](the red at 20%) is not fixed to an opaquebg-destructive, nordark:border-[#fff]to a darkborderthat is 10% white. - The message gives both opacities, and an opacity modifier stays on the token (
bg-[#fff]/40→bg-background/40). - A fix is only offered for a token of the same hue (within 15°), or a gray for a gray, whether the color is a palette class, an arbitrary value or a literal: a pale color counts as a hue by its chroma relative to its lightness, so
bg-[#fef2f2]is never swapped for a light gray that happens to be close. - Status colors (
destructive,warning,success,infoand their foregrounds) are only offered for nearly the same hue (within 8°), never for a gray, so a brand-orange button does not becomebg-destructive. - The other way round, a fix to another token is held back when a status color of the color's hue (within 15°) is close too and at most ΔE 0.03 further: next to a rose
brand,bg-[#ef4444]may be an error, so the message offersbg-destructiveif the color shows a status andbg-brandotherwise, and error text does not follow the next rebrand. - When a color is a hue and no token has it, the finding is a warning that names no token: add a token for the hue, or keep the color with a suppression comment and a reason (
{/* */}between JSX children). - A chart token outside a chart, such as
text-chart-2on a green "Active" label in a theme with no success color, is a warning with no fix: it is a token, but it changes with the chart palette and does not say what a status color says, so add a status token (status colors) or use the token that fits. - A file that draws a chart (it imports a chart library, renders
<ChartContainer>or<BarChart>, declareschartData, or is named for charts) is left alone, legend dots and all, as is an element in an<svg>, a<figure>or arole="img", and every chart token when the design system's own components use them outside a chart. - Tailwind's
whiteandblack(bg-white,border-black) are fixed only to a token of exactly that color, such asbg-backgroundforbg-whitein a stock shadcn/ui theme. - A hardcoded background (white or black, a palette class or an arbitrary color) is not fixed to a token while hardcoded text on it stays as it is and would no longer stand out from the token in some mode.
- The text is white or black, a tint of them (
text-black/80), or a color whose own finding has no fix (text-neutral-900held back as another shade,text-[#000], an allowed class), on the element or an element inside it, in the background's state (hover:bg-black), or on an element around it whose text color the element inherits (no element in between sets one or is a component, which can set its own, and the element has content). - So
bg-black text-whiteandbg-zinc-900 text-whiteare not fixed tobg-primary, which is near white in shadcn/ui's dark mode, andbg-white text-neutral-600is not fixed to a background token that is black in dark mode. - The text stands out from a color 0.25 apart in lightness (OKLCH L) or with 3:1 contrast (WCAG's minimum for large text), and the fix is held when the token takes away either one that the hardcoded background gave it:
text-neutral-600is 0.44 lighter than black, but has 2.7:1 on it. - The message names the token to change the text to with it (
text-primary-foreground), except for a hue (text-green-800), which a gray foreground would not keep. - The fix stays when the text's own finding fixes it too, when the class list sets the dark-mode background or text itself (
dark:bg-zinc-900,dark:text-white), or when the token keeps the text standing out in each mode; a token with no dark value onsystem reads may still have one, so it counts as changing. - A theme that defines
--color-whiteor--color-blackmakes them its own tokens, which are not reported. - White or black text, fill or stroke is a warning without a fix, since its token depends on the surface under it, and is not reported on a surface it stands out from in each mode it shows in (dark mode too, unless its class list sets its dark color): a color at least 0.25 apart in lightness (OKLCH L), a gradient, an image, a background in
style(a swatch known only at run time counts) or a tint it stands out from (bg-black/60under white text), set in its class list (in the same state:hover:bg-red-600 hover:text-white), by its component's variants or by the nearest element around it that sets a background. - A tint it does not stand out from (
bg-white/10under white text) shows what is under it: the element around it, or else the theme'sbackground. - So shadcn/ui's
bg-destructive text-whitepasses, andtext-whiteonbg-muted, onbg-white, or onbg-primarywhereprimaryis near white in dark mode, is reported. - With an opacity modifier (
bg-black/50,border-white/10) white and black tint what is under them and are left alone, as they are inside an SVG<mask>. - Among the tokens that qualify, the one made for the utility wins:
foregroundandmuted-foregroundfortext-*,fill-*andstroke-*; surfaces such asmutedforbg-*;border,inputandringforborder-*andring-*. - Tokens named
on-*are text colors, and so arecontent-*tokens unless the rest of the name says border or background (content-border,content-background). - A close token made for another role is named in the message but never swapped in.
sidebar-*andchart-*tokens are only suggested in a sidebar or a chart (by file, enclosing component or classes), and so is any other family that at most one design-system file uses, such as syntax-highlighting colors or one screen's background, outside that file's components;dark:classes are compared with dark-mode values.- A class under a condition (
hover:,focus-visible:,md:) is not fixed to the token the same class list has or gets without it, nor the other way round, unless the two already have exactly the same color:bg-[#2563eb] hover:bg-[#1d4ed8]would becomebg-primary hover:bg-primary, and the hover would change nothing. - The message suggests keeping them apart (
hover:bg-primary/90). dark:is not such a condition: adark:class is compared with dark-mode values, so the same token there is a fix.- Nor is a variant for a pseudo-element or other elements (
placeholder:,*:,prose-a:,[&_svg]:), whose color the class without it does not set. - Two hardcoded classes of exactly the same color (a palette class and its hex count as one) keep their fixes too, since the condition changed nothing before either:
border-red-500 focus:border-red-500keeps an error border red on focus. - A slight change is still a change:
bg-[#fff] hover:bg-[#fafafa]keeps its hover, though both are within 0.02 ofbackground. - A state class is compared with the class it starts from: a
dark:hover:class with the list'sdark:class, when there is one. - Likewise, a spacing or radius step that is off by more than half the value (and more than 4px) is suggested but not auto-fixed.
- Spacing of 1px or less is not reported unless the scale has that exact step and the value is not negative (
py-[1px]→py-px): the nearest step (4px, say) would change the layout, and a negative hairline (mt-[-1px],-mt-[1px],marginTop: -1) is a deliberate border overlap. - A length in
em(px-[0.5em],padding: "0.5em") grows with the font, which no step of the scale does, so its nearest step is suggested and never fixed. - Rules that need tokens are skipped when the design system defines none of that category; a stylesheet that imports
tailwindcssbrings Tailwind's default spacing unit and radius scale, and so does a Tailwind v4 theme partial (@theme, where no token stylesheet importstailwindcss, such as a design-system package ships) in a project on Tailwind v4 (@tailwindcss/postcss,@tailwindcss/viteor@tailwindcss/cliin itspackage.json, ortailwindcssin a range other than v3's), unless the theme resets that namespace (--spacing-*: initial,--radius-*: initial), in which case only the project's own steps are suggested. - Syntax errors are reported as
syntax, and so is code nested too deeply for TypeScript's parser (thousands of levels), which is then not checked. - An icon button's label is fixed only when the icon means one thing on a button (a trash can, pencil, magnifier, gear, copy, download, upload, share or filter icon, named plainly:
Trash2orTrashIcon, notBinaryorFilterX) or the code says what the button does: "More options" on a menu's trigger, and for an X, "Close" in a close part (DialogClose) whatever itsonClickcalls, or elsewhere "Remove", "Clear" or "Close" when every function itsonClickcalls says that one action (removeAssertion(index),clearSearch(),setOpen(false);clearTimeoutdoes not count). - Otherwise the message names a label without a fix, since a plus may add or expand, a chevron go to the next page or expand a row, and an X close, remove or clear: an X that resets a form and closes (
form.reset(); setOpen(false)) is named "Close", and one that callscloseDeleteDialogoronCancelDelete, or acts only in a callback such asonSuccess, is named without a fix. - A chevron or arrow in a collapsible's or accordion's trigger, or on a button with
aria-expanded,data-stateordata-[state=open]:classes, is named "Toggle", not "Next" or "Previous".
Options
Its default severity is "warn". Set it to "off", "warn" or "error" in onsystem.config.json, or as onsystem/no-hardcoded-radius in the ESLint plugin.
Values to accept anyway, as the class or the length.
{ "rules": { "no-hardcoded-radius": "error" }}The config file covers the rest, including overrides for folders.
Suppressing a finding
When a finding is intended, a comment turns the rule off for the next line and says why after --. Checked when the site was built: the comment hides the finding on the line below it, and the others stay.
// onsystem-disable-next-line no-hardcoded-radius -- why this one is intended<div className="rounded-[7px] border p-4"> <Badge className="rounded-[999px]">New</Badge></div>onsystem-disable-next-line covers the next line, onsystem-disable-line its own, and /* onsystem-disable */ the rest of the file (at the top, the whole file). Without rule names they turn every rule off. A misspelled rule name is reported as a suppression warning, with the closest one, and suppresses nothing; syntax errors cannot be suppressed. For whole folders or kinds of files, such as legacy screens or generated code, use overrides in the config.