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.
<div class="chart">
<h1>Daily visitors</h1>
<p>The daily amount of unique visitors of <a href="fossheim.io">fossheim.io</a>, measured during the last week (11 May 2020 to 17 May 2020). Days where the visitor count was below your predefined threshold of 100 are highlighted.</p>
</div>
<svg width="0" height="0">
<defs>
<pattern id="dots" x="0" y="0" width="3" height="3" patternUnits="userSpaceOnUse">
<rect fill="#5D92F6" x="0" y="0" width="3" height="3"></rect>
<circle fill="#11419B" cx="1" cy="1" r="1">
</circle>
</pattern>
<pattern id="lines" x="0" y="0" width="3" height="3" patternUnits="userSpaceOnUse">
<rect fill="#F06B5A" x="0" y="0" width="3" height="3"></rect>
<rect fill="#B91919" x="0" y="0" width="3" height="1"></rect>
</pattern>
</defs>
</svg>
body {
background-color: #F6F6FC;
font-family: sans-serif;
}
h1 {
margin-left: 1.5rem;
font-size: 1.25rem;
color: #110952;
}
p {
margin-left: 1.5rem;
padding-right: 1.5rem;
color: #49456C;
}
.chart {
width: 700px;
min-height: 450px;
margin: 60px auto 0 auto;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 0 10px #D8D8E9;
padding: 20px;
}
text {
font-family: sans-serif;
font-size: 0.65rem;
fill: #49456C;
}
.bar {
fill: #5D92F6;
fill: url(#dots)
}
.bar.danger {
fill: #F06B5A;
fill: url(#lines);
}
.yTicks .domain, .yTicks .tick line {
opacity: 0;
}
.yTicks .tick text {
opacity: 0.75;
}
const data = [
{day: "Mon", visitors: 100},
{day: "Tue", visitors: 174},
{day: "Wed", visitors: 92},
{day: "Thu", visitors: 193},
{day: "Fri", visitors: 103},
{day: "Sat", visitors: 104},
{day: "Sun", visitors: 294}];
const margin = {left: 50, right: 50, top: 100, bottom: 50};
const width = 700 - margin.left - margin.right;
const height = 450 - margin.top - margin.bottom;
const chart = d3.select(".chart").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom);
const x = d3.scaleLinear().rangeRound([0, width]);
const y = d3.scaleLinear().rangeRound([0, height]);
const maxYValue = d3.max(data, row => row.visitors) || 10;
x.domain([0, data.length]);
y.domain([maxYValue + 10, 0]);
const legend = chart.append("g")
.attr("class", "legend")
.attr("aria-label", "Legend")
.attr("x", 0)
.attr("y", -margin.top);
legend.append("rect")
.attr("fill", "url(#dots)")
.attr("width", 13)
.attr("height", 13)
.attr("rx", 2)
.attr("x", margin.left / 2)
.attr("y", 0);
legend.append("text")
.text("Over 100 daily visitors")
.attr("x", margin.left / 2 + 20)
.attr("y", 10);
legend.append("rect")
.attr("fill", "url(#lines)")
.attr("width", 13)
.attr("height", 13)
.attr("rx", 2)
.attr("x", margin.left / 2)
.attr("y", 30);
legend.append("text")
.text("Under or equal to 100 daily visitors")
.attr("x", margin.left / 2 + 20)
.attr("y", 40);
const xLabel = chart.append("text");
xLabel.append("tspan")
.text("X Axis")
.attr("class", "xAxis")
.attr("text-anchor", "middle")
.attr("x", -width)
.attr("y", -height);
xLabel.append("tspan")
.text("Days of the week (11/05 to 17/05)")
.attr("class", "xAxis")
.attr("text-anchor", "middle")
.attr("x", (width + margin.left + margin.right) / 2)
.attr("y", height + margin.top + margin.bottom / 1.5);
const xTicks = chart.append("g")
.attr("aria-label", "Range of the X-axis");
xTicks.selectAll(".xTicks")
.data(data)
.enter().append("text")
.text((data) => data.day)
.attr("class", "xTicks")
.attr("x", function(row, index) { return x(index + 1) + 5; })
.attr("y", height + margin.top)
.attr("width", 30)
.attr("text-anchor", "middle");
const yLabel = chart.append("text")
.attr("transform", "rotate(-90)")
.attr("class", "yAxis");
yLabel.append("tspan")
.text("Y Axis")
.attr("x", -width)
.attr("y", -height);
yLabel.append("tspan")
.text("Amount of unique visitors")
.attr("text-anchor", "middle")
.attr("x", -height / 2 - margin.top )
.attr("y", margin.left / 2 + 5);
const yRange = [];
const topYValue = Math.ceil(maxYValue/100)*100;
for(var i = 0; i <= (topYValue / 100); i++) {
yRange.push(i * 100);
}
const yTicks = chart.append("g")
.attr("class", "yTicks")
.attr("aria-label", "Range of the Y-axis");
yTicks.selectAll(".tick")
.data(yRange)
.enter()
.append("text")
.text(row => row)
.attr("x", row => row >= 100 ? margin.left - 5 : margin.left + 5)
.attr("y", row => y(row) + margin.top - 13)
.attr("opacity", 0.75)
.attr("width", 30);
yTicks.selectAll(".line")
.data(yRange)
.enter()
.append("line")
.attr("x1", margin.left + 20)
.attr("x2", width + margin.left )
.attr("y1", row => y(row) + margin.top - 15)
.attr("y2", row => y(row) + margin.top - 15)
.attr("stroke", "#49456C")
.attr("stroke-width", 1)
.attr("opacity", 0.15);
/* const yTicks = chart.append("g")
.attr("transform", "translate(" + (margin.left + 20) + ", " + (margin.top - 15) + ")")
.attr("class", "yTicks")
.call(d3.axisLeft(y).ticks(5)); */
chart.selectAll(".bar")
.data(data)
.enter().append("rect")
.attr("class", row => row.visitors > 100 ? "bar" : "bar danger")
.attr("x", (row, index) => x(index + 1) )
.attr("y", row => y(row.visitors) + margin.top - 15)
.attr("width", 10)
.attr("height", row => height - y(row.visitors))
.attr("rx", 5);
const barLabels = chart.selectAll(".label")
.data(data)
.enter().append("text").attr("class","label");
barLabels.append("tspan")
.text(row => row.day)
.attr("text-anchor", "middle")
.attr("x", -width)
.attr("y", -height);
barLabels.append("tspan")
.text(row => row.visitors)
.attr("text-anchor", "middle")
.attr("x", (row, index) => x(index + 1) + 5)
.attr("y", row => y(row.visitors) + margin.top - 20);
Also see: Tab Triggers