Search

Base Styles

This page introduces the base styles defined in the lism-base layer.

Reset CSS

The Reset CSS is defined as the lism-base.reset layer.

Source code
/*
  方針:
    できるだけブラウザの標準スタイルに従いながら、レイアウト崩れを防止し、最低限のアクセシビリティの確保する。
    文書構造を壊して読みづらくなるようなスタイルリセットはしない。
    @layer で優先度を下げる。

  参考:
    https://gist.github.com/EllyLoel/4ff8a6472247e6dd2315fd4038926522
    https://keithjgrant.com/posts/2024/01/my-css-resets/
    https://www.joshwcomeau.com/css/custom-css-reset/
    https://piccalil.li/blog/a-modern-css-reset/
    https://codepen.io/argyleink/pen/KKvRORE
 */

@layer reset {
  *,
  ::before,
  ::after {
    /* box-sizing は 全要素に対して border-box で統一 */
    box-sizing: border-box;
  }

  /* margin は(dialog以外)全て 0 にリセットする (padding はリセットしない) */
  *:not(dialog) {
    margin: 0;
  }

  /* --------------------------------------------------
   Documents
  -------------------------------------------------- */
  html {
    /* iOSで横向きにした時のフォントサイズ自動調節をオフにする */
    -webkit-text-size-adjust: none;
    text-size-adjust: none;

    /* 文章の折り返し指定 🔗:https://ics.media/entry/240411/ */
    word-break: normal; /* 単語の分割はデフォルトに依存 */
    line-break: strict; /* 禁則処理を厳格に適用 */
    overflow-wrap: anywhere; /* 収まらない場合に折り返す */

    /* 要素はみ出しによる横スクロールの発生を防止. (overflow は 継承プロパティではないので両方記述) */
    overflow-x: clip;

    /* モーダルが開いている時はコンテンツをスクロールさせない */
    &:has(:modal[open]) {
      overflow: clip; /* sticky 要素がくずれないように clip */
    }
  }

  body {
    /* htmlから継承する */
    overflow: inherit;

    /* bodyの高さを最低限確保する (子要素でheight:100%が効くわけではない) */
    min-height: 100dvh;
  }

  /* --------------------------------------------------
   Texts
  -------------------------------------------------- */
  abbr[title] {
    /* Safar で アンダーラインが出ないので明示的に指定して統一する */
    text-decoration: underline;
    text-decoration-style: dotted;
  }

  pre {
    /* 水平スクロールできるようにする */
    overflow-x: auto;
  }

  /* クラスを持つリストのみスタイルをリセットする。(ブラウザ標準スタイルを利用できる余地を残す) */
  menu,
  :is(ul, ol)[class] {
    list-style: none;
    padding: 0;
  }

  /* --------------------------------------------------
   Medias
  -------------------------------------------------- */
  svg,
  img,
  video,
  audio,
  iframe,
  object,
  canvas {
    /* 隙間ができるのを防ぐ。( display はいじらない。) */
    vertical-align: middle;

    /* 親要素をはみ出さないようにする */
    max-inline-size: 100%;
  }

  img,
  video {
    /* img,video の縦横比を維持。(svg,iframe や audioは 高さがつぶれるので指定しない */
    block-size: auto;
  }

  iframe {
    border: none;
  }

  /* --------------------------------------------------
   Form Fields
  -------------------------------------------------- */
  input,
  button,
  textarea,
  select,
  ::file-selector-button {
    /* 基本要素のフォントとカラーを本文から継承 */
    font: inherit;
    color: inherit;

    /* iOSで入力時の拡大を防ぐ. ( button には必要ないが、フォーム全体のフォントサイズを揃えるために一括で適用する ) */
    font-size: max(16px, 1em);
  }

  fieldset {
    /* デフォルトの min-content によってコンテンツ( colsの大きい textarea など )がはみ出すのを防ぐ */
    min-inline-size: 0;
  }

  textarea {
    /* リサイズ方向を制限する. */
    resize: block;
    max-inline-size: 100%;
  }

  /* --------------------------------------------------
   cursor 初期セット
  -------------------------------------------------- */
  label[for],
  select,
  summary,
  [type='radio'],
  [type='checkbox'] {
    cursor: pointer;
  }

  button,
  [role='tab'],
  [role='button'],
  [role='option'],
  [type='button'],
  [type='reset'],
  [type='submit'],
  ::file-selector-button {
    cursor: pointer;

    /* ダブルタップ時のズームアクションを無効化 */
    touch-action: manipulation;
  }

  :disabled {
    cursor: not-allowed;
  }

  /* --------------------------------------------------
   その他
  -------------------------------------------------- */
  [hidden='until-found'] {
    /* 意図せず他の要素の上にかぶってしまうのを防ぐ (until-found は stacking context を生成する) */
    z-index: -1;
  }
}

The reset is designed to stay as close to browser defaults as possible, keeping only what is strictly necessary.

Loading only the Lism CSS reset.css

Import via JavaScript
import 'lism-css/reset.css';

Or alternatively:

Load via CDN
<link href="https://cdn.jsdelivr.net/npm/lism-css@0.22.2/dist/css/reset.css" rel="stylesheet" />

Base styles

In addition to the Reset CSS, the lism-base layer defines default base styles for HTML elements, making use of tokens defined on :root.

The styles are presented below, grouped by element type.

For details on the CSS variables (tokens) used in each style, refer to the Design Tokens page.

body

Basic settings for font, color, and text decoration are applied to body.

body {
--hl: var(--hl--base);
font-size: var(--fz--base);
font-family: var(--ff--base);
letter-spacing: var(--lts--base);
background-color: var(--base);
color: var(--text);
text-underline-offset: 0.125em;
tab-size: 4;
}

--hl is a variable that manages the half-leading (the spacing above and below a line). On body, --hl--base is set and inherited by child elements.

text-underline-offset adjusts the position of link underlines, and tab-size sets the display width of tab characters.

Line height for all elements

In Lism CSS, the following style is applied to all elements.

* {
line-height: calc(1em + var(--hl) * 2);
}

Unlike a typical declaration such as line-height: 1.6, this approach produces a fixed line spacing that does not depend on font size. The formula works by defining the half-leading amount first, then adding it above and below the cap height (approximately 1em).

Because line spacing doesn’t grow with font size, it unifies the “vertical rhythm” of your typography, letting you compose layouts with harmonious spacing from headings down to body text.

For more details, see Half-Leading (line-height).

Headings (h1–h6)

Font family, weight, and size are set for heading elements.

:is(h1, h2, h3, h4, h5, h6) {
font-family: var(--headings-ff, inherit);
font-weight: var(--headings-fw, var(--fw--bold));
}
h1 { font-size: var(--fz--3xl); }
h2 { font-size: var(--fz--2xl); }
h3 { font-size: var(--fz--xl); }
h4 { font-size: var(--fz--l); }
h5, h6 { font-size: var(--fz--m); }

By defining --headings-ff and --headings-fw, you can customize the font family and weight for all headings at once.

CSS variables for link color and underline are set on the a tag.

a {
color: var(--link-c, var(--link));
text-decoration: var(--link-td, underline);
}
VariableFallbackPurpose
--link-cvar(--link)Link text color
--link-tdunderlineText decoration type

Inline text elements

small {
--hl: var(--hl--s);
font-size: var(--fz--xs);
}
b, strong {
font-weight: var(--fw--bold);
}
sup, sub {
--hl: var(--hl--xs);
font-size: 80%;
}
code, kbd, var, samp {
font-family: var(--ff--mono);
letter-spacing: normal;
}

For small and sup/sub, --hl is set to a smaller value to adjust the line spacing to match the font size.

Blockquote and preformatted text

q, blockquote {
font-style: italic;
}
blockquote, pre {
background-color: var(--base-2);
padding: var(--s20);
}

q and blockquote are displayed in italic, while blockquote and pre get a simple background color and padding.

Other text elements

caption, figcaption {
font-size: var(--fz--s);
}

The font size of these elements is set slightly smaller by default.

Divider

hr {
border: none;
block-size: 0;
border-block-start: 1px solid var(--divider);
}

hr uses a fixed block-start direction and is set to the --divider color.

Lists (ul, ol)

:is(ul, ol):where(:not([class])) {
list-style: revert;
padding-inline-start: var(--list-ps, 1.75em);
}

While the Reset CSS strips list styles from elements that have a class, this rule automatically restores browser defaults for lists with no class at all.

A ul / ol decorated only with Property Classes (e.g. <ul class="-fz:l">) remains in the reset state. If you want to keep the list markers in that case, add set--revert explicitly.

<ul class="-fz:l set--revert">
<li>item 1</li>
<li>item 2</li>
</ul>
VariableFallbackPurpose
--list-ps1.75emList padding-inline-start

Definition lists (dl)

dt {
font-weight: var(--fw--bold);
}
dd + dt {
margin-block-start: var(--s20);
}

dt is displayed in bold, and spacing is added between consecutive dd + dt pairs to clearly separate entries.

Tables

The padding of td and th can be customized via --cells-p.

td, th {
padding: var(--cells-p, 0.625em 0.875em);
}
VariableFallbackPurpose
--cells-p0.625em 0.875emCell padding

Form elements

Consistent styles are applied to form controls.

input:not([type='range']), button, textarea, select, ::file-selector-button {
background-color: var(--controls-bgc, var(--base-2));
border: solid 1px var(--controls-bdc, var(--divider));
padding: var(--controls-p, 0.25em 0.5em);
}
VariableFallbackPurpose
--controls-bgcvar(--base-2)Background color
--controls-bdcvar(--divider)Border color
--controls-p0.25em 0.5emPadding

Border radius is left to the browser default. If you want a consistent rounding, apply border-radius directly to each selector in your theme.

Others

:disabled {
opacity: var(--o--pp);
}
:focus-visible {
outline-offset: var(--focus-offset, 0px);
}

Disabled elements receive an opacity of --o--pp (0.5), and :focus-visible allows the outline offset to be adjusted with --focus-offset.


Preview of basic HTML styles

The following is a preview of HTML elements with the base styles applied above.

Preview

View in full screen

Source code
/* --------------------------------------------------
  body
-------------------------------------------------- */
body {
  --hl: var(--hl--base);
  font-size: var(--fz--base);
  font-family: var(--ff--base);
  letter-spacing: var(--lts--base);
  background-color: var(--base);
  color: var(--text);

  text-underline-offset: 0.125em;
  tab-size: 4;
}

/* --------------------------------------------------
  line-height
-------------------------------------------------- */
* {
  line-height: calc(1em + var(--hl) * 2);
}

/* --------------------------------------------------
  Heading
-------------------------------------------------- */
:is(h1, h2, h3, h4, h5, h6) {
  font-family: var(--headings-ff, inherit);
  font-weight: var(--headings-fw, var(--fw--bold));
}
h1 {
  font-size: var(--fz--3xl);
}
h2 {
  font-size: var(--fz--2xl);
}
h3 {
  font-size: var(--fz--xl);
}
h4 {
  font-size: var(--fz--l);
}
h5,
h6 {
  font-size: var(--fz--m);
}

/* --------------------------------------------------
  texts
-------------------------------------------------- */
a {
  color: var(--link-c, var(--link));
  text-decoration: var(--link-td, underline);
}

small {
  --hl: var(--hl--s);
  font-size: var(--fz--xs);
}

b,
strong {
  font-weight: var(--fw--bold);
}

sup,
sub {
  --hl: var(--hl--xs);
  font-size: 80%;
}

code,
kbd,
var,
samp {
  font-family: var(--ff--mono);
  letter-spacing: normal;
}

:where(blockquote > p) + p {
  margin-block-start: var(--s10);
}

q,
blockquote {
  font-style: italic;
}

blockquote,
pre {
  background-color: var(--base-2);
  padding: var(--s20);
}

caption,
figcaption {
  font-size: var(--fz--s);
}

hr {
  border: none;
  block-size: 0;
  border-block-start: 1px solid var(--divider);
}

/* --------------------------------------------------
  list
-------------------------------------------------- */
// classを持たないリスト要素はブラウザ標準のスタイルを復活させる。
// Property Class だけの ul/ol など、明示的に戻したい場合は `.set--revert` を付与する(base/set/_revert.scss)。
:is(ul, ol):where(:not([class])) {
  list-style: revert;
  padding-inline-start: var(--list-ps, 1.75em);
}

dt {
  font-weight: var(--fw--bold);
}
dd + dt {
  margin-block-start: var(--s20);
}

/* --------------------------------------------------
  table
-------------------------------------------------- */
td,
th {
  padding: var(--cells-p, 0.625em 0.875em);
}

/* --------------------------------------------------
  Form fields
-------------------------------------------------- */
input:not([type='range']),
button,
textarea,
select,
::file-selector-button {
  // フォーム系コントロールの最低限の見た目(テーマ差し替えは --controls-*)
  background-color: var(--controls-bgc, var(--base-2));
  border: solid 1px var(--controls-bdc, var(--divider));
  padding: var(--controls-p, 0.25em 0.5em);
}

:disabled {
  opacity: var(--o--pp);
}

/* --------------------------------------------------
  フォーカス要素
-------------------------------------------------- */
:focus-visible {
  outline-offset: var(--focus-offset, 0px);
}

© Lism CSS. All rights reserved.