---
title: Input for Astro
description: "Native Astro inputs with shared focus, error, and disabled styles."
seo:
    title: Input for Astro | Shadcn & Tailwind CSS
related:
    - /components/textarea
    - /components/input-group
    - /components/floating-input
sidebar:
    label: "Input"
---

```astro
---
import { Input } from "@/components/ui/input"
---

<Input class="max-w-sm" placeholder="Email" />
```

## Installation

### Command

```sh
bunx --bun shadcn@latest add @gnostic/input
```

### Manual

Complete the [Installation guide](/docs/installation) first. Then copy the component files below.

No extra packages are required.

#### src/components/ui/input/index.ts

```ts
export { default as Input } from "./input.astro"
```

#### src/components/ui/input/input.astro

```astro
---
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"input">

const {
  class: className,
  "data-slot": dataSlot = "input",
  ...props
} = Astro.props
---

<input data-slot={dataSlot} class={cn("font-sans border-input bg-background text-foreground ring-ring/24 placeholder:text-muted-foreground/72 dark:bg-input/32 focus-visible:border-ring aria-invalid:border-destructive/36 focus-visible:aria-invalid:border-destructive/64 focus-visible:aria-invalid:ring-destructive/16 dark:aria-invalid:ring-destructive/24 file:text-foreground h-9 w-full min-w-0 rounded-lg border px-[calc(--spacing(3)-1px)] text-base shadow-xs/5 transition-shadow outline-none not-disabled:not-focus-visible:not-aria-invalid:inset-shadow-[0_1px_--theme(--color-black/4%)] file:me-3 file:border-0 file:bg-transparent file:text-sm file:font-medium autofill:[-webkit-text-fill-color:var(--foreground)] focus-visible:shadow-none focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-64 sm:h-8 sm:text-sm dark:not-disabled:not-focus-visible:not-aria-invalid:inset-shadow-[0_-1px_--theme(--color-white/6%)]", className)} {...props} />
```

Component classes use the preset configured during project setup. Select the same preset in the docs before copying Manual source. To change installed component classes, edit or reinstall their source. See [Theming](/docs/theming) for details.


## Usage

```ts
import { Input } from "@/components/ui/input"
```

```astro
<Input />
```

## Examples

### Basic

```astro
---
import { Input } from "@/components/ui/input"
---

<Input class="max-w-sm" placeholder="Email" />
```

### Disabled

```astro
---
import { Input } from "@/components/ui/input"
---

<Input class="max-w-sm" placeholder="Email" disabled />
```

### Invalid

```astro
---
import { Input } from "@/components/ui/input"
---

<Input class="max-w-sm" placeholder="Email" aria-invalid="true" />
```

### File

```astro
---
import { Input } from "@/components/ui/input"
---

<Input class="max-w-sm" type="file" />
```

## Notes

- Use `Input` for single-line text-like controls such as email, password, and
  phone fields.
- Pair it with `Label` for simple forms, or use [Field](/components/field)
  when you also need descriptions, validation, or grouped layouts.
- Use [Floating Input](/components/floating-input) when the label sits in the
  field and floats to the border.
- Set `aria-invalid` when the control should display an invalid state.

## API Reference

Read the [installed source](/r/input.json) for the complete prop types.

## When to use Input

Set the native input type, name, and ID for the data you need. Link a visible Label with `for`. Use autocomplete values that match the field purpose and keep placeholders as examples rather than labels.

## Keyboard and behavior

This is a native input, so browser editing, form submission, required checks, and disabled behavior remain available. `aria-invalid` applies the error style but does not validate the value. Link error text with `aria-describedby`.

## Theme and layout

The single input carries its own border and inset shadow. It does not add the React wrapper used by Coss. Native `size` retains its HTML meaning; use classes for visual width. Check autofill and file controls in the browsers you support.
