Web Application Development

Chapter 2
Web Standards, HTML, CSS, and Responsive Design

Bachelors Program in Computer Science Engineering
Web Application Development   •   Bachelor

Web Standards, HTML, CSS, and Responsive Design

Introduction

Web applications are experienced through interfaces rendered by browsers on phones, tablets, laptops, assistive technologies, search engines, and automated tools. A professional interface therefore cannot depend only on visual appearance. It must have meaningful structure, predictable behavior, readable presentation, usable interaction, and resilience across devices and browsers.

HTML, CSS, and web standards provide the foundation for these qualities. HTML describes document meaning and structure; CSS describes presentation and layout; browser standards define how these technologies should be interpreted. Responsive design extends this foundation by allowing a single interface to adapt to different viewport sizes, input methods, and environmental conditions.

This chapter treats front-end development as an engineering discipline. It emphasizes semantic structure, the cascade, the box model, layout systems, accessibility, progressive enhancement, cross-browser compatibility, and reusable design systems.

Learning Objectives

After studying this chapter, you should be able to:

  1. Explain the purpose of web standards and standards-compliant development.
  2. Construct semantic HTML documents using appropriate elements.
  3. Apply CSS selectors, inheritance, the cascade, specificity, and the box model.
  4. Choose effectively among normal flow, Flexbox, Grid, and positioning.
  5. Design responsive interfaces using fluid sizing, flexible layouts, and media queries.
  6. Apply accessibility and progressive-enhancement principles.
  7. Diagnose common browser-compatibility and layout problems.
  8. Organize styles with a maintainable design system.

1. Web Standards and the Browser Platform

Web standards are agreed technical specifications that allow independent browsers, authoring tools, assistive technologies, and servers to interoperate. The World Wide Web Consortium (W3C), the Web Hypertext Application Technology Working Group (WHATWG), and the Ecma International standards community contribute to important parts of the modern platform. HTML is maintained as a living standard by WHATWG, while CSS specifications are developed through W3C working groups.

A browser generally performs the following conceptual process:

  1. It retrieves resources such as HTML, CSS, fonts, images, and scripts.
  2. It parses HTML into a Document Object Model (DOM).
  3. It parses CSS into rules and combines them with the DOM.
  4. It calculates styles, constructs layout boxes, paints pixels, and composites layers.
  5. It exposes the result to users and, through an accessibility tree, to assistive technologies.

This process is not a simple drawing operation. An invalid or poorly structured document may still appear acceptable in one browser, but it can produce different results in another browser or when interpreted by a screen reader, crawler, or automated testing tool.

Standards compliance does not mean that every browser implements every feature identically. It means that developers use defined behavior, test important variations, and provide reasonable fallbacks. Validation tools, browser developer tools, automated accessibility testing, and manual testing are complementary rather than interchangeable.

Separation of concerns

A maintainable interface separates:

  • Structure: HTML elements and document relationships.
  • Presentation: CSS rules, layout, typography, color, and visual state.
  • Behavior: JavaScript and browser APIs.
  • Content and data: Text, media, and server-provided information.

Separation is not absolute: HTML may provide accessible states, CSS may respond to user interaction, and JavaScript may create dynamic content. Nevertheless, keeping responsibilities distinct reduces coupling and improves testing.

2. Semantic HTML

Semantic HTML uses elements according to their meaning rather than their default appearance. A heading communicates a section heading; a button communicates an action; a navigation element identifies a group of navigation links. Semantics help users, assistive technologies, search engines, maintainers, and automated tools understand a document.

A basic document has the following form:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Course Catalogue</title>
  </head>
  <body>
    <header>
      <h1>Course Catalogue</h1>
    </header>
    <main>
      <section aria-labelledby="featured-heading">
        <h2 id="featured-heading">Featured Courses</h2>
        <p>Explore current courses in computing and design.</p>
      </section>
    </main>
    <footer>© 2025 University</footer>
  </body>
</html>

The lang attribute supports pronunciation and language selection. The viewport declaration makes the layout viewport correspond more closely to the device viewport. The title identifies the page in a browser tab, history list, and assistive contexts.

Structural elements

Common semantic elements include header, nav, main, section, article, aside, and footer. These elements are not merely visual containers. Their use should reflect the information architecture of the page.

  • main identifies the dominant content of a document and should normally occur once.
  • nav groups important navigation links.
  • article represents a self-contained composition, such as a news item or product review.
  • section groups related content, usually with a heading.
  • aside contains tangentially related content.
  • header and footer may belong to the page or to a nested article or section.

Heading levels should express hierarchy, not font size. A page usually has one principal h1, followed by logically nested headings. Skipping a level solely to obtain a desired size is a presentation problem that should be solved with CSS.

Choosing controls correctly

Use a button for an action performed in the current interface, such as opening a dialog or submitting a form. Use an a element with a valid href for navigation to a resource or location. Replacing either with a styled div loses keyboard behavior, semantics, focus handling, and often accessibility.

Forms should use explicit labels, appropriate input types, grouped controls, and useful validation messages:

<label for="email">University email</label>
<input id="email" name="email" type="email" autocomplete="email" required>

The for and id values associate the label and control. Native controls should be preferred before adding custom ARIA roles. The principle is often summarized as: use native HTML first, add ARIA only when native semantics are insufficient.

Images and alternative text

An informative image needs alternative text that communicates its purpose. A decorative image should usually use an empty alternative, alt="", so that assistive technology does not announce irrelevant content. An image containing essential text should have an equivalent textual representation, although text in images should generally be avoided.

3. CSS Foundations

CSS consists of rules. A rule contains a selector and declarations:

.card {
  padding: 1rem;
  border: 1px solid #cbd5e1;
  background: white;
}

The selector identifies elements; each declaration consists of a property and value. CSS is declarative: the author describes desired constraints, while the browser determines the final rendering.

Selectors

Important selector types include:

SelectorMeaningExample
TypeElements of a typep
ClassElements with a class.card
IDElement with an ID#profile
AttributeElements with an attribute conditioninput[type="email"]
DescendantElement inside another.card p
ChildDirect child.card > h2
Pseudo-classState or structural conditiona:hover, li:first-child
Pseudo-elementGenerated part of an element::before

Classes are usually preferable for reusable styling. IDs are useful for document references, such as label associations, but excessive ID-based styling creates unnecessarily strong rules.

The cascade and specificity

When multiple declarations apply, the cascade considers origin and importance, selector specificity, and source order. In ordinary author styles, a more specific selector generally wins; if specificity is equal, the later declaration wins. Inline styles and !important can alter this process, but they should not become routine substitutes for organization.

Specificity can be understood as a tuple with categories for ID selectors, class/attribute/pseudo-class selectors, and type/pseudo-element selectors. For example, #menu .item is stronger than .item, while nav .item is stronger than p. This is a comparison model rather than a reason to create increasingly complicated selectors.

Useful practices include keeping selectors shallow, defining component styles in a predictable order, using cascade layers where appropriate, and reserving !important for carefully justified cases such as utility overrides or user-preference safeguards.

Inheritance and values

Some properties, such as color and font-family, commonly inherit from a parent. Others, such as margin and border, do not inherit by default. CSS-wide keywords include inherit, initial, unset, and revert. Custom properties support reusable values:

:root {
  --color-primary: #155eef;
  --space-md: 1rem;
  --radius-sm: 0.375rem;
}

.button {
  background: var(--color-primary);
  border-radius: var(--radius-sm);
  padding: var(--space-md);
}

Custom properties are especially valuable for design tokens, themes, and controlled variation.

4. The CSS Box Model

Every rendered element is represented conceptually by a box containing content, padding, border, and margin. The default content-box model calculates the declared width and height for the content area only. With border-box, the declared dimensions include content, padding, and border.

A useful relationship for a horizontal dimension is:

Outer width = margin-left + border-left + padding-left + content width + padding-right + border-right + margin-right

This relationship assumes a conventional non-replaced block-level box and expresses the contribution of each layer; actual layout can also be affected by overflow, scrollbars, writing mode, and formatting context. A common reset is:

*, *::before, *::after {
  box-sizing: border-box;
}

Worked example

Suppose an element has width: 20rem, horizontal padding of 1rem on each side, and borders of 0.125rem on each side. Under content-box, its border-box width is:

20rem + 1rem + 0.125rem + 1rem + 0.125rem = 22.25rem

Under border-box, the total border-box width is 20rem, and the content width is reduced to 17.75rem, assuming the padding and borders fit within the declared width. Margins remain outside both models.

5. Layout Systems

Normal flow

Normal flow is the browser’s default arrangement of block and inline content. It should be the starting point for most documents because it naturally supports variable content, zooming, and accessibility. Removing elements from flow without a strong reason can cause overlap and maintenance problems.

Flexbox

Flexbox is a one-dimensional layout system. It distributes items along a main axis and aligns them along a cross axis. It is appropriate for navigation bars, toolbars, rows of controls, and component-level alignment.

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
}

Important concepts include flex-direction, flex-wrap, flex-grow, flex-shrink, flex-basis, align-items, align-content, and justify-content. The gap property expresses spacing without requiring margins on individual children.

Grid

CSS Grid is a two-dimensional layout system. It is appropriate when both rows and columns matter, such as dashboards, page shells, and card collections.

.dashboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: 1rem;
}

minmax(16rem, 1fr) establishes a minimum track size while allowing tracks to share available space. auto-fit collapses empty tracks and helps the grid adapt to the container width. Grid should express relationships in the layout rather than forcing every element into absolute coordinates.

Positioning

relative establishes a positioning context for descendants; absolute removes an element from normal flow and positions it relative to an appropriate ancestor; fixed positions relative to the viewport in common cases; sticky combines flow behavior with a threshold during scrolling. Positioning is useful for badges, overlays, and persistent controls, but it should not replace normal flow for primary page structure.

6. Responsive Design

Responsive design is an approach in which content and layout adapt to the user’s environment. Relevant variables include viewport width, height, orientation, pixel density, input capability, motion preference, contrast preference, and available bandwidth.

The viewport meta element is essential for mobile pages:

<meta name="viewport" content="width=device-width, initial-scale=1">

A responsive interface commonly combines:

  • Fluid widths such as percentages and max-width.
  • Flexible layout systems such as Flexbox and Grid.
  • Relative units such as rem, em, and viewport units where suitable.
  • Responsive images using srcset, sizes, or the picture element.
  • Media and container queries.
  • Content-driven breakpoints rather than device-name assumptions.

Media queries

A media query applies styles when an environmental condition is true:

.page {
  padding: 1rem;
}

@media (min-width: 48rem) {
  .page {
    padding: 2rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto;
    animation-duration: 0.01ms;
    transition-duration: 0.01ms;
  }
}

A mobile-first strategy begins with a usable narrow layout and adds enhancements for larger conditions. Breakpoints should be selected when the content becomes difficult to read or operate, not merely because a particular phone or tablet has a named size.

Container queries allow a component to respond to the size of its containing context rather than the viewport. This is valuable for reusable cards that may appear in a sidebar, grid, or full-width region.

Responsive images and typography

Images should not exceed their containers:

img, svg, video {
  max-width: 100%;
  height: auto;
}

However, responsive images also require suitable source selection for performance. srcset can provide multiple resolutions, while sizes helps the browser estimate rendered width. Typography should preserve readable line length, adequate contrast, and sufficient zoom behavior. Avoid fixed heights around text because localization, user font settings, and content variation can cause clipping.

7. Accessibility and Inclusive Design

Accessibility means that people with varied sensory, motor, cognitive, and technological circumstances can perceive, operate, understand, and interact with a system. The Web Content Accessibility Guidelines organize guidance around perceivable, operable, understandable, and robust principles.

Core practices include:

  • Use semantic HTML and logical heading structure.
  • Ensure keyboard access and visible focus indicators.
  • Do not communicate information through color alone.
  • Maintain sufficient text and control contrast.
  • Associate labels with form fields.
  • Provide meaningful alternative text and captions where appropriate.
  • Respect zoom, text resizing, reduced motion, and high-contrast preferences.
  • Ensure touch targets have adequate size and spacing.
  • Manage focus when opening and closing dialogs or changing views.

Accessibility is not a final cosmetic audit. It begins during information architecture and interaction design. Automated tools can detect missing labels, some contrast failures, and structural issues, but they cannot reliably judge whether alternative text is meaningful or whether a workflow is understandable. Keyboard and screen-reader testing remain necessary.

8. Progressive Enhancement and Compatibility

Progressive enhancement starts with essential content and functionality that work in a broadly supported baseline, then adds richer capabilities when the platform supports them. For example, a form may submit through a normal HTTP request before JavaScript adds inline validation and asynchronous behavior.

Feature detection is preferable to browser-name detection. CSS supports queries can test whether a feature is understood:

@supports (display: grid) {
  .layout {
    display: grid;
  }
}

Compatibility work includes checking standards documentation, consulting reliable compatibility data, testing representative browsers, and providing fallbacks. A fallback should preserve the essential task rather than merely hide an unsupported feature.

Common causes of cross-browser defects include invalid markup, reliance on undocumented behavior, inconsistent default styles, unsupported CSS features, font metrics, date and locale assumptions, and differences in input or scrolling behavior. A small reset or normalization layer can reduce default-style variation, but it cannot replace testing.

9. Design Systems and Maintainability

A design system is a coordinated collection of principles, tokens, components, usage rules, and implementation guidance. It supports consistency without requiring every page to look identical.

A practical system may define:

  • Color, spacing, type, radius, elevation, and motion tokens.
  • Component states such as default, hover, focus, disabled, and error.
  • Layout primitives such as stack, cluster, container, and grid.
  • Accessibility requirements and content guidance.
  • Naming conventions and contribution rules.

Tokens should express purpose when possible. --color-action communicates intent more effectively than --blue-500 when the value may change across themes. Components should expose controlled variation rather than dozens of unrelated overrides.

CSS architecture should manage scope and cascade deliberately. Techniques include component classes, naming conventions, cascade layers, custom properties, and avoiding selectors that depend heavily on DOM depth. Maintainability also requires removing unused styles, documenting exceptions, and testing components in isolation and in real page contexts.

10. Illustrative Case: Responsive University Course Catalogue

Background

A university publishes a course catalogue used by prospective students on mobile phones, large monitors, and assistive technologies. The first version uses nested div elements, fixed card heights, image-only controls, and a desktop layout that becomes horizontally scrollable on small screens.

Problem

Users report that course cards are difficult to navigate by keyboard, headings are unclear to screen readers, filters disappear on narrow screens, and translated course descriptions are clipped. The development team also observes inconsistent spacing between browsers.

Analysis

The defects arise from several interacting causes: non-semantic structure, fixed dimensions, inadequate focus styling, excessive reliance on viewport-specific assumptions, and styles tied to browser defaults. The team identifies the course catalogue as a collection of meaningful articles within a searchable main region, with filters represented as form controls.

Approach and solution

The team redesigns the markup using header, main, form, fieldset, legend, article, headings, buttons, and links. Each course article has a stable heading and a text alternative for its image. The page begins with a single-column mobile layout. A Grid layout is introduced when the catalogue container is wide enough, using flexible minimum card widths rather than fixed card heights. Text is allowed to wrap, and images use responsive sources.

The team defines design tokens for spacing, colors, borders, and focus rings. Keyboard focus is visible, filter controls have labels, and the filter panel remains available through a button on narrow screens. Motion is reduced when the user requests reduced motion. JavaScript enhances filtering but the page still exposes course content and a usable form submission path when scripting is unavailable.

Testing includes keyboard-only navigation, screen-reader checks, zoom to 200%, narrow and wide viewports, translation with longer text, and representative browsers. Automated checks are used for regression detection rather than treated as proof of accessibility.

Outcome

The catalogue no longer requires horizontal scrolling for ordinary content, course descriptions remain readable under zoom and translation, and the essential browsing task works without JavaScript. The design system reduces inconsistent spacing in later pages, while semantic markup improves navigation for assistive technology and search indexing.

Learning points

The case demonstrates that responsive design is not simply shrinking a desktop layout. It is an integrated activity involving semantics, content priorities, flexible layout, accessibility, performance, testing, and progressive enhancement.

11. Challenges, Limitations, and Professional Practice

No single CSS technique solves every interface problem. Flexbox can become difficult for complex two-dimensional relationships; Grid can produce confusing implicit tracks when the design is underspecified; absolute positioning can fail with dynamic content; and media queries based only on width ignore user preferences and component context.

Accessibility standards provide measurable guidance but do not guarantee a usable experience. Browser support data is informative but cannot predict every defect caused by fonts, extensions, operating systems, or embedded web views. Design systems can improve consistency, yet over-standardization may prevent appropriate solutions for unusual content.

Professional practice therefore combines standards knowledge with inspection and evidence. Use valid semantic HTML, inspect the accessibility tree, test at multiple zoom levels, test with keyboard and assistive technology, check layout with real content, and monitor performance. Document intentional exceptions and revisit them as the platform evolves.

Privacy and ethics also matter. Avoid dark patterns that make cancellation harder than subscription, do not use color or motion to manipulate users, collect only necessary data, and ensure that accessibility is treated as an inclusion obligation rather than an optional feature. AI-assisted code generation may accelerate prototyping, but generated HTML and CSS must be reviewed for semantics, security, accessibility, licensing, and maintainability.

Chapter Summary

Web standards provide the interoperability foundation for browser-based applications. Semantic HTML communicates document meaning and gives users, search engines, and assistive technologies a reliable structure. CSS controls presentation through selectors, inheritance, the cascade, specificity, custom properties, and the box model. Normal flow should be the default, while Flexbox supports one-dimensional relationships and Grid supports two-dimensional layouts.

Responsive design combines fluid dimensions, flexible layout, responsive media, media queries, container queries, and user-preference queries. Accessibility requires semantic controls, keyboard operation, visible focus, meaningful alternatives, readable contrast, robust forms, and respect for user settings. Progressive enhancement preserves essential functionality while allowing richer features on capable platforms. Cross-browser quality depends on valid code, feature detection, fallbacks, representative testing, and careful use of standards.

Finally, design systems translate principles into reusable tokens, components, states, and guidance. Effective front-end engineering is therefore not the pursuit of one perfect visual rendering; it is the construction of interfaces that remain understandable, usable, adaptable, and maintainable under changing content and conditions.

Key Terms

Web standard: An agreed technical specification supporting interoperable web technologies.

Semantic HTML: HTML whose elements express the meaning and role of content.

DOM: The structured object representation of an HTML document.

Accessibility tree: A browser representation of interface semantics exposed to assistive technologies.

CSS cascade: The process used to resolve competing style declarations.

Specificity: The selector-priority mechanism used during cascade resolution.

Inheritance: The transfer of selected property values from an ancestor to a descendant.

Box model: The content, padding, border, and margin model of an element.

Normal flow: The default arrangement of elements in a document.

Flexbox: A one-dimensional CSS layout system.

Grid: A two-dimensional CSS layout system.

Media query: A conditional CSS rule based on an environmental feature.

Container query: A conditional rule based on the size or characteristics of a containing element.

Responsive design: Designing interfaces that adapt to varied devices and conditions.

Progressive enhancement: Providing a baseline experience before adding optional capabilities.

Design token: A named reusable value representing a design decision.

Fallback: An alternative implementation used when a preferred feature is unavailable.

Semantic control: A native interface element whose meaning and interaction behavior are built into the platform.

Review Questions

Short Answer Questions

  1. What is the difference between semantic HTML and presentational markup?
  2. What factors influence the CSS cascade?
  3. Distinguish Flexbox from CSS Grid.
  4. Why is box-sizing: border-box commonly used?
  5. What is progressive enhancement?

Long Answer Questions

  1. Explain how a browser transforms HTML and CSS into a rendered and accessible interface.
  2. Discuss semantic HTML, native controls, labels, headings, and alternative text as foundations of accessibility.
  3. Explain the CSS box model and compare content-box with border-box, using an example.
  4. Develop a responsive-layout strategy for a content-rich university website.
  5. Evaluate the role of design systems in maintaining consistency and accessibility across a large application.

Analytical / Application Questions

  1. A dashboard uses absolute positioning for every panel and clips text when users zoom. Diagnose the design weaknesses and propose a standards-based replacement.
  2. A course card works visually but cannot be reached by keyboard and uses a clickable div. Redesign its HTML and explain the accessibility improvements.
  3. A catalogue displays four fixed-width columns on desktop and horizontal scrolling on mobile. Propose a mobile-first Grid or Flexbox solution, including how you would test it with long translated content.

Multiple Choice Questions with Answers

Question 1

Which element is most appropriate for a control that performs an action without navigating to another resource?

A. button

B. a without href

C. div

D. span

Correct Answer: A. button

Question 2

Under the default content-box model, what does a declared width represent?

A. The margin box

B. The border box

C. The content box

D. The complete outer width

Correct Answer: C. The content box

Question 3

Which CSS layout system is primarily one-dimensional?

A. CSS Grid

B. Flexbox

C. Normal flow only

D. Table layout

Correct Answer: B. Flexbox

Question 4

Which practice best supports progressive enhancement?

A. Requiring JavaScript before any content is available

B. Using browser-name detection for every feature

C. Providing essential functionality through a baseline implementation

D. Replacing semantic HTML with custom elements in all cases

Correct Answer: C. Providing essential functionality through a baseline implementation

Question 5

What is the main purpose of the lang attribute on the html element?

A. To select a CSS stylesheet

B. To identify the document language

C. To set the viewport width

D. To define the page encoding

Correct Answer: B. To identify the document language

Question 6

Which selector generally has greater specificity?

A. .card

B. p

C. #profile

D. *

Correct Answer: C. #profile

Question 7

Which CSS feature allows a component to respond to the size of its containing context?

A. Container query

B. DNS query

C. Selector reset

D. Font query

Correct Answer: A. Container query

Question 8

What is the preferred first choice for a standard accessible form control?

A. A styled div with a click handler

B. A native HTML control

C. An image with text embedded in it

D. A paragraph with a keyboard listener

Correct Answer: B. A native HTML control

Question 9

A box has width: 20rem, horizontal padding of 1rem on each side, and borders of 0.125rem on each side. Under content-box, what is its border-box width, ignoring margins?

A. 20rem

B. 21rem

C. 22rem

D. 22.25rem

Correct Answer: D. 22.25rem

Question 10

Which approach is most appropriate for selecting responsive breakpoints?

A. Use only the names and dimensions of popular devices

B. Choose them when the content or layout requires adaptation

C. Use one breakpoint for every project

D. Avoid flexible units and use fixed pixel widths

Correct Answer: B. Choose them when the content or layout requires adaptation

Web Application Development
Chapter 2 of 15