Your phone's text size
Many people make the text bigger on their phone. Some turn on dark mode, or bold text. They choose once, and every app follows.
Netheret's staff asked for features for users with extra needs. An engineer may read a job brief in bright sunlight. A manager may have low vision.
The app should let each person choose, and remember.
Key words
| Word | What it means | Example |
|---|---|---|
| Accessibility | Making an app work for everyone, including disabled people. | |
| Contrast | How different the text colour is from the background. | |
| rem | A CSS size that grows with the page's base text size. | 1.5rem |
| Screen reader | Software that reads a page aloud. | |
| WCAG | The international guidelines for accessible web pages. | |
| Equality Act 2010 | The UK law that expects reasonable changes for disabled people. |
The cells students fill in are left blank in this preview.
By the end of this lesson
Note
I can save each user's text size and contrast and apply them to every page.
Starter: what you already know
Have a go
Starter: what you already know
3 questionsSprint 4, step 13: the goal and stories
| Part | For this step |
|---|---|
| Sprint (a short block of work) | Sprint 4: reports, accessibility and security. |
| E6.1 | As a user with low vision, I want larger text, so that I can read every page. |
| E6.2 | As a user who finds pale colours hard, I want high contrast, so that text stands out. |
| E6.4 | As any user, I want error pages in plain words, so that I know what to do next. |
The cells students fill in are left blank in this preview.
Settings are saved on the user
The User table has had two columns since step 3: text_size and high_contrast. Now a settings page writes them.
Because they live in the user's stored row, not in one browser, they follow the person. Sign in on another computer and the page looks the same.
The text size must be one of the allowed values. Anything else is refused with a message.
Step 13: the settings route
# helpdesk/settings.py (part)
@bp.route("/settings", methods=["GET", "POST"])
@login_required
def accessibility():
if request.method == "POST":
text_size = request.form.get("text_size")
if text_size not in TEXT_SIZES:
flash("Choose one of the text sizes.")
else:
g.user.text_size = text_size
g.user.high_contrast = request.form.get("high_contrast") == "yes"
db.session.commit()
flash("Your settings are saved.")
return redirect(url_for("settings.accessibility"))
return render_template("settings.html", text_sizes=TEXT_SIZES)
Make a free account to save your work and track your progress.
Check: saving settings
Have a go
Check: saving settings
3 questionsA class on the page changes everything
The base template turns the settings into classes on the <html> tag, such as text-larger high-contrast.
Every size in the CSS is in rem. So one rule for html.text-larger makes all the text bigger at once.
Every colour is a CSS variable (a named value). html.high-contrast gives the variables new values: white on black, yellow links. The whole page follows, even the charts.
Step 13: the settings as html classes
{# helpdesk/templates/base.html: the settings become classes on <html> #}
<html lang="en-GB"{% if g.user %} class="text-{{ g.user.text_size }}{{ ' high-contrast' if g.user.high_contrast }}"{% endif %}>
{# Flash messages are announced by screen readers when they appear. #}
<div class="flashes" role="status"> ... </div>
Step 13: the CSS those classes use
/* helpdesk/static/css/style.css (part) */
/* Larger text: everything is sized in rem, so changing the root size
makes the whole page bigger. */
html.text-large { font-size: 118.75%; }
html.text-larger { font-size: 137.5%; }
/* High contrast: change the colour variables, and the whole page follows. */
html.high-contrast {
--ink: #ffffff;
--paper: #000000;
--brand: #000000;
--link: #ffff00;
--focus: #00ffff;
--chart-bar: #ffff00;
}
Try it: larger text and high contrast
<div class="page">
<h1>Request NTH-0012</h1>
<p>Router lights flashing red. <a href="#">Read the timeline</a></p>
<p><span class="badge">Open</span></p>
<button id="bigger">Larger text</button>
<button id="contrast">High contrast</button>
</div>
Make a free account to save your work and track your progress.
A common mistake
Warning
Many students think accessibility is one feature added at the end. It is built in from the start: labels, the skip link, focus rings and real tables came in earlier steps. Settings give extra choice on top. Without the basics, they cannot help much.
Check: classes and variables
Have a go
Check: classes and variables
3 questionsMessages that everyone can follow
Flash messages now have role="status", so a screen reader reads them out when they appear.
Error 403 and 404 used to show Flask's own page, in technical words. Now each shows a plain heading, one sentence and a way back.
These choices follow WCAG, and they help meet the Equality Act 2010.
Step 13: friendly error pages
# helpdesk/main.py (part)
# Friendly pages for errors, in plain words, with a way back.
@bp.app_errorhandler(403)
def forbidden(error):
return render_template(
"errors/error.html", heading="You cannot open this page",
message="Your account does not have access to this page.",
), 403
@bp.app_errorhandler(404)
def not_found(error):
return render_template(
"errors/error.html", heading="Page not found",
message="Check the address, or go back and follow a link.",
), 404
Make a free account to save your work and track your progress.
Match each feature to who it helps
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Build it yourself: step 13
Build step 13. 1. Add a settings page that saves text size and high contrast on the user, refusing a size not on the list. 2. Put the settings on the html tag as classes in base.html. 3. Make sure your CSS sizes are in rem and your colours are variables, then add the larger text and high contrast rules. 4. Add role="status" to flash messages and plain pages for errors 403 and 404. 5. Test by hand: choose larger text and high contrast, sign out and in again, and check every page. Take screenshots for your test log. 6. Commit and write the change log row.
A teacher marks this in a college. Nothing you write here is kept: it goes when you leave the page.
Make a free account to save your work, or press Start lab to work through the whole lesson.
Compare with the step 13 code
Tip
Compare yours with the step 13 code on GitHub. Turn on high contrast and check every page, including the reports.
Change log entry for step 13
| Date | Version and files | What changed | Why |
|---|---|---|---|
| 19 March | step-13: settings.py, main.py, style.css, charts.js, base.html, settings.html, errors/error.html | Larger text and high contrast saved per user and applied as classes, announced messages, plain error pages | Staff asked for accessibility features, and the Equality Act 2010 expects reasonable changes |
The cells students fill in are left blank in this preview.
Next: security and the law
In step 14 the app protects its forms from other websites and sends safer headers and cookies. A privacy notice explains what it does with people's data.
Exit quiz
Have a go