Skip to content

Commit bf0cf9e

Browse files
authored
Merge pull request #11 from paceaux/10-accessibility
10 accessibility
2 parents fcc1c1d + 8e35aef commit bf0cf9e

File tree

4 files changed

+168
-85
lines changed

4 files changed

+168
-85
lines changed

README.md

+128-54
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,44 @@
11
# Typography-baseline.css
2+
23
> A good start to your CSS typography that covers all the semantic nooks and crannies
34
45
[![License][license-image]][license-url] [![Downloads][downloads-image]][downloads-url]
56

67
**NPM**
7-
```
8+
9+
```bash
810
npm install --save typography-baseline.css
911
```
1012

1113
**Download**
1214
`https://raw.githubusercontent.com/paceaux/typography-baseline/master/src/baseline.css`
1315

1416
## What does it do?
17+
1518
### It gives you a good start
16-
Before you start the layout of a web site or web application, and before you dive into applying to brand, you need something to which you should apply your brand. This is that thing.
1719

18-
The easiest place to start in a design is with the typography. This makes it easy to do that.
20+
Before you start the layout of a web site or web application, and before you dive into applying to brand, you need something to which you should apply your brand. This is that thing.
21+
22+
The easiest place to start in a design is with the typography.
23+
24+
This makes it easy to do that.
1925

2026
### It covers all your semantic markup
21-
Driven by the [W3C spec](https://www.w3.org/TR/html5/) this addresses almost every semantic element that will wrap text and makes sure that everything looks like _something_.
27+
28+
Driven by the [W3C spec](https://www.w3.org/TR/html5/) this addresses almost every semantic element that will wrap text and makes sure that everything looks like _something_.
2229

2330
The <samp>test.html</samp> file uses each and every element according to its semantic definition, too. So you have a miniature guide to semantics built in.
2431

2532
This saves you from a scare down the road when someone wants to output the `<kbd>` element, use `<dfn>`, or try some other obscure element.
2633

2734
### Gives you a "no-design" design
28-
For those times where you need just a bit more than a [Normalize](http://necolas.github.io/normalize.css/), but way less than [Bootstrap](https://getbootstrap.com/), this gets you there.
2935

30-
This is a fairly unopinionated approach to making sure that the text has a decent font family, decent spacing, and decent visual appeal.
36+
For those times where you need just a bit more than a [Normalize](http://necolas.github.io/normalize.css/), but way less than [Bootstrap](https://getbootstrap.com/), this gets you there.
37+
38+
This is a fairly unopinionated approach to making sure that the text has a decent font family, decent spacing, and decent visual appeal.
3139

3240
## Browser Support
41+
3342
* Firefox
3443
* Chrome
3544
* Edge
@@ -38,6 +47,7 @@ This is a fairly unopinionated approach to making sure that the text has a decen
3847

3948

4049
## Usage
50+
4151
While this is relatively unopinionated, there are a few "opinions" to consider:
4252

4353
* [`em` for for `font-size`](https://css-tricks.com/rems-ems/)
@@ -46,68 +56,76 @@ While this is relatively unopinionated, there are a few "opinions" to consider:
4656
* [text-spacing based on the golden ratio ](https://pearsonified.com/golden-ratio-typography-intro/)(.618 / 1.618)
4757

4858
### Fitting it into a CSS architecture
59+
4960
This would come after a reset / [normalize](https://necolas.github.io/normalize.css/) and before you set baseline styles for forms or tables. If you're a fan of [ITCSS](https://www.xfive.co/blog/itcss-scalable-maintainable-css-architecture/), this is in the Elements layer.
5061

51-
If you were to load this into a [CSS Layer](https://developer.mozilla.org/en-US/docs/Web/CSS/@layer), you would want it to come very early so that you could over ride it.
62+
If you were to load this into a [CSS Layer](https://developer.mozilla.org/en-US/docs/Web/CSS/@layer), you would want it to come very early so that you could over ride it.
5263

53-
Wherever you place it, place it _early_ in the cascade so that other things can use and/or re-declare the variables.
64+
Wherever you place it, place it _early_ in the cascade so that other things can use and/or re-declare the variables.
5465

5566
#### Using it in a project
67+
5668
1. Add the baseline
57-
- import into your project with NPM `@import typography-baseline.css`
58-
- <kbd>copy</kbd> + <kbd>paste</kbd> this project's `baseline.css`
69+
* import into your project with NPM `@import typography-baseline.css`
70+
* <kbd>copy</kbd> + <kbd>paste</kbd> this project's `src/baseline.css`
5971
2. Add your own `typography.css` file that comes after the baseline, but before you style anything else.
6072
3. Add something like `html {}` or `body {}`.
6173
4. Modify the variables _in those rulesets_.
62-
5. Then add your own element styles.
74+
5. Then add your own element styles.
6375

6476
**Don't modify the typography-baseline directly. Modify the variables it sets with new rulesets.**
6577

6678
### Modifying without Swearing or Heavy Drinking
79+
6780
One of the really annoying things about other CSS frameworks (cough cough <small>Bootstrap</small>) is that you mostly have to write new CSS to overwrite the existing styles. Often that means raising specificity, which is really stinking annoying. This is designed to avoid that by using [CSS Variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties)
6881

82+
See [Standards and Conventions](#standards-and-conventions) for understanding why variables are named the way they are.
83+
84+
#### Override close to (or at) the root
6985

7086
The typography baseline sets all of the CSS variables on the `:root`. As CSS variables are subject to the cascade, you can override _any_ variable at any time by changing its value &mdash; on the same selector *or* a more specific one.
7187

72-
You can import this into your current CSS setup, and overwrite all the variables by setting new ones on the `html` element.
88+
You can import this into your current CSS setup, and overwrite all the variables by setting new ones on the `html` element.
7389

7490
So if you want the `--baseLinkColor` to be different, you can write the following in your own stylesheet:
7591

76-
```
92+
```css
7793
html {
7894
--baseLinkColor: #c0ffee
7995
}
8096
```
8197

82-
**No raising specificity. Just changing a variable.**
98+
#### No raising specificity; just changing a variable
8399

84100
If you want to theme a special area of the site, or even a particular widget, it's just:
85101

86-
```
102+
```css
87103
.theme {
88104
--baseLinkColor: #c0ffee
89105
}
90106
```
91107

108+
#### Color Palette(s)
92109

93-
#### Color Palette
94-
Colors are derivatives of a base value of 55. All of the neutral colors are multipliers of rgb(55,55,55). Even the non-neutral colors are close-ish to that.
110+
The color palette contains predominantly neutral colors.
95111

112+
Neutral colors are derivatives of a base value of 31. All of the neutral colors are multipliers of rgb(31,31,31).
113+
114+
```css
115+
--colorNeutralDarker: rgb(31,31,31); /* base */
116+
--colorNeutralDark: rgb(62,62,62); /* base * 2 */
117+
--colorNeutral: rgb(155,155,155); /* base * 5 */
118+
--colorNeutralLight: rgb(186,186,186); /* base * 6 */
119+
--colorNeutralLighter: rgb(217,217,217); /* base * 7 */
96120
```
97-
--colorNeutralDarker: rgb(55,55,55); /* base */
98-
--colorNeutralDark: rgb(110,110,110); /* base * 2: */
99-
--colorNeutral: rgb(165,165,165); /* base * 3: */
100-
--colorNeutralLight: rgb(192.5,192.5,192.5); /* base * 3.5 */
101-
--colorNeutralLighter: rgb(220,220,220); /* base * 4: */
102-
```
103-
Color-naming convention follows a pattern established [here](https://codepen.io/paceaux/pen/XdxQza). A big huge and heavy thanks to Sarah Braumiller for suggesting that convention years ago.
104121

105-
[The great big idea](https://blog.frankmtaylor.com/2021/10/21/a-small-guide-for-naming-stuff-in-front-end-code/#css-pre-processor-naming-scss-sass-less-stylus) is that these color name tells you a meaningful aspect of the value, not the value itself. That way it feels safer changing it.
122+
The color-naming convention follows a pattern established [here](https://codepen.io/paceaux/pen/XdxQza). A big huge and heavy thanks to Sarah Braumiller for suggesting that convention years ago.
106123

107-
#### Colors
108-
All of the color variables are abstractions from the color palette. This is so you can change these colors without having to touch your neutral palette.
124+
#### Applying Colors
109125

110-
```
126+
All of the color variables are abstractions from the color palette. This is so you can change these colors without having to touch your neutral palette &mdash; and you can add new palettes if you want.
127+
128+
```css
111129
--baseTextColor: var(--colorNeutralDarker);
112130
--baseEditorialTextColor: var(--colorNeutralDark);
113131
--baseLinkColor: var(--colorCool);
@@ -116,18 +134,19 @@ All of the color variables are abstractions from the color palette. This is so y
116134
```
117135

118136
#### Line Heights
137+
119138
The `--baseLineHeight` is applied to body copy, and the `--smallLineHeight` is used on titles:
120139

121-
```
140+
```css
122141
--baseLineHeight: 1.618;
123142
--smallLineHeight: 1.2;
124143
```
125144

126-
#### Text Sizes
127-
You have a minimum of 6 text sizes in two categories: `--<n>TextSize` and `--<n>TitleSize`. You have a "base" and then superlatives or diminutives to describe the deviation from that base. e.g.:
145+
#### Text and Title Sizes
128146

147+
You have a minimum of 6 text sizes in two categories: `--<n>TextSize` and `--<n>TitleSize`. You have a "base" and then superlatives or diminutives to describe the deviation from that base. e.g.:
129148

130-
```
149+
```css
131150
--biggestTextSize: 1.3em;
132151
--biggerTextSize: 1.2em;
133152
--bigTextSize: 1.1em;
@@ -137,12 +156,11 @@ You have a minimum of 6 text sizes in two categories: `--<n>TextSize` and `--<n>
137156
--smallestTextSize: .618em;
138157
```
139158

140-
For _titles_ you have only _six_ sizes, instead of seven. That's because each title size corresponds to an `<h/>` element.
159+
For _titles_ you have only _six_ sizes, instead of seven. That's because each title size corresponds to an `<h/>` element.
141160

142-
You may also notice that title sizes overlap with base text sizes. This is intentional! You have the flexibility to have your smaller headings be the same as larger text, or to create new title sizes for your headings that won't overlap with the text.
161+
You may also notice that title sizes overlap with base text sizes. This is intentional! You have the flexibility to have your smaller headings be the same as larger text, or to create new title sizes for your headings that won't overlap with the text.
143162

144-
145-
```
163+
```css
146164
--biggestTitleSize: 2.617924em; /* (16 x 1.618) x 1.618 */
147165
--bigTitleSize: 1.618em;
148166
--baseTitleSize: 1.5em;
@@ -151,16 +169,18 @@ You may also notice that title sizes overlap with base text sizes. This is inten
151169
--smallestTitleSize: var(--bigTextSize);
152170
```
153171

154-
You may notice that all of the font-sizes are in `em`. This is _intentional_ so that your headlines can scale easily relative to the font-size of their containers. That means **you should be careful about how many times you change `font-size`**.
172+
You may notice that all of the font-sizes are in `em`. This is _intentional_ so that your headlines can scale easily relative to the font-size of their containers. That means **you should be careful about how many times you change `font-size`**.
155173

156-
If you think you'll be changing `font-size` _a lot_, you may want to set these in `rem` instead, to avoid FOUC (Flash Of Unstyled Content).
174+
If you think you'll be changing `font-size` _a lot_, you may want to set these in `rem` instead, to avoid FOUC (Flash Of Unstyled Content).
157175

158176
#### Spacing
177+
159178
Spacing is done with the golden ratio (.618 / 1.618)
160-
`rem` is used for horizontal spacing so that text remains aligned, regardless of size. `em` is used for vertical spacing so that bigger text gets more room to breathe.
161-
You have two spacings to start with.
179+
`rem` is used for horizontal spacing so that text remains aligned, regardless of size. `em` is used for vertical spacing so that bigger text gets more room to breathe.
162180

163-
```
181+
You have two spacings to start with.
182+
183+
```css
164184
--bigSpacingHorizontal: 1.618rem;
165185
--baseSpacingHorizontal: .618rem;
166186

@@ -171,28 +191,30 @@ You have two spacings to start with.
171191
#### Font Modifications
172192

173193
##### Font families
174-
You have three font families to choose from. `--baseFontFamily` is applied to the html element.
175194

176-
```
195+
You have three font families to choose from. `--baseFontFamily` is applied to the html element.
196+
197+
```css
177198
--baseFontFamily: Georgia, 'Times New Roman', serif;
178199
--titleFontFamily: Helvetica, Arial, sans-serif;
179200
--codeFontFamily: monospace;
180201
```
181202

182203
##### Font Weights
204+
183205
You have three font weights to choose from.
184206

185-
```
207+
```css
186208
--lightestFontWeight: 100;
187209
--baseFontWeight: 400;
188210
--heaviestFontWeight: 700;
189211
```
190212

191-
While the browser technically has nine font-weights, you're only able to add another four (for a total of seven) by following the pattern of adding "er" or "est". If you *really* need nine font-weights, consider naming the ones at the heavy end `--ultraHeavy` and `--ultraHeaviest`.
192-
213+
While the browser technically has nine font-weights, you're only able to add another four (for a total of seven) by following the pattern of adding "er" or "est". If you *really* need nine font-weights, consider naming the ones at the heavy end `--ultraHeavy` and `--ultraHeaviest`.
214+
193215
*Just make sure you've added those typefaces!*
194216

195-
```
217+
```css
196218
--lightFontWeight: 300;
197219
--lighterFontWeight: 200;
198220
--heavyFontWeight: 500;
@@ -202,41 +224,93 @@ You have three font weights to choose from.
202224
If you add more font-weights, remember that [the browser will synthesize the font weights unless proper font-families with those weights are provided](https://w3c.github.io/csswg-drafts/css-fonts-4/#missing-weights)&mdash; unless you are using a [variable font ](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight#variable_fonts). **Add more font-weights carefully**.
203225

204226
##### Font Styles
205-
You have three font styles to use. These are called `fontVoice` because it's important for you to imagine how a person might read the text _out loud_. If you think someone might enunciate or pronounce it differently, that's "italic" (what you might use for `<em>` or `<i>`). The browser will actually look for an italic font.
227+
228+
You have three font styles to use. These are called `fontVoice` because it's important for you to imagine how a person might read the text _out loud_. If you think someone might enunciate or pronounce it differently, that's "italic" (what you might use for `<em>` or `<i>`). The browser will actually look for an italic font.
206229

207230
If you just want to show slanted text, that's "oblique". The browser is just going to angle the font.
208231

209-
```
232+
```css
210233
--shiftedFontVoice: oblique 15deg;
211234
--baseFontVoice: normal;
212235
--alternateFontVoice: italic;
213236
```
214237

215238
#### Quote Styles
239+
216240
One of the very few strong opinions in this baseline is the look and feel of a blockquote. However, you can set the quotes that come before and after the `<blockquote>` and `<q>` elements. This is useful for internationalization; you have one place to make sure all quote symbols are updated!
217241

218-
```
242+
```css
219243
--baseTextQuotes: "\201C""\201D""\2018""\2019";
220244
```
221245

222246
`<blockquote>` and `<samp>` both share a thick left "quote border":
223247

224-
```
248+
```css
225249
--baseQuoteBorder: 10px solid var(--colorNeutralLighter);
226250
--smallQuoteBorder: 5px solid var(--colorNeutralLight);
227251
```
228252

229-
## Conventions and Standards
253+
#### Links
254+
255+
One of the only strong opinions here is how links are presented. Instead of using using `text-decoration`, they use a bottom border. This is because I like just a little more space between text and line than what `text-decoration` offers.
256+
257+
Your core link-related styles are:
258+
259+
```css
260+
--baseLinkColor: var(--colorCool);
261+
--baseLinkColorHover: var(--colorCoolDarker);
262+
263+
--idleTextLineStyle: dotted; /* default */
264+
--interestTextLineStyle: solid; /* :hover and :focus*/
265+
--activeTextLineStyle: solid; /* :active */
266+
--idleTextDecoration: var(--idleTextLineStyle) underline 2px;
267+
```
268+
269+
Since we indicate interaction with color and border, if you wanted to change how links behave, you would need to target `:hover`, `:focus`, and `:active` states. e.g.:
270+
271+
```css
272+
a {
273+
border-bottom: 1px var(--idleTextLineStyle);
274+
}
275+
276+
a:hover,
277+
a:focus {
278+
border-bottom-style: var(--interestTextLineStyle);
279+
}
280+
281+
a:active {
282+
border-bottom-style: var(--activeTextLineStyle);
283+
}
284+
```
285+
286+
## Standards and Conventions
287+
288+
### Accessibility (A11Y)
289+
290+
The <samp>test.html</samp> file passes [WCAG 2.1](https://www.w3.org/TR/WCAG21/) level AA guidelines. It is tested _manually_ using the [Axe dev tools](https://chrome.google.com/webstore/detail/axe-devtools-web-accessib/lhdoppojpmngadmnindnejefpokejbdd) Chrome extension.
291+
292+
The text and link colors were determined by testing how they contrast each other and a white background using [WebAIM's Contrast Checker](https://webaim.org/resources/contrastchecker/).
230293

231294
### Style guide
232-
The CSS follows the guidelines established [here](https://gist.github.com/paceaux/f31e278613ab29b74a412a7eb5046422).
295+
296+
The CSS is linted against [stylelint](https://stylelint.io/). The rules are in the `.stylelintrc` file. There is a specific order for CSS properties (content, position, font, inside-out box sizing, effects).
233297

234298
### Naming Conventions
299+
235300
CSS Variable names follow a convention established [here](https://blog.frankmtaylor.com/2021/10/21/a-small-guide-for-naming-stuff-in-front-end-code/).
236301

302+
The guiding principles for the variable names are:
303+
304+
* camelCased
305+
* Describe usage or purpose
306+
* Favor descriptors (adjectives) that can use common comparatives and superlatives (e.g <samp>er</samp> and <samp>est</samp>) to indicate how variations of a common value are related.
307+
* Start by indicating if it's a base or a derivative with a modifier(adjective): <samp>base</samp>, <samp>small</samp>, <samp>big</samp>, <samp>shifted</samp>, <samp>alternate</samp>
308+
* Then indicate the domain of the user experience the variable affects with a noun: <samp>color</samp>, <samp>font</samp>, <samp>lineHeight</samp>, <samp>spacing</samp>, <samp>text</samp>, <samp>title</samp>, <samp>voice</samp>
309+
* If necessary, narrow the domain with another noun:
310+
* Subdomain of the affected value: <samp>LineStyle</samp>, <samp>Size</samp>, <samp>Weight</samp>
311+
* A specific state where the value might change: <samp>Hover</samp>, <samp>interest</samp>
237312

238313
[license-image]: http://img.shields.io/npm/l/typography-baseline.css.svg
239314
[license-url]: LICENSE
240315
[downloads-image]: http://img.shields.io/npm/dm/typography-baseline.css.svg
241316
[downloads-url]: http://npm-stat.com/charts.html?package=typography-baseline.css
242-

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typography-baseline.css",
3-
"version": "4.0.0",
3+
"version": "5.0.0",
44
"description": "A good start to your CSS typography that covers all the semantic nooks and crannies",
55
"main": "src/baseline.css",
66
"style": "src/baseline.css",

0 commit comments

Comments
 (0)