--- author: [Teemu Lahjalahti](https://www.linkedin.com/in/teemulahjalahti/) index: https://salty-css.dev/llms.txt --- # Accessibility Salty can't make your site accessible. What it can do is make the accessible version the *shorter* one to write — and that matters more than it sounds, because most accessibility bugs in a component tree aren't exotic. They're a `
` a keyboard can't reach, an action that only appears on hover, a focus ring someone deleted because it looked wrong after a mouse click, a list that stopped being a list the moment the design turned it into a grid. Nobody sets out to do any of that. It happens because in the moment, the correct version was the one that needed more work — an extra wrapper, an extra prop, an extra thing to remember at forty call sites. Salty doesn't solve the hard part. A combobox, a modal, a drag-and-drop reorder — those are real engineering problems, and no styling library hands them to you. What it removes is a set of small excuses: you can swap the rendered element per instance, style directly off the attributes assistive tech already reads, and bind attributes to a component so nobody has to remember them. Nine patterns below, each one a define-then-use pair. Where a platform detail deserves more than my summary of it, I link to MDN instead of restating it here — the web has never been short of good accessibility guides, settled patterns, or purpose-built APIs. It's short of people using them, and no amount of documentation has fixed that yet. --- ## 1. Render the element the job actually calls for Heading level is document structure. Screen reader users navigate by it — jumping heading to heading the way you skim a page with your eyes — so an outline with a hole in it is a page with a broken table of contents. Font size is a visual decision. Tie the two together and every design tweak becomes a structural change. `styled` keeps them as two separate knobs. ### How you define it The tag is the first argument; the looks are variants: ```ts import { styled } from "@salty-css/react/styled"; export const Heading = styled("h2", { base: { margin: 0, fontWeight: 700, lineHeight: 1.1 }, variants: { size: { sm: { fontSize: "1.25rem" }, md: { fontSize: "1.75rem" }, lg: { fontSize: "2.5rem" }, xl: { fontSize: "3.5rem" }, }, }, defaultVariants: { size: "md" }, }); ``` ### How you use it `as` overrides the rendered tag per instance. The variant props stay typed regardless of what it resolves to: ```tsx // The page's one

, rendered large. Salty CSS // A section heading —

is the default, so no `as` needed. What you'll learn // Looks like a headline, isn't one: a card label under an existing

. Recipe ``` That last one is the case people miss. Not every big bold string is a heading, and a card grid that emits fifteen `

`s gives a screen reader user a table of contents made of noise. At definition time the same override is the `element` option — `styled("div", { element: "section" })` styles one thing and renders another. When the first argument is a *component* rather than a tag, that component owns the tag; wrap the one that already renders what you want, forwarding whatever it needs with `passProps`: ```ts import { styled } from "@salty-css/react/styled"; import NextLink from "next/link"; const buttonLook = { display: "inline-flex", alignItems: "center", gap: "0.5em", padding: "0.6em 1.2em", borderRadius: "6px", }; export const Button = styled("button", { base: buttonLook }); // Same look, but it's a real link — href and all. export const ButtonLink = styled(NextLink, { passProps: ["href"], base: buttonLook, }); ``` A link and a button are not the same control even when they're identical to look at. A link navigates: it gets ⌘-click, right-click *open in new tab*, a status-bar preview, and it's announced as a link. A button acts: it fires on Space as well as Enter, participates in forms, and can be genuinely `disabled`. Choosing between them by appearance is how you end up at `
` with a hand-rolled key handler that only listens for Enter — which is the spaghetti this whole page is trying to talk you out of. The tag is the cheapest accessibility decision you'll make all week. --- ## 2. Semantic wrappers that don't cost you the layout The usual reason a `
    ` disappears from a card grid: the grid is on the parent, the `
  • `s are children of the list, and adding the list breaks the layout. So the list gets deleted and the cards become bare `
    `s. Now nothing announces "list, 6 items," and nothing lets a screen reader user jump past it. `display: contents` removes an element's own box while leaving its children exactly where they were in the flow. The layout stops seeing the wrapper; the accessibility tree keeps it. ### How you define it ```ts import { styled } from "@salty-css/react/styled"; export const CardGrid = styled("section", { base: { display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(16rem, 1fr))", gap: "{spacing.medium}", }, }); // Semantics with no box of its own. export const CardList = styled("ul", { defaultProps: { role: "list" }, base: { display: "contents", listStyle: "none", margin: 0, padding: 0, }, }); ``` ### How you use it ```tsx
  • …
  • …
  • ``` The `
  • `s are the grid items. The grid doesn't know the list is there; assistive tech does. The same move works for a `