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; /* 収まらない場合に折り返す */

    /* デフォルトの 8 はでかすぎる */
    tab-size: 4;

    /* 要素はみ出しによる横スクロールの発生を防止. (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.css is designed to follow browser default styles as closely as possible.

It is intentionally minimal, containing 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.16.0/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.

Here, the styles applied to each element are introduced by group.

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: var(--under-offset, 0.125em);
}

--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 can be overridden with the --under-offset variable.

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 achieves a fixed line spacing that is independent of font size. The formula works by defining the half-leading amount first, then adding it above and below the cap height (approximately 1em).

Because the line spacing does not grow excessively as font size increases, it helps unify the “vertical rhythm” in typography, allowing you to compose layouts with harmonious spacing from headings 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);
text-decoration-thickness: var(--link-td-thickness, auto);
text-decoration-color: var(--link-td-color, currentColor);
}
VariableFallbackPurpose
--link-cvar(--link)Link text color
--link-tdunderlineText decoration type
--link-td-thicknessautoUnderline thickness
--link-td-colorcurrentColorUnderline color

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);
}

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

Blockquote

blockquote {
background-color: var(--base-2);
padding: var(--s30);
}

A simple background color and padding are applied to blockquote.

Other text elements

legend, 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-px-s, 1.75em);
}

While the Reset CSS removes list styles from elements with a class, this rule automatically restores the browser default list style for lists that have 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-px-s1.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

Table cell styles can be customized with CSS variables.

table {
--td-c: inherit;
--td-bgc: transparent;
--td-p: var(--s10);
--td-min-sz: initial;
}
td {
color: var(--td-c);
background-color: var(--td-bgc);
padding: var(--td-p);
min-inline-size: var(--td-min-sz);
}
th {
color: var(--th-c, var(--td-c));
background-color: var(--th-bgc, var(--td-bgc));
padding: var(--th-p, var(--td-p));
min-inline-size: var(--th-min-sz, var(--td-min-sz));
}
VariableFallbackPurpose
--td-cinheritCell text color
--td-bgctransparentCell background color
--td-pvar(--s10)Cell padding
--td-min-szinitialCell minimum width
--th-cvar(--td-c)Header cell text color
--th-bgcvar(--td-bgc)Header cell background color
--th-pvar(--td-p)Header cell padding
--th-min-szvar(--td-min-sz)Header cell minimum width

Since th uses the td variables as fallbacks, setting --td-* on table also affects th. To override th individually, use --th-*.

Form elements

Consistent styles are applied to form controls.

input, 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, var(--s5) var(--s10));
border-radius: var(--controls-bdrs, var(--bdrs--10));
}
VariableFallbackPurpose
--controls-bgcvar(--base-2)Background color
--controls-bdcvar(--divider)Border color
--controls-pvar(--s5) var(--s10)Padding
--controls-bdrsvar(--bdrs--10)Border radius

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: var(--under-offset, 0.125em);
}

/* --------------------------------------------------
  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);
  text-decoration-thickness: var(--link-td-thickness, auto);
  text-decoration-color: var(--link-td-color, currentColor);
}

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);
}

blockquote {
  background-color: var(--base-2);
  padding: var(--s30);
}

legend,
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-px-s, 1.75em);
}

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

/* --------------------------------------------------
  table
-------------------------------------------------- */
table {
  --td-c: inherit;
  --td-bgc: transparent;
  --td-p: var(--s10);
  --td-min-sz: initial;
}
td {
  color: var(--td-c);
  background-color: var(--td-bgc);
  padding: var(--td-p);
  min-inline-size: var(--td-min-sz);
}
th {
  // デフォルト: tdと同じスタイル
  color: var(--th-c, var(--td-c));
  background-color: var(--th-bgc, var(--td-bgc));
  padding: var(--th-p, var(--td-p));
  min-inline-size: var(--th-min-sz, var(--td-min-sz));
}

/* --------------------------------------------------
  Form fields
-------------------------------------------------- */
input,
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, var(--s5) var(--s10));
  border-radius: var(--controls-bdrs, var(--bdrs--10));
}

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

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

© Lism CSS. All rights reserved.