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

              
                <div id="app">
	
</div>
              
            
!

CSS

              
                :root {
	--dark: #53565a;
	--yellow: #ffd100;
	--lightgray: #eee;
	--background: #67e4ff;
	--breakpoint: 420px;
}

* {
	box-sizing: border-box;
	font-family: inherit;
	color: inherit;
}

body {
	line-height: 1.6;
	margin: 2em;
	background: var(--background);
	font-size: 18px;
	font-family: 'Nunito', sans-serif;
	color: var(--dark);
}

button {
	background: var(--yellow);
}

#app {
	width: 100%;
	
	ul {
		display: grid;
		grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr));
		grid-gap: 2rem;
		align-content: flex-start;
		align-items: stretch;
		padding: 1rem;
	}
	
	#image-group {
		width: 100%;
		grid-column: 1 / -1;
		display: flex;
		justify-content: space-between;
		align-items: center;
		
		@media(max-width: var(--breakpoint)){
			flex-wrap: wrap;
		}
		
		label {
			line-height: 1;
		}
		
		input {
			flex: 1 1 50%;
			margin: 0 1rem;

			@media(max-width: var(--breakpoint)){
				margin: .6em 0;
			}
		}
		
		button {
			text-transform: uppercase;
		}
		
		input, button {
			font-size: 1rem;
			border: 2px solid var(--dark);
			padding: .5em;
			&:focus {
				outline: 2px solid var(--yellow);
			}
		}
	}
}

.filter-group {
	margin: auto;
	display: flex;
	flex-wrap: wrap;
	align-items: flex-start;
	background: #fff;
	border-radius: 4px;
	position: relative;
	overflow: hidden;
	max-width: 100%;
	
	& > * {
		width: 100%;
	}
	
	img {
		height: auto;
	}
	
	.flex-wrapper {
		display: flex;
		justify-content: space-between;
		padding: 1rem;
	}
	
	label {
		text-transform: capitalize;
		font-size: 1.2rem;
		display: flex;
		align-items: center;
	}
	
	pre {
		background: var(--lightgray);
		color: var(--dark);
		padding: 1.2rem;
		font-size: 14px;
		font-weight: bold;
		background-color: var(--lightgray);
		margin: 0;
	}
}
              
            
!

JS

              
                const { useState } = React

//You can change this to alter the default image (or just fill out the form)
const defaultImage = "https://media.giphy.com/media/BSx6mzbW1ew7K/giphy.gif"

const App = () => {
	const [imgURL, setImgURL] = useState(defaultImage)
	
	const handleSubmit = (e, url) => {
		console.log(e, url)
		e.preventDefault()
		setImgURL(url)
	}
	
	return(
		<>
			<ImgInput imgURL={imgURL} handleSubmit={handleSubmit}/>
			<ul>
				<Filter src={imgURL}/>
				<Filter type="sepia" max={1} default={0.7} src={imgURL}/>
				<Filter type="blur" max={12} default={2} unit="px" src={imgURL}/>
				<Filter type="contrast" max={500} default={50} unit="%" src={imgURL}/>
				<Filter type="saturate" max={10} default={2} src={imgURL}/>
				<Filter type="hue-rotate" max={360} default={180} unit="deg" src={imgURL}/>
				<Filter type="grayscale" max={100} default={100} unit="%" src={imgURL}/>
				<Filter type="brightness" max={5} default={1.5} src={imgURL}/>
				<Filter type="invert" max={1} default={1} src={imgURL}/>
				<Filter type="opacity" max={1} default={0.5} src={imgURL}/>
			</ul>
		</>
	)
}


//ImgInput element; handles the URL input, button, and change/submit events
const ImgInput = (props) => {
	const [inputValue, setInputValue] = useState(props.imgURL)
	
	const handleInputChange = (e) => {
		e.preventDefault()
		setInputValue(e.target.value)
	}

	const handleClick = (e) => {
		e.target.select()
	}

	return (
		<form id="image-group" onSubmit={(e) => props.handleSubmit(e, inputValue) }>
			<label htmlFor="imageURL">Image URL:</label>
			<input 
				type="url"
				id="imageURL"
				value={inputValue}
				onChange={handleInputChange}
				onClick={handleClick}
			/>
			<button type="submit">Apply</button>
		</form>
	)
}

//Filter reusable component for CSS filters
const Filter = (props) => {
	const { type, min, max, unit, src } = props
	const [filterVal, setFilterVal] = useState(props.default)
	const filterToReadableString = () => {
		if (type) return `${type}(${filterVal}${unit ? unit : ''});`
		return 'none;'
	}
	const filterCSS = { filter: `${type}(${filterVal}${unit ? unit : ''})`}
	
	return(
		<li className="filter-group" id={type + '-group'}>
			<div className="flex-wrapper">
				<label htmlFor={type}>{type || 'Original'}</label>
				{type &&
					<input
						type="range"
						id={type}
						min={min ? min : 0 }
						max={max}
						step="0.01"
						onChange={(e) => setFilterVal(e.target.value)}
						value={filterVal}
					/>
			 }
			</div>
			<img src={src} alt="" style={filterCSS}/>
			<pre>filter: { filterToReadableString() }</pre>
		</li>
	)
}

ReactDOM.render(<App />, document.getElementById('app'))
              
            
!
999px

Console