HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
- const startingYear = 2010;
- const endingYear = 2020;
- const monthsCount = 12;
- const datePattern = 'd M Y';
- const daysInWeek = 7;
- const currentDate = new Date();
//- 'id' and 'name' must be changeable (by form; for multiple datepicker)
- const idPrefix = 'cal_';
- const calName = 'calendar';
- const dateName = 'calendar_date';
//- TODO: Make variable:'daysLabel' changeable by language
- const daysLabel = [
- 'Sun',
- 'Mon',
- 'Tue',
- 'Wed',
- 'Thu',
- 'Fri',
- 'Sat'
- ];
//- TODO: Make variable:'monthsLabel' changeable by language
- const monthsLabel = [
- 'January',
- 'February',
- 'March',
- 'April',
- 'May',
- 'June',
- 'July',
- 'August',
- 'September',
- 'October',
- 'November',
- 'December'
- ];
.calendar
- for (var year = startingYear; year <= endingYear; year++)
- for (var month = 0; month < monthsCount; month++)
//- For the year/month picker
input(
type="radio"
id=idPrefix + "year_select_" + year + "_" + month
name=calName
).cal-year-check
input(
type="radio"
id=idPrefix + "month_select_" + year + "_" + month
name=calName
data-cal-year=year
).cal-month-check
.cal
.cal-head
.controls
label(for=idPrefix + year + "_" + month).cal-change-year #{monthsLabel[month]} #{year}
// Borrowed Google's 'Material Design Icons'
svg(viewBox="0 0 24 24")
path(d="M13,20H11V8L5.5,13.5L4.08,12.08L12,4.16L19.92,12.08L18.5,13.5L13,8V20Z")
.controls
.cal-body.year-picker
- for (var yearPick = startingYear; yearPick <= endingYear; yearPick++)
.cal-date
label(for=idPrefix + "month_select_" + yearPick + "_" + month)
span #{yearPick}
- for (var yearPick = startingYear; yearPick <= endingYear; yearPick++)
.cal-body.month-picker(data-cal-year=yearPick)
- for (var monthPick = 0; monthPick < monthsCount; monthPick++)
.cal-date
label(for=idPrefix + yearPick + "_" + monthPick)
span #{monthsLabel[monthPick]}
//- For the actual calendar
input(
type="radio"
id=idPrefix + year + "_" + month
name=calName
checked=currentDate.getFullYear() == year && currentDate.getMonth() == month
).cal-check
.cal
.cal-head
.controls
label(for=idPrefix + "year_select_" + year + "_" + month).cal-change-year #{monthsLabel[month]} #{year}
// Borrowed Google's 'Material Design Icons'
svg(viewBox="0 0 24 24")
path(d="M11,4H13V16L18.5,10.5L19.92,11.92L12,19.84L4.08,11.92L5.5,10.5L11,16V4Z")
.controls
- var lastMonth = new Date(year, month - 1);
- var nextMonth = new Date(year, month + 1);
label(for=idPrefix + lastMonth.getFullYear() + "_" + lastMonth.getMonth()).cal-change-month
// Borrowed Google's 'Material Design Icons'
svg(viewBox="0 0 24 24")
path(d="M20,11V13H8L13.5,18.5L12.08,19.92L4.16,12L12.08,4.08L13.5,5.5L8,11H20Z")
label(for=idPrefix + nextMonth.getFullYear() + "_" + nextMonth.getMonth()).cal-change-month
// Borrowed Google's 'Material Design Icons'
svg(viewBox="0 0 24 24")
path(d="M4,11V13H16L10.5,18.5L11.92,19.92L19.84,12L11.92,4.08L10.5,5.5L16,11H4Z")
.cal-body
- var firstDate = new Date(year, month, 1);
- var lastDate = new Date(year, (month + 1), 0);
//- Days of week
- for (var day = 0; day < daysInWeek; day++)
.cal-day #{daysLabel[day]}
//- Extra spaces before starting date
- for (var date = 0; date < firstDate.getDay(); date++)
.cal-date
//- Actual date
- for (var date = 1; date <= lastDate.getDate(); date++)
//- TODO: Date pattern must be changeable
.cal-date
//- Name here must be changeable
label
input(
type="radio"
name=dateName
value=year + "/" + month + "/" + date
checked=currentDate.getFullYear() == year && currentDate.getMonth() == month && currentDate.getDate() == date
)
span #{date}
//- Extra spaces after ending date
- for (var date = lastDate.getDay() + 1; date < daysInWeek; date++)
.cal-date
// ----- About: Calendar
$starting-year: 2010;
$ending-year: 2020;
$months-count: 12;
$days-in-week: 7;
// ----- Global
$cell-size: 100%;
$hover-background-color: #efefef;
$primary-color: #ffffff;
$primary-background-color: #0681ff;
// ----- Styles
$calendar-background-color: #ffffff;
$calendar-width: 280px;
$calendar-box-shadow: 0 5px 10px 2px rgba(0, 0, 0, 0.5);
$cal-head-color: $primary-color;
$cal-head-background-color: $primary-background-color;
$cal-head-height: 50px;
$cal-head-controls-width: 30px;
$cal-head-controls-height: $cal-head-height;
$cal-change-month-width: $cal-head-controls-width;
$cal-change-month-height: $cal-head-controls-height;
$cal-change-month-active-background-color: darken($primary-background-color, 10%);
$cal-change-month-svg-fill: #ffffff;
$cal-change-month-svg-width: 24px;
$cal-change-month-svg-height: 24px;
$cal-change-year-height: $cal-head-controls-height;
$cal-change-year-padding: 0 8px;
$cal-change-year-svg-width: 12px;
$cal-change-year-svg-height: 12px;
$cal-change-year-svg-fill: #ffffff;
$cal-change-year-active-background-color: darken($primary-background-color, 10%);
$cal-day-background-color: #dfdfdf;
$cal-day-height: 30px;
$cal-date-height: 40px;
$cal-date-span-hover-background-color: $hover-background-color;
$cal-date-span-active-color: $primary-color;
$cal-date-span-active-background-color: $primary-background-color;
$cal-date-span-transition: background-color ease-out 150ms, color ease-out 150ms;
$cal-body-min-height: $cal-day-height + ($cal-date-height * 6);
// ----- SCSS codes
.calendar {
background-color: $calendar-background-color;
width: $calendar-width;
margin: auto;
user-select: none;
box-shadow: $calendar-box-shadow;
flex-grow: 0;
flex-shrink: 0;
.cal-check {
display: none;
&:checked + .cal {
display: block;
}
}
.cal-year-check {
display: none;
&:checked + .cal-month-check + .cal {
display: block;
}
}
@for $year from $starting-year through $ending-year {
.cal-month-check[data-cal-year="#{$year}"] {
display: none;
&:checked + .cal {
display: block;
.year-picker {
display: none;
}
.month-picker[data-cal-year="#{$year}"] {
display: grid;
}
}
}
}
.cal {
display: none;
.cal-head {
color: $cal-head-color;
background-color: $cal-head-background-color;
width: 100%;
height: $cal-head-height;
display: flex;
.controls {
width: 50%;
height: $cal-head-controls-height;
line-height: $cal-head-controls-height;
box-sizing: border-box;
&:first-child {
font-weight: bold;
text-align: left;
}
&:last-child {
display: flex;
justify-content: flex-end;
}
.cal-change-year {
height: $cal-change-year-height;
line-height: $cal-change-year-height;
padding: $cal-change-year-padding;
display: inline-block;
&:hover, &:active {
background-color: $cal-change-year-active-background-color;
}
svg {
width: $cal-change-year-svg-width;
height: $cal-change-year-svg-height;
fill: $cal-change-year-svg-fill;
vertical-align: middle;
}
}
.cal-change-month {
text-align: center;
width: $cal-change-month-width;
height: $cal-change-month-height;
line-height: $cal-change-month-height;
display: flex;
&:hover, &:active {
background-color: $cal-change-month-active-background-color;
}
svg {
width: $cal-change-month-svg-width;
height: $cal-change-month-svg-height;
fill: $cal-change-month-svg-fill;
vertical-align: middle;
margin: auto;
}
}
}
}
.cal-body {
min-height: $cal-body-min-height;
display: grid;
align-content: start;
grid-template-columns: repeat(7, 1fr);
&.year-picker {
grid-template-columns: repeat(4, 1fr);
}
&.month-picker {
display: none;
grid-template-columns: repeat(3, 1fr);
}
.cal-day {
background-color: $cal-day-background-color;
height: $cal-day-height;
line-height: $cal-day-height;
text-align: center;
}
.cal-date {
height: $cal-date-height;
line-height: $cal-date-height;
text-align: center;
input[type="radio"] {
display: none;
&:checked + span {
color: $cal-date-span-active-color;
background-color: $cal-date-span-active-background-color;
}
}
label, label span {
text-align: center;
display: block;
}
label span {
transition: $cal-date-span-transition;
&:hover {
background-color: $cal-date-span-hover-background-color;
}
}
}
}
}
}
// -----
html, body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
@import url("https://fonts.googleapis.com/css?family=Montserrat:400,400i,700");
body {
background-color: #082946;
display: flex;
.calendar {
font-family: Montserrat, sans-serif;
font-size: 14px;
}
}
Also see: Tab Triggers