DHTMLX Booking. Styling with custom CSS example
Live example
Booking takes its colors, borders, and input styles from CSS variables, so a theme is a block of CSS rather than a config. Redefining those variables on the widget class restyles the cards, the search bar, the slot grid, and the dialog in one place. This demo builds a dark palette out of about twenty of them.
const widget = new booking.Booking("#root", {
start: buildToday(),
data: dataset,
});
widget.setConfirmHandler(function(event){
const { confirm } = event;
setTimeout(() => {
Math.random() < 0.5 ? confirm.error() : confirm.done();
}, 1000);
});<!-- component container -->
<div id="root" style="height:100%"></div>
<!-- custom styling -->
<style>
.wx-booking{
--wx-background: #404151;
--wx-background-alt: #212329;
--wx-button-background: #7F808C;
--wx-color-primary: #14B195;
--wx-color-secondary-font-hover: #fff;
--wx-input-background: #2E2E3A;
--wx-color-link: var(--wx-color-primary);
--wx-border: 1px solid #6B6C79;
--wx-input-border: 1px solid #6B6C79;
--wx-icon-color: #c0c3ce;
--wx-input-icon-color: #c0c3ce;
--wx-color-font: #fff;
--wx-input-font-color: var(--wx-color-font);
--wx-color-font-alt: #9fa1ae;
--wx-input-placeholder-color: var(--wx-color-font-alt);
--wx-label-font-color: var(--wx-color-font);
--wx-checkbox-font-color: #fff;
--wx-checkbox-border-color: var(--wx-color-font-alt);
--wx-calendar-icon-color: var(--wx-icon-color);
--wx-calendar-font-color: var(--wx-color-font);
--wx-color-primary-selected: rgba(32, 84, 84, 0.75);
--wx-color-secondary-font: var(--wx-color-font);
--wx-color-font-disabled: rgba(255, 255, 255, 0.4);
--wx-checkbox-font-color: var(--wx-color-font);
--wx-modal-background: var(--wx-background);
--wx-popup-background: var(--wx-input-background);
--wx-input-border-focus: 1px solid var(--wx-color-primary);
}
</style>
<script>
function buildToday(){const params = new URLSearchParams(typeof location !== 'undefined' ? location.search : '');const fixed = params.get('fixedDate') || (typeof window !== 'undefined' && window.FIXED_DATE);return fixed ? new Date(fixed) : new Date();}
const dataset = [
{
id: "ee828b5d-a034-420c-889b-978840015d6a",
title: "Natalie Tyson",
category: "Therapist",
subtitle: "2 years of experience",
details: "Cleveland Clinic\n9500 Euclid Ave",
preview: "https://snippet.dhtmlx.com/codebase/data/booking/01/img/01.jpg",
price: "$35",
review: {
stars: 4,
count: 120,
},
slots: [
{
from: 9,
to: 20,
days: [1, 2, 3, 4, 5],
},
{
from: 10,
to: 18,
days: [6, 0],
},
],
},
{
id: "5c9b64ad-1830-4e5b-a5f9-8acea10706df",
title: "James Anderson",
category: "Allergist",
subtitle: "3 years of experience",
details: "UCLA Medical Center\n57 Westwood Plaza",
preview: "https://snippet.dhtmlx.com/codebase/data/booking/01/img/11.jpg",
price: "$30",
review: {
stars: 4,
count: 64,
},
slotSize: 45,
slotGap: 10,
slots: [
{
from: "9:15",
to: 17,
days: [1, 2, 3, 4, 5],
},
],
},
// ... 44 more items (see Live Editor for full data)
];
function getDate(addDays, hoursValue = 0, minutesValue = 0) {
const date = buildToday();
const secondsValue = 0; // round to minutes
const msValue = 0;
date.setDate(date.getDate() + addDays);
date.setHours(hoursValue, minutesValue, secondsValue, msValue);
return date.getTime();
}
</script>Use case
A booking screen almost never stands alone. It sits inside an admin panel that already has a dark mode, or it ships to a customer who expects their own colors. Sometimes it is embedded in a partner portal, where it must not look borrowed. Variables make that a stylesheet question: one block per brand, no fork of the widget.
How to do this in your app
- Declare the variables on the widget:
.wx-booking { --wx-background: #404151; ... }, or put them on a class of your own on the container. - Set the frame first:
--wx-background-altis the page, and--wx-backgroundis the cards.--wx-color-fontand--wx-bordercover the text and the lines. The dialog follows--wx-backgroundthrough--wx-modal-background, so a palette that darkens only the page leaves the cards and the dialog white. - Style the controls:
--wx-input-backgroundand--wx-input-borderstyle the fields. The search placeholder reads--wx-color-font-alt, and--wx-input-placeholder-colorcovers the date, time, and form fields. The Search button and the form submit button use--wx-color-primary. Slot chips and date buttons use--wx-background. - Cover the date states:
--wx-color-primary-selectedhighlights the days inside a range,--wx-color-font-disabledcolors a disabled date, and--wx-color-secondary-font-hovercolors the selected date chip. The Material defaults for all three are light-theme values: a light blue, a near-black, and dark text. - Override a layer that should differ from the cards:
--wx-popup-background: var(--wx-input-background)makes the search, date, and time menus match the fields.--wx-modal-backgroundalready follows--wx-background, so the dialog stays with the cards until that variable gets its own value. - Use a selector for extra control: a plain rule on
.wx-cardor.wx-date-itemcan set a color the variables do not give you.
Good to know
- Variables can point at each other:
--wx-color-link: var(--wx-color-primary)keeps the accent color in one place instead of three. - A built-in Material theme is available: add the
wx-material-themeclass to the container or include skins/material.css, then override its variables the same way. - Recheck the names after an update: the styling guide warns that variables can be renamed between releases, so a theme is worth a quick visual pass after upgrading.
FAQ
How do you apply a dark theme to a booking widget?
Redefine the color variables on .wx-booking or on your own container class. A dark palette usually starts with --wx-background-alt, --wx-background, --wx-color-font, --wx-input-background, and --wx-border.
Which variables affect the booking dialog?
The dialog background is --wx-modal-background. The Material theme sets that to var(--wx-background), so the dialog matches the cards. Text follows --wx-color-font.
Can you style a part that has no variable?
Yes. The widget markup uses stable class names such as .wx-booking, .wx-list, and .wx-card, so a plain CSS rule covers what the variables do not.
API reference
- Styling guide: CSS variables, the Material theme, and custom selectors
- Initialization guide: Including booking.css and sizing the container
Related examples
- Card template: replace the card block with your own markup
- Dialog info template: do the same inside the booking dialog
- Card fields: drop fields you do not need before restyling the rest