Pen Settings

HTML

CSS

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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

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.

HTML

              
                <circle-text r="3em" rotate="-90deg">
  CSS is super fun & cool & I like CSS!!!
</circle-text>
<circle-text r="70">
  Our Tricks Are Treats Because CSS Is Sweet!
</circle-text>
<circle-text style="color: hotPink; text-shadow: lightYellow 1px 1px 2px;">
  CSS in JS in CSS in JS in CSS in JS in CSS in JS in CSS in JS in CSS in JS
</circle-text>

<script> // for the demo only
  window.addEventListener("load", testScriptedCreation);
  
  function testScriptedCreation() {    
    let ct = document.createElement("circle-text");
    ct.textContent = "123456789";
    document.body.appendChild(ct);
    
    window.setTimeout(()=>{ct.textContent="updated live from script"}, 1000);
    window.setTimeout(()=>{ct.setAttribute("r", "3em")}, 2000);
    window.setTimeout(()=>{ct.setAttribute("rotate", "0.5turn")}, 3000);
  }
</script>
              
            
!

CSS

              
                /* to hide the content when custom elements aren't supported */
circle-text {
  display: none;
}
circle-text:defined {
  display: inline-block;
}


/* styles for this demo */
circle-text {
  /* customize the color and font as normal with CSS */
  color: skyBlue;
  text-transform: uppercase;
  font: large Tahoma, sans-serif;
  
  vertical-align: middle;
  /* position as you wish */
}

body {
  background: #222;
}

              
            
!

JS

              
                if (window.customElements && document.body.attachShadow) { //mustard
  
class CircleText extends HTMLElement {
  static get observedAttributes() {
    return ['r', 'rotate'];
  }
  static defaultRadius = 100;
  
  constructor() {
    super();
    let shadow = this.attachShadow({mode: 'open'});
    shadow.innerHTML = `
<svg id="s">
  <style>
    svg { display: block; overflow: visible; padding: 1em; }
    textPath { fill: currentColor; }
  </style>
  <defs><path id="p"/><circle id="r"/></defs>
  <text id="t"><textPath id="tp" xlink:href="#p"></textPath></text>
</svg>`;
    // save links to the elements we'll need to modify
    this.svg = shadow.getElementById("s");
    this.path = shadow.getElementById("p");
    this.text = shadow.getElementById("t");
    this.textPath = shadow.getElementById("tp");
    
    // SVGLength object on a circle for unit conversion for path data
    // (since Safari and Firefox don't support text on a <circle> element)
    this.radius = shadow.getElementById("r").r.baseVal;
      
    this.updateText();    
    // create a mutation observer for text content updates
    let watchText = new MutationObserver(this.updateText.bind(this));
    watchText.observe(this, {childList: true, characterData: true});
  }
  
  connectedCallback() {
    // re-calculate dimensions, in case of font-relative units
    this.updateRadius(this.getAttribute("r"));
  }
  
  attributeChangedCallback(name, oldValue, newValue) {
    switch (name) {
      case "r":
        if (this.svg.isConnected) this.updateRadius(newValue);
        break;
      case "rotate":
        this.updateTransform(newValue);
        break;
    }
  }
  
  updateRadius(newValue) {
    var r;
    
    if (this.svg.isConnected) {
      //force an initial style calc to get em values
      let f = getComputedStyle(this.svg)["font-size"];
    }
    
    try {
      this.radius.valueAsString = newValue;
      r = this.radius.value;
    } catch(e) {
      r = CircleText.defaultRadius;
    }
    let d = 2*r;
    let offset = -1*r;
    [
      {name: "height", value:d },
      {name: "width", value:d },
      {name: "viewBox", value: [offset, offset, d, d].join() }
    ].forEach(
      ({name, value})=>this.svg.setAttribute(name, value)
    ); 
    this.path.setAttribute("d",
      `M${-r},0 A${r},${r},0 1 1 ${r},0 A${r},${r},0 1 1 ${-r},0Z`
    );
  }
  
  updateTransform(rotate) {
    if (rotate) {
      this.text.style["transform"] = `rotate(${rotate})`;
    } else {
      this.text.style["transform"] = "none";
    }
  }
  
  updateText() {
    this.textPath.textContent = this.textContent.trim();
  }
  
}//end class
  
customElements.define("circle-text", CircleText, {});
  
}

              
            
!
999px

Console