Style the documents

1. Remove default style

options: html-style:nil

2. Use a CSS reset

Org tangles all the following sections into reset.css.

html_head: <link rel="stylesheet" type="text/css" href="reset.css" />

Historically the main goal of a CSS reset was to ensure consistency between browsers. But in recent times the differences have drastically decreased and we might want to keep some styling like font-style: italic for <em> elements.

From CSS Reset and A Modern CSS Reset.

2.0.1. Use a more intuitive box-sizing model

*,
*::after,
*::before {
    box-sizing: border-box;
}

2.0.2. Add accessible line height

body {
    line-height: 1.5;
}

2.0.3. Improve text rendering

body {
    -webkit-font-smoothing: antialiased;
}

2.0.4. Improve media defaults

canvas, img, picture, svg, video {
    display: block;
    max-width: 100%;
}

2.0.5. Inherit fonts for form controls

button, input, select, textarea {
    font: inherit;
}

2.0.6. Avoid text overflows

h1, h2, h3, h4, h5, h6, p {
    overflow-wrap: break-word;
}

2.0.7. Improve line wrapping

p {
    text-wrap: pretty;
}
h1, h2, h3, h4, h5, h6 {
    text-wrap: balance;
}

2.0.8. Create a root static context

#__next, #root {
    isolation: isolate;
}

3. Define a custom stylesheet

Uses the html_head metadata to set the stylesheet.

html_head: <link rel="stylesheet" type="text/css" href="stylesheet.css" />

Tangle the stylesheet as stylesheet.css.

<<variables>>

<<body>>
<<code>>
<<grid>>
<<headings>>
<<links>>
<<pre>>

3.1. Set global variables

:root {
    <<border>>
    <<color>>
    <<font-family>>
}

3.1.1. Color

--color: #cfbcba;
--color-background: #0f0e06;

--color-doc: #5f9f6f;
--color-function: #3dbbb0;
--color-link:  #c48702;
--color-string: #f06a3f;
--color-variable: #6fafff;

--color-org-1: #64aa0f;
--color-org-2: #ef656a;
--color-org-3: #3dbbb0;
--color-org-4: #df8f6f;
--color-org-meta: #887c8a;

3.1.2. Font family

--font-mono: ui-monospace, "Menlo", monospace;
--font-family: var(--font-mono);

--font-size-small: 0.875rem;
--font-size-base: 16px;
--font-size-large: 1.25rem;

--text-size-6xl: 2.75rem;
--text-size-5xl: 2.25rem; /* Desktop h1 */
--text-size-4xl: 1.75rem; /* Mobile h1, desktop h2 */
--text-size-3xl: 1.5rem; /* Mobile h2 */
--text-size-2xl: 1.25rem;
--text-size-xl: 1.125rem;

--font-weight-light: 300;
--font-weight-regular: 400;
--font-weight-semi-bold: 600;
--font-weight-bold: 700;

--font-line-height: 1.5;
--font-line-height-heading: 1.2;

3.1.3. Border

--border-radius-s: 4px;
--border-radius-m: 8px;
--border-radius-l: 16px;

--border-width-s: 1px;
--border-width-m: 2px;
--border-width-l: 4px;

3.2. Use grid layout

.layout {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-areas:
        "header"
        "toc"
        "content";
}

@media only screen and (min-width: 48rem) {
    .layout {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        grid-template-areas:
            "header header header"
            "content content toc";
    }
}

header {
    grid-area: header;
}

.content {
    grid-area: content;
}

.toc {
    grid-area: toc;
}

3.3. Set code styling to match my editor

code {
    font-weight: bold;
}

.src {
    border: 1px solid var(--color);
    background-color: var(--color-background);
    color: var(--color);
    padding: var(--border-radius-m);
}

3.4. Prevent preformatted text overflowing its box

pre {
    overflow-x: auto;
}

3.5. Set body

body {
    background-color: var(--color-background);
    color: var(--color);
    font-family: var(--font-family);
    font-size: var(--font-size-base);
}

3.6. Set links

a {
    color: var(--color-link);
}

3.7. Set headings

h1 {
    color: var(--color-org-1);
    font-size: var(--text-size-4xl);
}
h2 {
    color: var(--color-org-2);
    font-size: var(--text-size-3xl);
}
h3 {
    color: var(--color-org-3);
    font-size: var(--text-size-2xl);
}
h4 {
    color: var(--color-org-4);
    font-size: var(--text-size-xl);
}

@media only screen and (min-width: 48rem) {
    h1 {
        font-size: var(--text-size-5xl);
    }
    h2 {
        font-size: var(--text-size-4xl);
    }
    h3 {
        font-size: var(--text-size-3xl);
    }
    h4 {
        font-size: var(--text-size-2xl);
    }
}