Web Component

Calendar

Easily create nice looking calendar.

Table of contents

Usage

You can build your calendar manually using server-side rendering with the following classes, or use our web components that have been built from scratch with the <uk-calendar> markup.

Manual server-side rendering

Use the following classes to create your calendar:

ClassDescription
uk-calThe calendar wrapper
uk-cal-oomFor dates that are out-of-month
uk-activeTo show the active date
uk-disabledTo disable a date (add disabled attribute to the button for full disablement)
uk-cal-markedTo add an indicator for “marked dates” (dates with events)
uk-cal-dividerTo add a divider between calendar weeks.
  • Su Mo Tu We Th Fr Sa
PR

Web components

Alternatively, you can use our web components with the <uk-calendar> markup.

Setting the current day

To automatically set today’s date as the active date in the calendar, use the today attribute. This will highlight the current day in the calendar, making it easy for users to quickly identify the current date.

By default, this attribute is set to false, meaning today’s date will not be automatically highlighted.

Enabling month and year selection

To allow month and year selection, use the jumpable attribute. This will enable a dropdown menu for selecting the month and a text input field for entering the year, allowing users to quickly “jump” to a specific date.

By default, this attribute is set to false, meaning the calendar will not provide month and year selection options.

Setting the starting day of the week

To customize the starting day of the week in the calendar, use the starts-with attribute. This allows you to specify whether the week should start on Sunday (0) or Monday (1). By default, the week starts on Sunday (0).

Disabling specific dates

To disable specific dates in the calendar, use the disabled-dates attribute. This attribute accepts a comma-separated list of dates. Please note that dates must be in the format YYYY-MM-DD (e.g. 2022-07-25). Dates that do not follow this format will be ignored and a console error will be thrown. The calendar will still render, but the invalid dates will not be disabled.

Marking specific dates

To add an indicator to specific dates in the calendar, use the marked-dates attribute. This attribute accepts a comma-separated list of dates. Please note that dates must be in the format YYYY-MM-DD (e.g. 2022-07-25). Dates that do not follow this format will be ignored and a console error will be thrown. The calendar will still render, but the invalid dates will not be marked.

Setting the view date

To customize the initial view date of the calendar, use the view-date attribute. By default, the calendar will display the current date. To set a custom view date, provide a date in the format YYYY-MM-DD (e.g. 2023-06-30). This will cause the calendar to display the specified month and year.

Setting the minimum and maximum date

To set the minimum and maximum date that can be selected in the calendar, use the min and max attributes. These attributes accept dates in the format YYYY-MM-DD (e.g. 2022-07-25).

Setting the current value

To set the current value of the calendar, use the value attribute. This attribute accepts a date in the format YYYY-MM-DD (e.g. 2020-05-06). Please note that this attribute takes precedence over view-date and today, so setting value will override any settings made with those attributes.

Capturing values

There are several ways to capture values from the <uk-calendar> component. The simplest approach is to add a name attribute to the component. When you do this, a hidden input field with the specified name will be automatically generated, allowing you to easily capture the selected value on your server.

This is useful when you need to include the calendar component in a form and capture the selected date as part of the form submission.

Internationalization

The Calendar component supports internationalization through multiple methods with the following priority order (highest to lowest):

  • Component-level i18n (via i18n attribute or script tag)
  • Global component-specific namespace (via <script id="uk-i18n">)
  • Default values

Using the i18n attribute

Using a configuration script

PR

Using global i18n

Place this in your document <head> or before any components:

Available i18n options

KeyDefaultDescription
prev-monthPrevious monthAria-label for the previous month navigation button
next-monthNext monthAria-label for the next month navigation button
prev-yearPrevious yearAria-label for the previous year navigation button
next-yearNext yearAria-label for the next year navigation button
select-monthSelect monthAria-label for the month dropdown selector
select-yearSelect yearAria-label for the year input field

Custom classes

The Calendar component supports custom CSS classes through the cls attribute. This allows you to style specific elements within the calendar without modifying the component’s internal structure.

Using simple string format

Apply a class to the default element (host-inner):

Using JSON object format

Target specific elements within the calendar:

Using configuration script

Available cls targets

TargetDescription
host-innerThe main calendar wrapper element
headerThe calendar header containing navigation and title
previous-buttonPrevious month/year navigation button
next-buttonNext month/year navigation button
titleThe calendar title (month and year display)
jumperThe jumper container (when jumpable is enabled)
month-selectMonth dropdown selector (when jumpable is enabled)
year-inputYear input field (when jumpable is enabled)
gridThe calendar grid table element
weekdaysThe weekdays header row
weekdayIndividual weekday header cell
weekIndividual week row
dayIndividual day cell
day-buttonDay button element
jumper-monthMonth jumper wrapper
jumper-yearYear jumper wrapper
jumper-buttonJumper navigation buttons
day-outside-monthClass for days outside current month
day-selectedClass for the selected day cell
day-todayClass for today’s day cell
day-markedClass for marked day cells
button-outside-monthClass for day buttons outside current month
button-selectedClass for the selected day button
button-todayClass for today’s day button
button-markedClass for marked day buttons

Custom inline styles

The Calendar component supports custom inline styles through the stl attribute. This allows you to apply specific CSS styles to individual elements within the calendar.

Using simple string format

Apply styles to the default element (host-inner):

Using JSON object format

Target specific elements with custom styles:

Using configuration script

Available stl targets

The stl attribute supports the same targets as the cls attribute. See the Available cls targets table above for a complete list of targetable elements.

Custom icons

The Calendar component allows you to customize navigation icons through the template system:

Available icon keys

KeyDescription
chevron-leftLeft navigation arrow icon
chevron-rightRight navigation arrow icon

Attributes

The following attributes are available for this component:

NameTypeDefaultDescription
todayBooleanfalseAutomatically sets today as the active date.
jumpableBooleanfalseEnables month dropdown and year input for quick date navigation.
starts-withNumber0 (Sunday)Sets the starting day of the week. 0 for Sunday, 1 for Monday.
disabled-datesStringComma-separated list of dates to disable. Dates must be in format YYYY-MM-DD.
marked-datesStringComma-separated list of dates to mark with indicator. Dates must be in format YYYY-MM-DD.
view-dateStringCurrent dateSets the initial view date of the calendar. Must be in format YYYY-MM-DD.
minStringSets the minimum selectable date (inclusive). Must be in format YYYY-MM-DD.
maxStringSets the maximum selectable date (exclusive). Must be in format YYYY-MM-DD.
valueStringSets the selected date value. Must be in format YYYY-MM-DD. Takes precedence over today.
weekday-formatStringshortFormat for weekday labels: long, short, or narrow.
langStringen-usLocale string for date formatting (e.g., “en-US”, “fr-FR”, “de-DE”).
nameStringName attribute for the hidden input field, enabling form submission.
disabledBooleanfalseDisables the entire calendar, preventing user interaction.
requiredBooleanfalseMarks the calendar as required for form validation.
placeholderStringPlaceholder text (used in parent components like input-date).
clsStringCustom CSS classes. Can be a simple string or JSON object for targeting specific elements.
stlStringCustom inline styles. Can be a simple string or JSON object for targeting specific elements.
i18nStringInternationalization strings as JSON object or via configuration script.
force-prevent-rerenderBooleanfalsePrevents component rerendering (useful for HTMX or SPA scenarios).

Events

The Calendar component triggers the following event:

NameDescription
uk-calendar:changeFired when the selected date changes. Event detail contains {value: string}.