Marketing sectionsContactForm
Searchastronomic.dev# ContactForm
For a contact page that is mostly the form: a short header and the message form, centered.
Interactive: inline script.
## Usage
```astro
import ContactForm from "@astronomic/ui-pro/components/ContactForm.astro";
```
## Examples
### The form, centered
A centered header, then the message form under it, centered at a reading width (at most 36rem), so the fields never stretch across a wide page. Here it asks for a company, has a privacy note, and posts to #. For your details beside the form, use ContactSplit.
```astro
---
import Badge from "@astronomic-dev/ui/components/Badge.astro";
import ContactForm from "@astronomic/ui-pro/components/ContactForm.astro";
---
<div class="mx-auto max-w-6xl px-6 py-16">
<ContactForm heading="Tell us about your project" text="A few lines are enough. We answer within two business days." form={{ action: "#", company: true }}>
<Badge slot="eyebrow">Contact</Badge>
<p slot="note" class="m-0">We only use your details to answer you. No newsletter, no sharing.</p>
</ContactForm>
</div>
```
## Props
### ContactForm
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `heading` | `string` | None | The section heading, in the title role in display type. Without it there is no section and no header: a plain <div> holds only the body. |
| `emphasis` | `boolean` | `false` | Turn one *phrase* in the heading into <em>: exactly two asterisks around text with no space inside, as in "Built for *the long run*". Any other asterisks show as typed. Off by default, so the heading shows as typed. How the <em> looks is the theme's. |
| `mark` | `string` | None | A short mark after the heading, such as "(12)" or "©2026", in small muted type. It sits beside the heading, outside it, so the heading's name stays plain. Shown only with a heading. |
| `markLabel` | `string` | None | What the mark says to a screen reader, such as "12 projects": the mark is then hidden from screen readers and this is read in its place. Without it, the mark is read as written. |
| `text` | `string` | None | One or two sentences under the heading, in the lead role, muted. Shown only with a heading. |
| `headingTag` | `"h2" \| "h3" \| "h4"` | `"h2"` | The heading element. Channel titles sit one level under it. |
| `class` | `string` | None | More classes for the root (the <section>, or the <div> without a heading), merged with cn(), so yours win on conflicts. The root is a named size container (inline-size containment): in a shrink-to-fit parent (inline-flex, a float, fit-content) it collapses, so give it a width there. |
| `form` | `MessageFormOptions` | None | Required. The form's settings: its action (required) and any MessageForm prop but tone and class (MessageFormOptions), spread onto the form, such as { action: "https://formspree.io/f/<id>", topics: ["Sales", "Support"], enhance: "fetch" }. A plain post is the safe default; enhance="fetch" needs an endpoint that answers JSON (see MessageForm). |
| Slot | Description |
| --- | --- |
| `eyebrow` | A short line above the heading, such as a Badge. Shown only with a heading. |
| `note` | Under the form, small and muted: a privacy line or consent text. Passed to the MessageForm. |
Any other attribute goes on the <section>, or on the <div> without a heading.
## Accessibility
- With a heading, renders a <section> named by it, so it is a region landmark. The heading id is unique on the page.
- Without a heading, renders a plain <div>. Put your own heading above it.
- Every field has a visible label (Field) and its autocomplete value (name, email, organization, tel), so the browser can fill it. Name, email and message are required and marked so.
- With no script, or before it loads, the form posts to its action and the browser checks the required fields and the email itself.
- The topic is a native <select>: its first option is empty and selected, so a reader who never picks one sends no topic. It works with the keyboard and screen readers as any select does.
- With enhance="fetch", a bad field gets its error text under it, aria-invalid and the error id in aria-describedby, and focus moves to the first bad field. The FormStatus under the button says sending, then success or the error.
ContactForm
ProFor a contact page that is mostly the form: a short header and the message form, centered.
- File
- ContactForm.astro
- Group
- Marketing sections
- Kind
- Interactive: inline script
- Examples
- 1
Examples
Drag the orange handle to set the width. Frames get real breakpoints.
- Static
- Interactive
- Framed
The form, centered
A centered header, then the message form under it, centered at a reading width (at most 36rem), so the fields never stretch across a wide page. Here it asks for a company, has a privacy note, and posts to #. For your details beside the form, use ContactSplit.
This preview did not load.
main.astro
examples/contactform/main.astro
---
import Badge from "@astronomic-dev/ui/components/Badge.astro";
import ContactForm from "@astronomic/ui-pro/components/ContactForm.astro";
---
<div class="mx-auto max-w-6xl px-6 py-16">
<ContactForm heading="Tell us about your project" text="A few lines are enough. We answer within two business days." form={{ action: "#", company: true }}>
<Badge slot="eyebrow">Contact</Badge>
<p slot="note" class="m-0">We only use your details to answer you. No newsletter, no sharing.</p>
</ContactForm>
</div>Minimal · Light