Date Input Examples
The examples below assume that you have imported the component and set up the theme.
Basic
Take a date in a form. name submits the date, value holds it as ISO 8601 text like 2026-10-29, and the valuechange event reports each change.
The controls switch the field between a date, a time, both, and a range.
<form class="date-input-basic"> <label for="date-input-date">Date</label> <sv-date-input id="date-input-date" name="date"></sv-date-input> <p> value: <code></code> </p></form>
<script type="application/x-typescript" module> const form = document.querySelector<HTMLFormElement>(".date-input-basic")!; const dateInput = form.querySelector<DateInput>("sv-date-input")!; const valueOutput = form.querySelector("code")!;
form.addEventListener("submit", event => event.preventDefault());
dateInput.addEventListener("valuechange", () => { valueOutput.textContent = JSON.stringify(dateInput.value); });
valueOutput.textContent = JSON.stringify(dateInput.value);</script>
<style> .date-input-basic { display: grid; gap: 0.5em; place-content: center; justify-items: center;
label { font-weight: 600; }
p { margin: 0; font-size: 0.9em; color: var(--sv-gray-3); }
svg[slot="before"] { inline-size: 1.25em; margin-inline-start: 0.75em; fill: currentcolor; } }</style>Limits
Keep the date inside a range, like the next 45 days. min and max move the date inside them when the focus leaves the field or on Enter.
<form class="date-input-limits"> <label for="date-input-appointment">Appointment</label> <sv-date-input id="date-input-appointment" clearable name="appointment"></sv-date-input> <p>In the next 45 days</p></form>
<script type="application/x-typescript" module> const form = document.querySelector<HTMLFormElement>(".date-input-limits")!; const dateInput = form.querySelector<DateInput>("sv-date-input")!;
const now = new Date(); const today = new Date(Date.UTC(now.getFullYear(), now.getMonth(), now.getDate()));
function getDateAfterToday(dayCount: number) { const date = new Date(today); date.setUTCDate(date.getUTCDate() + dayCount); return date.toISOString().slice(0, 10); }
dateInput.min = getDateAfterToday(1); dateInput.max = getDateAfterToday(45);
form.addEventListener("submit", event => event.preventDefault());</script>
<style> .date-input-limits { display: grid; gap: 0.5em; place-content: center; justify-items: center;
label { font-weight: 600; }
p { margin: 0; font-size: 0.9em; color: var(--sv-gray-3); } }</style>