
Simple Week Calendar is a dependency-free JavaScript scheduler with day, workweek, and seven-day views.
It allows you to create, move, and resize appointments directly in a time grid and arranges overlapping events side by side.
Features
- A built-in dialog creates, edits, and deletes events.
- Configurable visible hours, time-slot intervals, and first weekday.
- Business-hour highlighting and a current-time indicator.
- Localized time labels with 12-hour and 24-hour formats.
- Read-only mode and independent controls for creating, moving, and resizing events.
- CSS custom properties for colors, typography, and sizing.
- Callbacks for event clicks, creation, changes, and deletion.
How to Use It
Basic Usage
Download & load week-calendar.css and week-calendar.js files in the document.
<link rel="stylesheet" href="week-calendar.css"> <div id="week-calendar" style="height: 600px;"></div>
Set the container height for the calendar grid.
<script src="week-calendar.js"></script>
Generate a basic weekly calendar. You can click an event to edit it in the built-in dialog.
const start = new Date();
start.setHours(10, 0, 0, 0);
const end = new Date(start);
end.setHours(11, 0, 0, 0);
const calendar = new WeekCalendar('#week-calendar', {
daysToShow: 7,
startHour: 8,
endHour: 19,
events: [
{
id: 'meeting-1',
title: 'Design Review',
start,
end,
color: '#0d9488'
}
],
onEventCreate: event => console.log('Created:', event),
onEventChange: (event, action) => console.log(action, event),
onEventDelete: id => console.log('Deleted:', id)
});
Event Data
Event times accept JavaScript Date objects or strings parsed by new Date(). Keep the start and end on the same date. The grid places events under their start date.
| Property | Description |
|---|---|
id | Event identifier. A string ID is generated when the property is omitted. |
title | Text displayed in the event. Defaults to Untitled Event if empty. |
start | Start date and time, converted to a Date. |
end | End date and time, converted to a Date. |
color | Optional CSS background color for the event. |
Update the Schedule
Copy the events.json beside your HTML file and serve the page over HTTP.
calendar.setView(5);
calendar.updateEvent('meeting-1', {
title: 'Design Review: Revised'
});
fetch('./events.json')
.then(response => response.json())
.then(events => {
calendar.setEvents(events);
if (events.length) calendar.gotoDate(events[0].start);
});
Configuration Options
Pass these options as the second argument to new WeekCalendar(container, options).
| Option | Description |
|---|---|
date | Date, default new Date(). Date initially displayed. |
daysToShow | number, default 7. Set 1 for Day, 5 for Workweek, or 7 for Week. |
firstDayOfWeek | number, default 1. Use 0 for Sunday or 1 for Monday. |
startHour | number, default 0. First visible hour, from 0 to 23. |
endHour | number, default 24. End of the visible time range, from 1 to 24. |
slotsPerHour | number, default 4. Number of slots per hour. 4 creates 15-minute slots. |
slotHeight | number, default 24. Height of each time slot in pixels. |
use24Hour | boolean, default false. Displays time in 24-hour format when enabled. |
locale | string, default navigator.language. Locale used by Intl.DateTimeFormat. |
businessHours | { start: 9, end: 18 } by default. Hours highlighted as working time. Set false to disable. |
events | Array, default []. Initial event records. |
readonly | boolean, default false. Disables creating, moving, resizing, and editing from the grid. |
enableCreate | boolean, default true. Enables dragging across empty slots to create events. |
enableMove | boolean, default true. Enables dragging existing events to new times or days. |
enableResize | boolean, default true. Displays handles for changing an event’s duration. |
showCurrentTime | boolean, default true. Updates the current-time marker every minute. Setting false does not suppress the marker during a render. |
onEventClick | Function | null, default null. Runs with the clicked event and replaces the default edit dialog. |
onEventChange | Function | null, default null. Runs with (event, action) after a move, resize, or dialog edit. |
onEventCreate | Function | null, default null. Runs with (event) after the create dialog saves an event. |
onEventDelete | Function | null, default null. Runs with (id) after the delete dialog removes an event. |
Public Methods
| Method | Description |
|---|---|
prev() | Go back one day in Day view or seven days in Workweek and Week views. |
next() | Move forward one day in Day view or seven days in Workweek and Week views. |
today() | Navigate to the current date. |
gotoDate(date) | Navigate to a Date or parseable date string. |
setView(days) | Show 1, 5, or 7 days. |
scrollToHour(hour) | Scroll the time grid to the specified hour. |
getEvents() | Return a new array containing the current event objects. The objects themselves are shared. |
setEvents(events) | Replace the current events and render the calendar. |
addEvent(event) | Add an event and return its normalized event object. |
updateEvent(id, updates) | Update an existing event by ID and redraw events. |
deleteEvent(id) | Remove an event by ID and redraw events. |
openCreateModal(start, end) | Open the new-event dialog with Date values for the start and end. |
openEditModal(event) | Open the edit dialog for an event object. |
destroy() | Clear the current-time timer, empty the container, and remove the root calendar class. |
Event Callbacks
| Callback | Arguments and behavior |
|---|---|
onEventClick | (event). Overrides the default click-to-edit action. Call calendar.openEditModal(event) in your handler if you want to retain the dialog. |
onEventCreate | (event). Runs after a new event is saved in the built-in dialog. |
onEventChange | (event, action). action is 'move', 'resize', or 'edit'. |
onEventDelete | (id). Runs with the deleted event’s string ID. |
Styling and CSS Variables
Load your CSS overrides after week-calendar.css and set the variables on .modern-week-calendar.
.modern-week-calendar {
--wc-primary: #0d9488;
--wc-primary-hover: #0f766e;
--wc-primary-light: #ccfbf1;
--wc-event-bg: #0d9488;
--wc-current-time: #dc2626;
}
| CSS Variable | Default and purpose |
|---|---|
--wc-font-family | System font stack for the calendar and dialog. |
--wc-bg | #fff. Main background. |
--wc-surface | #f8fafc. Toolbar, gutter, and dialog surface. |
--wc-border | #e2e8f0. Main borders and hour lines. |
--wc-border-subtle | #f1f5f9. Minor time-slot lines. |
--wc-text | #1e293b. Main text. |
--wc-text-muted | #64748b. Secondary text. |
--wc-primary | #3b82f6. Primary accent. |
--wc-primary-hover | #2563eb. Primary button hover. |
--wc-primary-light | #eff6ff. Highlighted day background. |
--wc-non-business-hour | #f8fafc. Shading outside business hours. |
--wc-current-time | #ef4444. Current-time marker. |
--wc-time-col-width | 65px. Width of the time-label column. |
--wc-event-bg | #3b82f6. Default event background. |
--wc-event-color | #fff. Event text color. |
--wc-event-border-radius | 6px. Event corner radius. |
Alternatives and Related Resources
- Vanilla Calendar JS Library for Date Picking, Scheduling, and Timelines
- Full-Featured Drag-and-Drop JavaScript Event Calendar with Resource & Timeline Views
- Feature-rich Event Calendar In JavaScript – Calendar.js







