WebDev Bites: Spacer Component Demo

horizontal and vertical spacer elements

Demo

Components <v-s> and <h-s> are user-defined HTML elements that insert vertical and horizontal space where they are declared in the page flow. Their size can be supplied as element content or via the size attribute. Colors inherit from context or can be set with inline styles. Their purpose is to provide a meaningful and slightly abbreviated syntax for their alternatives: <div style="width: 20rem;"></div> 0.75rem
<h-s style="height:100%; background-color: orange;">15rem</h-s> 15rem <h-s size="10rem"></h-s> <v-s>80px</v-s> 80px <v-s size="60px" style="background-color: orange;"></v-s>

Interface

Tags & Aliases

RoleTags
Horizontal spacer <h-space>...</h-space>  |  short alias: <h-s>...</h-s>
Vertical spacer <v-space>...</v-space>  |  short alias: <v-s>...</v-s>

Size Input Precedence

  1. Attribute: <h-s size="20rem"></h-s>
  2. Inner text: <h-s>20rem</h-s>
  3. CSS var on host: <h-s style="--h-space-size: var(--gap-xl)"></h-s>
  4. Default: 1rem

Note: Unitless values are treated as rem (e.g., 22rem).

Attributes

ComponentAttributes
Common
  • size: CSS length for the gap (e.g., 12px, 1.5rem, 6ch, var(--gap)).
<h-space> / <h-s>
  • block: if present, renders as display:block (default inline-block).
  • thickness: optional visual height; default 0 (examples: 2px, 0.25rem).
<v-space> / <v-s>
  • inline: if present, renders as display:inline-block (default block).

CSS Custom Properties (host)

NamePurpose
--h-space-size Width of <h-space> / <h-s>.
--h-thickness Height (visual thickness) of <h-space> / <h-s> (default 0).
--v-space-size Height of <v-space> / <v-s>.

Styling & Behavior

JS Properties

Examples

<span>abc</span><h-s>20rem</h-s><span>123</span>
<h-s size="28rem" thickness="2px" style="background-color: orange;"></h-s>
<v-s>1.5rem</v-s>  Line 1 <v-s inline>0.75rem</v-s> Line 2
<h-s style="--h-thickness:2px; background-color: rgba(255,165,0,.5)">var(--gap-xl)</h-s>