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

              
                <!--
Resources by Ana Tudor:
https://codepen.io/thebabydino/pen/gOpMeWv
https://codepen.io/thebabydino/pen/LYGGwrm
-->

<form class="controls">
	<fieldset>
		<legend>Blend mode</legend>
		<div>
			<label for="r1">Multiply</label>
			<input type="radio" id="r1" checked name="blendMode" value="multiply">
		</div>
		<div>
			<label for="r2">Screen</label>
			<input type="radio" id="r2" name="blendMode" value="screen">
		</div>
		<div>
			<label for="r3">None</label>
			<input type="radio" id="r3" name="blendMode" value="none">
		</div>
	</fieldset>
	<div>
		<label for="dotSize">Background size: <span data-size>0.75rem</span></label>
		<input type="range" min="0.3" max="1.5" step="0.1" value="0.5" id="dotSize" name="dotSize">
	</div>
	<div>
		<label for="contrast">Contrast: <span data-contrast>20</span></label>
		<input type="range" min="1" max="20" step="1" value="20" id="contrast" name="contrast">
	</div>
	<div>
		<label for="dotRadius">Dot radius: <span data-radius>53rem</span></label>
		<input type="range" min="20" max="100" step="1" value="70" id="dotRadius" name="dot radius">
	</div>
	<div>
		<label for="invert">Invert </label>
		<input type="checkbox" id="invert">
	</div>
</form>
<div class="grid">
	<div class="card">
		<div class="halftone"></div>
	</div>
	<div class="card">
		<div class="halftone"></div>
	</div>
	<div class="card">
		<div class="halftone"></div>
	</div>
	<div class="card">
		<div class="halftone"></div>
	</div>
	<div class="card">
		<div class="halftone"></div>
	</div>
	<div class="card">
		<div class="halftone"></div>
	</div>
	<div class="card">
		<div class="halftone"></div>
	</div>
	<div class="card">
		<div class="halftone"></div>
	</div>
</div>
              
            
!

CSS

              
                * {
	box-sizing: border-box;
}

body {
	--size: 0.75rem;
	font-family: Helvetica, sans-serif;
	margin: 0;
	min-height: 100vh;
	padding: clamp(1rem, 2vw, 5rem);
	background: hsl(200deg 20% 10%);
	color-scheme: dark;
	color: white;
	accent-color: hotpink;
}

.grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(min(100%, 350px), 1fr));
	gap: 1rem;
	margin-top: 1rem;
}

.card {
	--mask: linear-gradient(rgb(0 0 0), rgb(0 0 0 / 0.5));
	--dotsColor: 255 255 255;
	--bg: radial-gradient(circle at center, rgb(var(--dotsColor)) 3%, rgb(var(--dotsColor) / 0.4) var(--dotRadius, 70%));
	--bgSize: var(--size);
	--cardBg: linear-gradient(135deg, hotpink, blue);
	background: var(--cardBg);
	overflow: hidden;
	border: 2px solid;
	border-image: var(--cardBg) 30;
}

.halftone {
	position: relative;
	aspect-ratio: 1;
	background: rgb(0 0 0);
	filter: contrast(var(--contrast, 20)) invert(var(--invert, 0));
	mix-blend-mode: var(--blendMode, multiply);
}

.halftone::before {
	content: '';
	position: absolute;
	inset: 0;
	background-image: var(--bg);
	background-size: var(--bgSize, 0.75rem) var(--bgSize, 0.75rem);
	background-repeat: round;
	background-position: 0 0, var(--bgPosition) var(--bgPosition);
	-webkit-mask-image: var(--mask);
	mask-image: var(--mask);
	mask-size: cover;
	mask-position: center;
	transition: background-size 100ms;
}

.card:nth-child(even) {
	--bgSize: calc(var(--size) * 1.3);
	--bgPosition: calc(var(--bgSize) / 2);
	--stops: rgb(var(--dotsColor)) 3%, rgb(var(--dotsColor) / 0.15) calc(var(--dotRadius, 53%) * 0.95);
	--bg: radial-gradient(circle at center, var(--stops)), radial-gradient(circle at center, var(--stops));
}

.card:nth-child(3),
.card:nth-child(4) {
	--mask: radial-gradient(circle at center, rgb(0 0 0), rgb(0 0 0 / 0.2));
}

.card:nth-child(5),
.card:nth-child(6) {
	--mask: repeating-linear-gradient(45deg, rgb(0 0 0), rgb(0 0 0 / 0.55) 20%, rgb(0 0 0) 40%);
}

.card:nth-child(7),
.card:nth-child(8) {
	--mask: url(https://assets.codepen.io/85648/mask-test-2.png);
}

.card:nth-child(7) .halftone::before,
.card:nth-child(8) .halftone::before {
	mask-size: 80%;
	mask-repeat: no-repeat;
}

/* Controls */
.controls {
	columns: 300px;
	gap: 1rem;
	background: hsl(200, 20%, 15%);
	border-radius: 0.5rem;
	box-shadow: 0.1rem 0.1rem 1rem rgb(0 0 0 / 0.5);
	padding: clamp(1rem, 2vw, 5rem);
}

.controls > * {
	display: block;
	break-inside: avoid;
}

.controls * + * {
	margin-top: 0.5rem;
}

.controls > * + * {
	margin-top: 1rem;
}

input[type="range"] {
	display: block;
	margin-top: 0.5em;
}

fieldset {
	border: 1px solid grey;
}

legend {
	font-weight: 700;
}


              
            
!

JS

              
                const blendModeInputs = [...document.querySelectorAll('input[name="blendMode"]')]
const dotSizeInput = document.querySelector('#dotSize')
const contrastInput = document.querySelector('#contrast')
const radiusInput = document.querySelector('#dotRadius')
const invertInput = document.querySelector('#invert')
const sizeLabel = document.querySelector('[data-size]')
const contrastLabel = document.querySelector('[data-contrast]')
const dotRadiusLabel = document.querySelector('[data-radius]')

blendModeInputs.forEach((input) => {
	input.addEventListener('change', (e) => {
		document.body.style.setProperty('--blendMode', e.target.value)
	})
})

dotSizeInput.addEventListener('input', (e) => {
	document.body.style.setProperty('--size', `${e.target.value}rem`)
	sizeLabel.innerText = `${e.target.value}rem`
})

contrastInput.addEventListener('input', (e) => {
	document.body.style.setProperty('--contrast', e.target.value)
	contrastLabel.innerText = e.target.value
})

invertInput.addEventListener('change', (e) => {
	const val = e.target.checked ? 1 : 0
	document.body.style.setProperty('--invert', val)
})

radiusInput.addEventListener('input', (e) => {
	document.body.style.setProperty('--dotRadius', `${e.target.value}%`)
	dotRadiusLabel.innerText = `${e.target.value}rem`
})


              
            
!
999px

Console