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

              
                <html>
	<title>CSS Background</title>
	<body>
		<div style="margin-top: 38px; width: 500px;">
			<div>
        <span>
					<label>Background Image:</label> 
          	<select onchange="return onChange(event, 'image')">
              <option selected>none</option>
						  <option>Image</option>
					</select>
				</span>
        <br />
        <br />
				<span>
					<label>Background Color:</label> <input value="red" type="text" onkeyup="return onChange(event, 'color')" />
				</span>
        <br />
        <br />
				<span>
					<label>Background Clip:</label>
					<select onchange="return onChange(event, 'clip')">
						<option>border-box</option>
						<option>content-box</option>
						<option>padding-box</option>
					</select>
				</span>
        <br />
        <br />
				<span>
					<label>Background Origin:</label>
					<select onchange="return onChange(event, 'origin')">
						<option>border-box</option>
						<option>content-box</option>
						<option>padding-box</option>
					</select>
				</span>
        <br />
        <br />
        <span>
					<label>Background Attachment:</label>
					<select onchange="return onChange(event, 'attachment')">
						<option>scroll</option>
						<option>fixed</option>
						<option>local</option>
					</select>
				</span>
        <br />
        <br />
        <span>
					<label>Background Position:</label>
					<select onchange="return onChange(event, 'position')">
						<option>top</option>
						<option>left</option>
						<option>center</option>
						<option>bottom</option>
						<option>right</option>
            <option>50%</option>
            <option>3em 25%</option>
            <option>50%, 25%, 60%</option>
					</select>
				</span>
        <br />
        <br />
        <span>
					<label>Background Repeat:</label>
					<select onchange="return onChange(event, 'repeat')">
						<option>repeat</option>
						<option>no-repeat</option>
						<option>round</option>
						<option>repeat-x</option>
						<option>repeat-y</option>
					</select>
				</span>
        <br />
        <br />
        <span>
					<label>Background Size:</label>
					<select onchange="return onChange(event, 'size')">
						<option>cover</option>
						<option>contain</option>
						<option>auto</option>
            <option>50%</option>
            <option>3em 25%</option>
            <option>50%, 25%, 60%</option>
					</select>
				</span>
			</div>
      <div style="width: 500px; height:500px; margin-top: 10px">
			  <div class="background" style="width:100%; height:100%;">
        </div>
			  
			</div>
		</div>
	</body>
</html>

              
            
!

CSS

              
                
              
            
!

JS

              
                var background = document.querySelector(".background")
background.style.backgroundColor = 'red'
        function onChange(evt, type) {
            var val = evt.target.value
            switch (type) {
                case "image":
                  if(val == "Image"){
                    val = "url('https://via.placeholder.com/600/92c952')"
                  }
                   background.style.backgroundImage = val
                    break;

                case "clip":
                    background.style.backgroundClip = val
                break;
                
                case "color":
                    background.style.backgroundColor = val
                break;
                
                case "origin":
                    background.style.backgroundOrigin = val
                break;
                                
                case "attachment":
                    background.style.backgroundAttachment = val
                break;
                
                case "position":
                    background.style.backgroundPosition = val
                break;
                                
                case "repeat":
                    background.style.backgroundRepeat = val
                break;
                          
                case "size":
                    background.style.backgroundSize = val;
                break;
            
                default:
                    break;
            }
        }
              
            
!
999px

Console