1.0.1 • Published 3 months ago

alku v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

Alku

A classless + HTML attribute utility CSS. Might become a component library later on, we shall see.

  • Ideal for sites that are written in plain HTML or in markdown: you get good looking content by default when you use semantic elements.
  • Familiarity: you know browser defaults, they are mostly retained.
  • Opt-in resets: utilities do resets. Use utilities for UI development.
  • Typography: lots of font stacks to choose form.

Also: does not change the default box-sizing behavior!

Installation

npm install alku --save-dev
pnpm install alku --save-dev
yarn add alku --save-dev

Usage: Astro

---
import 'alku/alku.css';
---

Usage: HTML

<!-- minified -->
<link rel="stylesheet" href="https://www.unpkg.com/alku/alku.css" />
<!-- source -->
<link rel="stylesheet" href="https://www.unpkg.com/alku/src/alku.css" />

Or host it yourself.

Sources of inspiration

Stealing ideas from many sources (as we all do) and mixing in some ideas of my own.

There are others, maybe I find or remember them again some day.

Customization

You can customize these CSS variables in your own stylesheet:

:root {
	--page-default-font: var(--system-sans-stack);
	--page-marker-font: var(--mono-stack);
	--page-heading-font: var(--old-style-serif-stack);
	--page-mono-font: var(--mono-stack);

	--focus-color: Highlight;
	--link-color: currentColor;

	--ol-indent: 2em;
	--ul-indent: 1.375em;
}

You can check the available font stack variables from source alku.css file.

HTML attribute utilities

These are opinioned usability related extensions of HTML via the CSS.

HTML attributesPurpose
data-before="cover"Insert a transparent ::before pseudo element which covers the container. Useful to make links cover their entire container.
data-scrolling="horizontal"Wrap tables and other elements that are allowed to grow to be wider than the viewport.
data-scrolling="vertical"Wrap elements that you desire to scroll vertically. Note that you do need to have something that defines the height for the element such as a parent grid element.
<a aria-describedby rel="noopener noreferrer" target="_blank" />Link to external site with a matching icon. 1
<ol role="list" /><ul role="list" />Remove list-style and reset margin and padding of the list. Safari VoiceOver workaround to retain list semantics.
data-textTypographic utilities 2
data-text="visually-hidden"Hide text visually, keep it available for screen readers. Display if focused (useful for skip link). 3

Notes

1) External link icon

aria-describedby should point to an element which describes that the link leads to an external site. For example:

<!-- best place is in the beginning of body element -->
<div id="link-to-external-site" hidden>Opens external site</div>

<!-- example link -->
<a href="https://www.example.com" aria-describedby="link-to-external-site" rel="noopener noreferrer" target="_blank">
	Example
</a>
  • rel="noopener noreferrer" is recommended for security reasons.
  • Icon is part of the last word and does not wrap alone to a new line. (Except in Samsung Internet.)
  • Implemented using ::after pseudo-element.

2) Typographic utilities

data-text works as a typographic style reset (zero specificity), and it removes margin and padding, and inherits color by default (specificity of 0, 1, 0). If you only need the resets you can write data-text="".

ValueDescription
heading1<h1 /> without margin
heading2<h2 /> without margin
heading3<h3 /> without margin
heading4<h4 /> without margin
heading5<h5 /> without margin
heading6<h6 /> without margin
headingUse page default heading font
defaultUse page default font
monoUse page default monospace font
linkLink style
external linkExternal link style. Note that the words must be in this order.
thinWeight 100
extralightWeight 200
lightWeight 300
regularWeight 400
mediumWeight 500
semiboldWeight 600
boldWeight 700
extraboldWeight 800
blackWeight 900
extrablackWeight 950
italicOblique 10% (italic)
underlineUnderline

So for example <div data-text="heading3 italic external link mono" /> will result into what you would expect from what it says: text in the size and weight of heading3, monospace italic, and looking like an external link.

The following font sizes are available: 24, 22, 20, 18, 16, 14. Usage:

<span data-text="regular 18">Slightly bigger text than the usual 16.</span>

The sizes are fluid and increase gradually from 400px to 800px viewport width being 4px bigger at the end.

All the variants from Modern Font Stacks are also available:

ValueDescription
systemSystem sans serif stack
handwrittenHandwritten stack
transitionalTransitional serif stack
oldstyleOld style serif stack
slabSlab serif stack
antiqueAntique serif stack
didoneDidone serif stack
humanistHumanist sans serif stack
geometricGeometric humanist sans serif stack
classicalClassical humanist sans serif stack
grotesqueNeo-grotesque sans serif stack
industrialIndustrial sans serif stack
roundedRounded sans serif stack
monoslabMonospace slab serif stack
monocodeMonospace code stack

So if you want a part of the site use operating system default font you can do it with data-text="system".

3) Visually hidden

This is a modernized variant:

:root [data-text='visually-hidden' i]:not(:focus):not(:active) {
	all: initial;
	clip-path: inset(50%);
	contain: content;
	position: absolute;
	height: 1px;
	width: 1px;
	white-space: nowrap;
}

Rendering fixes

ElementDescription
ListsList elements do not align correctly against floated elements. Especially noticeable with nested lists where the nesting is lost entirely next to a float.
TablesWhen border-collapse: collapse; is enabled and you apply filter on a table cell part of it's border is or may be included to the effect in both Chrome and Firefox.
SubscriptSuperscriptAs in original normalize.css these elements have been fixed not to have effect on line height.

Opinionated stylings

This list may get outdated over time or may be incomplete.

FeatureDescription
AnchorLink style is also applied to regular anchor. Anchors as such have no use so this allows easy repurposing of them as buttons that appear as links.
BodyThe page is in a centered grid column by default.
CursorDisabled elements have not-allowed. Busy elements have progress.
Disabled elementsReduced saturation and opacity.
Fieldset and legendPadding removed by default.
Focus indicationStrong focus-visible is applied to all elements by default.
Form inputs, iframe, imagesheight: auto; max-width: 100%;
HeadingsHave default font-weight of semibold (600).
Inline media and embedsvertical-align: middle by default.
LinksHave font-weight of medium (500) by default. They are also underlined and inherit color.
Nested listsHave no margin.
Scroll behaviorSmooth scrolling is enabled by default.
Search inputAppear as regular text field for consistent styling.
StrongHas default font-weight of semibold (600). <b /> is bold (700).
SVGfill: currentColor; by default.
Textarearesize: vertical; by default.
1.1.0-rc.30

3 months ago

1.1.0-rc.29

3 months ago

1.1.0-rc.28

3 months ago

1.1.0-rc.27

4 months ago

1.1.0-rc.26

4 months ago

1.1.0-rc.25

6 months ago

1.1.0-rc.24

6 months ago

1.1.0-rc.23

6 months ago

1.1.0-rc.22

7 months ago

1.1.0-rc.21

7 months ago

1.1.0-rc.20

7 months ago

1.1.0-rc.19

7 months ago

1.1.0-rc.18

7 months ago

1.1.0-rc.17

7 months ago

1.1.0-rc.16

7 months ago

1.1.0-rc.15

7 months ago

1.1.0-rc.14

7 months ago

1.1.0-rc.13

8 months ago

1.1.0-rc.12

8 months ago

1.1.0-rc.11

8 months ago

1.1.0-rc.10

8 months ago

1.1.0-rc.9

8 months ago

1.1.0-rc.8

8 months ago

1.1.0-rc.7

8 months ago

1.1.0-rc.6

8 months ago

1.1.0-rc.5

8 months ago

1.1.0-rc.4

8 months ago

1.1.0-rc.3

8 months ago

1.1.0-rc.2

8 months ago

1.1.0-rc.1

8 months ago

1.1.0-rc.0

8 months ago

1.0.1

8 months ago

1.0.1-rc.0

8 months ago

1.0.0

8 months ago