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="content-container">
<header>
<h1>Defensive CSS</h1>
<h2>Flex Wrapping</h2>
</header>
<main>
<p>Since CSS flexbox gained wide support, its most frequent issue concerns items overflowing their container. This is because, by default, flex items do not wrap to a new row when they reach the edge of their container. To prevent this, and ensure flex items wrap to new lines as needed, always include a <code class="inline">flex-wrap</code> property on every flex container.</p>
<div class="content-section">
<section class="demo">
<h3>Without Defensive CSS</h3>
<div class="flex-container">
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
</div>
</section>
<section class="demo">
<h3>With Defensive CSS</h3>
<div class="flex-container with-defensive">
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
</div>
</section>
</div>
</main>
<footer>
<p>Linting Defensive & Logical CSS With Stylelint Plugins</p>
<a href="https://twitter.com/DanielYuschick" aria-label="@Daniel Yuschick on Twitter">@DanielYuschick</a>
</footer>
</div>
.flex-container {
border: 1px solid var(--color-aux-100);
display: flex;
gap: var(--space-base-4x);
overflow: hidden;
max-inline-size: 100%;
padding: 1em;
.flex-item {
background-color: var(--color-core-secondary);
padding: var(--space-base-8x);
}
&.with-defensive {
flex-wrap: wrap;
}
}
/**********
*** SETUP
**********/
/***** Properties *****/
:root {
--color-aux-50: rgb(10, 10, 11);
--color-aux-100: rgb(29, 29, 32);
--color-aux-200: rgb(48, 48, 54);
--color-aux-300: rgb(77, 77, 86);
--color-aux-400: rgb(96, 96, 108);
--color-aux-500: rgb(115, 115, 130);
--color-aux-600: rgb(147, 147, 159);
--color-aux-700: rgb(169, 169, 178);
--color-aux-800: rgb(190, 190, 197);
--color-aux-900: rgb(223, 223, 226);
--color-aux-950: rgb(242, 239, 233);
--color-core-primary: #754abc;
--color-core-secondary: #8b3257;
--font-family-body: "Poppins", sans-serif;
--font-family-heading: "Roboto Slab", serif;
--space-base: 4px;
--space-base-half: calc(var(--space-base) / 2);
--space-base-1x: var(--space-base);
--space-base-2x: calc(var(--space-base) * 2);
--space-base-3x: calc(var(--space-base) * 3);
--space-base-4x: calc(var(--space-base) * 4);
--space-base-6x: calc(var(--space-base) * 6);
--space-base-8x: calc(var(--space-base) * 8);
--space-base-12x: calc(var(--space-base) * 12);
--space-base-16x: calc(var(--space-base) * 16);
--space-base-24x: calc(var(--space-base) * 24);
}
/***** Landmarks *****/
body {
background-image: linear-gradient(
335deg,
hsl(263deg 46% 51%) 0%,
hsl(263deg 44% 46%) 50%,
hsl(263deg 46% 40%) 100%
);
padding: 1rem;
}
main {
max-inline-size: 100vw;
overflow: hidden;
}
footer {
--padding-offset: var(--space-base-4x);
align-items: center;
display: flex;
flex-wrap: wrap;
gap: 1rem;
justify-content: space-between;
border-block-start: 1px solid var(--color-aux-50);
padding-block: var(--padding-offset);
margin-block-start: var(--padding-offset);
}
/***** Textual *****/
a,
a:visited,
a:active,
a:link {
color: var(--color-core-secondary);
}
span,
p {
font-family: var(--font-family-body);
}
p + p {
margin-block-start: 1rem;
}
h1,
h2,
h3,
h4,
h5,
h6 {
font-family: var(--font-family-heading);
}
code {
background: var(--color-aux-100);
color: var(--color-aux-950);
display: block;
padding: 0.25rem 0.5rem;
&.inline {
display: inline-block;
}
}
/***** Other *****/
.content-container {
inline-size: 75%;
margin-inline: auto;
}
/**********
*** RESET
**********/
* {
margin: 0;
padding: 0;
}
*,
::before,
::after {
box-sizing: border-box;
}
*:where(:not(fieldset, progress, meter)) {
background-origin: border-box;
border-style: solid;
border-width: 0;
}
html {
-webkit-text-size-adjust: none;
block-size: 100%;
}
@media (prefers-reduced-motion: no-preference) {
html:focus-within {
scroll-behavior: smooth;
}
}
body {
-webkit-font-smoothing: antialiased;
line-height: 1.5;
min-block-size: 100%;
text-rendering: optimizeSpeed;
}
:where(img, svg, video, canvas, audio, iframe, embed, object) {
display: block;
}
:where(img, svg, video) {
block-size: auto;
max-inline-size: 100%;
}
:where(svg) {
fill: currentColor;
stroke: none;
}
:where(svg):where(:not([fill])) {
fill: none;
stroke-linecap: round;
stroke-linejoin: round;
stroke: currentColor;
}
:where(svg):where(:not([width])) {
inline-size: 5rem;
}
:where(input, button, textarea, select),
:where(input[type="file"])::-webkit-file-upload-button {
color: inherit;
font-size: inherit;
font: inherit;
letter-spacing: inherit;
word-spacing: inherit;
}
:where(textarea) {
resize: block;
}
:where(span, p, h1, h2, h3, h4, h5, h6) {
overflow-wrap: break-word;
max-inline-size: 90ch;
}
:where(ul, ol) {
list-style-position: inside;
}
:where(ul, ol, [role="list"]) {
list-style: none;
}
:where(ul, ol, [role="list"]) li::before {
border: 0px;
clip: rect(0px, 0px, 0px, 0px);
content: "\\200B";
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0px;
position: absolute;
white-space: nowrap;
width: 1px;
}
a:not([class]) {
text-decoration-skip-ink: auto;
}
:where(a[href], area, button, input, label[for], select, summary, textarea, [tabindex]:not([tabindex*="-"])) {
cursor: pointer;
touch-action: manipulation;
}
:where(input[type="file"]) {
cursor: auto;
}
:where(input[type="file"])::-webkit-file-upload-button,
:where(input[type="file"])::file-selector-button {
cursor: pointer;
}
@media (prefers-reduced-motion: no-preference) {
:focus-visible {
transition: outline-offset 145ms cubic-bezier(0.25, 0, 0.4, 1);
}
:where(:not(:active)):focus-visible {
transition-duration: 0.25s;
}
}
:where(:not(:active)):focus-visible {
outline-offset: 5px;
}
:where(button, button[type], input[type="button"], input[type="submit"], input[type="reset"]),
:where(input[type="file"])::-webkit-file-upload-button,
:where(input[type="file"])::file-selector-button {
-webkit-tap-highlight-color: transparent;
-webkit-touch-callout: none;
text-align: center;
user-select: none;
}
:where(button, button[type], input[type="button"], input[type="submit"], input[type="reset"])[disabled] {
cursor: not-allowed;
}
/**********
*** UTILITIES
**********/
.content-container {
min-block-size: calc(100vb - 2rem);
inline-size: 100%;
max-inline-size: 100vi;
overflow: hidden;
background-color: var(--color-aux-950);
border: 1px solid bvar(--color-core-primary);
border-radius: 4px;
padding: 0 2rem;
display: grid;
grid-template-rows: min-content 1fr min-content;
}
.content-section {
display: flex;
flex-wrap: wrap;
gap: var(--space-base-8x);
align-items: start;
padding-block: var(--space-base-8x);
justify-content: space-between;
overflow: hidden;
max-inline-size: 100vi;
}
.demo {
inline-size: max(calc(50% - var(--space-base-8x)), 500px);
}
Also see: Tab Triggers