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.
<h1>
SVG Turbulence Filter Test
</h1>
<p id="sentence" contenteditable="true" spellcheck="false">
The <strong>feTurbulence</strong> SVG filter generates and renders <em>Perlin noise</em>. This can be used
by CSS to distort <strong>elements and text</strong>. Try selecting or editing <em>this text</em>. You can fiddle
with the sliders below to <strong>change the effect</strong>.
</p>
<div class="sliders">
<div class="slider">
<label for="turbulenceNumOctavesRange">Turbulence Number of Octaves</label>
<output for="turbulenceNumOctavesRange" id="turbulenceNumOctavesRangeOutput"></output>
<input class="slider__range" type="range" name="turbulenceNumOctavesRange" id="turbulenceNumOctavesRange" data-filter-id="turbulence" data-filter-attr="numOctaves" min="1" max="9" value="5" />
</div>
<div class="slider">
<label for="turbulenceBaseFrequencyRange">Turbulence Base Frequency</label>
<output for="turbulenceBaseFrequencyRange" id="turbulenceBaseFrequencyRangeOutput"></output>
<input class="slider__range" type="range" name="turbulenceBaseFrequencyRange" id="turbulenceBaseFrequencyRange" data-filter-id="turbulence" data-filter-attr="baseFrequency" min="0.0001" max="0.002" step="0.0001" value="0.0002" />
</div>
<div class="slider">
<label for="turbulenceBaseSeedRange">Turbulence Seed</label>
<output for="turbulenceBaseSeedRange" id="turbulenceBaseSeedRangeOutput"></output>
<input class="slider__range" type="range" name="turbulenceBaseSeedRange" id="turbulenceBaseSeedRange" data-filter-id="turbulence" data-filter-attr="seed" min="0" max="1000" step="1" value="500" />
</div>
<div class="slider">
<label for="displacerScaleRange">Displacer Scale</label>
<output for="displacerScaleRange" id="displacerScaleRangeOutput"></output>
<input class="slider__range" type="range" name="displacerScaleRange" id="displacerScaleRange" data-filter-id="displacer" data-filter-attr="scale" min="1" max="100" value="50" />
</div>
</div>
<svg class="filter">
<defs>
<filter id="filter">
<feTurbulence id="turbulence" type="fractalNoise" baseFrequency="0.0001 " numOctaves="5" result="NOISE">
</feTurbulence>
<feGaussianBlur in="SourceGraphic" result="BLURRED" stdDeviation="0"></feGaussianBlur>
<feDisplacementMap id="displacer" in2="NOISE" in="BLURRED" scale="15" xChannelSelector="R" yChannelSelector="R" result="DISPLACED"></feDisplacementMap>
</filter>
</defs>
</svg>
:root {
--color-surface: Black;
--color-background: PaleGoldenRod;
}
/* Box sizing rules */
*,
*::before,
*::after {
box-sizing: border-box;
}
/* Remove default margin */
body,
h1,
h2,
h3,
h4,
p,
figure,
blockquote,
dl,
dd {
margin: 0;
font-size: 100%;
}
html {
height: 100vh;
line-height: 1.3;
font-size: 87.5%;
font-weight: 600;
text-transform: uppercase;
font-family: ui-monospace, Menlo, Monaco, "Cascadia Mono", "Segoe UI Mono",
"Roboto Mono", "Oxygen Mono", "Ubuntu Monospace", "Source Code Pro",
"Fira Mono", "Droid Sans Mono", "Courier New", monospace;
display: grid;
place-items: center;
color: var(--color-surface);
background-color: var(--color-background);
}
body {
padding: 2rem;
max-width: 74rem;
}
::selection {
background: var(--color-surface);
color: var(--color-background);
}
*:focus {
outline: none;
}
*:focus-visible {
outline: 3px solid currentColor;
outline-offset: 3px;
}
h1 {
margin-bottom: 2rem;
}
p {
font-size: 4rem;
font-size: clamp(2rem, 0.9349rem + 4.1420vw, 4rem);
font-weight: normal;
filter: url(#filter);
border: 3px solid currentColor;
padding: 0.75em;
font-family: "Bebas Neue", sans-serif;
}
em {
font-style: normal;
font-weight: normal;
text-decoration: underline;
text-decoration-thickness: 0.1em;
text-underline-offset: 0.05em;
}
strong {
font-weight: normal;
background-color: var(--color-surface);
color: var(--color-background);
padding: 0 0.25em;
}
label,
output,
h1 {
font-size: inherit;
}
/* style for the range input */
input[type="range"] {
--range__thumb-size: 1.5em;
--range__border-width: 3px;
--range__thumb-bgc: var(--color-background);
-webkit-appearance: none;
margin: 1em 0;
width: 100%;
display: block;
color: inherit;
background-color: transparent;
}
input[type="range"]::-webkit-slider-runnable-track {
width: 100%;
height: var(--range__border-width);
cursor: pointer;
background: currentColor;
border: 0px solid currentColor;
}
input[type="range"]::-webkit-slider-thumb {
border: var(--range__border-width) solid currentColor;
height: var(--range__thumb-size);
width: var(--range__thumb-size);
background: var(--range__thumb-bgc);
cursor: pointer;
-webkit-appearance: none;
margin-top: calc(
-1 * calc(var(--range__thumb-size) / 2) + 1 * calc(var(
--range__border-width
) / 2)
);
}
input[type="range"]::-moz-range-track {
width: 100%;
height: var(--range__border-width);
cursor: pointer;
background: currentColor;
border: 0px solid currentColor;
}
input[type="range"]::-moz-range-thumb {
border-radius: 0;
border: var(--range__border-width) solid currentColor;
height: var(--range__thumb-size);
width: var(--range__thumb-size);
background: var(--range__thumb-bgc);
cursor: pointer;
-webkit-appearance: none;
margin-top: calc(
-1 * calc(var(--range__thumb-size) / 2) + 1 * calc(var(
--range__border-width
) / 2)
);
}
.sliders {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 1.5rem 3rem;
}
.slider {
display: grid;
grid-template-columns: 1fr auto;
grid-template-rows: auto auto;
gap: 0.5rem;
}
.slider input[type="range"] {
grid-column: 1 / -1;
grid-row: 2;
}
* + .sliders {
margin-top: 3rem;
}
.filter {
position: absolute !important;
height: 1px; width: 1px;
overflow: hidden;
clip: rect(1px 1px 1px 1px);
clip: rect(1px, 1px, 1px, 1px);
}
// set the value of the element turbulenceBaseSeedRange to a random number between 0 and 1000
document.getElementById("turbulenceBaseSeedRange").value = Math.floor(
Math.random() * 1000
);
// set each atrribute of the filter of the svg element to the values of the corresponding range inputs based on the data-filter-id and data-filter-attr attributes and set the output element's value to the value of the range input when the input's value changes
const sliders = document.querySelectorAll(".slider__range");
const filter = document.querySelector(".filter");
sliders.forEach((slider) => {
// set the output element to the value of the range input
const output = slider.parentNode.querySelector("output");
output.value = slider.value;
const filterId = slider.dataset.filterId;
const filterAttr = slider.dataset.filterAttr;
const filterElement = filter.querySelector(`#${filterId}`);
filterElement.setAttribute(filterAttr, slider.value);
slider.addEventListener("input", function () {
output.value = this.value;
filterElement.setAttribute(filterAttr, this.value);
});
});
Also see: Tab Triggers