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.
<section aria-labelledby="region-title">
<h2 class="region-title">Card Pattern (categories moved visually)</h2>
<div class="cards">
<div class="card-group">
<div class="card-item">
<h3 class="card-title">Flowers</h3>
<p class="categories">weddings, events, funerals</p>
<img src="https://images.unsplash.com/photo-1607664675739-40ba5b75982d?crop=entropy&cs=srgb&fm=jpg&ixid=MXwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHw&ixlib=rb-1.2.1&q=85" alt="">
<p>A flower, sometimes known as a bloom or blossom, is the reproductive structure found in flowering plants (plants of the division Angiospermae). The biological function of a flower is to facilitate reproduction, usually by providing a mechanism for the union of sperm with eggs. Flowers may facilitate outcrossing (fusion of sperm and eggs from different individuals in a population) resulting from cross-pollination or allow selfing (fusion of sperm and egg from the same flower) when self-pollination occurs.</p>
<a href="https://en.wikipedia.org/wiki/Flower">Read all about flowers</a>
</div>
</div>
<div class="card-group">
<div class="card-item">
<h3 class="card-title">Plants</h3>
<p class="categories">indoors, outdoors, offices</p>
<img src="https://images.unsplash.com/photo-1530968464165-7a1861cbaf9f?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80" alt="">
<p>Plants are predominantly photosynthetic eukaryotes of the kingdom Plantae. Historically, the plant kingdom encompassed all living things that were not animals, and included algae and fungi; however, all current definitions of Plantae exclude the fungi and some algae, as well as the prokaryotes (the archaea and bacteria). By one definition, plants form the clade Viridiplantae (Latin name for "green plants"), a group that includes the flowering plants, conifers and other gymnosperms, ferns and their allies, hornworts, liverworts, mosses, and the green algae, but excludes the red and brown algae.</p>
<a href="https://en.wikipedia.org/wiki/Plant">Read all about plants</a>
</div>
</div>
<div class="card-group">
<div class="card-item">
<h3 class="card-title">Pots</h3>
<p class="categories">small, medium, large</p>
<img src="https://images.unsplash.com/photo-1620876719541-98ebe444d3e9?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80" alt="">
<p>A flowerpot, flower pot, planter, planterette, or alternatively plant pot is a container in which flowers and other plants are cultivated and displayed. Historically, and still to a significant extent today, they are made from plain terracotta with no ceramic glaze, with a round shape, tapering inwards. Flowerpots are now often also made from plastic, metal, wood, stone, or sometimes biodegradable material. An example of biodegradable pots are ones made of heavy brown paper, cardboard, or peat moss in which young plants for transplanting are grown.</p>
<a href="https://en.wikipedia.org/wiki/Flowerpot">Read all about pots</a>
</div>
</div>
</div>
</section>
<section aria-labelledby="region-title">
<h2 class="region-title">Card Pattern (visual order matches code order)</h2>
<div class="cards-links">
<div class="card-group">
<div class="card-item">
<h3 class="card-title">Flowers</h3>
<ul class="categories as-is"><li><span><a href="#">weddings</a></span></li><li><span><a href="#">events</a></span></li><li><span><a href="#">funerals</a></span></li></ul>
<img src="https://images.unsplash.com/photo-1607664675739-40ba5b75982d?crop=entropy&cs=srgb&fm=jpg&ixid=MXwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHw&ixlib=rb-1.2.1&q=85" alt="">
<p>A flower, sometimes known as a bloom or blossom, is the reproductive structure found in flowering plants (plants of the division Angiospermae). The biological function of a flower is to facilitate reproduction, usually by providing a mechanism for the union of sperm with eggs. Flowers may facilitate outcrossing (fusion of sperm and eggs from different individuals in a population) resulting from cross-pollination or allow selfing (fusion of sperm and egg from the same flower) when self-pollination occurs.</p>
<a href="https://en.wikipedia.org/wiki/Flower">Read all about flowers</a>
</div>
</div>
<div class="card-group">
<div class="card-item">
<h3 class="card-title">Plants</h3>
<ul class="categories as-is"><li><span><a href="#">indoors</a></span></li><li><span><a href="#">outdoors</a></span></li><li><span><a href="#">offices</a></span></li></ul>
<img src="https://images.unsplash.com/photo-1530968464165-7a1861cbaf9f?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80" alt="">
<p>Plants are predominantly photosynthetic eukaryotes of the kingdom Plantae. Historically, the plant kingdom encompassed all living things that were not animals, and included algae and fungi; however, all current definitions of Plantae exclude the fungi and some algae, as well as the prokaryotes (the archaea and bacteria). By one definition, plants form the clade Viridiplantae (Latin name for "green plants"), a group that includes the flowering plants, conifers and other gymnosperms, ferns and their allies, hornworts, liverworts, mosses, and the green algae, but excludes the red and brown algae.</p>
<a href="https://en.wikipedia.org/wiki/Plant">Read all about plants</a>
</div>
</div>
<div class="card-group">
<div class="card-item">
<h3 class="card-title">Pots</h3>
<ul class="categories as-is"><li><span><a href="#">small</a></span></li><li><span><a href="#">medium</a></span></li><li><span><a href="#">large</a></span></li></ul>
<img src="https://images.unsplash.com/photo-1620876719541-98ebe444d3e9?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1470&q=80" alt="">
<p>A flowerpot, flower pot, planter, planterette, or alternatively plant pot is a container in which flowers and other plants are cultivated and displayed. Historically, and still to a significant extent today, they are made from plain terracotta with no ceramic glaze, with a round shape, tapering inwards. Flowerpots are now often also made from plastic, metal, wood, stone, or sometimes biodegradable material. An example of biodegradable pots are ones made of heavy brown paper, cardboard, or peat moss in which young plants for transplanting are grown.</p>
<a href="https://en.wikipedia.org/wiki/Flowerpot">Read all about pots</a>
</div>
</div>
</div>
</section>
<section class="articles" aria-labelledby="region-title">
<h2 class="region-title">Card Pattern (no paragraph and informative images)</h2>
<div class="cards">
<div class="card-group">
<div class="card-item">
<h3 class="card-title"><a href="#" aria-describedby="date-1">
Enterprise SEO: What You Need to Know to Be Successful</a></h3>
<p id="date-1" class="date">May 20th, 2021</p>
<img src="https://images.unsplash.com/photo-1562577309-2592ab84b1bc" alt="SEO - Photo by Merakist on Unsplash">
</div>
</div>
<div class="card-group">
<div class="card-item">
<h3 class="card-title"><a href="#" aria-describedby="date-2">2021 State of Accessibility Report: Where Do We Stand Today?</a></h3>
<p id="date-2" class="date">October 31th, 2021</p>
<img src="https://images.unsplash.com/photo-1618044733300-9472054094ee" alt="Report - Photo by Markus Spiske on Unsplash">
</div>
</div>
<div class="card-group">
<div class="card-item">
<h3 class="card-title"><a href="#" aria-describedby="date-3">Webinar Series: Accessibility in the Enterprise</a></h3>
<p id="date-3" class="date">December 3rd, 2021</p>
<img src="https://images.unsplash.com/photo-1679226953835-2588f5ae8af7" alt="Building in Hong Kong - Photo by Chromatograph on Unsplash.">
</div>
</div>
</div>
</section>
<section class="articles focusable" aria-labelledby="region-title">
<h2 class="region-title">Card Pattern (whole card has focus outline)</h2>
<div class="cards">
<div class="card-group">
<div class="card-item">
<h3 class="card-title"><a href="#" aria-describedby="date-1">
Enterprise SEO: What You Need to Know to Be Successful
</a></h3>
<p id="date-1" class="date">May 20th, 2021</p>
<img src="https://images.unsplash.com/photo-1562577309-2592ab84b1bc" alt="SEO - Photo by Merakist on Unsplash">
</div>
</div>
<div class="card-group">
<div class="card-item">
<h3 class="card-title"><a href="#" aria-describedby="date-2">2021 State of Accessibility Report: Where Do We Stand Today?</a></h3>
<p id="date-2" class="date">October 31th, 2021</p>
<img src="https://images.unsplash.com/photo-1618044733300-9472054094ee" alt="Report - Photo by Markus Spiske on Unsplash">
</div>
</div>
<div class="card-group">
<div class="card-item">
<h3 class="card-title"><a href="#" aria-describedby="date-3">
Webinar Series: Accessibility in the Enterprise</a></h3>
<p id="date-3" class="date">December 3rd, 2021</p>
<img src="https://images.unsplash.com/photo-1679226953835-2588f5ae8af7" alt="Building in Hong Kong - Photo by Chromatograph on Unsplash.">
</div>
</div>
</div>
</section>
<div>
<h2>Considerations</h2>
<p>This example takes into account the following:</p>
<ul>
<li>The heading is the first element of each card.</li>
<li>The entire card is clickable with the pointer.</li>
<li>The focus lands on the link element only.</li>
<li>A region is specified for the group of cards.</li>
<li>The browser's default visible focus colour is used.</li>
<li><a href="https://www.nngroup.com/articles/cards-component/">Specific UI properties for a Card component</a></li>
<li>This code was worked in collaboration with Joe Humbert, Dennis Lembree and Michael Mistak.</li>
</ul>
<p>Original code taken from <a href="https://codepen.io/erikkroes/pen/JjRLLjZ">Erik Kroes' Progressive enhanced card</a></p>
</div>
body {
background: gainsboro;
}
h2 {
margin-top: 2rem;
}
.card-group {
flex: 0 0 33.333%;
display: flex;
}
.card-group:last-child {
margin-right: 0;
}
.card-item {
background: white;
border: 1px solid transparent;
border-radius: 1rem;
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
display: flex;
flex-direction: column;
position: relative;
max-width: 24rem;
flex: 0 0 100%;
}
.cards .card-item {
}
.card-item img {
max-width: 100%;
order: -1;
border-radius: 1rem 1rem 0 0;
}
.card-item :not(img) {
padding-left: 1rem;
padding-right: 1rem;
}
.card-item:last-child {
padding-bottom: 1rem;
}
.card-item:last-child:after {
content: "";
display: block;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.card-item .categories {
position: absolute;
background-color: white;
padding: 0.5rem;
border-radius: 0 0.5rem 0.5rem 0;
}
.card-item .categories.as-is {
position: relative;
border-radius: none;
margin: 0;
}
.card-item .categories.as-is span {
background-color: #aeffc7;
border-radius: 0.5rem;
padding: 0.2rem 0.5rem;
margin: 0.2rem;
font-size: 0.9rem;
}
:where(:is(.card-item, .card-title) > a)::before {
border-radius: 1rem;
content: "";
inset: 0;
position: absolute;
z-index: 10;
}
.cards-links a {
z-index: 1;
}
.cards-links a::before {
content: unset;
}
.cards-links .card-item ul.categories.as-is {
list-style: none;
z-index: 10;
}
.cards-links .card-item ul.categories.as-is li {
display: inline;
padding: 0;
}
.cards-links .card-item ul.categories.as-is li a {
padding: 0;
}
.articles .card-item h3 {
padding: 0 16px;
margin-bottom: 0;
}
.articles .card-item h3 :not(img) {
padding-left: 0;
padding-right: 0;
}
.articles .card-item a {
display: block;
z-index: 1;
}
.articles .card-item .date {
position: absolute;
background-color: white;
padding: 0.5rem;
border-radius: 0.5rem 0 0.5rem 0;
margin-top: 0;
}
.articles .card-item img {
padding-bottom: 0;
}
.articles.focusable .card-item {
border: 2px solid transparent;
}
.articles.focusable .card-item:focus-within {
border: 2px solid blue;
}
.articles.focusable .card-item a {
outline: none;
}
@media screen and (max-width: 1220px) {
.card-group {
margin-bottom: 1rem;
}
}
@media screen and (min-width: 768px) {
.cards-links,
.cards {
display: flex;
flex-flow: row wrap;
}
}
@media screen and (max-width: 767px) {
.cards-links .card-item,
.cards .card-item {
max-width: 100%;
}
}
@media screen and (min-width: 1220px) {
.card-group {
flex: none;
}
.cards-links .card-item,
.cards .card-item {
width: 100%;
margin-right: 1rem;
}
}
@media screen and (max-width: 1220px) and (min-width: 600px) {
.card-group {
margin-right: 1rem;
}
}
Also see: Tab Triggers