The snippet library.
Small, practical examples. Search by task or narrow things down below.
Accept several lines of text
HTML: Learn how to accept several lines of text in a complete browser example.
HTML✓ Tested
Add a button with an explicit type
HTML: Learn how to add a button with an explicit type in a complete browser example.
HTML✓ Tested
Add a multiline text field
Set a maximum length and visible rows on a labeled HTML textarea.
HTML✓ Tested
Add an expandable explanation
HTML: Learn how to add an expandable explanation in a complete browser example.
HTML✓ Tested
Add semantic page landmarks
Identify the header, navigation, main content and footer with semantic HTML.
HTML✓ Tested
Allow embedded scripts without granting same-origin access
HTML: Grant only allow-scripts so the sandboxed document retains an opaque origin.
HTML✓ Tested
Allow one disclosure in a named group to stay open
HTML: Matching details name attributes create an exclusive native accordion in supporting browsers.
HTML✓ Tested
Allow several selected options
HTML: A multiple select exposes each selected option as a value with the same control name.
HTML✓ Tested
Associate a control outside the form element
HTML: The form attribute links an external named control to the form’s ID.
HTML✓ Tested
Associate a data cell with explicit table headers
HTML: The headers attribute lists header IDs for a more complex cell association.
HTML✓ Tested
Associate a label with an input
Give an HTML text input an accessible name using for and id.
HTML✓ Tested
Associate a text field with its label
HTML: Learn how to associate a text field with its label in a complete browser example.
HTML✓ Tested