Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource

Packages

Add Packages

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.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <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&amp;cs=srgb&amp;fm=jpg&amp;ixid=MXwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHw&amp;ixlib=rb-1.2.1&amp;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&amp;ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&amp;auto=format&amp;fit=crop&amp;w=1470&amp;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&amp;ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&amp;auto=format&amp;fit=crop&amp;w=1470&amp;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&amp;cs=srgb&amp;fm=jpg&amp;ixid=MXwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHw&amp;ixlib=rb-1.2.1&amp;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&amp;ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&amp;auto=format&amp;fit=crop&amp;w=1470&amp;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&amp;ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&amp;auto=format&amp;fit=crop&amp;w=1470&amp;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>
              
            
!

CSS

              
                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;
  }
}

              
            
!

JS

              
                
              
            
!
999px

Console