You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/components/MarkdownSample.mdx
+52-63Lines changed: 52 additions & 63 deletions
Original file line number
Diff line number
Diff line change
@@ -3,37 +3,57 @@
3
3
[View on GitHub](https://github.com/tailwindcss/typography)
4
4
5
5
<pclassName="lead">
6
-
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown
7
-
printer took a galley of type and scrambled it to make a type specimen book.
6
+
Until now, trying to style an article, document, or blog post with Tailwind has been a tedious
7
+
task that required a keen eye for typography and a lot of complex custom CSS.
8
8
</p>
9
9
10
-
A plugin that provides a `rich-text` class you can use to add sensible typographic defaults to any vanilla HTML you don't control (like HTML rendered from Markdown, or pulled from a CMS).
10
+
By default, Tailwind removes all of the default browser styling from paragraphs, headings, lists and more. This ends up being really useful for building application UIs because you spend less time undoing user-agent styles, but when you _really are_ just trying to style some content that came from a rich-text editor in a CMS or a markdown file, it can be surprising and unintuitive.
11
+
12
+
We get lots of complaints about it actually, with people regularly asking us things like:
13
+
14
+
> Why is Tailwind removing the default styles on my `h1` elements? How do I disable this? What do you mean I lose all the other base styles too?
15
+
16
+
We hear you, but we're not convinced that simply disabling our base styles is what you really want. You don't want to have to remove annoying margins every time you use a `p` element in a piece of your dashboard UI. And I doubt you really want your blog posts to use the user-agent styles either — you want them to look _awesome_, not awful.
17
+
18
+
The `@tailwindcss/typography` plugin is our attempt to give you what you _actually_ want, without any of the downside of doing something stupid like disabling our base styles.
19
+
20
+
It adds a new `prose` class that you can slap on any block of vanilla HTML content and turn it into a beautiful, well-formatted document:
11
21
12
22
```html
13
-
<divclass="rich-text">
14
-
{{ markdown }}
15
-
</div>
23
+
<articleclass="prose">
24
+
<h1>Garlic bread with cheese: What the science tells us</h1>
25
+
<p>
26
+
For years parents have espoused the health benefits of eating garlic bread with cheese to their
27
+
children, with the food earning such an iconic status in our culture that kids will often dress
28
+
up as warm, cheesy loaf for Halloween.
29
+
</p>
30
+
<p>
31
+
But a recent study shows that the celebrated appetizer may be linked to a series of rabies cases
32
+
springing up around the country.
33
+
</p>
34
+
<!-- ... -->
35
+
</article>
16
36
```
17
37
18
-
What follows is just a big block of example content designed to dogfood the plugin.
38
+
For more information about how to use the plugin and the features it includes, [read the documentation](#).
19
39
20
40
---
21
41
22
-
It includes every sensible typographic element I could think of, like **bold text**, unordered lists, ordered lists, code blocks, block quotes, _and even italics_.
42
+
## What to expect from here on out
43
+
44
+
What follows from here is just a bunch of absolute nonsense I've written to dogfood the plugin itself. It includes every sensible typographic element I could think of, like **bold text**, unordered lists, ordered lists, code blocks, block quotes, _and even italics_.
23
45
24
46
It's important to cover all of these use cases for a few reasons:
25
47
26
48
1. We want everything to look good out of the box.
27
49
2. Really just the first reason, that's the whole point of the plugin.
28
-
3. Here's a third pretend reason though because three is a better number of items.
50
+
3. Here's a third pretend reason though a list with three items looks more realistic than a list with two items.
29
51
30
-
Now we're going to try out a header style.
52
+
Now we're going to try out another header style.
31
53
32
-
---
54
+
### Typography should be easy
33
55
34
-
## Typography should be easy
35
-
36
-
So that's a header for you — with any luck by the time I'm done writing this plugin that will look pretty reasonable.
56
+
So that's a header for you — with any luck if we've done our job correctly that will look pretty reasonable.
37
57
38
58
Something a wise person once told me about typography is:
39
59
@@ -58,102 +78,69 @@ Now I'm going to show you an example of an unordered list to make sure that look
58
78
- In this example we're keeping the items short.
59
79
- Later, we'll use longer, more complex list items.
60
80
61
-
It's also possible to have an ordered list with _lots_ of items in it. I think more than maybe 25 is probably not worth optimizing for but let's at least try 25 to see how it looks.
62
-
63
-
1. Here's the first item.
64
-
2. Now a second item has appeared.
65
-
3. A third item could also be in this list.
66
-
4. If we added fourth it would go here.
67
-
5. Five is the number of fingers most people have on each hand.
68
-
6. Six.
69
-
7. Seven is a great name for a baby.
70
-
8. Eight is the number of the black ball in pool.
71
-
9. Nine is one of my favorite numbers because I like 3 and 9 has three 3s.
72
-
10. This is the number my daughter normally stops counting at.
73
-
11. Add a seven before this one and you've got a great convenience store.
74
-
12. Monkeys.
75
-
13. Some elevators don't have this number, maybe most even?
76
-
14. Now we are entering the territory where numbers don't have any cool meaning.
77
-
15. Yep still holding true.
78
-
16. You could learn to drive now in many places.
79
-
17. At this point you should be pretty good at driving.
80
-
18. Not old enough to drink but old enough to play bingo.
81
-
19. Now you can booze up baby.
82
-
20. Still not old enough to drink in the US though.
83
-
21. But now you can.
84
-
22. You've probably gotten a DUI at this point.
85
-
23. And now you're in jail.
86
-
24. Still in jail.
87
-
25. Now you could rent a car if you hadn't got a DUI.
88
-
89
81
And that's the end of this section.
90
82
91
83
## What if we stack headings?
92
84
93
85
### We should make sure that looks good, too.
94
86
95
-
Sometimes you have headings directly underneath each other. In those cases you have to be careful not to use too much margin, because typically the space you need between a heading and a paragraph is more than you want between two headings.
87
+
Sometimes you have headings directly underneath each other. In those cases you have often have to undo the top margin on the second heading because it usually looks better for the headings to be closer together than a paragraph followed by a heading should be.
96
88
97
-
### Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
89
+
### When a heading comes after a paragraph...
98
90
99
91
When a heading comes after a paragraph, we need a bit more space, like I already mentioned above. Now let's see what a more complex list would look like.
100
92
101
93
-**I often do this thing where list items have headings.**
102
94
103
95
For some reason I think this looks cool which is unfortunate because it's pretty annoying to get the styles right.
104
96
105
-
I often have two or three paragraphs in these list items too, so the hard part is getting the spacing between the paragraphs, list item heading, and separate list items to all make sense.
106
-
107
-
Pretty tough honestly.
97
+
I often have two or three paragraphs in these list items too, so the hard part is getting the spacing between the paragraphs, list item heading, and separate list items to all make sense. Pretty tough honestly, you could make a strong argument that you just shouldn't write this way.
108
98
109
99
-**Since this is a list, I need at least two items.**
110
100
111
-
I explained what I'm doing already in the previous list item, but a list wouldn't be a list if it only had one item, and we really want this to look realistic.
112
-
113
-
That's why I've added this second list item so I actually have something to look at when writing the styles.
101
+
I explained what I'm doing already in the previous list item, but a list wouldn't be a list if it only had one item, and we really want this to look realistic. That's why I've added this second list item so I actually have something to look at when writing the styles.
114
102
115
103
-**It's not a bad idea to add a third item either.**
116
104
117
105
I think it probably would've been fine to just use two items but three is definitely not worse, and since I seem to be having no trouble making up arbitrary things to type, I might as well include it.
118
106
119
-
With any luck this will make it even easier for me to get the styles right.
120
-
121
107
After this sort of list I usually have a closing statement or paragraph, because it kinda looks weird jumping right to a heading.
122
108
123
109
## Code should look okay by default.
124
110
125
-
I think most people are going to use highlight.js or Prism or something if they want to style their code blocks but it wouldn't hurt to make them look _okay_ out of the box, even with no syntax highlighting.
111
+
I think most people are going to use [highlight.js](https://highlightjs.org/) or [Prism](https://prismjs.com/) or something if they want to style their code blocks but it wouldn't hurt to make them look _okay_ out of the box, even with no syntax highlighting.
126
112
127
-
Here's the Tailwind config file for this docs site:
113
+
Here's what a default `tailwind.config.js` file looks like at the time of writing:
128
114
129
115
```js
130
116
module.exports= {
117
+
purge: [],
131
118
theme: {
132
119
extend: {},
133
120
},
134
121
variants: {},
135
-
plugins: [require('../src/index.js')],
122
+
plugins: [],
136
123
}
137
124
```
138
125
139
126
Hopefully that looks good enough to you.
140
127
141
128
### What about nested lists?
142
129
143
-
Nested lists basically always look bad which is why editors like Medium don't even let you do it, but I guess since some of you goofballs are going to do it I have to carry the burden of at least making it work.
130
+
Nested lists basically always look bad which is why editors like Medium don't even let you do it, but I guess since some of you goofballs are going to do it we have to carry the burden of at least making it work.
144
131
145
132
1.**Nested lists are rarely a good idea.**
146
133
- You might feel like you are being really "organized" or something but you are just creating a gross shape on the screen that is hard to read.
147
134
- Nested navigation in UIs is a bad idea too, keep things as flat as possible.
148
135
- Nesting tons of folders in your source code is also not helpful.
149
136
2.**Since we need to have more items, here's another one.**
150
-
- I'm not sure if I'll bother styling more than two levels deep.
137
+
- I'm not sure if we'll bother styling more than two levels deep.
151
138
- Two is already too much, three is guaranteed to be a bad idea.
152
139
- If you nest four levels deep you belong in prison.
153
140
3.**Two items isn't really a list, three is good though.**
154
141
- Again please don't nest lists if you want people to actually read your content.
155
142
- Nobody wants to look at this.
156
-
- I'm upset that I even have to bother styling this.
143
+
- I'm upset that we even have to bother styling this.
157
144
158
145
The most annoying thing about lists in Markdown is that `<li>` elements aren't given a child `<p>` tag unless there are multiple paragraphs in the list item. That means I have to worry about styling that annoying situation too.
159
146
@@ -178,21 +165,23 @@ The most annoying thing about lists in Markdown is that `<li>` elements aren't g
178
165
179
166
And finally a sentence to close off this section.
180
167
181
-
## There are other `elements` we need to style
168
+
## There are other elements we need to style
182
169
183
-
I almost forgot to style links, like [this link to the Tailwind CSS website](https://tailwindcss.com). How should those look by default, blue I guess? I dunno.
170
+
I almost forgot to mention links, like [this link to the Tailwind CSS website](https://tailwindcss.com). We almost made them blue but that's so yesterday, so we went with dark gray, feels edgier.
184
171
185
172
We also need to make sure inline code looks good, like if I wanted to talk about `<span>` elements or tell you the good news about `@tailwindcss/typography`.
186
173
187
174
### Sometimes I even use `code` in headings
188
175
189
-
Even though it's probably a bad idea, and I tend to have a hard time making it look good.
176
+
Even though it's probably a bad idea, and historically I've had a hard time making it look good. This _"wrap the code blocks in tildes"_ trick works pretty well though really.
190
177
191
-
Another thing I've done in the past is make some codea link, like if I wanted to tell you about [`@tailwindcss/custom-forms`](https://github.com/tailwindcss/custom-forms), a useful plugin for making it easier to style form elements in your Tailwind projects.
178
+
Another thing I've done in the past is put a `code` tag inside of a link, like if I wanted to tell you about the [`tailwindcss/docs`](https://github.com/tailwindcss/docs) repository. I don't love that there is an underline below the tildes but it is absolutely not worth the madness it would require to avoid it.
192
179
193
180
#### We haven't used an `h4` yet
194
181
195
-
But now we have. Please don't use `h5` or `h6` in your content, Medium only supports two heading levels for a reason you animals.
182
+
But now we have. Please don't use `h5` or `h6` in your content, Medium only supports two heading levels for a reason you animals. I honestly considered using a `before` pseudo-element to scream at you if you use an `h5` or `h6`.
183
+
184
+
We don't style them at all out of the box because `h4` elements are already so small that they are the same size as the body copy. What are we supposed to do with an `h5`, make it _smaller_ than the body copy? No thanks.
196
185
197
186
### We still need to think about stacked headings though.
0 commit comments