Chapter 3: The user interface
The chapter introduces a platform-first approach to UI and explains why Vanilla Web favors declarative HTML, CSS, and native controls.
After this chapter you will be able to
- Declarative native UI benefits. Distinguish declarative UI from step-by-step UI code and explain why the chapter favors HTML, CSS, and native controls.
- Declarative HTML and CSS. Explain how the book aims to define interfaces declaratively: HTML provides data and structure, CSS provides design and layout, and JavaScript can add dynamic behavior when suitable.
- HTML and Canvas UI stacks. Distinguish the common HTML-and-CSS stack from a Canvas UI, including the kinds of applications Canvas commonly serves and how the two stacks can be mixed.
- Common HTML document foundation. Explain why every web UI stack still needs an HTML document with metadata, and describe the principal contents named for a classic UI document.
- Flexible and screenless interface design. Explain why an interface should adapt beyond a fixed list of screen sizes, including screenless contexts.
- Search and generative optimization. Distinguish SEO from GEO and describe why clear, semantic content helps AI tools interpret a site.
- Purpose of web metadata. Explain what web metadata is and how it improves a site’s presentation outside the viewport, such as in a tab, browser interface, or operating-system integration.
- Document title purpose and quality. Explain where the <title> element identifies a document and why its text should be short, descriptive, and unique for each route.
- Title updates across views. Describe when server-rendered pages and single-page apps should set or update their titles, and name document.title as the client-side way to update one.
- Manifest file and purpose. Explain what a Web App Manifest is, how a website links it, and what the browser uses it for.
- Installed launch and navigation. Explain how scope, start_url, and display affect opening and using an installed app.
- Icon contexts and declarations. Explain how icons serve browser tabs, pinned shortcuts, and installed apps, and distinguish icons linked from HTML from the icon set declared in the Web App Manifest.
- Minimum icon file set. Describe the recommended minimum SVG and PNG icons, including where each is linked and what makes the maskable PNG different.
- Theme color purpose and preferences. Explain that the theme-color meta tag suggests a color for browser or OS UI chrome, and that light and dark colors can follow the operating system’s preference.
- Mobile viewport configuration. Explain why a mobile page needs a viewport definition and how the settings described here handle device width and notches.
- Page description metadata. Explain how classic meta tags describe a page to browsers, search engines, and agents, and distinguish useful descriptive hints from search-ranking guarantees.
- OpenGraph link previews. Explain how OpenGraph metadata supplies shared-link previews, identify its minimum recommended tags, and describe the limits of preview consistency.
- Data and semantic structure. Explain the difference between the raw information in a UI and the meaning that HTML tags give it. Describe how semantic markup makes a document’s hierarchy and relationships readable.
- Structure before visual design. Describe how to approach the HTML for an app interface by identifying its content and structural parts before considering its visual layout.
- Value of semantic elements. Explain why choosing the correct semantic HTML tag for a situation matters despite its limited visual impact.
- Costs of divitis. Explain why using <div> for most containers makes a document harder for people and tools to understand.
- Semantic element replacements. Describe how to replace generic containers with semantic elements when those elements fit the content.
- Native semantic attributes. Explain why an appropriate HTML attribute is preferable to recreating the same effect with CSS or JavaScript, and give an element-specific example.
- Visibility and interaction attributes. Distinguish what hidden, disabled, inert, and draggable indicate about an element or its subtree.
- Inclusive and resilient access. Explain that accessibility means making a site usable across abilities and contexts, not merely meeting legal requirements. Describe why an interface that works only in one context excludes people.
- Semantic HTML foundation. Explain why a Vanilla Web interface should start with the correct semantic HTML elements and add JavaScript interactivity afterward, rather than reinventing widgets with meaningless elements.
- ARIA as a fallback. Describe what ARIA adds when HTML alone is insufficient and state why a suitable semantic element should be preferred.
- Semantic HTML landmarks. Explain how elements such as <main> and <nav> help screen reader users navigate a large document.
- Accessible form labels and errors. Explain how to associate a label with every input and connect a clear error message to the input it concerns.
- Keyboard operation and order. Explain that users must be able to operate the app with a keyboard alone, that the DOM sets the natural navigation order, and that tabindex can refine it. Describe how to test the app’s main tasks without a mouse or trackpad.
- Visible keyboard focus. Explain why focus outlines should not simply be removed and what a replacement focus style must achieve.
- ARIA roles and native elements. Explain that an ARIA role labels an HTML element’s function and should be used only when there is no native equivalent, because browsers already map most semantic elements to roles.
- ARIA states and properties. Distinguish ARIA states that communicate a changing UI condition from properties that provide extra context, and explain why state attributes must be updated when the component changes.
- Text contrast requirements. State the minimum text-to-background contrast ratios given for standard and large text, and explain that contrast is part of accessibility.
- Meaning beyond color. Explain why an interface should pair color-coded meaning with text or icons.
- Native controls first. Explain why interactive elements should use native HTML controls whenever possible.
- Custom widget accessibility duties. Describe what a custom interactive widget must provide, including its behavior on touch devices.
- Screen reader DOM interpretation. Explain that screen readers read the DOM’s structure and content aloud, using headings, landmarks, and semantic roles to offer navigation shortcuts.
- Real screen reader testing. Justify testing a site with an actual screen reader instead of turning off CSS to assess screen reader usability.
- Media format selection. Explain why choosing an appropriate format for images, video, or 3D and AR models matters to a web UI.
- Bitmap format tradeoffs. Distinguish when PNG, JPEG, WebP, and AVIF are useful, including their tradeoffs in transparency, photo use, compression, browser support, and tooling.
- Picture source selection. Describe how <picture> lets a page offer multiple image resources and leaves selection to the browser.
- Web video format tradeoffs. Distinguish MP4 with H.264 from WebM with VP9 or AV1 in terms of compatibility, compression, and quality, and state the current limitation of AV1 in MP4.
- Embedded video playback choices. Describe the section’s guidance on controls, multiple sources, and autoplay with sound when embedding video.
- Progressive 3D display strategy. Describe when to use the HTML <model> element, the <model-viewer> web component, and an AR Quick Look link.
- Native controls as a foundation. Explain how modern native browser elements and APIs can provide interactive, accessible UI controls without the heavy JavaScript or third-party libraries those controls once required, and why small enhancements may be enough.
- Native disclosure behavior. Explain how <details> and <summary> let users show or hide content without JavaScript, including the interaction and accessibility support they provide.
- Exclusive accordion behavior. Explain how an accordion built with <details> expands and collapses content, and how giving multiple <details> elements the same name makes opening one close the previously open one.
- Modal dialog purpose and element. Explain what a modal dialog does and why the <dialog> element is useful for building one.
- CSS-powered carousel controls. Explain that CSS can enhance a scrolling list into an interactive carousel using horizontal overflow, scroll snapping, and scroll-button pseudo-elements, while the browser handles focus, keyboard navigation, and layout.
- Native popover setup and behavior. Describe a popover’s common uses, how popovertarget connects a trigger to a panel with the popover attribute, and what the browser handles automatically.
- Native select customization. Explain how appearance: base-select enables styling of a native <select>, including its option box, arrow, selected option, and displayed choice, without replacing its keyboard, focus, or form behavior.
- Emerging native UI controls. Describe the emerging controls named here and explain why they may reduce the need to build widgets from scratch, while noting that support is still evolving.
- Beyond HTML and CSS. Explain that the Web platform offers additional capabilities for creating or enhancing a user interface, and that most require JavaScript and a browser Web API.
- Canvas rendering area. Describe canvas as a portion of an HTML document, potentially the entire document, whose content JavaScript renders using a context such as 2D or a 3D API like WebGL.
- HTML and CSS preference. Justify the warning against using canvas for text, form controls, or other content HTML and CSS can render, unless there is a deliberate reason to do so.
- Media presentation and controls. Distinguish the UI purposes of Fullscreen, Picture-in-Picture, Casting, and Media Session APIs using the examples in the section.
- Progressive UI enhancement safeguards. Explain why these APIs should enhance, rather than replace, a usable semantic interface, and state the availability and user-action precautions the section gives.
What it builds on
- Web APIs (chapter 2) · Introduces Web APIs as part of the Web platform.
Section by section
Introduction
The chapter introduces a platform-first approach to UI and explains why Vanilla Web favors declarative HTML, CSS, and native controls.
- Platform-first UI priorities: Explain why Vanilla Web encourages using the web platform for UI without prescribing a particular visual design or user experience.
Why it matters: It frames the chapter’s UI choices as ways to serve more users, not as a prescribed look. - Declarative native UI benefits: Distinguish declarative UI from step-by-step UI code and explain why the chapter favors HTML, CSS, and native controls.
Why it matters: It explains why describing an interface with platform features can avoid unnecessary custom behavior.
Key terms: UI, UX, reachability, accessibility, usability, declarative, HTML, CSS, native controls, keyboard support
3.1 Defining our user interface
The section compares UI stacks, favors a declarative HTML-and-CSS approach, identifies the HTML document as the starting point for any web UI, and broadens UI design beyond the display.
- Declarative HTML and CSS: Explain how the book aims to define interfaces declaratively: HTML provides data and structure, CSS provides design and layout, and JavaScript can add dynamic behavior when suitable.
Why it matters: It establishes the book’s default approach to building a web interface. - HTML and Canvas UI stacks: Distinguish the common HTML-and-CSS stack from a Canvas UI, including the kinds of applications Canvas commonly serves and how the two stacks can be mixed.
Why it matters: Choosing a UI stack need not mean rendering every part of an app the same way. - Common HTML document foundation: Explain why every web UI stack still needs an HTML document with metadata, and describe the principal contents named for a classic UI document.
Why it matters: The underlying document remains necessary no matter how the visible interface is rendered. - Interaction beyond the display: Describe why UI design should consider interaction models beyond what appears on a screen, using examples from the section.
Why it matters: It keeps the definition of an interface from being limited to on-screen controls.
Key terms: declaratively, HTML, CSS, JavaScript, web rendering engines, UI stack, HTML and CSS, Canvas, <canvas>, web assembly
3.2 The ultimate responsive design
This section argues for interfaces that adapt to unpredictable screen sizes and screenless consumers, and distinguishes search-engine optimization from optimization for AI tools.
- Flexible and screenless interface design: Explain why an interface should adapt beyond a fixed list of screen sizes, including screenless contexts.
Why it matters: Flexible design prepares your content for devices and ways of accessing it that you cannot enumerate in advance. - Search and generative optimization: Distinguish SEO from GEO and describe why clear, semantic content helps AI tools interpret a site.
Why it matters: Your site's structure affects whether both search engines and AI tools can make sense of its content.
Key terms: responsive design, form factor, screenless systems, Search Engine Optimization, SEO, Generative Engine Optimization, GEO, semantic HTML, metadata
3.3 Web metadata
Defines web metadata as information that shapes the browser and operating-system presentation of a site without changing its viewport content, and notes that some metadata can vary by page or change dynamically.
- Purpose of web metadata: Explain what web metadata is and how it improves a site’s presentation outside the viewport, such as in a tab, browser interface, or operating-system integration.
Why it matters: It helps you distinguish metadata from the content displayed in the page. - Page-specific and dynamic metadata: Describe how some metadata can differ between pages in a multipage app or change through JavaScript in a client-side application.
Why it matters: It explains why a site’s tab or browser presentation can reflect the current page or application state.
Key terms: metadata, web rendering engine, viewport, browser’s chrome UI, title, icons, theme color, multipage app, client-side application
3.3.1 Title
Explains what the document title communicates and when to update it as a page or app view changes.
- Document title purpose and quality: Explain where the <title> element identifies a document and why its text should be short, descriptive, and unique for each route.
Why it matters: A useful title helps users tell one view from another, even outside the page itself. - Title updates across views: Describe when server-rendered pages and single-page apps should set or update their titles, and name document.title as the client-side way to update one.
Why it matters: Updating the title keeps the document's name aligned with the view the user is actually seeing.
Key terms: <title> element, route, server-side, single-page apps, document.title
3.3.2 Web app manifest
This section explains how a linked Web App Manifest supplies application metadata and how its basic properties shape an installed app’s identity, navigation, launch, and appearance.
- Manifest file and purpose: Explain what a Web App Manifest is, how a website links it, and what the browser uses it for.
Why it matters: The manifest gives the browser the metadata it needs to present the site as an app. - Installed app identity and names: Distinguish the roles of id, name, and short_name in an installed app.
Why it matters: These fields determine whether the OS treats an update as the same app and how it labels that app. - Installed launch and navigation: Explain how scope, start_url, and display affect opening and using an installed app.
Why it matters: These settings separate where the installed app opens, where it keeps navigation, and how it appears. - App colors and adaptive icons: Distinguish the purposes of background_color and theme_color, and describe why the manifest should include a maskable PNG.
Why it matters: These choices help an installed app’s launch screen, surrounding interface, and icon appear as intended.
Key terms: Web app manifest, JSON, link element, id, name, short_name, scope, start_url, display, standalone
3.3.3 Icons
This section explains where web app icons are used, which icon files to prepare, and where to declare them.
- Icon contexts and declarations: Explain how icons serve browser tabs, pinned shortcuts, and installed apps, and distinguish icons linked from HTML from the icon set declared in the Web App Manifest.
Why it matters: One icon declaration does not cover every place your app’s icon can appear. - Minimum icon file set: Describe the recommended minimum SVG and PNG icons, including where each is linked and what makes the maskable PNG different.
Why it matters: The recommended set gives browsers and operating systems icon files suited to their different display contexts. - Icon format compatibility: Justify the recommendation to use PNG for bitmap icons even when the project uses newer image formats elsewhere.
Why it matters: Choosing an icon format that operating systems can handle helps avoid missing icons.
Key terms: favicon, pinned shortcuts, Web App Manifest, Apple Touch icon, mask icon, SVG, PNG, rel=icon, rel=mask-icon, purpose=maskable
3.3.4 Theme color
Explains how to suggest browser and installed-app chrome colors using HTML theme-color metadata and a manifest theme_color value, including platform limits.
- Theme color purpose and preferences: Explain that the theme-color meta tag suggests a color for browser or OS UI chrome, and that light and dark colors can follow the operating system’s preference.
Why it matters: It helps the app’s surrounding UI suit the user’s light or dark preference without assuming every browser will honor it. - Manifest color and browser differences: Distinguish HTML’s theme-color meta tag from the manifest’s theme_color property, including their precedence and why both are useful.
Why it matters: Setting both values gives browsers and installed apps a suitable color even when they use different sources.
Key terms: theme-color meta tag, UI chrome, light and dark preferences, theme-color, theme_color, Web App Manifest
3.3.5 Viewport definition
This subsection explains how viewport settings affect mobile page width, display cutouts, and virtual-keyboard resizing.
- Mobile viewport configuration: Explain why a mobile page needs a viewport definition and how the settings described here handle device width and notches.
Why it matters: These settings help a mobile page fit its screen while accounting for display cutouts. - Virtual keyboard resize setting: Describe what the manifest’s interactive-widget property lets you choose when a virtual keyboard appears.
Why it matters: The setting gives you a way to choose how the browser responds when the on-screen keyboard opens.
Key terms: viewport, width=device-width, initial-scale=1, viewport-fit=cover, safe-area CSS env() variables, interactive-widget, manifest, resizes-visual, resizes-content, overlays-content
3.3.6 Semantic metadata
Explains how metadata in an HTML document’s head describes a page to search engines and other agents and helps shared links display rich previews.
- Page description metadata: Explain how classic meta tags describe a page to browsers, search engines, and agents, and distinguish useful descriptive hints from search-ranking guarantees.
Why it matters: Metadata helps other systems describe and interpret your page without changing what visitors see. - Crawling and encoding metadata: Describe what the robots and charset metadata specify, including the section’s guidance for declaring UTF-8.
Why it matters: These tags communicate how a page should be processed, not just what it is about. - OpenGraph link previews: Explain how OpenGraph metadata supplies shared-link previews, identify its minimum recommended tags, and describe the limits of preview consistency.
Why it matters: OpenGraph lets a shared link convey useful context instead of appearing as a bare URL or generic title.
Key terms: <meta>, description, keywords, author, generator, robots, noindex, nofollow, charset, UTF-8
3.3.7 Putting the metadata together
The section introduces a forthcoming HTML metadata example for a coffee-selling Vanilla Web application, but does not provide the example or explain any metadata.
3.4 Semantic HTML
Introduces semantic HTML as a way to describe an app’s content and structure before styling its appearance.
- Data and semantic structure: Explain the difference between the raw information in a UI and the meaning that HTML tags give it. Describe how semantic markup makes a document’s hierarchy and relationships readable.
Why it matters: Meaningful markup lets someone reading the HTML see the content’s hierarchy and relationships. - Structure before visual design: Describe how to approach the HTML for an app interface by identifying its content and structural parts before considering its visual layout.
Why it matters: Separating structure from appearance gives you a starting point for marking up an app interface.
Key terms: data, semantics, semantic HTML, HTML structure, CSS, title, navigation bar, sections
3.4.1 Using the Right Element
This section explains why choosing the right semantic HTML element matters even when it barely changes how a page looks.
- Value of semantic elements: Explain why choosing the correct semantic HTML tag for a situation matters despite its limited visual impact.
Why it matters: Element choice affects how useful and findable a page is, not just how it looks.
Key terms: semantic tag, usability, accessibility, discoverability, SEO, GEO
3.4.2 Avoiding divitis and other problems
This section explains why overusing <div> obscures a page’s meaning and how semantic elements and meaningful class names make markup clearer.
- Costs of divitis: Explain why using <div> for most containers makes a document harder for people and tools to understand.
Why it matters: Recognizing what anonymous containers conceal helps you make markup understandable beyond its visual appearance. - Semantic element replacements: Describe how to replace generic containers with semantic elements when those elements fit the content.
Why it matters: An appropriate element communicates a region’s purpose without requiring a generic container to carry all its meaning through a class or ID. - Meaningful class names: Explain how class names can convey categories even though semantic elements reduce the need for excessive classes.
Why it matters: Using semantic elements does not mean giving up useful classes that describe meaningful categories.
Key terms: <div>, divitis, HTML semantics, semantic elements, <header>, <footer>, <main>, <nav>, lists, class names
3.4.3 Semantic attributes
This section explains how HTML attributes convey meaning and behavior to browsers, CSS, JavaScript, and assistive technologies.
- Native semantic attributes: Explain why an appropriate HTML attribute is preferable to recreating the same effect with CSS or JavaScript, and give an element-specific example.
Why it matters: Using the appropriate attribute lets the browser understand the intended meaning or behavior directly. - Visibility and interaction attributes: Distinguish what hidden, disabled, inert, and draggable indicate about an element or its subtree.
Why it matters: These attributes have distinct effects, so choosing one depends on whether you mean to hide, deactivate, or enable dragging. - Language and translation cues: Describe what lang, dir, and translate communicate about an element’s content.
Why it matters: These attributes convey different information about how content should be interpreted or handled. - Classification roles and descriptions: Distinguish the information supplied by class, role, and title.
Why it matters: A class, an accessibility role, and a short description communicate different things.
Key terms: semantic attributes, inputmode, download, alt, hidden, disabled, inert, draggable, DOM, lang
3.5 Accessibility
This section explains why accessibility matters and introduces semantic HTML, resilient design, and careful use of ARIA as foundations for an accessible interface.
- Inclusive and resilient access: Explain that accessibility means making a site usable across abilities and contexts, not merely meeting legal requirements. Describe why an interface that works only in one context excludes people.
Why it matters: Thinking beyond one way of using an interface helps you avoid excluding users. - Semantic HTML foundation: Explain why a Vanilla Web interface should start with the correct semantic HTML elements and add JavaScript interactivity afterward, rather than reinventing widgets with meaningless elements.
Why it matters: Using the platform’s elements gives accessibility a stronger starting point than recreating their meaning yourself. - ARIA as a fallback: Describe what ARIA adds when HTML alone is insufficient and state why a suitable semantic element should be preferred.
Why it matters: ARIA is useful for genuine gaps, but it is not a substitute for choosing the right HTML element.
Key terms: accessibility, a11y, temporary disabilities, situational ones, resilience, semantic HTML, semantic tags, progressive enhancement, <div>, <span>
3.5.1 Landmarks
This section explains how semantic HTML landmarks help people navigate large documents with assistive technology.
- Semantic HTML landmarks: Explain how elements such as <main> and <nav> help screen reader users navigate a large document.
Why it matters: Choosing the right HTML element gives users a way to move around a page.
Key terms: landmarks, assistive technologies, screen reader
3.5.2 Forms
This section explains how to make form inputs accessible through labels and error messages, and why custom controls require extra care.
- Accessible form labels and errors: Explain how to associate a label with every input and connect a clear error message to the input it concerns.
Why it matters: Labels and correctly linked errors make form interactions more accessible. - Custom form control responsibilities: Describe the accessibility responsibilities that come with building custom form controls.
Why it matters: Custom UI kits are a common place for form accessibility to break down.
Key terms: <label>, for/id, placeholder text, aria-describedby, custom UI kits, focus, labels, ARIA attributes
3.5.3 Keyboard Navigation
This section explains how to make an app usable with a keyboard alone by preserving a sensible navigation order, visible focus, and testing without a pointer.
- Keyboard operation and order: Explain that users must be able to operate the app with a keyboard alone, that the DOM sets the natural navigation order, and that tabindex can refine it. Describe how to test the app’s main tasks without a mouse or trackpad.
Why it matters: Trying main tasks without a pointer exposes barriers that keyboard users will encounter. - Visible keyboard focus: Explain why focus outlines should not simply be removed and what a replacement focus style must achieve.
Why it matters: A visible focus indicator helps keyboard users tell where they are in the interface.
Key terms: keyboard alone, DOM, natural order, tabindex, Tab, Enter, outlines, focus indicator, custom focus style
3.5.4 ARIA Roles
This section explains what ARIA roles label and when to use them instead of native semantic elements.
- ARIA roles and native elements: Explain that an ARIA role labels an HTML element’s function and should be used only when there is no native equivalent, because browsers already map most semantic elements to roles.
Why it matters: Choosing a native element when one exists avoids adding a role the browser already provides.
Key terms: Roles, role, native equivalent, semantic elements
3.5.5 ARIA states and properties
This section explains how ARIA states and properties convey a component’s current condition and provide extra context.
- ARIA states and properties: Distinguish ARIA states that communicate a changing UI condition from properties that provide extra context, and explain why state attributes must be updated when the component changes.
Why it matters: ARIA information needs to reflect what the interface currently shows.
Key terms: ARIA states, ARIA properties, aria-expanded, aria-label, aria-describedby
3.5.6 Color and contrast
Explains how text contrast and non-color cues make a Vanilla Web interface more accessible, and how to check those choices.
- Text contrast requirements: State the minimum text-to-background contrast ratios given for standard and large text, and explain that contrast is part of accessibility.
Why it matters: Adequate contrast helps make text readable. - Meaning beyond color: Explain why an interface should pair color-coded meaning with text or icons.
Why it matters: A second cue lets people understand the meaning without relying on color alone. - Accessibility criteria and checks: Describe the role of WCAG and name ways the section suggests checking or improving accessibility in a Vanilla project.
Why it matters: Accessibility is something to check across several aspects of a page, not just its colors.
Key terms: contrast ratios, WCAG 2.1 AA, standard text, large text, color, text, icons, WCAG, browser DevTools, WAVE extension
3.5.7 Interactive elements
This section recommends native HTML controls for accessible interactions and states the responsibilities that come with custom widgets.
- Native controls first: Explain why interactive elements should use native HTML controls whenever possible.
Why it matters: Choosing a native control gives an interaction an accessible foundation without rebuilding those basics. - Custom widget accessibility duties: Describe what a custom interactive widget must provide, including its behavior on touch devices.
Why it matters: A custom widget must remain understandable and usable across input methods. - Accessibility from the start: State the section’s recommended accessibility practices for a Vanilla Web project.
Why it matters: These checks help catch barriers that choosing suitable markup alone may not reveal.
Key terms: native HTML controls, semantics, keyboard interaction, focus management, custom widgets, ARIA attributes, pointer and keyboard events, minimum target size, semantic HTML, ARIA
3.5.8 Screen readers
This section explains how screen readers use DOM semantics and why accessibility should be tested with a real screen reader rather than by disabling CSS.
- Screen reader DOM interpretation: Explain that screen readers read the DOM’s structure and content aloud, using headings, landmarks, and semantic roles to offer navigation shortcuts.
Why it matters: Meaningful structure helps screen reader users find their way through a page. - Real screen reader testing: Justify testing a site with an actual screen reader instead of turning off CSS to assess screen reader usability.
Why it matters: Testing with the tool people actually use reveals whether the site is usable with a screen reader.
Key terms: DOM, headings, landmarks, semantic roles, screen readers, screen reader, assistive tech, CSS, VoiceOver, NVDA
3.6 Media resources
This section explains why media format choices matter for a fast, accessible, and compatible web UI.
- Media format selection: Explain why choosing an appropriate format for images, video, or 3D and AR models matters to a web UI.
Why it matters: Format selection affects how efficiently and reliably people can use the UI.
Key terms: media, formats, bandwidth, compatibility
3.6.1 Image formats
This section compares common bitmap and vector image formats and explains how the browser selects among image sources supplied with <picture>.
- Bitmap format tradeoffs: Distinguish when PNG, JPEG, WebP, and AVIF are useful, including their tradeoffs in transparency, photo use, compression, browser support, and tooling.
Why it matters: These tradeoffs help you choose a suitable bitmap format rather than using one format for every image. - SVG for vector graphics: Explain why SVG is a useful standard format for logos, icons, and diagrams.
Why it matters: SVG offers useful properties for graphics that need to work at different sizes. - Picture source selection: Describe how <picture> lets a page offer multiple image resources and leaves selection to the browser.
Why it matters: Offering alternatives lets the browser choose an image suited to the current viewing conditions.
Key terms: bitmap images, PNG, JPEG, WebP, AVIF, vector graphics, SVG, resolution-independent, CSS, <picture>
3.6.2 Video formats
This section compares web video format choices and gives basic guidance for embedding accessible, compatible video.
- Web video format tradeoffs: Distinguish MP4 with H.264 from WebM with VP9 or AV1 in terms of compatibility, compression, and quality, and state the current limitation of AV1 in MP4.
Why it matters: The format choice balances broad playback against file size and quality. - Embedded video playback choices: Describe the section’s guidance on controls, multiple sources, and autoplay with sound when embedding video.
Why it matters: These choices let viewers control playback and let browsers select an available format.
Key terms: MP4, H.264, WebM, VP9, AV1, controls, multiple sources, autoplay with sound, decorative
3.6.3 AR formats
This section compares portable 3D asset formats, explains a progressively enhanced approach to displaying models and AR, and advises how to prompt AI coding tools for better web markup.
- Portable 3D asset formats: Distinguish glTF from USDZ by their roles in web-based 3D and AR.
Why it matters: The asset format affects where a model can be displayed. - Progressive 3D display strategy: Describe when to use the HTML <model> element, the <model-viewer> web component, and an AR Quick Look link.
Why it matters: This approach gives users a way to view the model even when the newest inline feature is unavailable. - AI prompting for modern markup: Explain why AI-generated UI code may need explicit guidance and what guidance the section recommends.
Why it matters: Specific instructions help keep generated UI code aligned with modern web practices.
Key terms: glTF, USDZ, AR Quick Look, progressive enhancement, <model>, <model-viewer>, <a rel="ar">, semantic HTML, accessibility, modern CSS layout techniques
3.7 Rich web UI controls
This section explains why native browser controls are a practical starting point for rich, accessible interfaces.
- Native controls as a foundation: Explain how modern native browser elements and APIs can provide interactive, accessible UI controls without the heavy JavaScript or third-party libraries those controls once required, and why small enhancements may be enough.
Why it matters: Starting with a native control can save work while retaining its built-in accessibility.
Key terms: native UI controls, widgets, CSS, accessibility
3.7.1 Summaries
This section explains how HTML provides a disclosure widget with native interaction and CSS styling options.
- Native disclosure behavior: Explain how <details> and <summary> let users show or hide content without JavaScript, including the interaction and accessibility support they provide.
Why it matters: A basic disclosure control does not need custom JavaScript to work. - Disclosure styling options: Describe the CSS styling options named for a disclosure widget, including its open state and its content apart from the summary.
Why it matters: These selectors let you change a disclosure widget’s appearance without replacing its native behavior.
Key terms: <details>, <summary>, disclosure widget, :open, ::details-content, summary marker
3.7.2 Accordions
This section explains how named <details> elements create an exclusive accordion without JavaScript state coordination.
- Exclusive accordion behavior: Explain how an accordion built with <details> expands and collapses content, and how giving multiple <details> elements the same name makes opening one close the previously open one.
Why it matters: You can make a space-saving accordion with built-in group behavior and keyboard support, without extra coordination code.
Key terms: accordion, <details>, name attribute, exclusive accordions
3.7.3 Modal dialogs
This section introduces modal dialogs and explains how the native <dialog> element supports focus control and simpler ways to open and close them.
- Modal dialog purpose and element: Explain what a modal dialog does and why the <dialog> element is useful for building one.
Why it matters: The native element supplies useful dialog behavior, including focus control, without building it all from scratch. - Declarative dialog controls: Describe how the named HTML enhancements simplify dismissing and opening a modal dialog.
Why it matters: These HTML options can simplify common modal interactions without giving up the native dialog's focus behavior.
Key terms: modal dialog, <dialog>, native focus trapping, closedby="any", command="show-modal", light-dismiss, declarative triggering
3.7.4 Carousels
This section explains what carousels are and how CSS and browser features can provide interactive, accessible carousels without JavaScript libraries.
- Carousels as scrolling lists: Describe a carousel as a kind of scrolling list that lets users browse multiple images or other pieces of content within one swipeable or clickable area.
Why it matters: Thinking of a carousel as a scrolling list makes the CSS approach easier to understand. - CSS-powered carousel controls: Explain that CSS can enhance a scrolling list into an interactive carousel using horizontal overflow, scroll snapping, and scroll-button pseudo-elements, while the browser handles focus, keyboard navigation, and layout.
Why it matters: You can build a usable carousel with minimal code by relying on CSS and built-in browser behavior.
Key terms: carousels, scrolling lists, overflow-x: auto, scroll-snap-type, ::scroll-button(left), ::scroll-button(right)
3.7.5 Popovers
This section introduces native popovers, how to connect a trigger to a panel, and how to style or extend them.
- Native popover setup and behavior: Describe a popover’s common uses, how popovertarget connects a trigger to a panel with the popover attribute, and what the browser handles automatically.
Why it matters: Native attributes provide a popover without requiring a library for its basic behavior. - Popover styling and extension: Explain how CSS and the :popover-open pseudo-class can customize a popover, and distinguish that styling from optional JavaScript control through the Popover API.
Why it matters: You can customize a native popover without replacing its built-in behavior.
Key terms: popover, popovertarget, :popover-open, Popover API
3.7.6 Rich selectors
This section shows how to customize a native select element’s appearance while retaining its built-in behavior and a working fallback.
- Native select customization: Explain how appearance: base-select enables styling of a native <select>, including its option box, arrow, selected option, and displayed choice, without replacing its keyboard, focus, or form behavior.
Why it matters: You can make a dropdown look distinctive without giving up the useful behavior of a native control. - Classic select fallback: Describe what happens to the customized select in a browser that does not support the new styling.
Why it matters: The dropdown remains usable even where the richer appearance is unavailable.
Key terms: <select>, appearance: base-select, ::picker(select), ::picker-icon, :checked, <selectedcontent>, non-compatible browser, classic select, falls back
3.7.7 Other UI controls
Introduces emerging native UI controls that may replace some custom-built widgets, while noting that browser support is still evolving.
- Emerging native UI controls: Describe the emerging controls named here and explain why they may reduce the need to build widgets from scratch, while noting that support is still evolving.
Why it matters: These controls show how the platform may provide UI widgets you would otherwise have to build yourself.
Key terms: hovercards, <progress>, progress ring, toolbars, menus
3.8 Beyond basic UI
This section introduces Web platform capabilities beyond HTML and CSS for creating or enhancing a user interface.
- Beyond HTML and CSS: Explain that the Web platform offers additional capabilities for creating or enhancing a user interface, and that most require JavaScript and a browser Web API.
Why it matters: It frames browser capabilities as another option for building a UI beyond HTML and CSS alone.
Key terms: HTML and CSS stack, JavaScript, Web API, user interface
3.8.1 Using canvas
Introduces canvas as a JavaScript-rendered area of an HTML document and cautions against using it for content better rendered with HTML and CSS.
- Canvas rendering area: Describe canvas as a portion of an HTML document, potentially the entire document, whose content JavaScript renders using a context such as 2D or a 3D API like WebGL.
Why it matters: This distinguishes canvas-rendered content from ordinary HTML content. - HTML and CSS preference: Justify the warning against using canvas for text, form controls, or other content HTML and CSS can render, unless there is a deliberate reason to do so.
Why it matters: Choosing HTML and CSS for ordinary content avoids unnecessary accessibility and usability difficulties.
Key terms: Canvas, context, 2D context, WebGL, HTML and CSS stack, accessibility, usability, discoverability
3.8.2 Using UI-related APIs
This section surveys browser APIs that extend interfaces beyond HTML and CSS and explains how to use them without making the core experience depend on their availability.
- Media presentation and controls: Distinguish the UI purposes of Fullscreen, Picture-in-Picture, Casting, and Media Session APIs using the examples in the section.
Why it matters: Choosing among these APIs starts with the experience you want to give the user. - Adaptation and alternative interactions: Describe the purposes of Window Segments, WebXR, and Web Speech APIs as examples of UI capabilities beyond a conventional screen layout.
Why it matters: The browser can adapt an interface to different devices and ways of interacting, not just display a page. - Progressive UI enhancement safeguards: Explain why these APIs should enhance, rather than replace, a usable semantic interface, and state the availability and user-action precautions the section gives.
Why it matters: A richer interface should not become unusable when an API is unsupported or unavailable to a user.
Key terms: Fullscreen API, Picture-in-Picture API, Casting APIs, Media Session API, Window Segments, WebXR APIs, Web Speech API, semantic markup, Baseline, feature detection
3.9 Summary
Where this is used later
- Maintainable and modular CSS (chapter 4) · Develops CSS as the means of styling the interface.
- Container queries and units (chapter 4) · Provides the motivation for adapting interfaces to their available space.
- Title and metadata (chapter 11) · Route rendering can update a page’s title and metadata.
- Make your web app installable (chapter 14) · Earlier coverage of the Web App Manifest as page metadata.
- Making the app installable and offline-capable (chapter 15) · The earlier discussion of web app manifests as metadata.
- Navigation and routing on the Web (chapter 10) · Provides context for navigation that remains inside an installed app.
- The document metadata (chapter 15) · The theme-color metadata introduced earlier.
- Modern Layout (chapter 4) · Takes up visual layout, which this section sets aside while defining structure.
Concepts explained in this chapter
- semantic markupThe practice of using HTML elements according to their meaning to represent a document's content and structure.
- fallbackAn alternative implementation or behavior used when a preferred feature or supplied content is unavailable.
- HTMLThe standard markup language for structuring content in web documents.
- accessibilityThe degree to which a product or service can be used by people with varied abilities and disabilities.
- web app manifestA Web App Manifest is a JSON document that supplies metadata describing a web application, such as its name, icons, colors, and launch URL.
- canvas elementCanvas is an HTML element and browser graphics interface that provides a drawable surface for script-generated visual content.
- responsive designResponsive web design is an approach to creating websites that adapt their layout and presentation to different screen sizes, devices, and contexts.
- feature detectionFeature detection is a technique for determining at runtime whether a browser or environment supports a particular capability.
- progressive enhancementProgressive enhancement is an approach that starts with broadly compatible baseline functionality and adds capabilities when supported by the user's device and browser.
- CSSVanilla CSS is an approach to styling web interfaces with modern CSS directly, without CSS pre-compilers or core styling libraries.
- attributeA JavaScript property is a named value associated with an object.
- metadataMetadata is information that defines settings and descriptive properties for a website or web application without changing the document contents displayed in the viewport.
- JavaScriptA programming language standardized as ECMAScript and widely used to implement behavior in web browsers.
- Web APIsA programming interface exposed by a web browser for accessing web-platform or device capabilities.
- web platformThe collection of browser-provided standards and technologies, including HTML, CSS, and JavaScript, that support web application development.
- vanilla webAn approach to building websites and web applications with core web technologies and browser APIs without a framework defining the application architecture.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.
