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

              
                <main class="max-w-3xl mx-auto my-8 pb-4 pl-4 border-l-8 border-l-teal-600">
  <h2 class="text-2xl font-medium text-amber-800">Useful</h2>
  <h1 class="mb-1 text-4xl font-light text-teal-800">Variables in Style Attribute</h1>
  <p class="font-medium">Recently, I came across some HTML code that looked like this: <code>&lt;span style="--w: .5"&gt;...&lt;/span&gt;</code>. 
  I had never seen (or thought of) setting CSS variables in an element's style attribute.  This pen explores some examples of this.
  </p>  
  
  <div class="boxset my-12 border-y-2 border-slate-200 p-4 w-full h-[16vw]">
    <div class="box" style="--t: 10; --l: 20"></div>
    <div class="box" style="--t: 20; --l: 40"></div>
    <div class="box" style="--t: 30; --l: 60"></div>
    <div class="box" style="--t: 40; --l: 80"></div>
  </div>
  
    <div class="boxset my-12 border-y-2 border-slate-200 p-4 w-full">
      <h3 class="font-bold text-amber-500">Ordered by Importance</h3>
      <div class="ordered">
        <div class="bar" style="--importance: 2">Apples</div>
        <div class="bar" style="--importance: 1">Bananas</div>
        <div class="bar" style="--importance: 4">Cherries</div>
        <div class="bar" style="--importance: 3">Dates</div>   
      </div>
      <h3 class="font-bold text-amber-500">Relative Importance</h3>
      <div class="chart">
        <div class="bar" style="--importance: 2">Apples</div>
        <div class="bar" style="--importance: 1">Bananas</div>
        <div class="bar" style="--importance: 4">Cherries</div>
        <div class="bar" style="--importance: 3">Dates</div>   
      </div>
  </div>
  
  <div class="boxset my-12 border-y-2 border-slate-200 p-4 w-full flex flex-wrap gap-4">
    <div class="veg" style="--color: green">
      <div class="name">Asparagus</div>
      <div class="desc">Stems</div>
    </div>
    <div class="veg" style="--color: red">
      <div class="name">Beetroot</div>
      <div class="desc">Roots</div>
    </div>
    <div class="veg" style="--color: mediumpurple">
      <div class="name">Cabbage</div>
      <div class="desc">Leaves</div>
    </div>
    <div class="veg" style="--color: orange">
      <div class="name">Carrots</div>
      <div class="desc">Roots</div>
    </div>
    <div class="veg" style="--color: yellow">
      <div class="name">Chili Peppers</div>
      <div class="desc">Fruit</div>
    </div>
  </div>
  
  <div class="boxset my-12 border-y-2 border-slate-200 p-4 w-full flex flex-wrap gap-4">
    <div class="profile" style="--color: green; --url-avatar: url(https://i.pravatar.cc/150?u=jamie)">
      <div class="name"><span>Jamie S.</span></div>
    </div>
    <div class="profile" style="--color: red">
      <div class="name"><span>Besie B.</span></div>
    </div>
    <div class="profile" style="--color: mediumpurple; --url-avatar: url(https://i.pravatar.cc/150?u=calin)">
      <div class="name"><span>Calin K.</span></div>
    </div>
    <div class="profile" style="--color: orange;  --url-avatar: url(https://i.pravatar.cc/150?u=danny)">
      <div class="name"><span>Danny D.</span></div>
    </div>
    <div class="profile" style=" --url-avatar: url(https://i.pravatar.cc/150?u=emily)">
      <div class="name">Emily M.</div>
    </div>
  </div>
  

  <div class="wrapper my-12 border-y-2 border-slate-200 p-4">
    
    <div class="sphere">
      <!-- default size and color -->
    </div>
    
    <div class="sphere" style="--size: 15cqw; --color: green">
      <!-- 15% of container width -->
    </div>
    
    <div class="sphere" style="--size: 15vw; --color: purple">
      <!-- 15% of viewport width -->
    </div>
    
    <div class="sphere" style="--size: 5rem; --color: yellow">
      <!-- 5x base font size -->
    </div>
    
    <div class="sphere" style="--size: 150px; --color: hotpink">
      <!-- static 150 pixels -->
    </div>
    
    <div class="sphere" style="--size: 30cqh; --color: olive">
      <!-- 30% of container's height -->
    </div>
    
    
  </div>
</main>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Lato:wght@100;300;400;700;900&display=swap');
html, body {
  font-family: "Lato", sans-serif;
  font-size: 20px;
}

.boxset {
  /* new stacking context */
  position: relative;
  z-index: 0;
  
  .box {
    position: absolute;
    top: calc(var(--t, 0) * 1%);
    left: calc(var(--l, 0) * 1%);
    width: 50px; height: 50px;
    background: slategray;
  }
  
  .ordered {
    display: flex;
    gap: 1rem;
    .bar {
      order: var(--importance, 100);  
    }
  }
  .chart {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    .bar {
      width: calc(100% - (var(--importance, 0%) * 10%));
      background: rgba(100,100,255, .1);
    }
  }
}

.veg {
  padding: 0.5rem;
  border: solid 1px var(--color, black);
  .name {
    color: hsl(from var(--color) h calc(s * .5) l);
  }
  .desc {
    font-size: 0.8rem;
    background-color: hsl(from var(--color) calc(h * .8) s l);
  }
}

.profile {
  --color: orchid;
  padding: 0.5rem;
  border: solid 1px var(--color, black);
  border-radius: 2rem;
  box-shadow: 1px 2px 6px hsl(from var(--color) h s 80%);
  .name {
    --size: 2rem;
    display: inline-flex;
    align-items: center;
    color: hsl(from var(--color) h s 20%);
    height: var(--size);
    &::before {
      content: '';
      display: inline-block;
      margin-right: 0.2rem;
      width: var(--size); height: var(--size);
      border-radius: 100%;
      background-color: hsl(from var(--color) h s 90%);
    }
  }
  &[style*='--url-avatar'] {
    .name::before {
      background-image: var(--url-avatar);
      background-repeat: none;
      background-size: cover;
    }
  }
}

.wrapper {
  /* new stacking context */
  position: relative;
  z-index: 0;
  
  /* flex it */
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 2rem;
  
  /* define container */
  container-name: wrapper;
  container-type: block-size;
  
  /* define the variables */
  --size: 10cqw;
  
  .sphere {
    display: inline-block;
    width: var(--size);
    height: var(--size);
    border: solid 1px gray;
    border-radius: 100%;
    
    --color: red;
    background: linear-gradient(-45deg,
      hsl(from var(--color) h calc(s * 6.5) l), 
      hsl(from var(--color) h calc(s * .5) l), 
      hsl(from var(--color) h s l),
      rgb(255,255,255),
      hsl(from var(--color) calc(h * 1.02) calc(s * 3) l)
    );
	  background-size: 400% 400%;
    
	  animation: sphereBG 15s ease infinite;
    
    box-shadow: 
      calc(var(--size) * .01) 
      calc(var(--size) * .01)
      calc(var(--size) * .1)
      hsl(from var(--color) h calc(s * 1.9) l);
  }
  
  
}


@keyframes sphereBG {
    0% {
		  background-position: 0% 50%;
	  }
	  50% {
		  background-position: 100% 50%;
	  }
	  100% {
		  background-position: 0% 50%;
	  }
  }
              
            
!

JS

              
                
              
            
!
999px

Console