Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ add another resource


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


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.


Save Automatically?

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.


                <!--  output of generated selector -->
<div class="selector"></div>

  <figure class="figure">
    <img src="" alt="Article-Image">
    <figcaption class="figure-caption"></figcaption>
  <div class="article-body">
    <h2 class="article-title">TITLE</h2>
    <p class="article-text">Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure nemo incidunt, similique
      blanditiis in quidem.</p>
    <button class="btn" type="button">READ MORE</button>


                @import url(';500;700&display=swap');

$lightColor: #fefefe;
$darkColor: #303030;
$blueColor: #9ac9ff;
$redColor: #ff9d9d;
$yellowColor: #ffe77b;

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;

body {
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: $darkColor;
  background: #f0f0f0;
  font-family: "Montserrat", sans-serif;

.selector {
  margin-bottom: 30px;

article {
  width: 250px;
  background: $lightColor;
  border-radius: 5px;
  overflow: hidden;

// figure
.figure {
  width: 100%;
  height: 150px;
.figure img {
  width: 100%;
  height: 100%;
  object-fit: cover;

// article body
.article-body {
  padding: 15px;
.article-title {
  text-transform: uppercase;
.article-text {
  margin: 15px 0 30px;
  font-size: 0.85rem;
  line-height: 1.5;
  letter-spacing: 0.25px;

button {
  appearance: none;
  outline: none;
  border: none;
  padding: 8px 12px;
  background: blueviolet;
  color: $lightColor;
  font-family: "Montserrat", sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  border-radius: 3px;
  cursor: pointer;



                function generateSelector(context) {
  let index, pathSelector, localName;

  if (context == "null") throw "not an dom reference";
  // call getIndex function
  index = getIndex(context);

  while (context.tagName) {
    // selector path
    pathSelector = context.localName + (pathSelector ? ">" + pathSelector : "");
    context = context.parentNode;
  // selector path for nth of type
  pathSelector = pathSelector + `:nth-of-type(${index})`;
  return pathSelector;

// get index for nth of type element
function getIndex(node) {
  let i = 1;
  let tagName = node.tagName;

  while (node.previousSibling) {
    node = node.previousSibling;
    if (
      node.nodeType === 1 &&
      tagName.toLowerCase() == node.tagName.toLowerCase()
    ) {
  return i;

// load document
document.addEventListener("DOMContentLoaded", () => {
  // click on element to get output
  document.body.addEventListener("click", (e) => {
    let selector = document.querySelector(".selector");
    // selector output
    let output = generateSelector(;

    selector.innerHTML = `<strong>Selector:</strong> ${output}`;

    // element that you select
    let element = document.querySelector(output);
    console.log("Selected Element:", element);