Navigation

v2.1.0
Materials

Texture

Dots, a grid, stripes, a crosshatch and a checker, drawn across the face of a surface.

On this page

A texture is one drawing repeated across the face of a surface. Use .texture on any element for room that holds no content and still has to say what it is. It is a background image in one quiet ink, so it stands on whatever color the element already has: a well stays a well, with dots across it.

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>

#Drawings

There are five, and each says one thing about the room it fills. Choose by that meaning, not by which looks best: a reader who meets stripes in two places should be able to assume the same thing about both.

Drawings

<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>
ClassSaysUse for
textureAn open stageThe field a specimen, a canvas or a diagram is seen against
texture texture-gridMeasured roomA canvas where position matters: an editor, a floor plan, a layout lesson
texture texture-stripesRoom kept emptyA gutter, a clear space, a slot nothing fills, a placeholder for a picture
texture texture-crosshatchRoom that cannot be usedA blocked time, a day that is closed, a range out of bounds
texture texture-checkerNothing at allThe ground under a transparent picture or a color with alpha

Words never stand on a texture. The marks run through the letters and make them harder to read, so put a caption beside the textured room or on a sheet over it.

#Kept and unavailable

Stripes and a crosshatch part two kinds of empty. A striped slot is kept free and may be filled later; a crosshatched one cannot be chosen. Say the same in words, since a drawing is not read by everyone: here the closed hours are also disabled and named.

Kept and unavailable

<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>

#Transparency

A checker is the ground under something that has none of its own. Put the picture on it, so the squares show where it is clear: here, through the hole in the mark.

Transparency

<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>

#Size, weight and ink

Three custom properties tune a drawing where it stands. --texture-size is the side of one tile, --texture-weight the radius of a dot or the width of a rule, and --texture-ink the color of the marks. A theme sets the ink for every texture at once with --color-texture.

Keep a texture quieter than what stands on it. On a stage that holds a specimen, a sparse, fine drawing is enough for the eye to find an edge against; a dense one competes with the specimen.

Size, weight and ink

<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>

Stripes turn 45° in a square tile, so they stand the tile's side over √2 apart: 5.7px in the default 8px tile. Keep the tile a whole number of pixels, or the lines drift from one tile to the next.

Tiles are counted from the middle of the room, so a drawing is cut the same way at opposite edges, whatever the room's size. Set background-position to start it from a corner instead.

#Fade

texture-fade thins the drawing out toward the edges, for a field behind a heading. It is a mask, and a mask fades what the element holds too, so put it on an element of its own behind the content and hide that element from assistive technology.

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>

#Layering

A texture takes the place of the face's own image, and the element keeps its color. To keep another image as well, or to cut a shape with the drawing, read --texture-image on the element that carries the class: the drawing is published there.

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

A crosshatch is two layers, so give it two sizes.

#Accessibility

A texture is a drawing, and it is removed in forced colors. Never let it carry a meaning alone:

  • Room that is only decorated needs nothing. An element that exists just to hold a texture takes aria-hidden="true".
  • Room whose texture means something (kept free, closed, transparent) says so in words that are seen: text beside it or in it, which forced colors keep. role="img" with an aria-label on the room names it for assistive technology too, but nobody sees it, so it does not replace the words.
  • A control that cannot be used is disabled first. A crosshatch only repeats what the attribute says.

#Classes

ClassDescription
textureDots: one point a tile, the field a specimen is seen against
texture-gridRuled squares, for room that is measuredApply with texture
texture-stripesDiagonal hairlines, for room that is kept empty: a gutter, a clear space, a slot nothing fillsApply with texture
texture-crosshatchHairlines both ways, for room that cannot be used: a blocked time, a range out of boundsApply with texture
texture-checkerAlternate squares, the ground under something transparentApply with texture
texture-fadeThe drawing thins out toward the edges. It masks what the element holds too, so it goes on an element of its ownApply with texture

#Custom properties

PropertyDefaultDescription
--texture-inkvar(--color-texture)The color of the marks. Rules and squares are drawn at half of itSet on texture
--texture-size12pxThe side of one tile: 12px for dots, 24px for a grid, 8px for stripes and a crosshatch, 16px for a checkerSet on texture
--texture-weight1pxThe radius of a dot or the width of a rule; a stripe's is .5px. A checker has noneSet on texture
--texture-imageThe drawing itself, to lay under another image or to use as a mask. A crosshatch is two layersSet on texture

#Source

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