Guide: How to Customize jQuery UI Datepicker

jQuery UI is a popular choice for web developers due to its user-friendly design and wide range of interactive features.

The Datepicker widget is one of the features provided in this post.

This tutorial will teach you how to create a custom calendar theme that matches your design, but you’ll need some knowledge of JavaScript and CSS first.

Ready to go, the team is prepared to begin.

The assets

It’s time to get ready for the upcoming year by prepping essential calendar components.

Download the Premium Pixels PSD file and two Subtle Patterns to create a calendar with black denim and dark leather backgrounds.

A web development tool such as Firebug is necessary to inspect the classes and IDs generated by jQuery user interfaces, experts say.

It’s time to take the first step: after sufficient preparation, of course.

Step 1: jQuery UI Datepicker

Visit the jQuery UI download page to find four options: UI Core, Widgets, Interactions and Effects.

All unnecessary components should be removed.

To select the datepicker from the Widgets section of jQuery UI, users must download the file, which includes all essential dependencies.

Include all downloaded files in your HTML document, except for the CSS. Attach them as instructed.

Step 2: Adjust the datepicker

This step will involve configuring a datepicker with specific options.

The code will cause a calendar to appear on an element with the ID “datepicker.” To create the calendar, add a div tag with the ID “datepicker” to the body section.

The calendar is now ready, with all the necessary features but no styling.

Step 3: The styles

Creating a new stylesheet, datepicker.css, and linking it to the HTML document is the first step in styling a calendar. All elements must be normalized before doing so.

To make our HTML more visually appealing, we’ll start by adding a background.

The background of a webpage has been set to a dark denim pattern, with the hex code #555.

The datepicker’s width will be set, and it will be centered with a drop shadow to give it prominence.

The .ui-datepicker class of CSS has been given a width of 216px, a height of car, and a margin of 5px auto 0. It also has a font size of 9pt Arial, sans-serif and box shadows with rgba (0, 0, 0, .5).

Anchor tags will no longer have the default underline decoration.

The styling of links in the datepicker has been changed, removing any text decoration.

To ensure the calendar in jQuery UI has the same maximum width as its wrapper, a table should be given a 100% width of 216px.

The ui-datepicker table has been given a width of 100%.

Styling the header section

The datepicker features a header section with a dark leather texture, white font color and 1px white shadow. The Month and Year of the calendar are displayed in this section.

The .ui-datepicker-header element has a dark background, light text color, and a drop shadow effect. It also has a bold font weight and a 1px border.

Let’s make it happen this month.

Replace the text for the “next” and “previous” buttons with arrow images taken from a Photoshop document.

The .ui-datepicker-prev and .ui-datepicker-next classes have been given a display of inline-block, width and height of 30px, text alignment of center, cursor of pointer, background image from the img/arrow.png file with no repeat, line height of 600%, and overflow set to hidden.

Move the arrow to the desired location.

The .ui-datepicker-prev and .ui-datepicker-next classes have been given a float of left and right respectively, with background positions of center -30px and center 0px.

The day names section will be wrapped with wire and feature a white gradient, while a tool will be used to generate the expiration code, simplifying our task.

The background color and image of the .ui-datepicker thead element has been set to a gradient of #f7f7f7 and #f1f1f1, with a 1px solid border at the bottom.

The day names feature a dark gray color (#666666) with a thin white text shadow, creating a pressed effect.

The text of the .ui-datepicker th element is transformed to uppercase letters, with a font size of 6pt, padding of 5px 0, color #666666 and a text shadow of 1px 0px 0px #fff. Additionally, a filter dropshadow is applied with color #fff and offsets of 1 and 0.

The current calendar shows that…

Styling the dates

To make the calendar dates more compact, we’re setting the padding to 0 and adding a 1px right border to the table data.

The .ui-datepicker tbody td element has been given a padding of 0 and a border-right of 1px solid #bbb.

The last table data element will not have a right edge, so its right edge was set to zero.

The last cell of each row in the .ui-datepicker table has no right border.

The last row of the table will feature a 1px border, just like the rest, but with one small difference.

The .ui-datepicker tbody tr element in a web page has been given a 1px solid #bbb border, while the last child of this element has been given no border.

Styles of the standard, float and active status

Defining the date hover and active styles, this step will center the date text position, add a gradient color and inner white shadow to create the default status.

The .ui-datepicker elements have been given a bold font weight, text alignment, width and height, color and text shadow. The background of the .ui-state-default element has been set to a gradient with a box shadow, while the background of the .ui-datepicker-non-selectable element has been set to a solid color.

When the mouse pointer is hovered over the date, it will become highlighted in white.

The hover state of the calendar in the user interface has been given a background color of #f7f7f7.

The date is active with distinct styles when in use.

The .ui-datepicker-calendar class has a background of #6eafbf, a text shadow of #4d7a85, and a border of #55838f. It also has a drop shadow filter and is positioned relative to its margin.

A new, improved calendar has been released, offering users a more organized and efficient way to keep track of their schedules.

Determine the position

When you click on the date in either the first or last column, it will appear to extend one pixel beyond the calendar’s border.

Minor adjustments are being made.

The date width was reduced to 29px, and the margins of the first and last columns were set to 0, reversing a -1px margin previously applied when active.

The width of the active state in the first and last cells of a calendar table has been set to 29px, with no margin on either side.

The final date on the calendar has been given the same treatment.

The last row of the calendar in the user interface datepicker has been given a height of 29 pixels and a margin-bottom of zero.

The calendar has been successfully redesigned to meet the design reference, and a demo and source code are available for download.

Bonus: extend the calendar

Today, we discovered how to customize the jQuery UI Datepicker. But there’s more to explore – with the right jQuery and CSS skills, you can transform the calendar into a text entry field with an overlay datepicker.

Read further

For a comprehensive overview of jQuery UI, check out the full documentation available here.

Start creating custom designs with jQuery UI Themes. With the jQuery UI library, developers can use the Theming API to create unique classes and styles for their projects.

Final Thoughts

If you found this tutorial helpful, let us know in the comments. We welcome any feedback or suggestions for improvement. Thanks for reading!

How to Customize jQuery UI Datepicker: benefits

Faq

Final note

We hope you enjoyed our guide on customizing jQuery UI Datepicker. If you have any questions, please don’t hesitate to reach out. Show your support by sharing this article with your friends!

Have a query about customizing jQuery UI Datepicker? Need to correct misinformation or add an alternate method? Contact us via our contact page, social media accounts, or Telegram channel. We’ll answer your questions within 24-48 hours (weekends excluded).