--- title: "Headings and text" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Headings and text} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) library(shinyGovstyle) ``` ## Overview This vignette covers all functions in shinyGovstyle that produce styled text content: headings, body text, lists, callout components, links, and typography. For page structure and layout, see the [Layout options](layout-options.html) vignette. --- ## `heading_text()` Creates a semantic HTML heading element with a GOV.UK heading CSS class. ```{r, eval = FALSE} heading_text("Summary", size = "l", level = 2) ``` ### Arguments | Argument | Default | Description | |---|---|---| | `text_input` | — | The heading text to display | | `size` | `"xl"` | Visual size: `"xl"`, `"l"`, `"m"`, or `"s"` | | `level` | `1` | HTML heading level: integer 1–6 | | `id` | auto | Element ID — auto-generated from `text_input` if omitted | ### Visual size and semantic level are independent `size` controls the CSS class applied (`govuk-heading-xl`, `govuk-heading-l`, etc.), which determines how the heading looks. `level` controls the HTML element used (`

`, `

`, etc.), which determines its position in the document outline read by screen readers and assistive technologies. These are independent because it is occasionally necessary to use a smaller visual heading at a higher semantic level, or vice versa. For example, a page where the first visible heading needs to be modest in size but is still structurally the `

`: ```{r, eval = FALSE} heading_text("User guide", size = "m", level = 1) ``` Always set both arguments deliberately. Do not leave `level` at its default of `1` for every heading on a page. ### Recommended size–level pairings **Standard pages** (most dashboards and data tools): | Heading role | `size` | `level` | |---|---|---| | Page title | `"l"` | `1` | | Section heading | `"m"` | `2` | | Sub-section heading | `"s"` | `3` | **Long-form content** (user guides, methodology, accessibility statements): | Heading role | `size` | `level` | |---|---|---| | Page title | `"xl"` | `1` | | Section heading | `"l"` | `2` | | Sub-section heading | `"m"` | `3` | | Sub-sub-section heading | `"s"` | `4` | ### Accessibility **Do not skip heading levels.** Moving from an `

` straight to an `

` breaks the document outline and makes it harder for screen reader users to navigate, as they commonly jump between headings to scan a page. This is a requirement under [WCAG 2.2 success criterion 1.3.1: Info and Relationships](https://www.w3.org/WAI/WCAG22/Understanding/info-and-relationships). **Write headings in sentence case.** Only capitalise the first word and proper nouns. ```{r, eval = FALSE} # Correct — sentence case heading_text("Summary of findings", size = "l", level = 1) # Incorrect — title case heading_text("Summary Of Findings", size = "l", level = 1) ``` For more information, read the [GOV.UK headings guidance](https://design-system.service.gov.uk/styles/headings/). ### Heading IDs If `id` is not supplied it is auto-generated by lowercasing `text_input` and replacing non-alphanumeric characters with underscores. Supply an explicit `id` when you need a stable anchor to link to, or when two headings would otherwise generate the same ID: ```{r, eval = FALSE} heading_text("Methodology", size = "l", level = 2, id = "methodology") ``` --- ## `gov_text()` A wrapper that produces a `

` paragraph element. Use it when you want to add body text with correct GOV.UK styling without writing raw tag calls. ```{r, eval = FALSE} gov_box( size = "two-thirds", gov_text("This is a paragraph of body text.") ) ``` --- ## `gov_list()` Creates a GOV.UK-styled list. The `style` argument controls both the HTML element used and the visual presentation: | `style` | HTML element | Appearance | |---|---|---| | `"none"` (default) | `