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.
<body class="primary-layout">
<main>
<h1>Smart design patterns with container queries</h1>
<section class='lets-get-griddy'>
<h2>Featured Articles</h2>
<div class="grid-auto-fit">
<article class="card">
<img src='https://images.unsplash.com/photo-1523380262778-076eb862d38f?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3wzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MTgwMjc2NTd8&ixlib=rb-4.0.3&q=70&w=800' alt='desk in a dark room, with a lamp illuminating a closed laptop'>
<h3>The Art of Minimalism</h3>
<p>Dive into the art of minimalism in interior design, exploring how less can indeed be more.</p>
<p> <a href="#">Read more about minimalism</a></p>
</article>
<article class="card">
<h3>Color Theory in Interior Design</h3>
<p>Discover the profound impact of color choices on mood and aesthetics in interior design.</p>
<p> <a href="#">Read more about color theory</a></p>
</article>
<article class="card">
<h3>Article title</h3>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quam, eius?</p>
<p> <a href="#">Read more about XYZ</a></p>
</article>
<article class="card">
<h3>Maximizing Small Spaces</h3>
<p>Learn creative strategies to maximize small spaces, making them feel larger and more inviting.</p>
<p> <a href="#">Read more about maximizing small spaces</a></p>
</article>
<article class="card">
<h3>Eco-Friendly Interiors</h3>
<p>Explore how to create stunning interiors using eco-friendly materials and sustainable practices.</p>
<p> <a href="#">Read more about eco-friendly interior design</a></p>
</article>
<article class="card">
<h3>The Influence of Art Deco in Modern Homes</h3>
<p>Examine the enduring influence of Art Deco on modern home design and how to incorporate it.</p>
<p> <a href="#">Read more about using Art Deco in modern homes</a></p>
</article>
<article class="card">
<h3>Article title</h3>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quam, eius?</p>
<p> <a href="#">Read more about XYZ</a></p>
</article>
<article class="card">
<h3>Incorporating Plants into Your Decor</h3>
<p>Discover how to breathe life into your home by incorporating plants into your decor.</p>
<p> <a href="#">Read more about using plants in your decor</a></p>
</article>
<article class="card">
<h3>The Psychology of Interior Design</h3>
<p>Understand the psychology behind interior design and how it affects our emotions and behavior.</p>
<p> <a href="#">Read more about the psychology of interior design</a></p>
</article>
<article class="card">
<h3>Trends in Kitchen Design</h3>
<p>Stay up-to-date with the latest trends in kitchen design, from smart appliances to color schemes.</p>
<p> <a href="#">Read more about kitchen design trends</a></p>
</article>
<article class="card">
<article>
<h3>Creating a Home Office That Works</h3>
<p>Create a home office that boosts productivity and balances work with home life.</p>
<p><a href="#">Read more about improving your home office</a></p>
</article>
</article>
</div>
</section>
<section>
<h2>Some other content that follows</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Fugit vitae delectus quo labore quidem corrupti ipsam, quasi velit ex temporibus amet numquam? Necessitatibus corrupti error inventore in. Voluptate, esse dolorum!</p>
<p>Ratione quo, accusantium commodi unde consequatur quidem dolorem numquam molestiae officia impedit, pariatur iure corrupti quaerat explicabo molestias. Impedit deleniti ipsam numquam voluptatem laboriosam dolorem atque deserunt quidem reprehenderit officia.</p>
<p>Praesentium quisquam tempora, voluptate animi quos consequatur aliquid ipsa repellat reprehenderit vel enim necessitatibus! Quas quaerat deleniti necessitatibus harum voluptates repellendus, voluptate earum delectus nemo. Nulla, quis. Velit, fugit beatae!</p>
<p>Eos, aperiam consectetur eius sed excepturi pariatur deserunt incidunt vel voluptatibus officia voluptates voluptatum expedita. Facere consequatur et quo perferendis atque, ducimus libero debitis nobis fugiat corporis quisquam sapiente recusandae?</p>
</section>
</main>
</body>
main {
container: main / inline-size;
}
.grid-auto-fit {
display: grid;
gap: 1rem;
grid-template-columns: repeat(auto-fit, minmax(min(30ch, 100%), 1fr));
container: grid-auto-fit / inline-size;
}
.card:has(> img) {
border: 2px solid var(--clr-primary-300);
@container grid-auto-fit (inline-size > calc(30ch * 2 + 1rem)) {
grid-column: span 2;
display: grid;
grid-template-columns: subgrid;
gap: 0;
> img {
grid-column: 2;
grid-row: 1 / 4;
}
}
@container grid-auto-fit (inline-size > calc(30ch * 4 + 3rem)) {
grid-column: span 2;
grid-row: span 2;
> :not(img) {
grid-column: 1 / -1;
}
> img {
grid-column: 1 / -1;
grid-row: 1;
}
}
}
@layer general-styling {
html {
color-scheme: dark light;
font-family: system-ui;
line-height: 1.6;
}
body {
font-size: 1.25rem;
margin: 0;
}
img {
max-width: 100%;
display: block;
}
h1,
h2,
h3 {
font-family: "Playfair Display", serif;
font-optical-sizing: auto;
/* font-style: italic; */
text-transform: uppercase;
font-weight: 400;
}
h1 {
font-size: 4rem;
/* font-size: round(up, clamp(2rem, 5cqi + .5rem, 5rem), 2rem); */
line-height: 1.1;
}
h2 {
font-size: 2.5rem;
}
h3 {
font-size: 1.5rem;
}
a:not([class]) {
justify-self: start;
color: white;
/* text-decoration: none; */
text-underline-offset: 4px;
transition: background-size 325ms ease, text-decoration 325ms;
&:hover,
&:focus-visible {
text-decoration-color: var(--clr-primary-400);
background-size: 100% 1px;
}
}
section {
padding-block: clamp(2rem, 5vb, 6rem);
}
.btn {
display: inline flex;
padding: 1rem 2rem;
text-decoration: none;
cursor: pointer;
background-color: var(--clr-primary-500);
color: white;
&:hover,
&:focus-visible {
background-color: var(--clr-primary-600);
}
}
}
@layer card-styling-not-specific-for-demo {
.card {
--padding: 1rem;
display: grid;
background: hsl(0 0% 50% / 0.2);
background-image: linear-gradient(
to bottom,
transparent 50%,
rgb(0 0 0 / 0.3)
);
overflow: hidden;
border-radius: 0.25rem;
h2,
h3 {
color: var(--clr-primary-200);
}
> img {
object-fit: cover;
width: 100%;
height: 100%;
}
> :not(img) {
margin-block-start: 0;
margin-inline: 1rem;
}
> :not(img):first-child {
margin-block-start: 1rem;
}
> :not(img):last-child {
margin-block-end: 1rem;
}
}
}
@layer theme {
:root {
--clr-neutral-900: ;
--clr-primary-600: hsl(22, 60%, 21%);
--clr-primary-500: hsl(22, 60%, 31%);
--clr-primary-400: hsl(22, 60%, 41%);
--clr-primary-300: hsl(22, 60%, 51%);
--clr-primary-200: hsl(22, 60%, 61%);
}
}
@layer layout {
.primary-layout {
display: grid;
grid-template-columns:
[full-width] minmax(2rem, 1fr) [content-start] min(1600px, 100% - 4rem)
[content-end] minmax(2rem, 1fr);
& > * {
grid-column: 2 / -2;
}
}
}
Also see: Tab Triggers