ナビゲーション

v2.1.0
質感

テクスチャ

サーフェスにドット、グリッド、斜線、交差斜線、チェック柄を描きます。

このページの内容

テクスチャは、サーフェス全体に繰り返し描く模様です。コンテンツがなくても領域の用途や状態を伝える必要がある場合は、任意の要素に .texture を指定します。模様は控えめな単色の背景画像なので、要素にもともとある背景色をそのまま使えます。たとえば、くぼみの見た目を保ったままドットを重ねられます。

テクスチャ

<div class="well texture flex items-center justify-center h(160)">  <button type="button" class="btn">Publish</button></div>
<div className="well texture flex items-center justify-center h(160)">  <button type="button" className="btn">Publish</button></div>
<div class="well texture flex items-center justify-center h(160)">  <button type="button" class="btn">Publish</button></div>
<template>  <div class="well texture flex items-center justify-center h(160)">    <button type="button" class="btn">Publish</button>  </div></template>

#パターン

パターンは 5 種類あり、それぞれが領域の用途や状態を示します。見た目の好みよりも、伝えたい意味を基準に選びます。たとえば、別々の場所で斜線を見たユーザーが、どちらも同じ意味だと判断できるようにします。

パターン

<div class="auto-grid auto-grid-fit" style="--auto-grid-min: 6rem">  <figure class="m(0) flex flex-col gap-xs">    <div class="well texture h(96)"></div>    <figcaption class="text-xs fg-text-muted">Dots</figcaption>  </figure>  <figure class="m(0) flex flex-col gap-xs">    <div class="well texture texture-grid h(96)"></div>    <figcaption class="text-xs fg-text-muted">Grid</figcaption>  </figure>  <figure class="m(0) flex flex-col gap-xs">    <div class="well texture texture-stripes h(96)"></div>    <figcaption class="text-xs fg-text-muted">Stripes</figcaption>  </figure>  <figure class="m(0) flex flex-col gap-xs">    <div class="well texture texture-crosshatch h(96)"></div>    <figcaption class="text-xs fg-text-muted">Crosshatch</figcaption>  </figure>  <figure class="m(0) flex flex-col gap-xs">    <div class="well texture texture-checker h(96)"></div>    <figcaption class="text-xs fg-text-muted">Checker</figcaption>  </figure></div>
<div className="auto-grid auto-grid-fit" style={{ '--auto-grid-min': '6rem' } as React.CSSProperties}>  <figure className="m(0) flex flex-col gap-xs">    <div className="well texture h(96)"></div>    <figcaption className="text-xs fg-text-muted">Dots</figcaption>  </figure>  <figure className="m(0) flex flex-col gap-xs">    <div className="well texture texture-grid h(96)"></div>    <figcaption className="text-xs fg-text-muted">Grid</figcaption>  </figure>  <figure className="m(0) flex flex-col gap-xs">    <div className="well texture texture-stripes h(96)"></div>    <figcaption className="text-xs fg-text-muted">Stripes</figcaption>  </figure>  <figure className="m(0) flex flex-col gap-xs">    <div className="well texture texture-crosshatch h(96)"></div>    <figcaption className="text-xs fg-text-muted">Crosshatch</figcaption>  </figure>  <figure className="m(0) flex flex-col gap-xs">    <div className="well texture texture-checker h(96)"></div>    <figcaption className="text-xs fg-text-muted">Checker</figcaption>  </figure></div>
<div class="auto-grid auto-grid-fit" style="--auto-grid-min: 6rem">  <figure class="m(0) flex flex-col gap-xs">    <div class="well texture h(96)"></div>    <figcaption class="text-xs fg-text-muted">Dots</figcaption>  </figure>  <figure class="m(0) flex flex-col gap-xs">    <div class="well texture texture-grid h(96)"></div>    <figcaption class="text-xs fg-text-muted">Grid</figcaption>  </figure>  <figure class="m(0) flex flex-col gap-xs">    <div class="well texture texture-stripes h(96)"></div>    <figcaption class="text-xs fg-text-muted">Stripes</figcaption>  </figure>  <figure class="m(0) flex flex-col gap-xs">    <div class="well texture texture-crosshatch h(96)"></div>    <figcaption class="text-xs fg-text-muted">Crosshatch</figcaption>  </figure>  <figure class="m(0) flex flex-col gap-xs">    <div class="well texture texture-checker h(96)"></div>    <figcaption class="text-xs fg-text-muted">Checker</figcaption>  </figure></div>
<template>  <div class="auto-grid auto-grid-fit" style="--auto-grid-min: 6rem">    <figure class="m(0) flex flex-col gap-xs">      <div class="well texture h(96)"></div>      <figcaption class="text-xs fg-text-muted">Dots</figcaption>    </figure>    <figure class="m(0) flex flex-col gap-xs">      <div class="well texture texture-grid h(96)"></div>      <figcaption class="text-xs fg-text-muted">Grid</figcaption>    </figure>    <figure class="m(0) flex flex-col gap-xs">      <div class="well texture texture-stripes h(96)"></div>      <figcaption class="text-xs fg-text-muted">Stripes</figcaption>    </figure>    <figure class="m(0) flex flex-col gap-xs">      <div class="well texture texture-crosshatch h(96)"></div>      <figcaption class="text-xs fg-text-muted">Crosshatch</figcaption>    </figure>    <figure class="m(0) flex flex-col gap-xs">      <div class="well texture texture-checker h(96)"></div>      <figcaption class="text-xs fg-text-muted">Checker</figcaption>    </figure>  </div></template>
クラス意味用途
texture表示用の領域見本、キャンバス、図を表示する背景
texture texture-grid位置の目安がある領域位置が重要なキャンバス。エディター、間取り図、レイアウト教材など
texture texture-stripes空けてある領域ガター、余白、何も入っていないスロット、画像のプレースホルダー
texture texture-crosshatch使用できない領域利用不可の時間帯、休業日、範囲外の領域
texture texture-checker透明な領域透明部分のある画像や、アルファ値を持つ色の下地

テクスチャに文字を直接重ねないでください。模様が文字にかかると読みにくくなるため、キャプションは領域の横に置くか、テクスチャに重ねたシートの上に置きます。

#空き領域と利用不可の領域

斜線と交差斜線は、何も入っていない領域の状態を区別します。斜線の枠は空けてあり、後から使えます。交差斜線の枠は選択できません。模様だけでは伝わらないことがあるため、同じ意味を文字でも示します。この例では、利用できない時間帯を無効にし、その状態を示すラベルも付けています。

空き領域と利用不可の領域

<div class="sheet grid grid-cols(4) gap-xs p-xs">  <button type="button" class="btn btn-quiet h(88)">9:00</button>  <button type="button" class="btn btn-quiet h(88)">10:00</button>  <div class="well texture texture-stripes h(88)" role="img" aria-label="11:00, kept free"></div>  <div class="well texture texture-crosshatch h(88)" role="img" aria-label="12:00, closed"></div></div><p class="m(0) mt-md text-xs fg-text-muted">11:00 is kept free. The office is closed at 12:00.</p>
<>  <div className="sheet grid grid-cols(4) gap-xs p-xs">    <button type="button" className="btn btn-quiet h(88)">9:00</button>    <button type="button" className="btn btn-quiet h(88)">10:00</button>    <div className="well texture texture-stripes h(88)" role="img" aria-label="11:00, kept free"></div>    <div className="well texture texture-crosshatch h(88)" role="img" aria-label="12:00, closed"></div>  </div>  <p className="m(0) mt-md text-xs fg-text-muted">    11:00 is kept free. The office is closed at 12:00.  </p></>
<div class="sheet grid grid-cols(4) gap-xs p-xs">  <button type="button" class="btn btn-quiet h(88)">9:00</button>  <button type="button" class="btn btn-quiet h(88)">10:00</button>  <div class="well texture texture-stripes h(88)" role="img" aria-label="11:00, kept free"></div>  <div class="well texture texture-crosshatch h(88)" role="img" aria-label="12:00, closed"></div></div><p class="m(0) mt-md text-xs fg-text-muted">11:00 is kept free. The office is closed at 12:00.</p>
<template>  <div class="sheet grid grid-cols(4) gap-xs p-xs">    <button type="button" class="btn btn-quiet h(88)">9:00</button>    <button type="button" class="btn btn-quiet h(88)">10:00</button>    <div class="well texture texture-stripes h(88)" role="img" aria-label="11:00, kept free"></div>    <div class="well texture texture-crosshatch h(88)" role="img" aria-label="12:00, closed"></div>  </div>  <p class="m(0) mt-md text-xs fg-text-muted">11:00 is kept free. The office is closed at 12:00.</p></template>

#透明部分

チェック柄は、背景が透ける部分を示す下地です。画像を上に重ねると、透明な箇所からチェック柄が見えます。この例では、マークのくり抜き部分から見えます。

透明部分

<div class="well texture texture-checker flex items-center justify-center w(240) h(136) fg-text-strong">  <svg width="80" height="80" viewBox="0 0 96 96" role="img" aria-label="A square mark with a round hole">    <path fill="currentColor" fill-rule="evenodd" d="M20 8h56a12 12 0 0 1 12 12v56a12 12 0 0 1-12 12H20A12 12 0 0 1 8 76V20A12 12 0 0 1 20 8Zm28 18a22 22 0 1 0 0 44 22 22 0 0 0 0-44Z" />  </svg></div>
<div className="well texture texture-checker flex items-center justify-center w(240) h(136) fg-text-strong">  <svg width="80" height="80" viewBox="0 0 96 96" role="img" aria-label="A square mark with a round hole">    <path fill="currentColor" fillRule="evenodd" d="M20 8h56a12 12 0 0 1 12 12v56a12 12 0 0 1-12 12H20A12 12 0 0 1 8 76V20A12 12 0 0 1 20 8Zm28 18a22 22 0 1 0 0 44 22 22 0 0 0 0-44Z" />  </svg></div>
<div class="well texture texture-checker flex items-center justify-center w(240) h(136) fg-text-strong">  <svg width="80" height="80" viewBox="0 0 96 96" role="img" aria-label="A square mark with a round hole">    <path fill="currentColor" fill-rule="evenodd" d="M20 8h56a12 12 0 0 1 12 12v56a12 12 0 0 1-12 12H20A12 12 0 0 1 8 76V20A12 12 0 0 1 20 8Zm28 18a22 22 0 1 0 0 44 22 22 0 0 0 0-44Z" />  </svg></div>
<template>  <div class="well texture texture-checker flex items-center justify-center w(240) h(136) fg-text-strong">    <svg width="80" height="80" viewBox="0 0 96 96" role="img" aria-label="A square mark with a round hole">      <path fill="currentColor" fill-rule="evenodd" d="M20 8h56a12 12 0 0 1 12 12v56a12 12 0 0 1-12 12H20A12 12 0 0 1 8 76V20A12 12 0 0 1 20 8Zm28 18a22 22 0 1 0 0 44 22 22 0 0 0 0-44Z" />    </svg>  </div></template>

#サイズ・太さ・色

3 つのカスタムプロパティで、要素ごとにパターンを調整できます。--texture-size はタイル一辺の長さ、--texture-weight はドットの半径または罫線の太さ、--texture-ink は模様の色です。テーマでは、--color-texture を使ってすべてのテクスチャの色をまとめて設定できます。

テクスチャは、その上に置くものより控えめにします。見本を置く背景には、細く間隔を空けた模様で輪郭を判別できれば十分です。模様が密になると、見本が目立ちにくくなります。

サイズ・太さ・色

<div class="auto-grid auto-grid-fit" style="--auto-grid-min: 9rem">  <figure class="m(0) flex flex-col gap-xs">    <div class="well texture h(96)" style="--texture-size: 20px"></div>    <figcaption class="text-xs fg-text-muted">A 20px tile</figcaption>  </figure>  <figure class="m(0) flex flex-col gap-xs">    <div class="well texture texture-stripes h(96)" style="--texture-weight: 1px; --texture-size: 12px"></div>    <figcaption class="text-xs fg-text-muted">A 1px stripe in a 12px tile</figcaption>  </figure>  <figure class="m(0) flex flex-col gap-xs">    <div class="well texture texture-grid h(96)" style="--texture-ink: var(--color-line-hair)"></div>    <figcaption class="text-xs fg-text-muted">The hairline's ink</figcaption>  </figure></div>
<div className="auto-grid auto-grid-fit" style={{ '--auto-grid-min': '9rem' } as React.CSSProperties}>  <figure className="m(0) flex flex-col gap-xs">    <div className="well texture h(96)" style={{ '--texture-size': '20px' } as React.CSSProperties}></div>    <figcaption className="text-xs fg-text-muted">A 20px tile</figcaption>  </figure>  <figure className="m(0) flex flex-col gap-xs">    <div className="well texture texture-stripes h(96)" style={{ '--texture-weight': '1px', '--texture-size': '12px' } as React.CSSProperties}></div>    <figcaption className="text-xs fg-text-muted">A 1px stripe in a 12px tile</figcaption>  </figure>  <figure className="m(0) flex flex-col gap-xs">    <div className="well texture texture-grid h(96)" style={{ '--texture-ink': 'var(--color-line-hair)' } as React.CSSProperties}></div>    <figcaption className="text-xs fg-text-muted">The hairline's ink</figcaption>  </figure></div>
<div class="auto-grid auto-grid-fit" style="--auto-grid-min: 9rem">  <figure class="m(0) flex flex-col gap-xs">    <div class="well texture h(96)" style="--texture-size: 20px"></div>    <figcaption class="text-xs fg-text-muted">A 20px tile</figcaption>  </figure>  <figure class="m(0) flex flex-col gap-xs">    <div class="well texture texture-stripes h(96)" style="--texture-weight: 1px; --texture-size: 12px"></div>    <figcaption class="text-xs fg-text-muted">A 1px stripe in a 12px tile</figcaption>  </figure>  <figure class="m(0) flex flex-col gap-xs">    <div class="well texture texture-grid h(96)" style="--texture-ink: var(--color-line-hair)"></div>    <figcaption class="text-xs fg-text-muted">The hairline's ink</figcaption>  </figure></div>
<template>  <div class="auto-grid auto-grid-fit" style="--auto-grid-min: 9rem">    <figure class="m(0) flex flex-col gap-xs">      <div class="well texture h(96)" style="--texture-size: 20px"></div>      <figcaption class="text-xs fg-text-muted">A 20px tile</figcaption>    </figure>    <figure class="m(0) flex flex-col gap-xs">      <div class="well texture texture-stripes h(96)" style="--texture-weight: 1px; --texture-size: 12px"></div>      <figcaption class="text-xs fg-text-muted">A 1px stripe in a 12px tile</figcaption>    </figure>    <figure class="m(0) flex flex-col gap-xs">      <div class="well texture texture-grid h(96)" style="--texture-ink: var(--color-line-hair)"></div>      <figcaption class="text-xs fg-text-muted">The hairline's ink</figcaption>    </figure>  </div></template>

斜線は正方形のタイル内で 45° 傾いているため、線の間隔はタイル一辺の長さを √2 で割った値になります。既定の 8px のタイルでは 5.7px です。タイルのサイズは整数ピクセルにしてください。端数があると、タイルの境目で線がずれます。

タイルは領域の中央を基準に並ぶため、領域の大きさにかかわらず、向かい合う端で模様が同じように切れます。角を起点にするには background-position を指定します。

#フェード

texture-fade は領域の端に向かって模様を薄くします。見出しの背景などに使えます。マスクによって要素内のコンテンツも薄くなるため、コンテンツの背後に専用の要素を置いて適用し、その要素を支援技術から隠します。

フェード

<div class="relative flex flex-col items-center justify-center gap-md h(192)">  <div class="texture texture-grid texture-fade absolute inset(0)" aria-hidden="true"></div>  <h3 class="relative m(0) text-xl fg-text-strong">Ship the first draft</h3>  <button type="button" class="relative btn btn-primary">Start a project</button></div>
<div className="relative flex flex-col items-center justify-center gap-md h(192)">  <div className="texture texture-grid texture-fade absolute inset(0)" aria-hidden="true"></div>  <h3 className="relative m(0) text-xl fg-text-strong">Ship the first draft</h3>  <button type="button" className="relative btn btn-primary">Start a project</button></div>
<div class="relative flex flex-col items-center justify-center gap-md h(192)">  <div class="texture texture-grid texture-fade absolute inset(0)" aria-hidden="true"></div>  <h3 class="relative m(0) text-xl fg-text-strong">Ship the first draft</h3>  <button type="button" class="relative btn btn-primary">Start a project</button></div>
<template>  <div class="relative flex flex-col items-center justify-center gap-md h(192)">    <div class="texture texture-grid texture-fade absolute inset(0)" aria-hidden="true"></div>    <h3 class="relative m(0) text-xl fg-text-strong">Ship the first draft</h3>    <button type="button" class="relative btn btn-primary">Start a project</button>  </div></template>

#重ね合わせ

テクスチャを適用すると、要素の背景画像が置き換わり、背景色はそのまま残ります。別の画像も重ねたり、模様で形を切り抜いたりする場合は、クラスを指定した要素の --texture-image を参照します。そこにパターンが公開されています。

.texture.stage {  background-image: var(--texture-image), linear-gradient(var(--color-surface-raised), var(--color-surface-raised-low));  background-size: var(--texture-size) var(--texture-size), auto;}

交差斜線は 2 レイヤーで構成されるため、サイズを 2 つ指定します。

#アクセシビリティ

テクスチャは視覚的な模様で、強制カラーモードでは表示されません。意味を伝える場合は、必ずほかの手段も併用します。

  • 既存の領域を装飾するだけなら、追加の指定は不要です。テクスチャの表示専用の要素には aria-hidden="true" を指定します。
  • テクスチャが「空けてある」「利用できない」「透明」などの状態を示す場合は、その意味を目に見えるテキストで、領域の隣か中に示します。強制カラーモードでもテキストは残ります。領域自体に role="img" と aria-label を指定すると支援技術にも名前が伝わりますが、画面には表示されないため、テキストの代わりにはなりません。
  • 操作できないコントロールには、まず disabled を指定します。交差斜線は、その属性が示す利用不可の状態を視覚的にも伝えます。

#クラス

クラス説明
textureドット。タイル1枚につき1点で、見本を見せる背景に使う
texture-grid寸法を示す領域に使う方眼texture と併用します
texture-stripesガター、余白、空のスロットなど、空けておく領域に使う極細の斜線texture と併用します
texture-crosshatch交差する極細の斜線で、選択できない時間帯や許容範囲外の区間など、利用できない領域を示します。texture と併用します
texture-checker透明な部分の下地に使う市松模様texture と併用します
texture-fade図柄は端に向かって薄くなります。要素の中身もマスクされるため、専用の要素に適用します。texture と併用します

#カスタムプロパティ

プロパティ既定値説明
--texture-inkvar(--color-texture)マークの色。罫線と正方形はこの色の半分の不透明度で描画します。指定先:texture
--texture-size12pxタイル 1 枚の一辺の長さです。ドットは 12px、方眼は 24px、ストライプと交差する斜線は 8px、市松模様は 16px です。指定先:texture
--texture-weight1pxドットの半径または線の太さです。ストライプの線は .5px です。市松模様には適用されません。指定先:texture
--texture-image図柄そのもの。他の画像の下に敷くか、マスクに使います。交差する斜線には 2 レイヤーを使います。指定先:texture

#ソース

@master/ui/components/texture.css
/* * Texture: one drawing repeated across the face of a surface. It is a background image in the theme's * texture ink, tiled at --texture-size, so it stands on whatever color the element already has and takes * the place of that face's own image only. Each texture says one thing about the room it fills: dots are an * open stage, a grid is measured room, stripes are room kept empty, a crosshatch is room that cannot be used * and a checker is nothing at all, the ground under something transparent. * * Every mark is a hard-stopped gradient, so one tile holds the drawing and --texture-weight is its real * thickness. Stripes turn 45° in a square tile, which sets them the tile's side over √2 apart. Tiles are counted * from the middle of the room, so the drawing is cut the same way at opposite edges. Where the browser has * round(), the middle is snapped to a whole pixel: a tile centered in a room of odd width would otherwise land * on half a pixel and blur every mark. The drawing is published as --texture-image, to lay under another image * or to use as a mask. * * In forced colors the drawing is removed: a texture never carries a meaning alone. */@layer components.ui {  .texture {    --texture-ink: var(--color-texture);    --texture-size: 12px;    --texture-weight: 1px;    /* Dots: one point in the middle of each tile, with a quarter pixel of edge so it stays round. */    --texture-image: radial-gradient(circle, var(--texture-ink) var(--texture-weight), transparent calc(var(--texture-weight) + .25px));    background-image: var(--texture-image);    background-size: var(--texture-size) var(--texture-size);    background-position: center;    background-position: round(50%, 1px) round(50%, 1px);    /* A rule along the top and the start of each tile. Rules cover more than points do, so they take half the ink. */    &.texture-grid {      --texture-size: 24px;      --texture-image: conic-gradient(from 90deg at var(--texture-weight) var(--texture-weight), transparent 25%, color-mix(in oklab, var(--texture-ink) 50%, transparent) 0);    }    /* Two hairlines a tile: one through its corners, one across its middle. */    &.texture-stripes {      --texture-size: 8px;      --texture-weight: .5px;      --texture-image: linear-gradient(135deg, var(--texture-ink) 0 var(--texture-weight), transparent 0 50%, var(--texture-ink) 0 calc(50% + var(--texture-weight)), transparent 0);    }    /* The same hairlines both ways. This drawing is two layers. */    &.texture-crosshatch {      --texture-size: 8px;      --texture-weight: .5px;      --texture-image:        linear-gradient(135deg, var(--texture-ink) 0 var(--texture-weight), transparent 0 50%, var(--texture-ink) 0 calc(50% + var(--texture-weight)), transparent 0),        linear-gradient(45deg, var(--texture-ink) 0 var(--texture-weight), transparent 0 50%, var(--texture-ink) 0 calc(50% + var(--texture-weight)), transparent 0);    }    /* Two squares of four. Squares cover half the face, so they take half the ink. */    &.texture-checker {      --texture-size: 16px;      --texture-image: conic-gradient(color-mix(in oklab, var(--texture-ink) 50%, transparent) 25%, transparent 0 50%, color-mix(in oklab, var(--texture-ink) 50%, transparent) 0 75%, transparent 0);    }    /* The drawing thins out toward the edges. A mask fades what the element holds too, so it goes on an element of its own. */    &.texture-fade {      mask-image: radial-gradient(farthest-side, black 30%, transparent);    }    @media (forced-colors: active) {      background-image: none;    }  }}