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. 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


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.


<h3>RGB color-mixer</h3>
<svg class="picker rgb-circles" viewBox="0 0 100 100" xmlns="">
    <circle class="r" id="r" r="25" cx="50" cy="28"></circle>
    <circle class="g" id="g" r="25" cx="35" cy="56"></circle>
    <circle class="b" id="b" r="25" cx="65" cy="56"></circle>
    <clipPath id="mask_rg">
      <use xlink:href="#g"></use>
    <clipPath id="mask_rb">
      <use xlink:href="#r"></use>
    <clipPath id="mask_gb">
      <use xlink:href="#g"></use>
    <clipPath id="mask_rgb">
      <use xlink:href="#g" clip-path="url(#mask_rb)"></use>
    <use class="draggable" xlink:href="#g" fill="chartreuse"></use>
    <use class="draggable" xlink:href="#r" fill="red"></use>
    <use class="rg" xlink:href="#r" fill="yellow" clip-path="url(#mask_rg)"></use>
    <use class="draggable" xlink:href="#b" fill="blue"></use>
    <use class="rb" xlink:href="#b" fill="magenta" clip-path="url(#mask_rb)"></use>
    <use class="gb" xlink:href="#b" fill="cyan" clip-path="url(#mask_gb)"></use>
    <use class="rgb" xlink:href="#b" fill="#212121" clip-path="url(#mask_rgb)"></use>
    <use class="draggable outline" xlink:href="#g"></use>
    <use class="draggable outline" xlink:href="#r"></use>
    <use class="draggable outline" xlink:href="#b"></use>
  <p>drag the citcles to mix colors</p>
<!-- <h3>HSL color-mixer</h3>
<div class="picker hsl-circles">
  <div class="h"></div>
  <div class="s"></div>
</div> -->


                :root {
  --c-bg: #212121;
  --s-line: 2px;
  --c-line: #fff;
  text-align: center;
  background: var(--c-bg);
  color: #fff;
  font-family: monospace;

svg {
  overflow: visible;

h3 {
  font-size: 2rem;
  padding: 0.75em;
  line-height: 1.3;

.picker {
  position: relative;
  background: var(--c-bg);
  height: 80vmin;
  width: 80vmin;

.rgb-circles {
  background: var(--c-bg);
.rgb-circles use {
  pointer-events: none;
.rgb-circles .draggable {
  pointer-events: all;
  cursor: move;
.rgb-circles .r, .rgb-circles .g, .rgb-circles .b {
  fill: var(--c-fill);
.rgb-circles .outline {
  fill: none;
  stroke: var(--c-line);
  stroke-width: 0;

.hsl-circles .h {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 50%;
  background: linear-gradient(90deg, black, rgba(255, 255, 255, 0), white), linear-gradient(180deg, red, #ffaa00, #aaff00, lime, #00ffaa, #00aaff, blue, #aa00ff, #ff00aa, red);
.hsl-circles .s {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  width: 50%;
  background: #bf4040;



const intersect = (x, y, X, Y, r, d = Math.hypot(x - X, y - Y)) => (r *= 2) * r * Math.acos(d / r) - d * (r * r - d * d) ** .5 >> 1;

function makeDraggable() {
  const svg = document.querySelector('.rgb-circles');

  svg.addEventListener('pointerdown', startDrag);
  svg.addEventListener('pointermove', drag);
  svg.addEventListener('pointerup', endDrag);
  svg.addEventListener('pointerleave', endDrag);

  function getMousePosition(evt) {
    const CTM = svg.getScreenCTM();
    return {
      x: (evt.clientX - CTM.e) / CTM.a,
      y: (evt.clientY - CTM.f) / CTM.d };


  let selectedElement, offset;

  function startDrag(evt) {
    if ('draggable')) {
      const targetID ='', 'href');
      selectedElement = document.querySelector(targetID);
      offset = getMousePosition(evt);
      offset.x -= parseFloat(selectedElement.getAttributeNS(null, 'cx'));
      offset.y -= parseFloat(selectedElement.getAttributeNS(null, 'cy'));

  function drag(evt) {
    if (selectedElement) {
      const coord = getMousePosition(evt);
      const cx = coord.x - offset.x;
      const cy = coord.y - offset.y;

      selectedElement.setAttributeNS(null, 'cx', cx);
      selectedElement.setAttributeNS(null, 'cy', cy);



  function endDrag(evt) {
    selectedElement = null;

  const $r = document.querySelector('#r');
  const $g = document.querySelector('#g');
  const $b = document.querySelector('#b');

  const $rg = document.querySelector('.rg');
  const $rb = document.querySelector('.rb');
  const $gb = document.querySelector('.gb');

  const $rgb = document.querySelector('.rgb');

  function getIntersections() {
    const area = Math.PI * 25 * 25;
    const rg = intersect(
    $g.getAttributeNS(null, 'cx'),
    $g.getAttributeNS(null, 'cy'),
    $r.getAttributeNS(null, 'cx'),
    $r.getAttributeNS(null, 'cy'),

    const gb = intersect(
    $g.getAttributeNS(null, 'cx'),
    $g.getAttributeNS(null, 'cy'),
    $b.getAttributeNS(null, 'cx'),
    $b.getAttributeNS(null, 'cy'),

    const br = intersect(
    $r.getAttributeNS(null, 'cx'),
    $r.getAttributeNS(null, 'cy'),
    $b.getAttributeNS(null, 'cx'),
    $b.getAttributeNS(null, 'cy'),

    $rg.setAttributeNS(null, 'fill', `rgb(${(1.35 - rg / area) * 255},${(1.35 - rg / area) * 255},0)`);
    $gb.setAttributeNS(null, 'fill', `rgb(0,${(1.35 - gb / area) * 255},${(1.35 - gb / area) * 255})`);
    $rb.setAttributeNS(null, 'fill', `rgb(${(1.35 - br / area) * 255},0,${(1.35 - br / area) * 255})`);
    $rgb.setAttributeNS(null, 'fill', `rgb(${br / area * 255},${rg / area * 255},${gb / area * 255})`);