--- title: Create your first component weight: 1 --- A component in django-components is the combination of four things: CSS, Javascript, a Django template, and some Python code to put them all together. ``` sampleproject/ ├── calendarapp/ ├── components/ 🆕 │ └── calendar/ 🆕 │ ├── calendar.py 🆕 │ ├── script.js 🆕 │ ├── style.css 🆕 │ └── template.html 🆕 ├── sampleproject/ ├── manage.py └── requirements.txt ``` Start by creating empty files in the structure above. First, you need a CSS file. Be sure to prefix all rules with a unique class so they don't clash with other rules. ```css title="[project root]/components/calendar/style.css" /* In a file called [project root]/components/calendar/style.css */ .calendar-component { width: 200px; background: pink; } .calendar-component span { font-weight: bold; } ``` Then you need a javascript file that specifies how you interact with this component. You are free to use any javascript framework you want. A good way to make sure this component doesn't clash with other components is to define all code inside an anonymous function that calls itself. This makes all variables defined only be defined inside this component and not affect other components. ```js title="[project root]/components/calendar/script.js" /* In a file called [project root]/components/calendar/script.js */ (function () { if (document.querySelector(".calendar-component")) { document.querySelector(".calendar-component").onclick = function () { alert("Clicked calendar!"); }; } })(); ``` Now you need a Django template for your component. Feel free to define more variables like `date` in this example. When creating an instance of this component we will send in the values for these variables. The template will be rendered with whatever template backend you've specified in your Django settings file. ```htmldjango title="[project root]/components/calendar/calendar.html" {# In a file called [project root]/components/calendar/template.html #}