HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
# bettertext.css
[![npm version](https://badge.fury.io/js/bettertext.css.svg)](http://badge.fury.io/js/bettertext.css) [![bower version](https://badge.fury.io/bo/bettertext.css.svg)](http://badge.fury.io/bo/bettertext.css)
Improved default typography styles for naked HTML (without any classnames) and Markdown-generated content. [Demo page](https://paulradzkov.github.io/bettertext.css/)
## Install
`npm install bettertext.css --save-dev`
`bower install bettertext.css --save`
or use compiled version from CDN
`https://unpkg.com/bettertext.css@latest/bettertext.css`
`https://unpkg.com/bettertext.css@latest/bettertext.min.css`
`https://unpkg.com/bettertext.css@latest/bettertext.min.css.map`
## Usage in HTML
Insert bettertext.css after [normalize.css](https://github.com/necolas/normalize.css) and after your `@font-face` declaration.
Or include bettertext.less into your project styles.
## Default values
Component has global mixin with settings named `.bettertext-settings();` and global variable `bettertext` which contains all the code.
Default settings:
```less
.bettertext-settings() {
//settings
@fz: 16px; // default font-size in px
@fz-small: 0.8em; // smaller font-size (em)
@rythm: 24px; // vertical rythm = line-height in pixels
@linel: 50rem; // max-width for text (em or rem)
@font-body: sans-serif; // body
@font-headers: sans-serif; // headers
@font-code: monospace, monospace; // code (duplication is intentional)
@scale1: 1.125; // header size multiplier for small screens
@scale2: 1.250; // header size multiplier for large screens
@section-pad: 5vw; // padding for article and section
@bettertext-breakpoint: ~"(min-width: 768px)";
//calculations
// ...
}
```
## Usage in LESS
Running with default parameters:
```less
@import (less) "node_modules/bettertext.css/bettertext.less";
```
Setting up basic parameters:
```less
@import (less) "node_modules/bettertext.css/bettertext.less";
.bettertext-settings() {
//settings
@fz: 16px; // default font-size
@font-body: 'Arial', sans-serif; // body
@font-headers: 'Georgia', serif; // headers
@bettertext-breakpoint: ~"(min-width: 50em)"; // large screens starts from that value
}
```
Deep customization: you able to redefine any formula in calculation section inside `bettertext-settings` mixin.
```less
@import (less) "node_modules/bettertext.css/bettertext.less";
.bettertext-settings() {
//settings
@fz: 16px; // default font-size
@font-body: 'Arial', sans-serif; // body
@font-headers: 'Georgia', serif; // headers
@bettertext-breakpoint: ~"(min-width: 50em)"; // large screens starts from that value
//redefining header margin-top
@h1-mt: 3em;
@h2-mt: 2.5em;
@h3-mt: 2em;
@h4-mt: 1.5em;
@h5-mt: unit((2 * @lh * @fz / @h5-fz), em);
@h6-mt: unit((2 * @lh * @fz / @h6-fz), em);
}
```
## Customizing without LESS
If you are not using LESS on your project you can fork and customize bettertext.css on [codepen](https://codepen.io/paulradzkov/pen/Mygdrb): adjust settings with your parameters, test with your HTML or Markdown, press "View Compiled" and grab compiled CSS.
<section>
<h1>This is section block</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Numquam sit asperiores iure! Molestiae beatae vel eligendi at, libero numquam doloremque. Reiciendis omnis eveniet veniam laudantium nisi maxime in aperiam velit.</p>
</section>
<section>
<h1>Second section block</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Numquam sit asperiores iure! Molestiae beatae vel eligendi at, libero numquam doloremque. Reiciendis omnis eveniet veniam laudantium nisi maxime in aperiam velit.</p>
</section>
<article>
<header>
<h1>This is article block</h1>
</header>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Numquam sit asperiores iure! Molestiae beatae vel eligendi at, libero numquam doloremque. Reiciendis omnis eveniet veniam laudantium nisi maxime in aperiam velit.</p>
<section>
<h2>This is section inside article</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Numquam sit asperiores iure! Molestiae beatae vel eligendi at, libero numquam doloremque. Reiciendis omnis eveniet veniam laudantium nisi maxime in aperiam velit.</p>
</section>
<section>
<h2>This is second section inside article</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Numquam sit asperiores iure! Molestiae beatae vel eligendi at, libero numquam doloremque. Reiciendis omnis eveniet veniam laudantium nisi maxime in aperiam velit.</p>
</section>
</article>
/*! bettertext.css v2.0.4 | MIT License | github.com/paulradzkov/bettertext.css */
.bettertext-settings() {
//settings
@fz: 16px; // default font-size in pixels
@rythm: 24px; // vertical rythm = line-height in pixels
@fz-small: 12px; // smaller font-size (px)
@linel: 50rem; // max-width for text (em or rem)
@font-body: sans-serif; // body
@font-headers: sans-serif; // headers
@font-code: monospace, monospace; // code (duplication is intentional)
@scale1: 1.125; // header size multiplier for small screens
@scale2: 1.250; // header size multiplier for large screens
// margins for body, articles and sections
@space-around: ~"calc(24px + 4vh) calc(10px + 4vw)";
// breakpoint to switch from 'mobile' to 'desktop'
@bettertext-breakpoint: ~"(min-width: 768px)";
}
.bettertext-calculations() {
//calculations
// you almost never need to edit below
// one rem is 16px by default
@onerem: 16px;
// base font-size in ems
@fz-ems: unit(((round( @onerem)) / @fz), em);
// unitless line-height
@lh: unit((@rythm / @fz));
// margins for paragraphs, lists and other tags
@m-default: unit(@lh, em);
// small font-size in ems
@fz-small-ems: unit(((round( @fz-small)) / @fz), em);
//headers size calculations for small screens
@h1-fz: unit(((round( @fz * pow(@scale1, 4))) / @fz), em);
@h2-fz: unit(((round( @fz * pow(@scale1, 3))) / @fz), em);
@h3-fz: unit(((round( @fz * pow(@scale1, 2))) / @fz), em);
@h4-fz: unit(((round( @fz * pow(@scale1, 1))) / @fz), em);
@h5-fz: unit(((round( @fz * pow(@scale1, 0))) / @fz), em);
@h6-fz: @fz-small-ems;
//headers size calculations for large screens
@h1-l-fz: unit(((round( @fz * pow(@scale2, 4))) / @fz), em);
@h2-l-fz: unit(((round( @fz * pow(@scale2, 3))) / @fz), em);
@h3-l-fz: unit(((round( @fz * pow(@scale2, 2))) / @fz), em);
@h4-l-fz: unit(((round( @fz * pow(@scale2, 1))) / @fz), em);
//headers lihe-height
@h1-lh: 1.1;
@h2-lh: 1.2;
@h3-lh: 1.3;
@h4-lh: 1.4;
@h5-lh: unit((@rythm / @fz));
@h6-lh: unit((@rythm / @fz-small));
//headers margin-top
@h1-mt: unit((@lh / @h1-fz * 3.5), em);
@h2-mt: unit((@lh / @h2-fz * 3), em);
@h3-mt: unit((@lh / @h3-fz * 2.5), em);
@h4-mt: unit((@lh / @h4-fz * 2), em);
@h5-mt: unit((@lh / @h5-fz * 1.5), em);
@h6-mt: unit((@lh / @h6-fz * 1), em);
//headers margin-top for large screens
@h1-l-mt: unit((@lh / @h1-l-fz * 5), em);
@h2-l-mt: unit((@lh / @h2-l-fz * 4), em);
@h3-l-mt: unit((@lh / @h3-l-fz * 3), em);
@h4-l-mt: unit((@lh / @h4-l-fz * 2), em);
//headers margin-bottom
@h1-mb: unit((@lh / @h1-fz), em);
@h2-mb: unit((@lh / @h2-fz), em);
@h3-mb: unit((@lh / @h3-fz), em);
@h4-mb: unit((@lh / @h4-fz), em);
@h5-mb: unit((@lh / @h5-fz), em);
@h6-mb: 0;
//headers margin-bottom for large screens
@h1-l-mb: unit((@lh / @h1-l-fz), em);
@h2-l-mb: unit((@lh / @h2-l-fz), em);
@h3-l-mb: unit((@lh / @h3-l-fz), em);
@h4-l-mb: unit((@lh / @h4-l-fz), em);
//double headers margin-top
@h1h2-mt: unit( @h2-lh ,em);
@h2h3-mt: unit( @h3-lh ,em);
@h3h4-mt: unit( @h4-lh ,em);
@h4h5-mt: unit((@lh / @h5-fz), em);
@h5h6-mt: unit((@lh / @h6-fz), em);
}
@bettertext: {
.bettertext-settings();
.bettertext-calculations();
body {
font-family: @font-body;
font-size: @fz-ems;
line-height: @lh;
}
body:not([class]),
article:not([class]),
section:not([class]) {
margin: @space-around;
article:not([class]),
section:not([class]) {
margin-left: 0;
margin-right: 0;
}
}
p {
margin: 0 0 @m-default;
max-width: @linel;
}
/* minimum paragraph width when floating http://css-tricks.com/minimum-paragraph-widths/ */
p:before,
ol:not([class]):before,
ul:not([class]):before {
content: '';
display: block;
width: 10em;
overflow: hidden;
}
li p:before {
content: none;
}
h1, h2, h3, h4, h5, h6 {
font-family: @font-headers;
font-weight: bolder;
}
h1 {
font-size: @h1-fz;
line-height: @h1-lh;
margin: @h1-mt 0 @h1-mb;
}
h2 {
font-size: @h2-fz;
line-height: @h2-lh;
margin: @h2-mt 0 @h2-mb;
}
h3 {
font-size: @h3-fz;
line-height: @h3-lh;
margin: @h3-mt 0 @h3-mb;
}
h4 {
font-size: @h4-fz;
line-height: @h4-lh;
margin: @h4-mt 0 @h4-mb;
}
h5 {
font-size: @h5-fz;
line-height: @h5-lh;
margin: @h5-mt 0 @h5-mb;
}
h6 {
font-size: @h6-fz;
line-height: @h6-lh;
margin: @h6-mt 0 @h6-mb;
text-transform: uppercase;
letter-spacing: 0.05em;
}
// do not create breakpoint and override if scale is not changing
& when not (@scale1 = @scale2) {
@media @bettertext-breakpoint {
h1 {
font-size: @h1-l-fz;
margin-top: @h1-l-mt;
margin-bottom: @h1-l-mb;
}
h2 {
font-size: @h2-l-fz;
margin-top: @h2-l-mt;
margin-bottom: @h2-l-mb;
}
h3 {
font-size: @h3-l-fz;
margin-top: @h3-l-mt;
margin-bottom: @h3-l-mb;
}
h4 {
font-size: @h4-l-fz;
margin-top: @h4-l-mt;
margin-bottom: @h4-l-mb;
}
}
}
h1:first-child,
h2:first-child,
h3:first-child,
h4:first-child,
h5:first-child,
h6:first-child {
margin-top: 0;
}
/* double headers */
h1 + h2 {
margin-top: @h1h2-mt;
}
h2 + h3 {
margin-top: @h2h3-mt;
}
h3 + h4 {
margin-top: @h3h4-mt;
}
h4 + h5 {
margin-top: @h4h5-mt;
}
h5 + h6 {
margin-top: @h5h6-mt;
}
/* lists */
/* lists without classes */
// 1) force reflow to fix bullet overlapping.
// See https://git.io/vHyUo for details.
ul:not([class]),
ol:not([class]) {
margin: 0 0 @m-default;
max-width: calc(@linel - 2.5em);
padding-left: 0;
padding-right: 2.5em;
ul,
ol {
margin-bottom: 0;
}
li {
transform: translateX(2.5em);
animation: fixlists 1s; // 1)
}
}
@keyframes fixlists {
0% { text-indent: -0.001em;}
100% { text-indent: 0;}
}
/* images */
img {
max-width: 100%;
height: auto;
vertical-align: bottom;
}
p img:not(:only-child) {
vertical-align: baseline;
}
figure:not([class]) {
margin: (@m-default * 2) 0;
& > p {
max-width: (@linel * 0.75);
font-size: @fz-small-ems;
margin: 0.5em 0 0;
}
}
figcaption {
max-width: (@linel * 0.75);
font-size: @fz-small-ems;
margin: 0.5em 0 (@m-default * 2);
& > p {
margin: 0.5em 0 0;
}
}
/* blockquotes */
blockquote {
max-width: calc(@linel - 5em);
margin: 0 0 (@m-default);
padding: (@m-default) 2.5em;
& > p:last-child {
margin-bottom: 0;
}
& > footer,
& > cite {
display: block;
font-size: @fz-small-ems;
}
}
/* code */
pre {
margin: (@m-default) 0;
white-space: pre-wrap;
}
p code {
line-break: loose;
overflow-wrap: break-word;
}
/* tables */
table:not([class]) {
margin-top: (@m-default * 2);
margin-bottom: (@m-default * 2);
border-collapse: separate;
border-spacing: 0;
caption {
text-align: left;
font-size: @fz-small-ems;
margin-bottom: 0.625em;
}
td, th {
padding: 0.5em 1em;
text-align: left;
vertical-align: top;
border-style: solid;
border-color: rgba(0,0,0,0.1);
border-width: 0 0 1px;
}
thead {
td, th {
vertical-align: bottom;
border-bottom-width: 2px;
}
}
}
/* definition lists */
dl:not([class]) {
max-width: @linel;
margin: 0 0 @m-default;
dt:not([class]) {
font-weight: bolder;
}
dd:not([class]) {
margin: 0 0 @m-default;
}
}
/* other tags */
hr:not([class]) {
border: 0;
border-bottom: 1px solid;
margin: @m-default 0;
max-width: @linel;
opacity: .1;
}
abbr {
letter-spacing: .05em;
margin-right: -.05em;
}
strong, b, dt {
font-weight: bolder;
}
code,
kbd,
pre,
samp {
font-family: @font-code;
font-size: 1em;
}
};
@bettertext();
Also see: Tab Triggers