Build it in HTML
One technique per guide, each with a live example you can try, edit and copy.
Guides 121-180 of 848. Page 3 of 15.
id vs class css
id vs class in CSS and HTML: which one to use
An id names one element, a class labels many. See why #id beats three classes, what a duplicate id breaks, and how to name and select each in CSS and JavaScript.
requestanimationframe javascript
requestAnimationFrame in JavaScript: build a smooth animation loop
How requestAnimationFrame works: the timestamp, speed that does not depend on frame rate, cancelAnimationFrame, and one update per frame. Live examples and fixes.
date format javascript
Format a date in JavaScript
Format dates in JavaScript for people and for machines: toLocaleDateString options, Intl.DateTimeFormat, "3 days ago", yyyy-mm-dd, and the off-by-one-day bug.
lightbox html
Build an HTML lightbox with the dialog element
Build an image lightbox in plain HTML and JavaScript with the dialog element: captions, next and previous, arrow keys, swipe, and focus back on the thumbnail.
grid template areas
CSS grid-template-areas: draw the layout as text
Draw a CSS layout as text with grid-template-areas. Try a live area editor, switch layouts with container queries, and fix areas that silently do nothing.
card layout html
Build a card layout with HTML and CSS
Build a card layout in HTML and CSS: the markup, buttons pinned to the bottom, a responsive grid, a whole-card link that keeps inner buttons working. Live examples.
css mix blend mode
CSS mix-blend-mode and background-blend-mode, with live examples
Try every CSS blend mode on a live example, make text that inverts over any background, tint images with background-blend-mode, and fix blending that does nothing.
css mask image
CSS mask-image: fade edges, shape images and recolour icons
Use CSS mask-image with a gradient to fade text and scroller edges, or with an SVG to recolour icons. Live examples, code to copy, and fixes.
css counter
CSS counters: automatic numbers for anything on the page
CSS counters beyond lists: counter-reset, counter-increment, counter-set, 01 and Roman styles, 1.1 headings, "Figure 3" captions and a no-JavaScript checkbox tally.
css accent color
CSS accent-color: one line to recolour native form controls
One CSS property tints native checkboxes, radio buttons, range sliders and progress bars. Live examples, which controls it reaches, dark mode and what it can't do.
play sound javascript
Play a sound with JavaScript
Play a sound effect from JavaScript with new Audio().play(), handle the autoplay error, overlap sounds, and make beeps with the Web Audio API. Live examples.
css writing mode
CSS writing-mode: vertical text, upright letters and sideways headers
Set vertical text with writing-mode: vertical-rl, keep letters upright with text-orientation, fit numbers with text-combine-upright, and build sideways headers.
css shape outside
Wrap text around any shape with CSS shape-outside
Wrap text around a circle, a polygon or an image's transparent parts with CSS shape-outside. Live examples, shape-margin, clip-path and fixes when it fails.
mutationobserver javascript
Watch DOM changes with MutationObserver
Detect DOM changes in JavaScript with MutationObserver: options, records, batching and the infinite-loop trap. Live examples to try, code to copy, and fixes.
resizeobserver javascript
ResizeObserver: react when an element changes size
Detect when an element changes size, not just the window. ResizeObserver entries, the box option, sharp canvas charts, and the fix for the loop error.
typewriter effect css
Typewriter effect with CSS (and when you need JavaScript)
Typewriter text in pure CSS with steps() and ch, why normal fonts break it, and a JavaScript version that types, deletes and loops. Live examples and code.
css container queries
CSS container queries: components that fit the space they get
Make a card change layout based on the box it sits in, not the window. container-type, @container, named containers and cqi units, with live examples and fixes.
camera html
Use the camera in an HTML page
Open the camera from a web page: a file input with capture, or getUserMedia into a video. Take a photo on a canvas, pick the back camera, and fix the errors.
css flex direction
CSS flex-direction: row, column and the two reverses
flex-direction sets which way flex items flow, and justify-content and align-items turn with it. Live examples of row, column, the reverse values and a phone layout.
css grid row start
Place CSS grid items by line number: row start, span and -1
Place grid items with grid-row-start, grid-column and span. A live lab shows line numbers, -1, implicit tracks, overlap with z-index and grid-auto-flow: dense.
css anchor positioning
CSS anchor positioning: place one element next to another
Attach a tooltip or menu to a button with anchor-name, position-anchor and position-area, flip it when space runs out, and add a small JavaScript fallback.
css outline
CSS outline and focus rings that people can actually see
How CSS outline works: width, style, colour and outline-offset, rounded outlines, :focus vs :focus-visible, a focus ring that survives forced colours, and fixes.
async await javascript
Async and await in JavaScript, with live examples
How async and await work in JavaScript: what a Promise is, try/catch, Promise.all vs allSettled vs race, await in loops, timeouts and cancelling. Live demos to try.
css logical properties
CSS logical properties: the full map from left and width to inline and block
CSS logical properties name sides by text flow, so one stylesheet works in ltr, rtl and vertical text. The full physical-to-logical map, live demos and fixes.
css image rendering
CSS image-rendering: sharp pixel art instead of a blur
Scale pixel art and QR codes without blur using image-rendering: pixelated. Compare auto, pixelated and crisp-edges live and turn off canvas smoothing.
footer html css
Build a footer with HTML and CSS
Build a footer with HTML and CSS: when footer is the page landmark, what goes inside, columns that stack on phones, a footer that stays at the bottom, dark contrast.
touch events javascript
Touch events in JavaScript: taps, swipes and pinches
How touchstart, touchmove and touchend work, why pointer events are the simpler choice, and how to detect a swipe and a pinch. Live examples to try on a phone.
random number javascript
Random numbers in JavaScript, from Math.random() to a fair shuffle
Get a random integer between min and max in JavaScript, shuffle an array fairly, and know when Math.random is not enough. Live examples and code to copy.
particles html
Make a particle effect in HTML with canvas and JavaScript
Build a particle effect in plain HTML and JavaScript: a fountain, a network background that reacts to the pointer, and a confetti burst. Live code to try and copy.
font feature settings css
Font feature settings in CSS: numbers, ligatures and small caps
Turn on tabular numbers, ligatures, small caps, slashed zeros and fractions in CSS. Live demos that test your installed fonts, the code, and why nothing changes.
css background clip
CSS background-clip: boxes, origin and gradient text
How background-clip and background-origin decide where a background is painted and where it starts. Live demos for gradient text, textured text and gradient borders.
tel link html
Tel links in HTML: call, text and email buttons
Build click-to-call, text and email links in HTML: the tel: format, sms: and mailto: with encoded text, button styling, accessible link text and sandbox limits.
css will change
CSS will-change: prepare an animation without breaking the page
will-change tells the browser a property is about to animate. Add it just before, remove it after, and watch for the z-index and position: fixed side effects.
css color mix
CSS color-mix(): lighten, darken and build a palette in plain CSS
Mix two colours in CSS with color-mix(), lighten or darken with relative colour syntax, and build a whole palette plus hover states from one brand variable.
css has selector
The CSS :has() selector: style an element by what is inside it
Style a parent by what it contains with CSS :has(). Cards, form states, a scroll lock, quantity queries and a theme switch, plus specificity and fallback rules.
h2 tag
The h2 tag and h3 to h6: heading levels that make an outline
How to use the h2 tag and h3 to h6 under it: picking a level from its place in the page, subtitles with hgroup, and a live outline viewer that checks your headings.
base tag
The HTML base tag: href, target and what it breaks
What the HTML base tag does to every relative link, image and #anchor on a page. Live examples for href and target, the trailing slash rule, and fixes.
kbd tag
The HTML kbd tag: show keyboard keys, program output and variables
How the HTML kbd tag marks keys and typed input, when to use samp and var instead, how to nest them for shortcuts, and CSS for key caps you can press.
css background size
CSS background-size: how big the background image is drawn
How background-size works: cover, contain, auto, one and two values, percentages and background-origin, plus repeat round and why fixed backgrounds fail on phones.
responsive images
Responsive images with srcset: which file the browser picks
How srcset w and x descriptors, sizes and the picture element decide which image file loads. Live demos show the chosen file through currentSrc.
del tag
The del tag, ins and s: crossed-out text that means something
When to use del, ins or s for crossed-out text, what datetime and cite do, how to mark a sale price, and a live diff that writes del and ins for you.
noscript tag
The HTML noscript tag: when it shows and what to put in it
The HTML noscript tag shows its content only when JavaScript is turned off, not when a script fails. Live examples, head vs body rules and mistakes to avoid.
nowrap css
white-space: nowrap and the other ways CSS handles spaces and line breaks
white-space: nowrap keeps text on one line. See nowrap, pre, pre-wrap, pre-line and break-spaces side by side, plus text-wrap balance and pretty.
sticky footer css
Sticky footer in CSS: keep the footer at the bottom
Keep the footer at the bottom of short pages with flexbox or grid and min-height: 100dvh. Live examples, plus why position fixed and sticky differ.
sidebar html
Build a sidebar with HTML and CSS
Build a sidebar in HTML with aside and CSS grid, make it sticky, turn it into a drawer on phones and collapse it to icons. Live examples and code to copy.
stopwatch html
Build a stopwatch in HTML and JavaScript
Build a stopwatch in HTML and JavaScript with performance.now(), pause and resume, lap times and digits that do not jitter. Live examples to try and code to copy.
flip card html
Build a flip card in HTML and CSS
Build a flip card in HTML and CSS with perspective, preserve-3d and backface-visibility. Hover or click to flip, keyboard support, and cards that fit their text.
css scroll snap
CSS scroll snap: make scrolling stop on whole items
CSS scroll snap in plain words: scroll-snap-type, scroll-snap-align, scroll-snap-stop and scroll-padding. Live examples to try, and fixes when nothing snaps.
css transition
CSS transition, one property at a time
How CSS transition works: property, duration, delay, ease, cubic-bezier and steps, allow-discrete for display: none, and the transitionend event.
css transform origin
CSS transform-origin: choose the point things turn around
How CSS transform-origin picks the point an element rotates and scales around: keywords, percentages, px, the 3D z value and transform-box for SVG. Live demos.
urlsearchparams
Read and write query strings with URLSearchParams
Read ?q=... from the address, build a query string from a form, and update the address bar without a reload. get, getAll, set, append and encoding, live.
svg stroke dasharray
SVG stroke-dasharray and stroke-dashoffset, with live examples
How stroke-dasharray and stroke-dashoffset cut an SVG stroke into dashes, draw a line on screen and fill a progress ring. Live examples, code and fixes.
css offset path
CSS offset-path: move an element along a curve
Make a dot follow a curve with CSS offset-path and offset-distance: path(), ray(), circle(), offset-rotate and offset-anchor, with live examples to copy.
css fill svg
CSS fill and stroke on SVG, including holes and outlines
Style SVG shapes from CSS with fill and stroke, cut holes with fill-rule evenodd, fade them without a dark band, and outline text with paint-order. Live examples.
view transition css
Animate page changes with CSS view transitions
Wrap a DOM change in document.startViewTransition() and style it with view-transition-name and ::view-transition-old/new. Live examples, fallback and reduced motion.
css scroll timeline
CSS scroll timelines: animations driven by scrolling
Run a CSS animation on scroll instead of time: animation-timeline with scroll() and view(), named timelines, timeline-scope and animation-range, plus a fallback.
css touch action
CSS touch-action: decide who gets the finger
What each touch-action value lets the browser do, why a finger drag scrolls the page, and how overscroll-behavior stops scroll chaining and pull-to-refresh.
css caret color
CSS caret-color: colour and shape the text cursor
Change the blinking text cursor colour with caret-color, try the block and underscore shapes of caret-shape, and build a terminal-style caret. Live examples.
css appearance none
CSS appearance: none, control by control
What appearance: none removes on each form control, why checkboxes vanish, and the states you must redraw. Live examples to toggle, test and copy.
css color scheme
CSS color-scheme: what it changes and how to use it
The CSS color-scheme property tells the browser which schemes a page supports, so inputs, scrollbars and default colours go dark. Live examples and light-dark().