Navigation

CSS Tabs

Tabs on radio buttons: switching, single selection within the group and arrow keys all come from the browser, no JS needed.

  • tabs
  • radio
  • no-js
  • css

Preview

1440pxHost theme

Use it with AI

  1. 1. Copy the link.
  2. 2. Write to your agent in your own words and drop the link into the sentence.
  3. 3. The agent opens the link and installs the component from the registry.

put this in the header: https://vibeui.ru/c/tabs-002?lang=en

Компонент рендерится без единого пропа: значения по умолчанию заданы прямо в файле.

Файл копируется в проект одной командой. Внешних зависимостей нет — только react.

Цвета живут в переменных с префиксом компонента, поэтому тема хозяина не перебивает их.

Show the full instructions

What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.

# Install and place "tabs-002" (CSS Tabs) from VibeUI

## 1. Install first — do not skip, do not recreate
Run this exact command before writing any code:
npx shadcn@latest add https://vibeui.ru/r/tabs-002.json

Registry item: https://vibeui.ru/r/tabs-002.json
Installs to: components/vibeui/tabs-002.tsx (the exact path follows this project's components.json aliases).
npm dependencies: none.
Registry dependencies: none.

Install it from the registry. Do not recreate it from the description,
do not substitute a similar component from another library, and do not
rewrite it to match the project's existing style.

## 2. What it is
Tabs on radio buttons: switching, single selection within the group and arrow keys all come from the browser, no JS needed.

Tabs without JS: a scrollable strip, the selected tab on a light pad, the panel revealed by a :has() selector. Zero dependencies, one file.

## 3. How to use it
import { Tabs002 } from "@/components/vibeui/tabs-002"

<Tabs002 tabs={[{ label: "Overview", text: "…" }]} name="docs" />

Read the installed file for the full prop list.

## 4. Where to place it
This is a small inline component. Put it exactly where the user asked,
inside the existing markup. Do not create a new page, section or
wrapper for it. If a similar control already sits in that spot,
replace it instead of adding a second one.

Placement: ___
(The user fills this line in. If it is still blank, ask where to put it
instead of guessing.)

## 5. Keep exactly as installed
- the local --vibeui-tabs-002-* palette — do not swap it for your theme tokens
- the radio buttons: the browser keeps a single selection and gives arrow keys
- a unique name per tab set on the page — otherwise the groups merge
- the :has() rules covering six tabs: a seventh needs one more CSS line
- scrolling the strip instead of wrapping the labels
- the visible focus ring on the selected tab

## 6. You may change
- the tabs array and their content
- name — the radio group name
- the accent through the accent prop
- the block width

## 7. Rules
- tab/tabpanel roles are deliberately absent: without JS their state cannot be maintained, so the strip is a radiogroup.
- The tab is not reflected in the URL: for a linkable section use tabs-001.
- Every panel's content ships at once: load heavy panels through your own code.
- Do not lift the CSS variables into globals.css: the component has to stay a single file.

## 8. Verify
- it renders with no console errors;
- it looks like the preview on the VibeUI page you copied this from;
- if it does not, you changed something listed in section 5 — put it back.

For developers

npx shadcn@latest add https://vibeui.ru/r/tabs-002.json
https://vibeui.ru/r/tabs-002.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-tabs-002-*. Серверный: хуков нет, состояние держат радиокнопки. Панель показывает селектор :has() по отмеченной кнопке, поэтому правила выписаны на шесть вкладок. Полоса вкладок прокручивается по горизонтали: на узком экране подписи не переносятся.

Component source

The same file your agent installs. Here in case you would rather copy it by hand.

import type { ComponentPropsWithoutRef, CSSProperties } from "react"

export type Tabs002Tab = {
  label: string
  text: string
}

export type Tabs002Props = Omit<ComponentPropsWithoutRef<"div">, "children"> & {
  tabs?: Tabs002Tab[]
  name?: string
  accent?: string
}

// Идея компонента: вкладки без единой строки JS. Переключение держат
// радиокнопки: браузер сам следит, что выбрана одна, и даёт стрелки по группе.
// Панель показывается селектором :has() по отмеченной кнопке, поэтому правила
// заданы на шесть вкладок — больше требует ещё одной строки CSS.
const STYLES = `
:where([data-vibeui-block="tabs-002"]){
--vibeui-tabs-002-bg:oklch(1 0 0);
--vibeui-tabs-002-fg:oklch(0.24 0.014 265);
--vibeui-tabs-002-muted:oklch(0.56 0.014 265);
--vibeui-tabs-002-border:oklch(0.91 0.006 265);
--vibeui-tabs-002-track:oklch(0.96 0.003 265);
--vibeui-tabs-002-accent:oklch(0.55 0.2 262);
--vibeui-tabs-002-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="tabs-002"]{
width:100%;max-width:24rem;box-sizing:border-box;padding:0.375rem;
background:var(--vibeui-tabs-002-bg);
border:1px solid var(--vibeui-tabs-002-border);border-radius:0.875rem;
font-family:var(--vibeui-tabs-002-font);color:var(--vibeui-tabs-002-fg);
}
[data-vibeui-block="tabs-002"] [data-part="strip"]{
display:flex;gap:0.125rem;padding:0.1875rem;
background:var(--vibeui-tabs-002-track);border-radius:0.625rem;
overflow-x:auto;scrollbar-width:none;
}
[data-vibeui-block="tabs-002"] [data-part="strip"]::-webkit-scrollbar{display:none}
[data-vibeui-block="tabs-002"] [data-part="strip"] label{flex:1 0 auto}
[data-vibeui-block="tabs-002"] input{position:absolute;opacity:0;pointer-events:none}
[data-vibeui-block="tabs-002"] [data-part="tab"]{
cursor:pointer;
display:flex;align-items:center;justify-content:center;
min-height:1.875rem;padding:0 0.75rem;border-radius:0.4375rem;
font-size:0.8125rem;color:var(--vibeui-tabs-002-muted);white-space:nowrap;
}
/* Отмеченная радиокнопка задаёт и вид вкладки, и видимость панели. */
[data-vibeui-block="tabs-002"] input:checked + [data-part="tab"]{
background:var(--vibeui-tabs-002-bg);color:var(--vibeui-tabs-002-fg);font-weight:650;
box-shadow:0 1px 2px oklch(0.2 0.02 265 / 12%);
}
[data-vibeui-block="tabs-002"] input:focus-visible + [data-part="tab"]{outline:2px solid var(--vibeui-tabs-002-accent);outline-offset:-2px}
/* Панель открывает :has() по отмеченной кнопке: правила заданы на шесть вкладок. */
[data-vibeui-block="tabs-002"] [data-part="panel"]{
display:none;padding:0.75rem 0.5rem 0.5rem;
font-size:0.8125rem;line-height:1.5;color:var(--vibeui-tabs-002-muted);
}
[data-vibeui-block="tabs-002"]:has(input[data-index="0"]:checked) [data-part="panel"][data-index="0"]{display:block}
[data-vibeui-block="tabs-002"]:has(input[data-index="1"]:checked) [data-part="panel"][data-index="1"]{display:block}
[data-vibeui-block="tabs-002"]:has(input[data-index="2"]:checked) [data-part="panel"][data-index="2"]{display:block}
[data-vibeui-block="tabs-002"]:has(input[data-index="3"]:checked) [data-part="panel"][data-index="3"]{display:block}
[data-vibeui-block="tabs-002"]:has(input[data-index="4"]:checked) [data-part="panel"][data-index="4"]{display:block}
[data-vibeui-block="tabs-002"]:has(input[data-index="5"]:checked) [data-part="panel"][data-index="5"]{display:block}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="tabs-002"] *{animation:none!important;transition:none!important}}
`

const DEFAULT_TABS: Tabs002Tab[] = [
  {
    label: "Обзор",
    text: "Компонент рендерится без единого пропа: значения по умолчанию заданы прямо в файле.",
  },
  {
    label: "Установка",
    text: "Файл копируется в проект одной командой. Внешних зависимостей нет — только react.",
  },
  {
    label: "Тема",
    text: "Цвета живут в переменных с префиксом компонента, поэтому тема хозяина не перебивает их.",
  },
]

/**
 * Вкладки на радиокнопках: переключение и стрелки без JS.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Tabs002({
  tabs = DEFAULT_TABS,
  name = "vibeui-tabs-002",
  accent,
  className,
  style,
  ...props
}: Tabs002Props) {
  const palette = {
    ...(accent ? { "--vibeui-tabs-002-accent": accent } : null),
    ...style,
  } as CSSProperties

  return (
    <>
      <style href="vibeui-tabs-002" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="tabs-002"
        className={className}
        style={palette}
      >
        <div data-part="strip" role="radiogroup" aria-label="Разделы">
          {tabs.map((tab, index) => (
            <label key={tab.label}>
              <input
                type="radio"
                name={name}
                value={tab.label}
                data-index={index}
                defaultChecked={index === 0}
              />
              <span data-part="tab">{tab.label}</span>
            </label>
          ))}
        </div>
        {tabs.map((tab, index) => (
          <p key={tab.label} data-part="panel" data-index={index}>
            {tab.text}
          </p>
        ))}
      </div>
    </>
  )
}