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.
<h5>DEMO</h5>
<h1>Using Container Query on a List of Quotes</h1>
<p><a href="https://developers.hubspot.com/blog/help-prevent-bad-design-using-container-queries-to-style-modules">Read Supporting Article</a> on the HubSpot Developer Blog. Written by <a href="https://bootstrapcreative.com/about/">Jake Lett</a></p>
<p>The animation demonstrates how the styles change based on the container width instead of the window width.</p>
<div class="controls"><button id="play">Play Animation</button> <button id="stop">Stop Animation</button></div>
<div class="testimonial__list animate" id="animation">
<blockquote class="testimonial__list-item">
<p>But thinking only of pages limits our potential to address design challenges at a lower level. Sure, starting with a page design may make sense. But by the time you start on the second page, the mindset should shift to looking for reusable chunks. By the third, fourth, and fifth page designs, reusable components become increasingly obvious.</p>
<cite><img src="https://m.media-amazon.com/images/I/21XBCgr-sXL._SY210_CR52%2C0%2C210%2C210_.jpg" alt="Nathan Curtis"> Nathan Curtis, <a href="https://www.amazon.com/Modular-Web-Design-Components-Documentation-ebook/dp/B003FJ64EE/ref=tmm_kin_swatch_0?_encoding=UTF8&qid=1681204585&sr=8-1">Modular Web Design</a></cite>
</blockquote>
<blockquote class="testimonial__list-item">
<p>A module is a reusable building block that can be added to templates and pages. While a
module instance is the individual rendered modules on the page. They can have separate field values and as a result look different from other module instances that are for the same module.</p>
<cite><img src="https://www.hubspot.com/hubfs/HubSpot_Logos/HubSpot-Inversed-Favicon.png" alt="HubSpot icon"> <a href="https://developers.hubspot.com/docs/cms/building-blocks/modules">developers.hubspot.com</a></cite>
</blockquote>
<blockquote class="testimonial__list-item testimonial__list-item--featured">
<p>Modular web design requires more testing and development time to build a solution for a broader set of widths, not just the viewport width.</p>
<cite><img src="https://i0.wp.com/bootstrapcreative.com/wp-bc/wp-content/uploads/2022/08/jake-lett-2022.png?resize=150%2C150&ssl=1" alt="Jake Lett HubSpot Developer"> Jake Lett, <a href="https://www.bootstrapcreative.com/jake-addons/modular-manifesto">Modular Web Design Manifesto</a></cite>
</blockquote>
<blockquote class="testimonial__list-item">
<p>Understanding modules is key to understanding the HubSpot CMS and its power. Modules are reusable components that can be used in templates or added to pages through drag and drop areas and flexible columns.</p>
<cite><img src="https://www.hubspot.com/hubfs/HubSpot_Logos/HubSpot-Inversed-Favicon.png" alt="HubSpot icon"> <a href="https://developers.hubspot.com/docs/cms/building-blocks/modules">developers.hubspot.com</a></cite>
</blockquote>
<blockquote class="testimonial__list-item">
<p>A component library isn’t about limiting innovation. Instead, it empowers designers to reuse solutions to problems that have already been solved so they can focus more on the problems that don’t have solutions. When individuals no longer reinvent vast portions of a design with every project, productivity increases and headaches diminish. In addition, a library provides a platform for improved governance, a deeper baseline for collaboration, and a structure for useful and predictable documentation.</p>
<cite><img src="https://m.media-amazon.com/images/I/21XBCgr-sXL._SY210_CR52%2C0%2C210%2C210_.jpg" alt="Nathan Curtis"> Nathan Curtis, <a href="https://www.amazon.com/Modular-Web-Design-Components-Documentation-ebook/dp/B003FJ64EE/ref=tmm_kin_swatch_0?_encoding=UTF8&qid=1681204585&sr=8-1">Modular Web Design</a>
</blockquote>
</div>
<p><a href="https://bootstrapcreative.com/about/">©2023 Bootstrap Creative</a></p>
.testimonial__list {
border: 10px solid rgba(150, 200, 200, 0.4);
padding: 2rem;
margin-bottom: 2rem;
display: flex;
flex-direction: row;
flex-wrap: wrap;
width: 100%;
gap: 2%;
container-type: inline-size;
container-name: list;
/* shorthand - container: list / inline-size; */
}
.testimonial__list-item {
quotes: "“" "”" "‘" "’";
width: 49%;
line-height: 1.2;
box-sizing: border-box;
margin-bottom: 2rem;
container-type: inline-size;
container-name: item;
/* shorthand - container: item / inline-size; */
}
.testimonial__list-item p {
background-color: #e4e4e7;
padding: 1rem 1.5rem;
quotes: "“" "”" "‘" "’";
border-radius: 20px;
font-style: italic;
}
.testimonial__list-item p::before {
content: open-quote;
font-weight: bold;
opacity: 0.5;
margin-left: -0.5rem;
}
.testimonial__list-item p::after {
content: close-quote;
font-weight: bold;
opacity: 0.5;
}
.testimonial__list-item img {
max-width: 80px;
border-radius: 50%;
border: 2px solid orange;
}
.testimonial__list-item--featured {
width: 100%;
}
.testimonial__list-item cite img {
margin-right: 0.5rem;
}
/* If quote list container is less than 500px wide */
@container list (max-width: 500px) {
.testimonial__list-item {
width: 100%;
}
.testimonial__list-item cite {
text-align: center;
display: block;
}
.testimonial__list-item cite img {
display: block;
margin: 0 auto;
}
}
/* If a quote item is larger than 500px */
@container item (min-width: 500px) {
.testimonial__list-item p {
font-size: 1.5rem;
font-weight: 600;
}
}
/* If a quote item is larger than 960px */
@container item (min-width: 960px) {
.testimonial__list-item p {
background-color: #dbeafe;
font-size: 2rem;
}
}
/* On mobile - increase all font sizes so its easier to read */
@media screen and (max-width: 500px) {
.testimonial__list-item {
font-size: 1.5rem;
}
}
/* styles only used for the demo */
body {
padding: 2rem;
}
.controls {
margin-bottom: 1rem;
}
.testimonial__list.animate {
animation: w100 10s 5 ease-in-out alternate;
animation-timing-function: ease-in-out;
}
@keyframes w100 {
0% {
width: 20%;
}
/* Finish changes by here */
70% {
width: 100%;
}
/* Between 20% and 100%, nothing changes */
100% {
width: 100%;
}
}
/* end demo styles */
// play animation
document.querySelector("#play").addEventListener('click', function() {
document.querySelector("#animation").classList.add("animate");
});
// stop animation
document.querySelector("#stop").addEventListener('click', function() {
document.querySelector("#animation").classList.remove("animate");
});
Also see: Tab Triggers