Skip to content

Commit fc94380

Browse files
committed
add check for page title
- Add detection for missing or empty title (missing uses has which is experimental, note added as code comment) - Update code and features - Update demo page (leave title empty) - Add tests for new feature - Build and minify
1 parent 861d656 commit fc94380

11 files changed

Lines changed: 110 additions & 4 deletions

File tree

checka11y-errors.css

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,34 @@ button:not([aria-label]):not([aria-labelledby]):empty::after {
192192
background-color: var(--checka11y-bg-error);
193193
}
194194

195+
head {
196+
display: block;
197+
}
198+
199+
head title:empty {
200+
border: 0.4rem solid;
201+
border-color: var(--checka11y-border-error);
202+
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="458px" height="80px" viewBox="0 0 458 80"><rect class="box" x="4" y="4" width="450" height="72" rx="12" ry="12" fill="rgba(255, 198, 198, 0.999999)" stroke-width="0.4rem" stroke="rgba(255, 0, 0, 0.999999)" /><g fill="rgba(114, 28, 36, 0.999999)" font-size="1rem" font-weight="700" font-family="verdana, geneva, tahoma, sans-serif" font-style="initial" letter-spacing="initial" text-decoration="none" text-transform="initial" text-shadow="none"><text x="15" y="35">ERROR (E0017): the page title tag must not</text> <text x="15" y="60">be empty.</text></g></svg>');
203+
background-position: bottom center;
204+
background-repeat: no-repeat;
205+
min-width: 458px;
206+
padding-bottom: 80px;
207+
display: block;
208+
border: 0;
209+
}
210+
211+
head:not(:has(title)) {
212+
border: 0.4rem solid;
213+
border-color: var(--checka11y-border-error);
214+
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="458px" height="80px" viewBox="0 0 458 80"><rect class="box" x="4" y="4" width="450" height="72" rx="12" ry="12" fill="rgba(255, 198, 198, 0.999999)" stroke-width="0.4rem" stroke="rgba(255, 0, 0, 0.999999)" /><g fill="rgba(114, 28, 36, 0.999999)" font-size="1rem" font-weight="700" font-family="verdana, geneva, tahoma, sans-serif" font-style="initial" letter-spacing="initial" text-decoration="none" text-transform="initial" text-shadow="none"><text x="15" y="35">ERROR (E0018): a title tag must be present</text> <text x="15" y="60">in the page head.</text></g></svg>');
215+
background-position: bottom center;
216+
background-repeat: no-repeat;
217+
min-width: 458px;
218+
padding-bottom: 80px;
219+
display: block;
220+
border: 0;
221+
}
222+
195223
h1:empty::after, h2:empty::after, h3:empty::after, h4:empty::after, h5:empty::after, h6:empty::after {
196224
display: block;
197225
font-size: 1rem;

checka11y-errors.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

checka11y-warnings.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

checka11y.css

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,34 @@ button:not([aria-label]):not([aria-labelledby]):empty::after {
477477
background-color: var(--checka11y-bg-error);
478478
}
479479

480+
head {
481+
display: block;
482+
}
483+
484+
head title:empty {
485+
border: 0.4rem solid;
486+
border-color: var(--checka11y-border-error);
487+
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="458px" height="80px" viewBox="0 0 458 80"><rect class="box" x="4" y="4" width="450" height="72" rx="12" ry="12" fill="rgba(255, 198, 198, 0.999999)" stroke-width="0.4rem" stroke="rgba(255, 0, 0, 0.999999)" /><g fill="rgba(114, 28, 36, 0.999999)" font-size="1rem" font-weight="700" font-family="verdana, geneva, tahoma, sans-serif" font-style="initial" letter-spacing="initial" text-decoration="none" text-transform="initial" text-shadow="none"><text x="15" y="35">ERROR (E0017): the page title tag must not</text> <text x="15" y="60">be empty.</text></g></svg>');
488+
background-position: bottom center;
489+
background-repeat: no-repeat;
490+
min-width: 458px;
491+
padding-bottom: 80px;
492+
display: block;
493+
border: 0;
494+
}
495+
496+
head:not(:has(title)) {
497+
border: 0.4rem solid;
498+
border-color: var(--checka11y-border-error);
499+
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="458px" height="80px" viewBox="0 0 458 80"><rect class="box" x="4" y="4" width="450" height="72" rx="12" ry="12" fill="rgba(255, 198, 198, 0.999999)" stroke-width="0.4rem" stroke="rgba(255, 0, 0, 0.999999)" /><g fill="rgba(114, 28, 36, 0.999999)" font-size="1rem" font-weight="700" font-family="verdana, geneva, tahoma, sans-serif" font-style="initial" letter-spacing="initial" text-decoration="none" text-transform="initial" text-shadow="none"><text x="15" y="35">ERROR (E0018): a title tag must be present</text> <text x="15" y="60">in the page head.</text></g></svg>');
500+
background-position: bottom center;
501+
background-repeat: no-repeat;
502+
min-width: 458px;
503+
padding-bottom: 80px;
504+
display: block;
505+
border: 0;
506+
}
507+
480508
h1:empty::after, h2:empty::after, h3:empty::after, h4:empty::after, h5:empty::after, h6:empty::after {
481509
display: block;
482510
font-size: 1rem;

checka11y.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codes.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ A list of every Checka11y.css error & warning code with details on what the issu
9393
- ### E0016
9494
The `longdesc` attribute has been detected in an `<img>` and it has an invalid value. The `longdesc` attribute must be a URL to a web page, but the detected `longdesc` is empty or it contains blank spaces so it's not a valid URL.
9595

96+
- ### E0017
97+
An empty `<title>` element has been found within the page's `<head>`. An empty title would be an accessibility issue because it makes it more difficult for some users to orient themselves and navigate through the pages.
98+
99+
- ### E0018
100+
The `<head>` element does not contian a `<title>`. An missing title would be an accessibility issue because it makes it more difficult for some users to orient themselves and navigate through the pages.
101+
96102
## Warnings <small>(Wxxx)</small>
97103

98104
- ### W0000

cypress/integration/head_spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
describe("<head>", () => {
2+
before(() => {
3+
cy.visit("/test/index.html");
4+
});
5+
6+
it('should not have an empty title', () => {
7+
cy.get("head title:empty")
8+
.each(element => {
9+
cy.get(element)
10+
.should('have.css', 'background-image') // yields data:image....
11+
.and('match', /data/)
12+
});
13+
});
14+
});

features.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ A list of every a11y concern Checka11y.css will check for and highlight with lin
2121
- [E0014](./codes.md#E0014): Checks for a tab index value of -1 on commonly tabbed to elements.
2222
- [E0015](./codes.md#E0015): Checks for an image with a `longdesc` pointing to an image.
2323
- [E0016](./codes.md#E0016): Checks for an image with an empty `longdesc`.
24+
- [E0017](./codes.md#E0017): Checks for an empty `<title>` in the `<head>`.
25+
- [E0018](./codes.md#E0018): Checks for an `<head>` without a `<title>` element inside.
2426

2527
## Warnings
2628

src/errors/features/_head.scss

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@use "../../shared/messages/" as *;
2+
3+
/* Make the head visible to show the title. This could have side effects but,
4+
in theory, all the elements in the head are non-visible. So we should be ok :P */
5+
head {
6+
display: block;
7+
}
8+
9+
/* E0017: title element must not be empty */
10+
head title:empty {
11+
@include vectorMessage(error, "E0017", 458, "the page title tag must not", "be empty.");
12+
display: block;
13+
border: 0;
14+
}
15+
16+
/* E0018: title element must be present in the header */
17+
/* Note that this is not supported in any browser yet */
18+
/* For more details about :has() - https://developer.mozilla.org/en-US/docs/Web/CSS/:has */
19+
head:not( :has( title ) ) {
20+
@include vectorMessage(error, "E0018", 458, "a title tag must be present", "in the page head.");
21+
display: block;
22+
border: 0;
23+
}

src/errors/features/_index.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@forward "./buttons";
22
@forward "./dir";
3+
@forward "./head";
34
@forward "./headings";
45
@forward "./html";
56
@forward "./iframe";

0 commit comments

Comments
 (0)