Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(font-size): recalibrate the legible font sizes #4550

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lighthouse-cli/test/fixtures/seo/seo-tester.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<style>
.small {
font-size: 15px;
font-size: 11px;
}
</style>
</head>
Expand All @@ -36,9 +36,9 @@ <h2>Anchor text</h2>
<a href='javascript:void(0);'>click this</a>

<h2>Small text</h2>
<!-- PASS(font-size): amount of illegible text is below the 75% threshold -->
<!-- PASS(font-size): amount of illegible text is below the 60% threshold -->
<p class='small'> 1 </p>
<small>2</small>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<small> has a font-size of ~13px , h6 is ~10px

<h6>2</h6>
<font size="1">3<b>4</b></font>
<p style='font-size:10px'>5 </p>
<script class='small'>
Expand Down
12 changes: 6 additions & 6 deletions lighthouse-core/audits/seo/font-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const URL = require('../../lib/url-shim');
const Audit = require('../audit');
const ViewportAudit = require('../viewport');
const CSSStyleDeclaration = require('../../lib/web-inspector').CSSStyleDeclaration;
const MINIMAL_PERCENTAGE_OF_LEGIBLE_TEXT = 75;
const MINIMAL_PERCENTAGE_OF_LEGIBLE_TEXT = 60;

/**
* @param {Array<{cssRule: SimplifiedStyleDeclaration, fontSize: number, textLength: number, node: Node}>} fontSizeArtifact
Expand Down Expand Up @@ -177,9 +177,9 @@ class FontSize extends Audit {
name: 'font-size',
description: 'Document uses legible font sizes',
failureDescription: 'Document doesn\'t use legible font sizes',
helpText: 'Font sizes less than 16px are too small to be legible and require mobile ' +
'visitors to “pinch to zoom” in order to read. Strive to have >75% of page text ≥16px. ' +
'[Learn more](https://developers.google.com/speed/docs/insights/UseLegibleFontSizes).',
helpText: 'Font sizes less than 12px are too small to be legible and require mobile ' +
'visitors to “pinch to zoom” in order to read. Strive to have >60% of page text ≥12px. ' +
'[Learn more](https://developers.google.com/web/fundamentals/design-and-ux/responsive/#optimize_text_for_reading).',
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rviscomi FYI I updated the link to avoid the redirect + BTW do we have anything better we can link to?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ok for now. Please work with @kaycebasques to get first-party LH SEO audit docs online and we can update this link when ready.

requiredArtifacts: ['FontSize', 'URL', 'Viewport'],
};
}
Expand Down Expand Up @@ -245,7 +245,7 @@ class FontSize extends Audit {
source: 'Add\'l illegible text',
selector: null,
coverage: `${percentageOfUnanalyzedFailingText.toFixed(2)}%`,
fontSize: '< 16px',
fontSize: '< 12px',
});
}

Expand All @@ -254,7 +254,7 @@ class FontSize extends Audit {
source: 'Legible text',
selector: null,
coverage: `${percentageOfPassingText.toFixed(2)}%`,
fontSize: '≥ 16px',
fontSize: '≥ 12px',
});
}

Expand Down
3 changes: 1 addition & 2 deletions lighthouse-core/gather/gatherers/seo/font-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ const CSSMatchedStyles = require('../../../lib/web-inspector').CSSMatchedStyles;
const Gatherer = require('../gatherer');
const FONT_SIZE_PROPERTY_NAME = 'font-size';
const TEXT_NODE_BLOCK_LIST = new Set(['SCRIPT', 'STYLE', 'NOSCRIPT']);
// 16px value comes from https://developers.google.com/speed/docs/insights/UseLegibleFontSizes
const MINIMAL_LEGIBLE_FONT_SIZE_PX = 16;
const MINIMAL_LEGIBLE_FONT_SIZE_PX = 12;
// limit number of protocol calls to make sure that gatherer doesn't take more than 1-2s
const MAX_NODES_VISITED = 500;
const MAX_NODES_ANALYZED = 50;
Expand Down
30 changes: 15 additions & 15 deletions lighthouse-core/test/audits/seo/font-size-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@ describe('SEO: Font size audit', () => {
assert.ok(auditResult.debugString.includes('missing viewport'));
});

it('fails when less than 75% of text is legible', () => {
it('fails when less than 60% of text is legible', () => {
const artifacts = {
URL,
Viewport: validViewport,
FontSize: {
totalTextLength: 100,
visitedTextLength: 100,
failingTextLength: 33,
analyzedFailingTextLength: 33,
failingTextLength: 41,
analyzedFailingTextLength: 41,
analyzedFailingNodesData: [
{textLength: 11, fontSize: 14, node: {nodeId: 1, localName: 'p', attributes: []}},
{textLength: 22, fontSize: 15, node: {nodeId: 2, localName: 'p', attributes: []}},
{textLength: 10, fontSize: 10, node: {nodeId: 1, localName: 'p', attributes: []}},
{textLength: 31, fontSize: 11, node: {nodeId: 2, localName: 'p', attributes: []}},
],
},
};

const auditResult = FontSizeAudit.audit(artifacts);
assert.equal(auditResult.rawValue, false);
assert.ok(auditResult.debugString.includes('33%'));
assert.ok(auditResult.debugString.includes('41%'));
});

it('passes when there is no text', () => {
Expand All @@ -58,7 +58,7 @@ describe('SEO: Font size audit', () => {
failingTextLength: 0,
analyzedFailingTextLength: 0,
analyzedFailingNodesData: [
{textLength: 0, fontSize: 14, node: {nodeId: 1, localName: 'p', attributes: []}},
{textLength: 0, fontSize: 11, node: {nodeId: 1, localName: 'p', attributes: []}},
],
},
};
Expand All @@ -67,7 +67,7 @@ describe('SEO: Font size audit', () => {
assert.equal(auditResult.rawValue, true);
});

it('passes when more than 75% of text is legible', () => {
it('passes when more than 60% of text is legible', () => {
const artifacts = {
URL,
Viewport: validViewport,
Expand All @@ -77,8 +77,8 @@ describe('SEO: Font size audit', () => {
failingTextLength: 33,
analyzedFailingTextLength: 33,
analyzedFailingNodesData: [
{textLength: 11, fontSize: 14, node: {nodeId: 1, localName: 'p', attributes: []}},
{textLength: 22, fontSize: 15, node: {nodeId: 2, localName: 'p', attributes: []}},
{textLength: 11, fontSize: 10, node: {nodeId: 1, localName: 'p', attributes: []}},
{textLength: 22, fontSize: 11, node: {nodeId: 2, localName: 'p', attributes: []}},
],
},
};
Expand Down Expand Up @@ -112,9 +112,9 @@ describe('SEO: Font size audit', () => {
failingTextLength: 7,
analyzedFailingTextLength: 7,
analyzedFailingNodesData: [
{textLength: 3, fontSize: 15, node: {nodeId: 1}, cssRule: style1},
{textLength: 2, fontSize: 14, node: {nodeId: 2}, cssRule: style2},
{textLength: 2, fontSize: 14, node: {nodeId: 3}, cssRule: style2},
{textLength: 3, fontSize: 11, node: {nodeId: 1}, cssRule: style1},
{textLength: 2, fontSize: 10, node: {nodeId: 2}, cssRule: style2},
{textLength: 2, fontSize: 10, node: {nodeId: 3}, cssRule: style2},
],
},
};
Expand All @@ -135,7 +135,7 @@ describe('SEO: Font size audit', () => {
failingTextLength: 50,
analyzedFailingTextLength: 10,
analyzedFailingNodesData: [
{textLength: 10, fontSize: 14, node: {nodeId: 1, localName: 'p', attributes: []}},
{textLength: 10, fontSize: 10, node: {nodeId: 1, localName: 'p', attributes: []}},
],
},
};
Expand All @@ -156,7 +156,7 @@ describe('SEO: Font size audit', () => {
failingTextLength: 50,
analyzedFailingTextLength: 50,
analyzedFailingNodesData: [
{textLength: 50, fontSize: 14, node: {nodeId: 1, localName: 'p', attributes: []}},
{textLength: 50, fontSize: 10, node: {nodeId: 1, localName: 'p', attributes: []}},
],
},
};
Expand Down