d1 CSS framework


Get started

d1 is lightweight yet functional responsive CSS microframework with optional JavaScript enhancements. It aims to implement most widely used interface components with less code.

Install with NPM

Install to your repository:

npm install d1css

Then use in your CSS file:

@import "../node_modules/d1css/dist/d1.min.css";

And optionally bundle into your JavaScript file:

var d1 = require("d1css");
d1.load();

CDN

To use from CDN just add following code to the head of your page.

<link href="https://cdn.jsdelivr.net/npm/d1css/dist/d1.min.css" rel="stylesheet">
<!-- optional -->
<script src="https://cdn.jsdelivr.net/npm/d1css/dist/d1.min.js"></script>
<script> d1.load(); </script>

Install manually

Download from GitHub:
https://github.com/vvvkor/d1

Add following code to the head of your page:

<link href="d1.min.css" rel="stylesheet">
<!-- optional -->
<script src="d1.min.js"></script>
<script> d1.load(); </script>

Typography

Nothing special here. Mostly, default styling is kept.

Headings

Add let class to remove margins.

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6

Inline

Bold Italic Strike Insert Delete Subscript Superscript
Abbr Quote Cite Mark Dfn
Code Var Kbd Samp
Link

Blocks

Paragraph
New line

Paragraph

Preformatted code
Blockqoute

Lists

Add let class to remove margins and list style.
  • Unordered
  • List
    1. Ordered
    2. List
Term
Definition
Another term
Another definition

Grid

For the container, add row class. Direct descendants of the container are columns. By default, they all have equal width.

To stack columns on small screen, add flip class to the container.

To allow row wrapping add let class to the container.

To set various proportions, add following classes to the columns: col-0 for minimal required width, col-2 for double width, col-3 for triple width, narrow for narrow width, read to limit maximal width for comfortable reading.

Width limiting classes (col-0, narrow, read) can be combined with: center to centrify column in its available space, shift to shift column to the right.

Wrap your rows into div with wrap class to limit maximal width of the whole thing.

div.col-0
div
div
div
div.col-2
div.col-3
div
div.col-2
div
div.col-3
div
div
div
div
div
div
aaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbb
ccccccccccccccc
ddddddddddddddd
eeeeeeeeeeeeeeee
wwwwwwwwwwrap!

Table

Table is styled with border, unless it is a direct descendant of form. Add hover class to highlight hovered row. Add let class to hide borders.
Add r#, l#, #c (where # is any number) classes to align cells of column number # to the right, left or center, respectively (JavaScript required). Wrap table inside div with class roll to have independent horizontal scrolling of table when it is too wide.

Table caption
ComponentPure CSSJS enhancements .toggleRemember state .memClose on EscapeModifications
Dropdown H =/T - +
Tree tC =/T + - .accordion
Toggle tC =/T + -
Popup HtC =/T- +
Tabs tC T + -
Modal T = - (+) .full
Drawer T = - (+)
Gallery T = - (+)

Legend
H — :hover
T — :target (t — with undesirable scroll)
C — :checked (checkbox hack)

Read
...
...

Buttons

Button and input of type submit have button styling by default. Add btn class to the element (usually a link) to make it look like a button (which is not recommended from accessability point of view). For color options see Colors section.

Link Span Link-pad-rad Link
Link-button Link-pad Link

Forms

Inline form


Stacked form



Link


Aligned form using grid

Fieldset

Aligned form using table

For aligned form, table may be used, which is arguably not semantic, but still very convenient. In this case, table must be a direct descendant of form. Table will become stacked on small screen.

Input types
Upload
Box
Switches
Box



Radio


Just add nav class to unordered list.

Add shift class to list item to shift (and following items) to the right.

Add hover class to highlight item's background on hover.


Add nav let classes to unordered list.

Add flip class to stack items on small screen. Add let class to stack items on any screen. With pure CSS, nested lists are shown on hover. Add toggle class to control behaviour with JavaScript. In this case, link's href must point to corresponding nested list's id. With JavaScript, nested lists are toggled on click.

Following code shows how to collapse navigation to a single hamburger icon on small screen, and expand it to horizontal dropdown navbar on large screen (add flip class).

Toggle

Pure CSS togglers based on :target behaviour. This approach is semantic, but has some drawbacks:

  • only one togglable block can be active (open) at the moment
  • nested togglable blocks are not possible
  • styling of active link is not possible
  • on/off behaviour of the link is not possible
  • page scrolls, which is in most cases undesirable

To overcome these drawbacks, JavaScript can be used. To control elements with Javascript, add toggle class like in following examples for popup, toggle, tabs, tree. To store elements state in local storage, add mem class like in following examples for toggle, tabs, tree. Dialogs and drawers do not require such enhancements.

Popup

Inside div with pop class, use link pointing at sibling element.
Optionally add shift class to the target element to pop up leftwards.

Popup
Pop

Toggle

Use link pointing at element with hide class.

Toggle
Togglable

Drawer

Use link pointing at element with drawer class.
Optionally add shift class to the drawer element for right side drawer.
Optionally use closing link pointing at #cancel inside target element.

× Demo drawer

Modal dialog

Use link pointing at element with hide dlg classes.
Add let class for larger width.
Optionally use closing link pointing at #cancel inside target element.

Dialog

Modal fullscreen

Use link pointing at element with hide full classes.
Optionally use closing link pointing at #cancel inside target element.

Fullscreen
× Full

Hidden gallery: non-CSS fallback #1 #2 #3

Inside div with class gal, add sequence of links, each one pointing at the next and having style attribute with --img CSS proprty pointing at image. Lastly, add closing link pointing at #cancel.

Pure CSS gallery is based on CSS variables. Images are lazy loaded. Next image is preloaded. Enter key press navigates to the next image (depends on browser).

Warning: for IE support, use background-image instead of --img in style attribute; no lazy-loading in this case.

Tabs

Use list with nav tabs classes as tabs headers.
Each list item should contain a link pointing at tab panel.
Next sibling div should contain div tab panels.

2
2
3
3
3
1

Tree

Inside list items, use links pointing at nested lists.
Optionally add accordion class for accordion behaviour.


Details

This element natively has similar functionality.
Warning: not supported in IE and Edge.

Summary
Details

Toggle with radio buttons

Pure CSS togglers based on checkbox hack. This approach introduces bad semantics and is not generally recommended. But it overcomes drawbacks of :target-based togglers without using JavaScipt.

Popup with radio buttons

Pop 2

Toggle with radio buttons

Togglable 2

Tabs with radio buttons

1
2
2
3
3
3

Tree with radio buttons

You can use checkbox inputs to toggle branches independently or radio inputs with the same name for accordion.
    • Item 1.1
    • Item 1.2
    • Item 1.1
    • Item 1.2

Colors

Inline

Buttons


Blocks

Error Error

Warning Warning

Info Info

Yes Yes

No No

Bg

Border

Bg+Border

Status+Border

Button-like


Links and Icons

Blocks

Media object

Some description

Link

Figure

Figure caption

Box

No items yet

Click the button to create new item

Add new item

No items yet


Full height

Full

Invert

Inverted text link colors

JavaScript enhancements

  • Dropdown .toggle — toggle, escape
  • Tree .toggle — multiple, unscroll, toggle, remember (.mem), .accordion
  • Toggle .toggle — multiple, unscroll, toggle, remember (.mem)
  • Popup .toggle — multiple, unscroll, toggle, escape
  • Tabs .toggle — multiple, unscroll, remember (.mem)
  • Dialog — escape
  • Gallery — previous, escape
  • Link or button with confirmation: .dialog[title][data-caption]
  • Link with prompt: a.dialog[title][data-caption][data-prompt]
  • Check group of boxes: input[data-group], [class~="data-group"]
  • Toggle class: a[href^='#'][data-class], a[data-nodes][data-class] ( test invert )
  • Set value of target input: a[href^='#'][data-value]
  • Show value of color input: input[type="color"]
  • Align table columns: table.r5
  • Class depending on resize ([data-class-mobile] or [data-class-desktop]).
  • Asynchronous request: [data-target]

AJAX

Plugins

Calendar

Replacement of standard HTML date inputs.

Text
Date
Datetime

Dialog

Replacement for standard Javascript dialogs.

Edit

Add class adjust to textarea for height auto-adjustment to content.

Add class edit to textarea tu turn it into WYSIWYG editor.
Optional data-tools attribute defines custom set of tools.
Optional data-wys attribute defines initial mode: "1" for WYSIWYG, "" for source editing. If absent, mode is defined automatically based on whether HTML tags are contained in text.


Place links with class pic inside div with class gallery to generate gallery similar to pure CSS gallery.


Lookup

Autocomplete lookups with data from XHTTP request.


Chained selects.


Tablex

Filter and sort HTML table.

StringNumberBytesIntervalDate
beta.0019 b1y2.1.2018
Alpha910 kb2m1/15/2018
kappa1232KB4 h2018-01-05
Gamma12.31 MB3d21.01.2018
delta1 2,41 MB3d21.01.2018
Totals144.3011.1 MB1y 2m 3d 4h-

...
...
...

Valid

Custom form validation.

Custom input validation messages

To customize input validation messages, provide validation hint in data-hint attribute of input element. Placeholders inside percent characters are replaced with value of corresponding attribute of input element.

Enter 2 up to 4 latin letters
Looks good
Box
Radio

Custom hint elements for input validation

Another option is to add sibling element with class text-e after input. It will be visible only if input value is not valid. Contrary, sibling element with class text-y will be visible only if input value is valid.

To improve usability, add class js-unhint to form. This will disble default brower-specific tooltips and disables reporting empty required inputs as invalid until submitting.

Validation hint inside small
Validation hint inside div
Looks good
Select language
Enter number between 1 and 10, step 0.1
Type something
Box
Radio
Form not valid

Customization with CSS vars

  • --text - base text color; default: #222
  • --bg - base background color; default: #fff
  • --bg-pane - panel background color; default: rgba(0,0,0,.05)
  • --border - border style; default: thin solid rgba(0,0,0,.16)
  • --bg-hilite - highlighted element background; default: rgba(0,0,0,.05)
  • --text-hilite - highlighted element text color; default: inherit
  • --link - base link text color; default: #03b
  • --hover - hovered link text color; default: #003
  • --visited - visited link text color; default: #90c
  • --rad - border radius in ems; default: .2
  • --gap - base gap for margins and paddings in ems; default: 1
  • --gap-rate - rate of vertical and horizontal gap; default: .5
Customize

Reference

CSS classDescriptionUsed withModifications
.rowGrid.col-0 div .col-2 .col-3.flip .stick .let .wrap .read .narrow .shift
.rollHorizontal scrolltable.hover
button, a.btnButtonform submit button a span.bg-x [data-target]
.navNavigationul.flip .hover .let .bg .act .shift
.drawerDrawerdiv a.close.shift
.flipResponsive.row .nav
.fixFixed block.r .l
.hideTogglable (hash)div ul .close.dlg.c.let .full.c .hide-mobile .hide-desktop .pop .tabs
.switchTogglable (radio)label div.pop .tabs
.galGallerya .close[data-info]
.toggleJavaScript toggleul div .js-control .js-hide.mem
.iconSmall imageimg svg a button
.text-Text color* .invert.text-e .text-w .text-i .text-y .text-n
.bgBackground color* .invert.bg-e .bg-w .bg-i .bg-y .bg-n .yel
.r .c .lAlign*
.centerCentrify*
.smallSmall font*
.marVertical margin*
.padPadding*
.bordBorder*
.radBorder radius*
.letLess formatting*, ul, table, .row
.nobrNo wrapping*
.hide-print .hide-screenShow by media*

Alphabetical reference

  1. .act — active link
  2. .bg — light background
  3. .bg-e — nominal "red" background
  4. .bg-i — nominal "blue" background
  5. .bg-n — nominal "gray" background
  6. .bg-w — nominal "yellow" background
  7. .bg-y — nominal "green" background
  8. .bord — add border
  9. .btn — button-like
  10. .c — centrify content inside block
  11. .center — centrify block itself
  12. .close — link to close togglable block
  13. .col-0 — grid cell with non-expanding width
  14. .col-2 — grid cell with expanding width (x2)
  15. .col-3 — grid cell with expanding width (x3)
  16. .dlg — card-like block
  17. .drawer — drawer
  18. .fix — fixed in corner
  19. .flip — responsive component, stacked view on small screen
  20. .full — fullscreen block
  21. .gal — fullscreen gallery
  22. .hide — hidden
  23. .hide-desktop — hidden only on large screen
  24. .hide-mobile — hidden only on small screen
  25. .hide-print — hidden on print
  26. .hide-screen — hidden on screen
  27. .hover — highlight link or table row on hover
  28. .icon — small image
  29. .invert — invert colors
  30. .js-control — visibility is controlled by JavaScript, shown by default
  31. .js-hide — hidden with JavaScript
  32. .l — align content to the left
  33. .let — remove some formatting: margin, table border, list style
  34. .mar — add vertical margins
  35. .narrow — narrow block width
  36. .nav — horizontal dropdown navigation
  37. .nobr — prevent automatic text wrapping
  38. .pad — add padding
  39. .pop — popup component wrapper
  40. .r — align content to the right
  41. .rad — rounded corners
  42. .read — block width for comfortable reading
  43. .roll — horizontal scrolling of contents
  44. .row — row of grid
  45. .shift — shift item of .row, .nav, .pop, .drawer to the right
  46. .small — small font size
  47. .stick — stick block to the top
  48. .switch — input controlling visibility of following block
  49. .tabs — tabs component
  50. .text-e — nominal "red" text color
  51. .text-i — nominal "blue" text color
  52. .text-n — nominal "gray" text color
  53. .text-w — nominal "yellow" text color
  54. .text-y — nominal "green" text color
  55. .wrap — reasonable page width limit
  56. .yel — temporary highlight targeted block