Part 13 · Technology for designers

Chapter 74: HTML and CSS

Part 13 · Technology for designers6 min read

HTML (HyperText Markup Language) says what each part of a web page is: a heading, a list, a link, a button. CSS (Cascading Style Sheets) says how those parts look and where they sit. Designers who know the two can read why a layout breaks, write handoff notes developers can use, and spot accessibility problems while they’re still cheap to fix.

Semantic HTML

An element is one piece of an HTML document, marked by tags: <h2>Delivery</h2> is a second-level heading. Semantic HTML is markup that uses each element for what it means, not for how it looks by default. The test: if the CSS failed to load, would the page still make sense as a document?

The earliest surviving list of tags, on a W3C archive page from 1992, already has headings H1 to H6, paragraphs, links and lists.1 Since 2019, HTML has been developed as a single Living Standard at the WHATWG, the browser makers’ group.2 That standard says authors must not use elements for purposes other than their intended meaning, because doing so stops software from processing the page correctly.3

The software in question is the browser, search engines, and above all the assistive technology people use (→ 49 Accessibility and inclusive design). MDN’s example is text styled to look like an <h1> but marked up as a plain <span>: it looks right and means nothing, so screen-reader users can’t jump to it as a heading.4 Page regions work the same way. A landmark is an element such as <header>, <nav>, <main> or <footer> that marks a region people can jump between. A <div> is a generic box with no meaning, to be used only when no other element fits.5

The costly case is the clickable div. A real <button> gets keyboard focus and responds to Enter and Space with no extra code. A div dressed as a button needs a role, a tabindex and keyboard handlers written by hand, and it often ships without them.6 ARIA (Accessible Rich Internet Applications) is a set of attributes that tell assistive technology what an element is, for widgets HTML has no element for. It promises behavior but doesn’t provide any.7 WebAIM’s 2026 survey of a million home pages found 59.1 detectable errors on pages that used ARIA against 42 on pages without, though the ARIA pages were also more complex.8

In practice:

  • Annotate designs with the element, not just the look: “this is a link”, “this is a button”, “this is the page’s only h1“.
  • Heading levels follow the outline of the content, never the font size you want.

The box model

The box model is the CSS rule that every element is a rectangle made of four layers. From the inside out: the content; padding, space inside the edge that takes the element’s background; the border; and the margin, transparent space outside that pushes neighbors away.9

content 350 × 150 content padding 25 border 5 margin 10 not part of the box’s size 410 px box-sizing: content-box content 290 × 90 350 px box-sizing: border-box
Figure 74.1 The same CSS gives two different box widths depending on box-sizing.

The number that surprises designers is width. By default, width sets the content alone, and padding and border are added on top. In MDN’s example, a box with width: 350px, 25 px of padding and a 5 px border takes up 410 px.9 Setting box-sizing to border-box makes width mean the visible box, so the same rule gives 350 px, closer to how design tools measure a frame. Most projects set it globally. Ask which one yours uses before comparing a spec to the browser.

Two more rules explain odd spacing. With margin collapsing, touching vertical margins merge: a 50 px bottom margin above a 30 px top margin leaves a 50 px gap, not 80.9 And logical properties name sides by text direction, so margin-inline-start is the left margin in English and the right one in Arabic or Urdu, with no second stylesheet.10

The cascade and specificity

A CSS rule is a selector, which picks elements, and one or more declarations, each a property and a value:

.card h2 { color: navy; font-size: 1.25rem; }

Håkon Wium Lie published the first proposal for CSS in October 1994, and Bert Bos soon joined him; CSS level 1 became a W3C Recommendation in December 1996.11 The “cascading” in the name was the new idea: several style sheets, from the browser, the reader and the author, can apply to one page at once.

The cascade is the algorithm that decides which declaration wins when several target the same property. In order, it checks: whether the rule applies at all (a print-only rule doesn’t apply on screen); origin and importance; cascade layer; specificity; and finally order of appearance, where the later rule wins.12 A cascade layer is a named group of styles, declared with @layer, whose order the author sets explicitly.

Specificity is a selector’s weight, counted in three columns: IDs, then classes, attributes and pseudo-classes such as :hover, then element types. #checkout scores 1-0-0, .card h2 scores 0-1-1. The columns are compared left to right, so one ID beats any number of classes.13 It’s not a decimal number: eleven classes still lose to one ID.

!important lifts a declaration above normal ones in the same origin and layer. MDN calls using it to win specificity fights bad practice.13 When a developer says a style “won’t apply”, the cause is usually a stronger selector somewhere else, and adding !important starts an arms race.

Flexbox and CSS Grid

Flexbox is the CSS layout method for one dimension: it lays items out along a single axis, a row or a column, and lets them grow to fill spare space or shrink to avoid overflowing.14 CSS Grid is the method for two: it places items into rows and columns at the same time.15

MDN’s rule of thumb is that flexbox works from the content out and grid from the layout in.16 A toolbar, a tag list or a button with an icon is flexbox: the items set their own widths and the container shares out what’s left. A page layout or a gallery whose cards must line up in both directions is grid: define the tracks first, then place items into them. When flex items wrap, each line is laid out on its own, so items don’t align with the row above. If you find yourself fighting that, switch to grid.

Flexbox Grid one axisone axis columns rows
Figure 74.2 Flexbox arranges each line on its own; grid aligns rows and columns together.

Grid has a long history for something so new in browsers. Microsoft wrote the first specification from its Internet Explorer 10 implementation, which shipped prefixed in 2012. From 2013 Bloomberg sponsored the consultancy Igalia to implement it in other engines, and Firefox 52 and Chrome 57 shipped standard grid in March 2017, with Safari 10.1 later that month.1718 CSS Grid and the designer’s column grid (→ 23 Grid systems) are related but separate: the CSS version can draw a twelve-column grid, but it can also draw tracks that have nothing to do with columns.

CSS custom properties

A custom property is a CSS variable: a name with two leading hyphens, set like any property and read with var().

:root  { --color-surface: white; }
.dark  { --color-surface: #111; }
.card  { background: var(--color-surface, white); }

The second value in var() is a fallback. Custom properties cascade and inherit like other properties, so redefining one on a parent changes every child that uses it.19 That’s how a dark theme can be one block of redefinitions, and it’s what separates them from Sass variables, which are replaced with fixed values before the browser sees the file. They are also how design tokens usually reach the browser (→ 65 Design systems). Two limits: names are case-sensitive, and var() can’t be used inside a media query’s condition.19

See also

23 Grid systems · 49 Accessibility and inclusive design · 65 Design systems · 67 Responsive, mobile-first and cross-device design · 75 JavaScript, browsers and performance · 81 Handoff and accessibility in code

Sources

  • Claburn, T. (2017). “Meet CSS Grid.” The Register, 31 March.
  • Lie, H. W. and Bos, B. (n.d.). “A brief history of CSS until 2016.” W3C.
  • MDN Web Docs (n.d.). “Semantics”; “<div>”; “ARIA: button role”; “The box model”; “CSS logical properties and values”; “Introduction to the CSS cascade”; “Specificity”; “Relationship of grid layout with other layout methods”; “Using CSS custom properties (variables)”. Mozilla.
  • Rego Casasnovas, M. (2017). “CSS Grid Layout is Here to Stay.” Igalia.
  • W3C (1992). “Tags used in HTML.” World Wide Web project archive.
  • W3C (2025). CSS Flexible Box Layout Module Level 1; CSS Grid Layout Module Level 1.
  • W3C and WHATWG (2019). “Memorandum of Understanding Between W3C and WHATWG.”
  • W3C WAI (n.d.). ARIA Authoring Practices Guide, “Read Me First.”
  • WebAIM (2026). The WebAIM Million.
  • WHATWG (n.d.). HTML Living Standard.

Notes

  1. W3C (archived 1992). “Tags used in HTML.” World Wide Web project archive, snapshot of 3 November 1992. https://www.w3.org/History/19921103-hypertext/hypertext/WWW/MarkUp/Tags.html ↩
  2. W3C and WHATWG (2019, May 28). “Memorandum of Understanding Between W3C and WHATWG.” https://www.w3.org/2019/04/WHATWG-W3C-MOU.html ↩
  3. WHATWG (n.d.). HTML Living Standard, §3.2.2 “Elements in the DOM: Semantics.” https://html.spec.whatwg.org/multipage/dom.html#semantics-2 ↩
  4. MDN Web Docs (n.d.). “Semantics.” https://developer.mozilla.org/en-US/docs/Glossary/Semantics ↩
  5. MDN Web Docs (n.d.). “<div>: The Content Division element.” https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/div ↩
  6. MDN Web Docs (n.d.). “ARIA: button role.” https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/button_role ↩
  7. W3C WAI (n.d.). “Read Me First.” ARIA Authoring Practices Guide. https://www.w3.org/WAI/ARIA/apg/practices/read-me-first/ ↩
  8. WebAIM (2026). “The WebAIM Million: The 2026 report on the accessibility of the top 1,000,000 home pages.” https://webaim.org/projects/million/ ↩
  9. MDN Web Docs (n.d.). “The box model.” https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Styling_basics/Box_model ↩ ↩ ↩
  10. MDN Web Docs (n.d.). “CSS logical properties and values.” https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Logical_properties_and_values ↩
  11. Lie, H. W. and Bos, B. (n.d.). “A brief history of CSS until 2016.” W3C. https://www.w3.org/Style/CSS20/history.html ↩
  12. MDN Web Docs (n.d.). “Introduction to the CSS cascade.” https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Cascade/Introduction ↩
  13. MDN Web Docs (n.d.). “Specificity.” https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Cascade/Specificity ↩ ↩
  14. W3C (2025, October 14). CSS Flexible Box Layout Module Level 1. Candidate Recommendation Draft. https://www.w3.org/TR/css-flexbox-1/ ↩
  15. W3C (2025, March 26). CSS Grid Layout Module Level 1. Candidate Recommendation Draft. https://www.w3.org/TR/css-grid-1/ ↩
  16. MDN Web Docs (n.d.). “Relationship of grid layout with other layout methods.” https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Grid_layout/Relationship_with_other_layout_methods ↩
  17. Rego Casasnovas, M. (2017, March 16). “CSS Grid Layout is Here to Stay.” Igalia. https://blogs.igalia.com/mrego/2017/03/16/css-grid-layout-is-here-to-stay/ ↩
  18. Claburn, T. (2017, March 31). “Y’know CSS was to kill off HTML table layout? Well, second time’s a charm: Meet CSS Grid.” The Register. https://www.theregister.com/2017/03/31/css_grids_browser_support/ ↩
  19. MDN Web Docs (n.d.). “Using CSS custom properties (variables).” https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Cascading_variables/Using_custom_properties ↩ ↩