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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <div class="app min-h-screen font-sans text-black bbg-grey flex items-center" :style='styleObj'>

  <div class="toolbar shadow-lg m-4 p-4 bg-white rounded relative " ref="toolbar" v-show="isUiVisible">

    <div class="absolute pin-r mr-4">
      <button data-tip="HIDE UI" @click="toggleUi">
        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-eye-off" color="#3a4049" data-reactid="497"><path d="M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"></path><line x1="1" y1="1" x2="23" y2="23"></line></svg>

      </button>

    </div>

    <div class="header">
      <div class="">
        <h3>SVG to Background</h3> <span class="text-grey-dark">by <a href="https://mesutkoca.com" class="no-underline text-grey-dark hover:text-grey-darkest">Mesut Koca</a></span></div>
    </div>

    <div class="" v-if="!isCSSCodeVisible">

      <div class="code mt-4">

        <textarea v-model="bg" class="bg-grey-light rounded p-2" placeholder="Paste SVG Code" cols="30" rows="5"></textarea>
        <div class="examples mt-4 flex items-center justify-center">
          <button class="example w-6 h-6 border mr-2" @click="bg = ''; bgColor='#b8c2cc'">
          </button>
          <button class="example w-6 h-6 mr-2" v-for="example in examples" @click="bg = example; bgColor='#ffffff'" :style='{backgroundImage: `url("${svgToDataUri(example)}")`}'>
          </button>
        </div>
      </div>

      <hr class="border my-4">

      <div>
        <h3 class="font-semibold">Background Settings</h3>

        <div class="py-2">
          <label class="text-grey-darker" for="">Color:</label>
          <input type="color" v-model="bgColor">
        </div>

        <div class="text-grey-darker">
          <label>Repeat:</label>
          <div class="inline text-sm">
            <label><input class="mx-1" v-model="bgRepeat" value="" type="radio"> All </label>
            <label><input class="mx-1" v-model="bgRepeat" value="repeat-x" type="radio"> X </label>
            <label><input class="mx-1" v-model="bgRepeat" value="repeat-y" type="radio"> Y </label>
          </div>
        </div>

      </div>

      <hr class="border my-4">

      <div class="mt-4 text-center">
        <button class="px-4 py-2 rounded text-white text-sm bg-indigo" @click="generateCode">Get CSS Code</button>
      </div>

    </div>

    <div class="css mt-4 text-center" v-if="isCSSCodeVisible">
      <textarea v-model="cssCode" class="bg-grey-light rounded p-2" cols="30" rows="5"></textarea>
      <div class="mt-3">
        <button @click="isCSSCodeVisible=false" class="bg-indigo px-4 py-2 text-white text-sm rounded">Go Back</button>
      </div>
    </div>

  </div>

</div>
              
            
!

CSS

              
                [data-tip] {
  position: relative;
}
[data-tip]:hover:after {
  opacity: 1;
}
[data-tip]:after {
  opacity: 0;
  transition: opacity 0.25s;
  position: absolute;
  pointer-events: none;
  font-size: 0.7rem;
  letter-spacing: 1px;
  content: attr(data-tip);
  background: rgba(0, 0, 0, 0.8);
  color: white;
  width: 4rem;
  border-radius: 5px;
  padding: 5px;
  right: 0;
  top: 2rem;
}
button:focus {
  outline: none;
}
.example{
  background-size: 25% 25%;
}

              
            
!

JS

              
                /* example patterns from https://philiprogers.com/svgpatterns/#specklednoise */
new Vue({
  el: ".app",
  data() {
    return {
      isUiVisible: true,
      isCSSCodeVisible: false,
      cssCode: "",
      bg: "",
      bgColor: "#b8c2cc",
      bgRepeat: "",
      examples: [
        `<svg xmlns='http://www.w3.org/2000/svg' width='60' height='60'>
          <rect width='60' height='60' fill='#fff'/>
          <rect width='42.42' height='42.42' transform='translate(30 0) rotate(45)' fill='#444'/>
        </svg>
        `,
        `<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15'>
          <rect width='50' height='50' fill='#282828'/>
          <circle cx='3' cy='4.3' r='1.8' fill='#393939'/>
          <circle cx='3' cy='3' r='1.8' fill='black'/>
          <circle cx='10.5' cy='12.5' r='1.8' fill='#393939'/>
          <circle cx='10.5' cy='11.3' r='1.8' fill='black'/>
        </svg>
        `,
        `<svg xmlns='http://www.w3.org/2000/svg' width='90' height='30'>
<rect width='90' height='30' fill='#00a9f1'/>
<rect width='90' height='18' fill='#26baf4'/>
</svg>
        `,
        `<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20'>
<rect width='20' height='20' fill='#fff'/>
<rect width='10' height='10' fill='#ccc'/>
<rect x='10' y='10' width='10' height='10' fill='#ccc'/>
</svg>
        `,
        `<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10'>
  <rect width='10' height='10' fill='white'/>
  <path d='M-1,1 l2,-2
           M0,10 l10,-10
           M9,11 l2,-2' stroke='slategray' stroke-width='3'/>
</svg>
        `
      ]
    };
  },
  computed: {
    styleObj() {
      return {
        "background-image": this.bg
          ? `url("${this.svgToDataUri(this.bg)}")`
          : "",
        "background-color": this.bgColor,
        "background-repeat": this.bgRepeat
      };
    }
  },
  mounted() {
    document.addEventListener("mousemove", () => {
      if (!this.isUiVisible) {
        this.isUiVisible = true;
      }
    });
  },
  methods: {
    toggleUi() {
      this.isUiVisible = !this.isUiVisible;
    },
    svgToDataUri(svgStr) {
      return miniSvgDataUri(svgStr);
    },
    generateCode() {
      this.isCSSCodeVisible = true;
      this.cssCode = this.bg
        ? `background-image: url("${this.svgToDataUri(this.bg)}") ${
            this.bgRepeat
          }`
        : "";
    }
  }
});

              
            
!
999px

Console