Menu

On this page

Content

A content wrapper that provides typographic styles for common HTML elements.

npm install @vrembem/content
Copied!
SCSS
@use "@vrembem/content";
Copied!

Options

Content is built as a Sass module. Sass options are used to control CSS output, while design token CSS variables control the styling of the component. Below are the available configuration options.

Sass

Content comes with the following Sass configuration options that can be set using either the config module or Sass with clause methods.

SCSS
Unlock scroll
@use "@vrembem/content" with (
  $config: (
    // Controls whether module styles are output. This can be overridden on a per 
    // module basis using the `content-output-exceptions` config option.
    // @type boolean
    "content-output": true,

    // Modules to exclude from the output rule set in `content-output`
    // @type list
    "content-output-exceptions": (),

    // A map containing module names as keys and their preferred class selectors
    // @type map
    "content-classes": (
      "separator": "sep"
    ),

    // A prefix to apply to content class selectors. Provided value is automatically 
    // suffixed with a "-" character when applied.
    // @type string
    "content-prefix": "",

    // Used to output the heading styles and their font-size/line-height CSS 
    // variables. Should contain a key of the heading level to output and the 
    // value of a font-size and optional line-height (space separated).
    // @type map
    "content-headings": (
      "h1": 2.75em 1.1,
      "h2": 2em 1.25,
      "h3": 1.75em 1.3,
      "h4": 1.5em 1.35,
      "h5": 1.25em 1.4
    ),

    // Map modules to their preferred content selectors
    // @type map
    "content-selectors": (
      "h1": "> h1",
      "h2": "> h2",
      "h3": "> h3",
      "h4": "> h4",
      "h5": "> h5",
      "h6": "> h6",
      "link": ":not(div) > a",
      "list": "> ul, > ol",
      "code": ":not(pre) > code",
      "pre": "> pre",
      "blockquote": "> blockquote",
      "separator": "> hr"
    )
  )
);
Copied!

Design tokens

Content uses design token CSS variables in a reference and fallback pattern. Variables are referenced in the component's styles but are not directly defined; instead, they are provided with sensible fallbacks.

VariableFallback
--vb-content-foreground
Copied!
var(--vb-foreground)
Copied!
--vb-content-font-family
Copied!
inherit
Copied!
--vb-content-font-size
Copied!
inherit
Copied!
--vb-content-line-height
Copied!
inherit
Copied!
--vb-content-spacing
Copied!
--vb-headings-foreground
Copied!
--vb-headings-font-family
Copied!
inherit
Copied!
--vb-headings-font-weight
Copied!
--vb-headings-line-height
Copied!
inherit
Copied!
--vb-list-indent
Copied!
var(--vb-spacing-lg)
Copied!
--vb-list-spacing
Copied!
var(--vb-spacing-sm)
Copied!
--vb-code-background
Copied!
color-mix(in oklch, currentcolor 10%, transparent)
Copied!
--vb-code-foreground
Copied!
--vb-code-border
Copied!
var(--vb-border)
Copied!
--vb-code-border-radius
Copied!
var(--vb-border-radius)
Copied!
--vb-code-font-size
Copied!
var(--vb-font-size-sm)
Copied!
--vb-code-padding
Copied!
0.125rem 0.375rem
Copied!
--vb-pre-background
Copied!
--vb-pre-foreground
Copied!
--vb-pre-border
Copied!
none
Copied!
--vb-pre-border-radius
Copied!
var(--vb-border-radius)
Copied!
--vb-pre-padding
Copied!
var(--vb-spacing-md)
Copied!
--vb-pre-font-size
Copied!
var(--vb-font-size-sm)
Copied!
--vb-blockquote-background
Copied!
transparent
Copied!
--vb-blockquote-foreground
Copied!
currentcolor
Copied!
--vb-blockquote-border
Copied!
var(--vb-border)
Copied!
--vb-blockquote-border-radius
Copied!
var(--vb-border-radius)
Copied!
--vb-blockquote-padding
Copied!
var(--vb-spacing-md)
Copied!
--vb-blockquote-spacing
Copied!
var(--vb-spacing-md)
Copied!
--vb-separator-border-width
Copied!
var(--vb-border-width)
Copied!
--vb-separator-border-style
Copied!
var(--vb-border-style)
Copied!
--vb-separator-border-color
Copied!
var(--vb-border-color)
Copied!
--vb-arrow-size
Copied!
6px 4px
Copied!
--vb-arrow-color
Copied!
currentcolor
Copied!
--vb-arrow-radius
Copied!
2px
Copied!
--vb-loading-size
Copied!
1em
Copied!
--vb-loading-duration
Copied!
0.6s
Copied!
--vb-loading-border
Copied!
2px solid
Copied!
--vb-loading-color
Copied!
currentcolor
Copied!

Output

Content modules each have their own output styles. These are all output by default when the content package is loaded. There are two ways to control which modules are output using the content-output and content-output-exceptions configuration options.

content-outputboolean

Controls whether module styles are output. Specify exceptions using the content-output-exceptions config option.

@include config.set("content-output", false);
Copied!

@defaulttrue

content-output-exceptionslist

Modules listed in this configuration are exceptions to the value set in content-output. If content-output is true, modules listed will not be output. If content-output is false, modules listed will be output.

@include config.set("content-output-exceptions", (
  "content", "headings"
));
Copied!

@default()

Example

Use the content-output configuration to toggle output for all modules. Add exceptions to the content-output-exceptions list to override the output option for specific modules.

SCSS
// Import the config module
@use "@vrembem/core/config";

// Disable the output of specific modules
@include config.set("content-output-exceptions", (
  "blockquote",
  "code",
  "list",
  "pre"
));

// Disable the output of all modules except for "content" and "headings"
@include config.set((
  "content-output": false
  "content-output-exceptions": (
    "content",
    "headings"
  )
));
Copied!

Basic usage

Selector:.content

Variables

The content component provides the .content wrapper class for styling blocks of HTML elements. It also makes available a number of element classes that can be applied directly when those styles are needed outside the context of a content wrapper.

Heading

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam ipsum ex, elementum ac dignissim quis, tempus non eros. Sed risus neque, tempus eget orci vel, sagittis lobortis ipsum.

  • One
  • Two
  • Three
HTML
<!-- Using the content wrapper -->
<div class="content">
  <h1>Heading</h1>
  <p>...</p>
  <ul>
    <li>...</li>
  </ul>
</div>

<!-- Using individual element classes -->
<h1 class="h1">...</h1>
<p>...</p>
<ul class="list">
  <li>...</li>
</ul>
Copied!

The entire output of the content component is placed in @layer base. This allows all components and utilities to override the styles set by content and it's member modules.

To customize the class selectors used by modules, map the module name to your preferred class selector in the content-classes config option.

content-classesmap

A map containing module names as keys and their preferred class selectors as values. For example, to use the class .props instead of .content, set the following value:

@include config.set("content-classes", (
  "content": "pros"
));
Copied!

@default("separator": "sep")

Provide a prefix to all content classes using the content-prefix config option.

content-prefixmap

A prefix to apply to content class selectors. Provided value is automatically suffixed with a "-" character when applied.

@include config.set("content-prefix", "vb");
// Result: .content > .vb-content
Copied!

@default""

The content module only applies styles to its direct children using the > child combinator. This is to allow nesting of other components within a content block and avoid style conflicts. Module specific content selectors are controlled using the content-selectors variable map.

content-selectorsmap

Map modules to content selectors. This configuration is used when a module runs the content.selector() function. The keys of the map should represent a content module name and it's value the selector to be used within the .content context.

@include config.set("content-selectors", (
  "h1": "> h1",
  "h2": "> h2",
  "h3": "> h3",
  // ...
));
Copied!

@default

"content-selectors": (
  "h1": "> h1",
  "h2": "> h2",
  "h3": "> h3",
  "h4": "> h4",
  "h5": "> h5",
  "h6": "> h6",
  "link": ":not(div) > a",
  "list": "> ul, > ol",
  "code": ":not(pre) > code",
  "pre": "> pre",
  "blockquote": "> blockquote",
  "separator": "> hr"
)
Copied!

Modules

Below is a list of each content module, their class selectors, design token CSS variables, and intended usage. Modules that reference CSS variables are provided with sensible fallbacks.

headings

Selector:.h1 - .h6

Variables

Section headings in HTML are represented by the <h1> through <h6> elements. This module helps style these elements by providing the .h1-.h6 CSS classes.

Heading h1

Heading h2

Heading h3

Heading h4

Heading h5
Heading h6
HTML
<h1 class="h1">...</h1>
<h2 class="h2">...</h2>
<h3 class="h3">...</h3>
<h4 class="h4">...</h4>
<h5 class="h5">...</h5>
<h6 class="h6">...</h6>
Copied!

Headings output and scale is controlled by the content-headings configuration option.

content-headingsmap

Used to output the heading styles and their font-size/line-height CSS variables. This map should contain a key of the heading level to output and the value of a font-size and optional line-height (space separated).

@include config.set("content-headings", (
  "h1": 3em 1.2,
  "h2": 2em 1.6,
  // ...
));
Copied!

@default

"content-headings": (
  "h1": 2.75em,
  "h2": 2em,
  "h3": 1.75em,
  "h4": 1.5em,
  "h5": 1.25em,
  "h6": 1em
)
Copied!

Selector:.link

Variables

A link—usually represented by an anchor (<a>) HTML element with href attribute—creates the styles for a hyperlink to anything a URL can address. This module helps style these elements by providing the .link CSS class.

HTML
<a href="#" class="link">Link</a>
Copied!

list

Selector:.list

Variables

The list module helps add styles to unordered (<ul>) and ordered (<ol>) lists by providing the .list class.

  • One
  • Two

    • One
    • Two
    • Three
  • Three
  1. One
  2. Two

    1. One
    2. Two
    3. Three
  3. Three
HTML
<ul class="list">
  <li>One</li>
  <li>Two
    <ul>
      <li>One</li>
      <li>Two</li>
      <li>Three</li>
    </ul>
  </li>
  <li>Three</li>
</ul>

<ol class="list">
  ...
</ol>
Copied!

code

Selector:.code

Variables

The HTML code element displays its contents styled in a fashion intended to indicate that the text is a short fragment of computer code. This module helps style these elements by providing the .code CSS class.

a = 17
HTML
<code class="code">a = 17</code>
Copied!

pre

Selector:.pre

Variables

This module helps style the HTML <pre> element by providing the .pre CSS class. Whitespace inside this element is displayed as written.

HTML
<pre class="pre">
-----------------------------
| I'm an expert in my field |
-----------------------------
     \   ^__^
      \  (oo)\_______
         (__)\       )\/\
             ||----w |
             ||     ||
</pre>
Copied!

blockquote

Selector:.blockquote

Variables

The HTML blockquote element is used for marking up extended quotations. This module helps style these elements by providing the .blockquote CSS class.

"All that is gold does not glitter, Not all those who wander are lost; The old that is strong does not wither, Deep roots are not reached by the frost."

Appears in "The Fellowship of the Ring" by J.R.R. Tolkien

HTML
<blockquote class="blockquote" cite="...">
  <p>...</p>
  <footer>
    ...
    <cite>...</cite>
  </footer>
</blockquote>
Copied!

separator

Selector:.sep

Variables

This module adds the .sep CSS classes which visually renders a horizontal separator. This is most commonly applied to an <hr> HTML element but can also be applied to a more generic <span> or <div> depending on the semantic context.


HTML
<hr class="sep" />
Copied!

arrow

Selector:.arrow

Variables

The arrow (caret) module provides classes for directional triangles drawn with CSS. These are typically applied to <span> elements and used along side other components as direction indicators.

HTML
<span class="arrow"></span>
<span class="arrow-up"></span>
<span class="arrow-left"></span>
<span class="arrow-right"></span>
Copied!

Arrows are great for buttons or menu items to visually indicate when it reveals toggle-able content such as popovers or dropdowns.

HTML
<button class="button">
  <span>Button</span>
  <span class="arrow"></span>
</button>
Copied!

loading-spinner

Selector:.loading-spinner

Variables

The loading-spinner module provides the .loading-spinner CSS class. A loading spinner is a visual indicator for when a process or action is taking place such as a loading state.

Loading text here...
HTML
<span class="loading-spinner"></span>
Copied!

sr-only

Selector:.sr-only

This module provides an accessibility class for rendering content meant only for screen readers. This keeps the content accessible in the DOM for screen readers while hiding it visually from all other users.

The following content is for screen readers only: Hello, screen readers!

HTML
<p>
  The following content is for screen readers only:
  <span class="sr-only">Hello, screen readers!</span>
</p>
Copied!