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="big-chart-container">
<div id="big-chart"></div>
</div>
.line {
fill: none;
stroke: #36B8BE;
stroke-width: 1px;
z-index: 2;
}
.area {
fill: url(#area-gradient);
stroke-width: 0;
z-index: 1;
}
g text {
font: 1.5rem 'avenir next', 'open sans', sans-serif;
font-size: 24px;
}
g.tick line {
stroke: #ccc;
}
g .tick text {
fill: #444;
}
path.domain {
stroke: #CCC;
}
.grid line {
stroke: #aeb0b5;
stroke-opacity: 0.7;
stroke-width: .2vh;
shape-rendering: crispEdges;
z-index: -1;
}
.grid path {
stroke-width: 0;
}
.data-point-label {
font-weight: 600;
font-size: 16px;
}
.y-axis-labels {
fill: #CCC;
}
// set the dimensions and margins of the graph
var margin = {
top: 20,
right: 60,
bottom: 90,
left: 90
},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
// parse the date / time
var parseTime = d3.timeParse("%A %B %d %Y %H");
var formatTime = d3.timeFormat("%a"); // %d
// set the ranges
var x = d3.scaleTime().range([0, width]);
var y = d3.scaleLinear().range([height, 0]);
// define the line
var valueline = d3.line()
.x(function (d) {
return x(d.date);
})
.y(function (d) {
return y(d.progress);
});
// define the area
var area = d3.area()
.x(d => x(d.date))
.y0(y(0))
.y1(d => y(d.progress));
var div = d3.select("#big-chart-container").append("div")
.attr("class", "tooltip")
.style("opacity", 0);
format = d3.format(".0f")
// append the svg to the chart container
var bigChartSvg = d3.select("#big-chart").append("svg")
.attr("viewBox", "0 0 " + (width + margin.left + margin.right) + " " + (height + margin.top +
margin.bottom))
.attr("preserveAspectRatio", "xMaxYMax meet")
.classed("svg-content", true)
.append("g")
.attr("transform",
"translate(" + margin.left + "," + margin.top + ")");
// Get the data
var data = [
{
"date": "Monday March 12 2018 00",
"progress": 8
},
{
"date": "Monday March 12 2018 06",
"progress": 11
},
{
"date": "Monday March 12 2018 12",
"progress": 9
},
{
"date": "Monday March 12 2018 18",
"progress": 11
},
{
"date": "Tuesday March 13 2018 00",
"progress": 19
},
{
"date": "Tuesday March 13 2018 06",
"progress": 21
},
{
"date": "Tuesday March 13 2018 12",
"progress": 19
},
{
"date": "Tuesday March 13 2018 18",
"progress": 21
},
{
"date": "Wednesday March 14 2018 00",
"progress": 23
},
{
"date": "Wednesday March 14 2018 06",
"progress": 28
},
{
"date": "Wednesday March 14 2018 12",
"progress": 24
},
{
"date": "Wednesday March 14 2018 18",
"progress": 34
},
{
"date": "Thursday March 15 2018 00",
"progress": 38
},
{
"date": "Thursday March 15 2018 06",
"progress": 38
},
{
"date": "Thursday March 15 2018 12",
"progress": 40
},
{
"date": "Thursday March 15 2018 18",
"progress": 40
},
{
"date": "Friday March 16 2018 00",
"progress": 40
},
{
"date": "Friday March 16 2018 06",
"progress": 48
},
{
"date": "Friday March 16 2018 12",
"progress": 52
},
{
"date": "Friday March 16 2018 18",
"progress": 62
},
{
"date": "Saturday March 17 2018 00",
"progress": 62
},
{
"date": "Saturday March 17 2018 06",
"progress": 59
},
{
"date": "Saturday March 17 2018 12",
"progress": 66
},
{
"date": "Saturday March 17 2018 18",
"progress": 78
},
{
"date": "Sunday March 18 2018 00",
"progress": 83
},
{
"date": "Sunday March 18 2018 06",
"progress": 84
},
{
"date": "Sunday March 18 2018 12",
"progress": 83
},
{
"date": "Sunday March 18 2018 18",
"progress": 83
}
];
// format the data
data.forEach(function (d) {
d.date = parseTime(d.date);
d.progress = +d.progress;
});
// scale the range of the data
x.domain(d3.extent(data, function(d) { return (d.date); }));
y.domain([0, 100]);
//attach gradient to area
bigChartSvg.append("linearGradient")
.attr("id", "area-gradient")
.attr("gradientUnits", "userSpaceOnUse")
.attr("x1", 0).attr("y1", y(0))
.attr("x2", 0).attr("y2", y(100))
.selectAll("stop")
.data([{
offset: "0%",
color: "#3997A7",
opacity: ".1"
},
{
offset: "15%",
color: "#3997A7",
opacity: ".3"
},
{
offset: "30%",
color: "#3997A7",
opacity: ".5"
},
{
offset: "45%",
color: "#3997A7",
opacity: ".6"
},
{
offset: "65%",
color: "#36B8BE",
opacity: ".7"
},
{
offset: "80%",
color: "#36B8BE",
opacity: "1"
}
])
.enter().append("stop")
.attr("offset", function (d) {
return d.offset;
})
.attr("stop-color", function (d) {
return d.color;
})
.attr("stop-opacity", function(d) {
return d.opacity;
});
// Add the filled area
bigChartSvg.append("path")
.datum(data)
.attr("class", "area")
.attr("d", area)
.style("opacity", .5);
console.log([data]);
// add the valueline path.
bigChartSvg.append("path")
.attr("class", "line")
.attr("d", valueline(data));
// add the x axis
bigChartSvg.append("g")
.attr("transform", "translate(0," + height + ")")
.call(d3.axisBottom(x).tickFormat(d3.timeFormat("%a")).ticks(7))
.selectAll("text")
.attr("y", 0)
.attr("x", 8)
.attr("dy", "40")
.attr("dx", "3.5%")
.attr("transform", "rotate(0)") //60
.style("text-anchor", "start");
// add the y axis
bigChartSvg.append("g")
.call(d3.axisLeft(y).ticks(5));
// add y axis labels
bigChartSvg.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 0 - margin.left)
.attr("x",0 - (height / 2))
.attr("dy", "1em")
.style("text-anchor", "middle")
.text("% Shift Goal");
bigChartSvg.append("g")
.attr("fill", "#003A52")
.attr("text-anchor", "end")
.style("font", "4px avenir-next")
.selectAll("text")
.data(data)
.enter().append("text")
.classed("data-point-label",true)
.attr("x", d => x(d.date))
.attr("y", d => y(d.progress) - 12)
.attr("dx", "0.35em")
.attr("dy", "0.25em")
.text(d => format(d.progress));
Also see: Tab Triggers