Writing a skin
A skin is a stylesheet and a short settings file that decide how a Fotobogen site looks. If you can write CSS, you can write one. Nothing is compiled, and a skin cannot break a site.
What you are making
data/skins/harbour/
├── skin.json its name, its colours for light and dark, its options
└── skin.css an ordinary stylesheet for the public pages
Fotobogen's public pages have fixed HTML with stable class names. Your stylesheet styles them. That division is what makes skins safe and switchable:
- Switching skins takes effect at once. Nothing is rebuilt and no photograph is touched.
- Every skin has a light and a dark mode. You give the colours for each; Fotobogen writes them into the page and handles the visitor's switch. You never write a mode selector.
- Your options become controls in the admin without any interface code: a colour picker, a menu, or a slider for each.
- A skin with a mistake in it is listed with the reason and cannot be chosen. The site carries on with the skin it had; if the broken one is the skin in use, the site shows Swiss until it is mended.
What a skin cannot do
Change the HTML, add pages, run scripts, or load anything from another website (fonts included: a font file must be served from your own site). It styles the public site only, never the admin. This is deliberate: installing someone else's skin can do no more than change how a site looks.
Step 1: copy a skin that works
Do not start from an empty file. The public pages include a masonry grid, a modal, and a slideshow, and a skin has to lay all of them out. Start from Swiss, the default, which does, and change it.
From a copy of Fotobogen's source:
mkdir -p data/skins
cp -R skins/swiss data/skins/harbour
Then open data/skins/harbour/skin.json and change "name" to harbour, and "label" to what people should see. The name must be the folder's name exactly: lowercase letters, digits, and hyphens, starting with a letter.
Restart Fotobogen and open Admin, Skins. Your skin is in the list. Choose it. It looks like Swiss; now make it yours.
Papier, Plakat, and Rangefinder Dreams were each made this way. Each one's stylesheet ends with a section headed "What makes this … rather than Swiss", which is a good thing to read: the skins folder.
Step 2: skin.json
A complete example. Every part is explained below it.
{
"name": "harbour",
"version": "1.0.0",
"label": "Harbour",
"description": "Sea blue, with wide margins.",
"mode": "light",
"modes": {
"light": { "ground": "#f3f6f8", "text": "#10202b", "muted": "#4a5b66", "line": "#cbd5db", "accent": "#0b6aa2" },
"dark": { "ground": "#0c161d", "text": "#e8eef2", "muted": "#9fb0bb", "line": "#263742", "accent": "#5fb8ee" }
},
"contrast": [["text", "ground"], ["muted", "ground"]],
"options": {
"accent": { "type": "color", "label": "Accent colour", "default": { "light": "#0b6aa2", "dark": "#5fb8ee" } },
"gutter": {
"type": "select", "label": "Space between photos",
"options": ["none", "hairline", "wide"], "default": "wide",
"values": { "none": "0px", "hairline": "3px", "wide": "1.25rem" }
},
"columns": { "type": "range", "label": "Columns on a wide screen", "min": 2, "max": 6, "step": 1, "default": 3 }
}
}
| Field | Required | What it is |
|---|---|---|
name | Yes | The folder's name, exactly. |
version | Yes | Any text that is not empty. Shown in the admin. |
label | Yes | The name people see. |
description | No | A sentence shown under the label on the Skins page. |
mode | No | "light" or "dark": which a visitor sees first, unless the site's owner chooses otherwise. Light if you leave it out. |
modes | Yes | Your colours, once for light and once for dark. |
contrast | No, but do | Which colours are text on which backgrounds, so they can be checked. |
options | No | Settings the site's owner can change. |
look | No | A look for every photo, set when the skin is chosen. |
Step 3: colours, for light and for dark
Under modes, name your colours twice. Each name becomes a CSS custom property, --fb-<name>, that your stylesheet uses.
| Name | In CSS | What the bundled skins use it for |
|---|---|---|
ground | var(--fb-ground) | The page |
text | var(--fb-text) | Words, headings, links, focus rings |
muted | var(--fb-muted) | Quieter words: the tagline, dates, the footer |
line | var(--fb-line) | Rules, and the space behind a photo while it loads |
accent | var(--fb-accent) | The one highlight: a hovered link's underline, a bar |
- Colours are six-digit hex, like
#0b6aa2. Not three digits, not a name, notrgb(). - Both modes must name the same colours.
- If you copied Swiss, keep these five names: its rules use them. You may add your own (
"panel": "#…"arrives as--fb-panel).
Fotobogen writes your colours into the page after your stylesheet, like this:
:root.fb-public { --fb-ground: #f3f6f8; --fb-text: #10202b; /* … */ color-scheme: light; }
:root.fb-public[data-fb-mode="dark"] { --fb-ground: #0c161d; --fb-text: #e8eef2; /* … */ color-scheme: dark; }
@media (prefers-color-scheme: dark) { :root.fb-public[data-fb-mode="auto"] { /* the dark colours again */ } }
The one rule that makes both modes work: never write a colour for the page into skin.css. Write var(--fb-text), not #10202b. A fixed colour is right in one mode and unreadable in the other. The only exception is the slideshow, which is a black stage in both modes.
The contrast check
contrast lists pairs: a text colour, then the background it sits on. Fotobogen measures each pair in both modes, when the skin loads and whenever an owner changes a colour, and warns on the Skins page about any below 4.5 to 1, the minimum for readable text (WCAG level AA):
In light mode, "muted" on "ground" has a contrast of 2.2:1. Text needs at least 4.5:1 to be readable.
List every pair you use for text. An option of type color with the same name as a colour replaces it in the check, so an owner who picks a faint colour is told.
Step 4: options
An option is a setting the site's owner can change under Admin, Skins. Each becomes --fb-<name>, written after your stylesheet, so it overrides the value you set there. Option names are lowercase letters, digits, and hyphens.
color: two colour pickers, one for each mode
"accent": { "type": "color", "label": "Accent colour", "default": { "light": "#0b6aa2", "dark": "#5fb8ee" } }
The default may also be a single colour, used for both modes. Name it after one of your colours and it replaces that colour.
select: a menu
"gutter": {
"type": "select", "label": "Space between photos",
"options": ["none", "hairline", "wide"], "default": "wide",
"values": { "none": "0px", "hairline": "3px", "wide": "1.25rem" }
}
The owner sees the names in options. values maps each name to what is written into the stylesheet; without it, the name itself is written. A value may contain letters, digits, and # % . , ( ) - and spaces, up to 60 characters, which covers lengths, numbers, and simple functions.
range: a slider
"columns": { "type": "range", "label": "Columns on a wide screen", "min": 2, "max": 6, "step": 1, "default": 3 }
Written as a bare number: --fb-columns: 3. To use it as a length, multiply in CSS: calc(var(--fb-size) * 1rem).
Set the same starting value in skin.css as each option's default, so the stylesheet makes sense by itself:
:root.fb-public {
--fb-gutter: 1.25rem;
--fb-columns: 3;
}
Step 5: skin.css
An ordinary stylesheet. Three things to hold to.
Start every rule from .fb-public
Public pages carry the class fb-public on the <html> element. The admin's own stylesheet is loaded on the same pages, so a bare a { … } or body { … } would fight with it. Start from the class:
:root.fb-public { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; line-height: 1.5; }
.fb-public body { margin: 0; background: var(--fb-ground); color: var(--fb-text); }
.fb-public a { color: inherit; }
Class names that begin fb- (such as .fb-site-header) need no prefix: the admin uses a few of them too, but your stylesheet is only ever loaded on public pages.
Set the text colour on the body
Keep the line .fb-public body { color: var(--fb-text); }. The admin's stylesheet gives the body a pale colour of its own, and without this line the headings and links of a light skin are nearly invisible.
Change the values first, then add rules at the end
Most of a new look is its colours (in skin.json), its measures (the first block of skin.css), and a handful of rules added at the end. Papier's are about fifteen lines:
/* A heavy rule under the header, and a larger name. */
.fb-site-header { margin: 0 var(--fb-margin) 2rem; padding: 2rem 0 1rem; border-bottom: 4px solid var(--fb-text); }
.fb-site-title { font-size: 1.5rem; letter-spacing: -0.03em; }
.fb-site-footer { margin: 0 var(--fb-margin); padding: 1.25rem 0 2.5rem; border-top: 4px solid var(--fb-text); }
Plakat turns the site's name into a poster headline with two:
.fb-site-title { font-size: clamp(2.75rem, 11vw, 8.5rem); line-height: 0.88; letter-spacing: -0.055em; overflow-wrap: anywhere; }
.fb-site-title::after { content: ""; display: block; width: clamp(3rem, 10vw, 7rem); height: clamp(0.4rem, 1vw, 0.7rem); background: var(--fb-accent); }
The HTML you are styling
These class names are stable; a skin may rely on them.
<html class="fb-public" data-fb-mode="light"> <!-- or "dark", or "auto" -->
<div class="fb-site"> <!-- around everything on the page -->
<a class="fb-skip">Skip to content</a>
<header class="fb-site-header">
<p class="fb-site-title"><a>Site title</a></p>
<p class="fb-site-tagline">Tagline</p>
<nav class="fb-nav">
<a>Photos</a><a>Albums</a><a>Slideshow</a><a>Search</a>
<!-- The light and dark switch. It holds both wordings; the stylesheet shows the one for the mode in use. -->
<button class="fb-mode"><span class="fb-mode__to-dark">Dark mode</span><span class="fb-mode__to-light">Light mode</span></button>
</nav>
</header>
<main class="fb-main">
<!-- The grid -->
<div class="fb-grid-wrap">
<ul class="fb-grid fb-grid--masonry"> <!-- or fb-grid--square -->
<li class="fb-tile" style="--fb-span: 13; background-image: url(...)">
<a class="fb-tile__link"><img class="fb-tile__image"></a>
</li>
</ul>
</div>
<nav class="fb-pager"><a class="fb-pager__more">More photos</a></nav>
<p class="fb-empty">No photographs have been published yet.</p>
<!-- A photo, on its own page or inside the modal -->
<p class="fb-photo__back"><a>All photos</a></p>
<article class="fb-photo">
<figure class="fb-photo__figure"> <!-- gains fb-photo__figure--expanded in full screen -->
<img class="fb-photo__image">
<button class="fb-photo__expand">Full screen</button>
</figure>
<div class="fb-photo__text">
<h1 class="fb-photo__title">Title</h1>
<p class="fb-photo__description">Description</p>
<dl class="fb-photo__facts">
<div class="fb-photo__fact"><dt>Camera</dt><dd>…</dd></div>
</dl>
<p class="fb-photo__albums">In <a>Album name</a></p>
<ul class="fb-tags"><li><a class="fb-tag">tag</a></li></ul>
<p class="fb-photo__licence">All rights reserved</p>
<p class="fb-photo__download"><a>Download</a></p>
<nav class="fb-photo__nav"><a class="fb-photo__prev">Previous</a><a class="fb-photo__next">Next</a></nav>
</div>
</article>
<!-- An album or tag page: a heading, then the same grid -->
<h1 class="fb-page-title">Album name</h1>
<p class="fb-page-description">Description</p>
<p class="fb-page-actions"><a>Play as a slideshow</a></p>
<!-- The list of albums -->
<ul class="fb-albums">
<li class="fb-album">
<a class="fb-album__link">
<span class="fb-album__cover"><img></span>
<span class="fb-album__title">Album name</span>
<span class="fb-album__count">12 photos</span>
</a>
</li>
</ul>
<!-- A photo opened over the grid -->
<dialog class="fb-modal">
<button class="fb-modal__close">Close</button>
<article class="fb-photo">…</article>
</dialog>
</main>
<footer class="fb-site-footer">
<p class="fb-site-footer__note">The owner's own line, if they wrote one</p>
<a>RSS feed</a>
</footer>
</div>
</html>
The words shown here are the defaults; an owner can change any of them, so never rely on a piece of text or its length. A site title may be three letters or forty.
Newer parts of the site are not in the outline above. A skin should also style them:
- The menu (
.fb-nav) also holds a Search link, the owner's pages, and up to eight links of the owner's own, so it must wrap onto a second line without breaking. - The album chooser on the front page:
nav.fb-chooserholdinga.fb-chooser__linkfor "All" and each album. The chosen one hasaria-current="page". - The search page:
.fb-searchand the classes that begin.fb-search__, for the form, its field and button, and the line that says how many photos were found. - The owner's pages:
.fb-pagearound.fb-page-body, which holds plain headings, paragraphs, lists, and links.
The skin guide on GitHub lists every class, and the bundled skins show each one styled.
The owner's logo
If the owner uploads a logo, the title holds pictures in place of text:
<p class="fb-site-title"><a>
<img class="fb-site-logo fb-site-logo--light" width="120" height="40" alt="The site's name">
<img class="fb-site-logo fb-site-logo--dark" width="120" height="40" alt="The site's name">
</a></p>
You do nothing for this: Fotobogen's own rules show the one for the mode in use. If your skin gives the title a very large size or decoration, check it still looks right with a picture in it.
The slideshow
/slideshow is a page of its own, without the header and footer:
<main class="fb-slideshow">
<button class="fb-slideshow__photo">
<img class="fb-slideshow__image fb-slideshow__image--front">
<img class="fb-slideshow__image">
</button>
<div class="fb-slideshow__foot">
<div class="fb-slideshow__details"> <!-- only while the details are shown -->
<h2 class="fb-slideshow__title">Title</h2>
<p class="fb-slideshow__description">Description</p>
<p class="fb-slideshow__facts">Date, camera, size</p>
<p class="fb-slideshow__facts">In <a>Album</a></p>
<ul class="fb-tags"><li><a class="fb-tag">tag</a></li></ul>
<p class="fb-slideshow__facts">Licence</p>
<p><a>Open this photo's page</a></p> <!-- a paragraph with no class of its own -->
</div>
<nav class="fb-slideshow__controls">
<button class="fb-slideshow__control">Previous</button>
<button class="fb-slideshow__control" aria-pressed="false">Pause</button> <!-- or Play -->
<button class="fb-slideshow__control">Next</button>
<span class="fb-slideshow__count">3 / 25</span>
<button class="fb-slideshow__control">Full screen</button>
<a class="fb-slideshow__control">Close</a>
</nav>
</div>
<!-- With nothing to show, the page holds only this: -->
<p class="fb-slideshow__empty">There are no photographs to show yet. <a>Go back</a></p>
</main>
fb-slideshow__foot is new in 1.11.0. It holds the details and the controls in one block at the foot of the screen, so the details rest on the controls however many rows those take on a phone. The built-in skins make it position: absolute; bottom: 0 and a column, and leave the two parts inside it unpositioned. A skin written before 1.11.0, which positions the details and the controls themselves, goes on working: the new block has no size of its own then. Copy the three rules from Swiss to get the phone layout right.
The words in the outlines are the defaults. Two images are stacked; the one with --front is showing, and the skin makes the change between them. Swiss fades opacity over a second, and not at all when the visitor's device asks for reduced motion. Unless you want a different slideshow, leave Swiss's rules for it as they are.
The grid
Both layouts are CSS grid with no JavaScript, so photos are read in the order they appear. If you copied Swiss you already have both; this is what its rules do, in case you change them.
- Square (
.fb-grid--square): each.fb-tilehasaspect-ratio: 1. - Masonry (
.fb-grid--masonry): each tile carries--fb-span, the number of rows its shape needs when one row is a twentieth of a column's width. The skin must make rows that size:
Put the space between rows inside the tile, as a border or padding, never in.fb-grid-wrap { container-type: inline-size; } .fb-grid--masonry { grid-auto-rows: calc((100cqw - (var(--fb-cols) - 1) * var(--fb-gutter)) / var(--fb-cols) / 20); } .fb-grid--masonry .fb-tile { grid-row: span var(--fb-span); }row-gap, or the arithmetic drifts and photos are cut off. - Each tile's inline
background-imageis a tiny blurred version of the photo, shown until the real one loads. Keepbackground-size: coveron.fb-tile. - Swiss sets the number of columns in steps as the screen narrows, down to two on a phone. Keep that, or write your own steps.
A look for every photo
A skin can bring a look with it: transforms from the modules, applied to every photo. Add look to skin.json:
"look": [
{ "module": "filmlooks", "transform": "film-look", "params": { "look": "Colour slide (Kodachrome style)" } }
]
Each step names a module, one of its transforms, and the settings to use; settings you leave out take the module's defaults. Up to four steps, run in order:
"look": [
{ "module": "filmlooks", "transform": "film-look", "params": { "look": "B&W 400 (Tri-X style)", "sharpen": 60 } },
{ "module": "filmframe", "transform": "negative-edge", "params": { "thickness": 5 } }
]
When an owner chooses your skin, the Skins page says what its look is and offers a ticked box to take the skin with or without it. With it, the look becomes the site's look and the modules it needs are switched on. A step naming a module the site does not have is left out. The names to use are on the modules page and in each module's code; a module of your own works too.
Make it work for everyone
The skins that come with Fotobogen are tested, in both modes, at 320 and 1280 pixels wide, against WCAG 2.2 level AA. Hold yours to the same; it is mostly a matter of not undoing what Swiss already does.
| What | How |
|---|---|
| Readable text | 4.5 to 1 between text and its background, in both modes. List the pairs under contrast. Do not use the accent as a text colour unless it passes; the bundled skins use it for underlines and bars. |
| Nothing scrolls sideways on a phone | Size large type with clamp() and a viewport unit; add overflow-wrap: anywhere to anything that could be one long word, such as the site title. |
| A visible focus ring | .fb-public :focus-visible { outline: 2px solid var(--fb-text); outline-offset: 3px; } The text colour contrasts with the page in both modes. |
| Reduced motion | Keep the @media (prefers-reduced-motion: reduce) block at the end of Swiss. |
| Things to press are big enough | Buttons in the bundled skins are at least 2.25rem tall. |
| The skip link | Keep .fb-skip off screen until it has focus, then on screen. |
| Do not hide things | Never display: none a part of the page to tidy it. The switch, the footer, and the photo's details are there for a reason. |
Step 6: look at all of it
Restart after each change to the files, then reload. A skin is read once, when Fotobogen starts.
Download the sample photos (Admin, Overview) so there is something to see, make an album and a tag, and go through this list in light and in dark, on a wide window and a narrow one:
- The grid, with the layout set to masonry, then to square (Admin, Settings).
- A photo, opened over the grid, and on a page of its own (Admin, Settings).
- An upright photo and a wide one.
- The Full screen button over a photo.
- The albums page, an album, and a tag.
- The slideshow.
- An address that does not exist, such as
/nothing-here. - A long site title, and a logo (Admin, Icon and logo).
- Every option of yours, at each end.
- The whole site with the Tab key alone: can you see where you are?
Then look at Admin, Skins: any contrast warning for your skin is shown there.
Your browser's developer tools will switch between light and dark for you (in Chrome: Rendering, "Emulate CSS media feature prefers-color-scheme"), or use the switch on the site.
Step 7: install it on a site
- Copy the folder into
data/skins/on the server, so that you havedata/skins/<name>/skin.jsonandskin.css. - Restart Fotobogen.
- Choose it under Admin, Skins.
A skin in data/skins cannot replace one that comes with Fotobogen: give yours its own name. Skins are part of every backup.
When something goes wrong
A skin that cannot be loaded is listed on the Skins page with one of these, and cannot be chosen.
| Message | What to fix |
|---|---|
| The folder is called "x" but skin.json names the skin "y". They must match. | Rename the folder, or change name. |
| skin.json must be a JSON object. / Option "x" must be an object. | Something that should be written in braces, { … }, is a list, a string, or a number. |
| skin.json needs a "name" of lowercase letters, digits, and hyphens. | No capitals, spaces, or underscores; start with a letter; 40 characters at most. |
| skin.json needs a "version". / a "label". | Add the missing field. |
| skin.css is missing or empty. | The stylesheet must be in the same folder, with that name. A file that is a link to somewhere else, or larger than 2 MB, is read as empty: put the file itself in the folder, and keep it under that size. The same goes for skin.json. |
| skin.json needs "modes" with a "light" and a "dark" set of colours. Every skin can be viewed in both. | Add modes with both. (A skin written before modes existed used tokens; move those colours under modes.) |
| The light and dark modes must name the same colours. | A name is in one and not the other. |
| Colour "x" (light) must be written like "#0a0a0b". | Six-digit hex only. |
| Colour names are lowercase letters, digits, and hyphens. | Rename the colour. |
| Option names are lowercase letters, digits, and hyphens. | Rename the option. |
| Colour option "x" needs a default like "#e30613", or one for each mode: { "light": "#e30613", "dark": "#ff5a4f" }. | Give a hex colour, or one for each mode. |
| Select option "x" needs a list of text options and a default that is one of them. | The default must appear in options. |
| Select option "x": "…" cannot be used as a CSS value. | A value in values has a character that is not allowed, such as ; or {. |
| Range option "x" needs numeric min, max, and default, with min below max. | All three as numbers, not text. |
| Option "x" has an unknown type. Use "color", "select", or "range". | One of those three. Note the spelling color. |
| "look" must be a list of up to four steps, each with a "module", a "transform", and "params". | Square brackets round the steps, and four at most. |
| Each step of "look" needs a "module" and a "transform". | Both are required in every step. |
If the file is not valid JSON at all (a missing comma, a trailing comma, a comment), the message is your computer's own description of where it stopped reading. JSON allows no comments and no comma after the last item.
If the skin loads but the page looks wrong: open the address /skin.css on the site. It is exactly what the browser receives: your stylesheet, then your colours for each mode, then the options as chosen.
Before you share it
- It has its own
name, alabel, and adescriptionthat says what it looks like. - No colour for the page is written in
skin.css; all arevar(--fb-…). - Both modes look intended, not like one mode inverted by accident.
- The Skins page shows no contrast warning.
- Everything in the list above has been looked at, wide and narrow.
- Every rule starts from
.fb-publicor anfb-class. - It loads nothing from another website. (The owner can add a counting service; a skin cannot.)
The reference kept with the source code is docs/SKINS.md.