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.
<svg width="100%" height="100%"
xmlns="http://www.w3.org/2000/svg" viewport = '0 0 500 500'
xmlns:xlink="http://www.w3.org/1999/xlink"
onload="start(evt)"
>
<defs>
<path id="Q" stroke="hsla(0,0%,0%,1)" stroke-width="3"/>
<linearGradient id="backsky" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset="0" stop-color="hsla(0,0%,53%,.7)"/>
<stop offset=".5" stop-color="hsla(184,100%,53%,.5)"/>
<stop offset=".9" stop-color="hsla(184, 95%, 15%, 1)"/>
</linearGradient>
<radialGradient id="sky" cx="500" cy="300" r="500" gradientUnits="userSpaceOnUse">
<stop offset="0" stop-color="hsla(184,100%,53%,1)" stop-opacity="1"/>
<stop offset=".2" stop-color="hsla(184,100%,53%,1)" stop-opacity=".6"/>
<stop offset=".71" stop-color="hsla(0,0%,0%,1)" stop-opacity="0"/>
<stop offset=".80" stop-color="hsla(204, 95%, 15%, .1)" stop-opacity="1"/>
</radialGradient>
<linearGradient id="peak2" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset="0" stop-color="hsla(204, 95%, 15%, 1)"/>
<stop offset=".2" stop-color="hsla(168,45%,73%,1)"/>
<stop offset=".4" stop-color="hsla(124, 35%, 33%, 1)"/>
<stop offset=".9" stop-color="hsla(244, 9%, 63%, 1)"/>
</linearGradient>
<linearGradient id="peak" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset="0" stop-color="hsla(304, 19%, 84%, 1)"/>
<stop offset=".2" stop-color="hsla(304, 7%, 17%, 1)"/>
<stop offset=".4" stop-color="hsla(83, 25%, 64%, 1)"/>
<stop offset=".9" stop-color="hsla(304, 47%, 54%, 1)"/>
</linearGradient>
<linearGradient id="mount" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset="0" stop-color="hsla(168, 26%, 46%, 1)"/>
<stop offset=".2" stop-color="hsla(83, 19%, 50%, 1)"/>
<stop offset=".6" stop-color="hsla(244, 7%, 56%, 1)"/>
</linearGradient>
<linearGradient id="foot" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset="0" stop-color="hsla(168, 26%, 46%, 1)"/>
<stop offset=".1" stop-color="hsla(340, 51%, 47%, 1)"/>
<stop offset=".70" stop-color="hsla(343, 46%, 60%,1)"/>
<stop offset=".90" stop-color="hsla(291, 40%, 63%,1)"/>
</linearGradient>
</defs>
<rect height="100%" width="100%" opacity="1" fill="url(#backsky)"/>
<path id="peaks2" d="M 0 500 400 400 800 500 z" fill="url(#peak2)" />
<path id="peaks" d="M 0 500 400 400 800 500 z" fill="url(#peak)" />
<path id="mountains" d="M 0 500 400 400 800 500 z" fill="url(#mount)" />
<path id="foothills" d="M 0 500 400 400 800 500 z" fill="url(#foot)" stroke="none"/>
<rect height="100%" width="100%" opacity="1" fill="url(#sky)"/>
<g id="balloon" opacity="0.7">
</g>
</svg>
body{
width:100%;
margin:0;
overflow:hidden;
}
svg{
width:100%;
height:100vh;
}
//sorry this is all just so ugly & messy.
var svgDocument;
balloon=null;
count=0
running=true
xlow=-200
xhigh=100
x=xlow
incr=5
dir=1
xdir=1
ydir=1
xspeed=.7
yspeed=.4
xcur=50
ycur=50
ylow=-25
yhigh=100
numlines=35
rightedge=null
Hi=new Array()
Up=new Array()
bottomedge=null
svgns = 'http://www.w3.org/2000/svg';
xlinkns = 'http://www.w3.org/1999/xlink';
function start(evt) {
O=evt.target;
svgDocument = O.ownerDocument;
balloon = svgDocument.getElementById("balloon");
path=svgDocument.getElementById("Q")
A=getDisplaySize()
rightedge=A.width
bottomedge=A.height - 40
sky=svgDocument.getElementById("sky")
sky.setAttribute("cy",50)
sky.setAttribute("cx",rightedge/2)
sky.setAttribute("r",rightedge/1.45)
draw("peaks2",7,90,30)
draw("peaks",10,80,25)
draw("mountains",15,55,22)
draw("foothills",22,35,15)
draw2();
}
function getDisplaySize()
{
var extents = {
width: window.innerWidth,
height: window.innerHeight
};
return extents;
}
function getDisplaySizeOLD()
{
var extents = null;
try
{
var view = document.documentElement.viewport;
extents = {
width: view.width,
height: view.height
};
}
catch(e)
{
extents = {
width: window.innerWidth,
height: window.innerHeight
};
}
return extents;
}
P=new Array()
offset=50
function draw(id,humps,hi,up){
IDS[IDS.length]=id
Hi[id]=hi
Up[id]=up
var peaks=3*humps
P[id]=new Array;
t=svgDocument.getElementById(id)
for (i=0;i<peaks;i++){
P[id][i]= {x: Math.floor(Math.random()*(rightedge+2*offset)-offset),
y: Math.floor(Math.random()*hi)+up};
}
P[id].sort(compare)
s=render(P[id],0)
t.setAttribute("d",s)
}
function compare(x,y){
if (x.x<y.x) return -1
else return 1
}
function render(Arr,lo){
var low=Math.floor(bottomedge*.9)
var s="M "+(-offset)+" "+(low)+" "
s+=(7-offset)+" "+(low - Arr[0].y)+" "
for (i=1;i<Arr.length;i++){
if ((i)%3==0) s+="C "+Arr[i].x+" "+(low - Arr[i].y)+" "
else
s+=Arr[i].x+" "+(low - Arr[i].y)+" "
}
s+="L "+(rightedge+offset)+" "+(low )+" Q "+(rightedge/2)+" "+(low)+" "+(-offset)+" "+(low)+" z"
return s
}
function draw2(){
for (j=0;j<numlines;j++) another(100+j*10)
Pa = svgDocument.createElementNS(svgns,"path");
Pa.setAttribute("d", "M 194 340 C 185 360 215 360 206 340");
Pa.setAttribute("stroke", "#440")
Pa.setAttribute("stroke-width", "3")
Pa.setAttribute("fill", "#551")
balloon.appendChild(Pa);
animate()
}
var xlinkns = "http://www.w3.org/1999/xlink";
function another(x){
Pa = svgDocument.createElementNS(svgns,"path");
Pa.setAttribute("id", "P"+count); count++
Pa.setAttribute("d", "M 100 0 C 200 200 300 200 100 300");
Pa.setAttribute("stroke", color(16,16,12))
Pa.setAttribute("stroke-width", "5")
Pa.setAttribute("fill", "none")
balloon.appendChild(Pa);
}
function animate(){
if (!running) return
x+=incr*dir
if ((x<xlow+incr)||(x>xhigh+incr))dir=-dir
onestep(x)
window.setTimeout("animate()",10)
}
IDS=new Array
mea=0
function onestep(x){
mea++
balloon.setAttribute("transform","translate("+xcur+","+ycur+")")
for (i=0;i<count;i++){
Pa = svgDocument.getElementById("P"+i);
Pa.setAttribute("d", "M 200 20 C "+((i*18)+x)+" 100 "+(220- x/2)+" 250 200 340 ");
}
adj=0
for (id in IDS){
for (j=0;j<P[IDS[id]].length;j++){
P[IDS[id]][j].x-=(adj*adj/4+1)/2
}
adj++
if(P[IDS[id]][3].x<0){
st=rightedge+offset
for (k=0;k<3;k++){
newx=st+Math.ceil(80*Math.random()/P[IDS[id]].length)
Q={x: newx,
y: Math.floor(Math.random()*Hi[IDS[id]]+Up[IDS[id]])}
st=newx
P[IDS[id]].push(Q);
R=P[IDS[id]].shift()
}
}
s=render(P[IDS[id]],R.y)
t=svgDocument.getElementById(IDS[id])
t.setAttribute("d",s)
}
xcur=xcur+xspeed*xdir
ycur=ycur+yspeed*ydir
if((xcur<xlow+150)||(xcur>rightedge/1.5)) xdir=-xdir
if((ycur<ylow)||(ycur>yhigh)) ydir=-ydir
if (Math.floor(xcur)%10==0)recolorone(color(16,12,8))
if (Math.floor(xcur)%20==1)recolorone(color(16,16,0))
if (Math.floor(xcur)%30==2)recolorone("#da0")
}
first=true
function recolorone(c){
r=Math.floor(Math.random()*count)
Pa = svgDocument.getElementById("P"+r);
Pa.setAttribute("stroke",c);
}
function color(xr,xg,xb){
r=Math.floor(Math.random()*xr)
R=r.toString(16)
g=Math.floor(Math.random()*xg)
G=g.toString(16)
b=Math.floor(Math.random()*xb)
B=b.toString(16)
return "#"+R+B+G
}
Also see: Tab Triggers