FIND YOUR NEXT FEW LINES

The snippet library.

Small, practical examples. Search by task or narrow things down below.

10 snippets foundClear filters
HTMLImages & embedded documents

Allow embedded scripts without granting same-origin access

HTML: Grant only allow-scripts so the sandboxed document retains an opaque origin.

HTML✓ Tested
HTMLImages & embedded documents

Block scripts in an embedded document

HTML: An empty sandbox attribute applies the default set of restrictions, including blocking script execution.

HTML✓ Tested
HTMLImages & embedded documents

Choose a different image for a small viewport

HTML: Picture evaluates source media conditions before falling back to the img source.

HTML✓ Tested
HTMLImages & embedded documents

Draw a basic rectangle on a labeled canvas

HTML: Canvas requires script to draw pixels; provide alternative content and an accessible label.

HTML✓ Tested
HTMLImages & embedded documents

Exclude a purely decorative image from accessible content

HTML: An empty alt indicates that this image adds no information beyond nearby content.

HTML✓ Tested
HTMLImages & embedded documents

Give an inline SVG an accessible name

HTML: Use a title referenced by aria-labelledby for a meaningful inline vector image.

HTML✓ Tested
HTMLImages & embedded documents

Keep an image and its visible caption together

HTML: Figure and figcaption represent a self-contained illustration with an associated caption.

HTML✓ Tested
HTMLImages & embedded documents

Name a meaningful image with alternative text

HTML: Alt supplies an accessible text alternative describing the image’s purpose.

HTML✓ Tested
HTMLImages & embedded documents

Name a self-contained embedded document

HTML: Give an iframe a descriptive title and provide its small document with srcdoc.

HTML✓ Tested
HTMLImages & embedded documents

Reserve an image’s display dimensions

HTML: Width and height attributes supply a known display size and aspect ratio before decoding finishes.

HTML✓ Tested