d1 v0.0.0 npm install d1css GitHub

d1 front-end framework


Get started

d1 is lightweight functional responsive CSS/JS front-end microframework. Its aim is to implement 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:

let d1 = require("d1css");

Install manually

Add the distributed CSS and JavaScript to the head of your document.

<!doctype html>
<html lang="en">
  <head>
    <title>Title</title>
    <meta charset="utf-8">
    <meta name="viewport" 
      content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="/css/d1.min.css">
    <script src="/js/d1.min.js"></script>
  </head>
  <body>
  </body>
</html>

CDN

Add CDN links to the head of your document.

<link href="https://cdn.jsdelivr.net/npm/d1css/dist/d1.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/d1css/dist/d1.min.js"></script>

Typography

Mostly, default styling is kept.

Inline

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

Headings

h1..h6Default margins
.marSmaller margins
.fitNo margins

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6

Blocks

Paragraph
New line

Paragraph

Preformatted code
Blockqoute

Grid

Grid row (container) div.row. Direct descendants of the container are columns. By default, they all have equal width.

Options



(disables column width modifiers)
Column width options (applied on central column here)



Left
Central
column
Very wide content — required to overflow available column width
Right
Column position options (applied on central column here)



Left
Central
column
Right

Lists

Basic lists

Options


  • Unordered
  • List
    1. Ordered
    2. Sub-list
Term
Definition
Another definition
Another term
Another definition

Tree

Expandable nested lists ul.tree.

Inside list items, use links pointing at nested lists, or links without [href]. When no such link is found, it is generated.

For accordion behaviour, use .accordion.
To remember state, use .mem.

  • Computer
    • Programming
      • JavaScript
      • PHP
    • Markup
      • HTML
      • CSS
  • Human
    • English
    • Spanish

Tables

Basic table

tableBy default, table is styled with border
form > tableNo borders if table is a direct descendant of form
.fitHide borders
.letRow dividers
.hoverHighlight row on hover
.shiftFull width
.roll > tableScroll overflowing width
.l1 .r2 .c3Align specific columns to the left/right/center
Table caption
ComponentCodeRemember stateFix positionClose on Escape
Dropdown .nav - + +
Tree .tree .mem - -
Toggle .target.mem - -
Popup .pop - + +
Tabs .tabs .mem - -
Modal .dlg - - +
Drawer .drawer- - +
Gallery .gal - - +
Topbar .topbar- - -

Legend
H — :hover
T — :target (t — with undesirable scroll)
J — javascript toggle
V — visible
S — scroll

Responsive table

Turn rows into cards on small screen table.flip.

Web languages
LanguageTypeYear
HTMLMarkup1993
JavaScriptProgramming1995
CSSStyle1996

Interactive table

Filter and sort table rows table.sort, table[data-filter].

StringNumberBytesIntervalDate
HTML49 B9d1993-07-09
JavaScript10.11 MB5m12/4/1995
CSS33 KB1y17.12.1996
Totals17.11.003 MB1y 5m 9h-

Forms

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 accessibility point of view). For color options see Colors section.

Link
Span Link-pad-bord Link-pad Link

Inline form

Stacked form



Link

Grid layout

Fieldset

Table layout

For aligned form, table may be used, which is arguably not semantic, but 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

Color

Checkbox group





Set input value

Test, Reset

Calendar

Replacement of standard HTML date inputs.

Text
Date
Datetime

Edit

Auto-adjust textarea height to content .adjust.

Turn textarea into WYSIWYG editor .edit.
Optionally define initial mode in [data-wys] ("1" for WYSIWYG, "" for source editing). If absent, mode is defined automatically based on whether HTML tags are contained in text.
Optionally define custom set of tools in [data-tools]. Example: data-tools="/bi_.".

Editor tools
CodeCommandDescription
/srcView source
*insertimageImage
@createlinkLink
xunlinkUnlink
bboldBold
iitalicItalic
_removeformatRemove format
.insertUnorderedListUnordered list
#insertOrderedListOrdered list
1formatblockHeading 1
2formatblockHeading 2
3formatblockHeading 3
pformatblockParagraph
|toolsExpand toolbar
cinserthtmlCode
,inserthtmlAbbreviation
sstrikeThroughStrike through
^subscriptSubscript
vsuperscriptSuperscript
dformatblockDiv
qformatblockBlock quote
fformatblockPreformatted
~inserthorizontalruleHorizontal ruler
TinserthtmlTable
(justifyLeftJustify left
=justifyCenterJustify center
)justifyRightJustify right
jjustifyFullJustify full
+indentIncrease indent
-outdentDecrease indent

Lookup

Autocomplete lookups with data from XHTTP request.

Chained selects.

Validation

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
Check to continue
Radio
Select to continue
Form not valid

Components

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 is used. To store elements state in local storage, add .mem class like in following examples for target, tabs, tree. Dialogs and drawers do not require such enhancements.

Target

Use link pointing at element with .target class.

Toggle
Togglable

Popup

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

Popup
Pop

To create a navigarion bar add .nav class to the ul element.

With pure CSS, nested lists are shown on hover. 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 dropdown navbar on large screen.

Options





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

Modal

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

Open modal

Modal fullscreen

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

Open fullscreen modal
× Fullscreen modal

Dialog

Replacement for standard Javascript dialogs.

  • Alert .alert
  • Confirm .dialog[title]
  • Prompt .dialog[data-prompt][data-caption]
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.

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

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

Topbar



<div class="topbar let">
  Topbar
</div>

Details

Warning: limited browser support.

Summary
Details

Utilities

Fetch

Toggle class

Toggle class or other attribute a[href^="#"][data-set][data-unset][data-attr], :is(a, select, [type="checkbox"], [type="radio"])[data-nodes][data-set][data-unset][data-attr].


Red text links in this block
Invert page
Change type of the following input
(invert)

Responsive class

Class depending on available width [data-class-mobile], [data-class-desktop].
Toggles on resize.

Mobile off on
Desktop off on

Items

Items are nodes with class .item. Container is items' common parent. Containers with items can be nested. Hashed links inside items invoke actions on containing item. If link needs to be outside of the item, point at item with query selector in link's [data-item] attribute.

  • #copy copy item
  • #hide hide item
  • #del delete item unless it is last in the container
  • #delete delete item, even the last one
  • #delall delete all items inside container defined by [data-item]
  • #clear delete all nodes inside container defined by [data-item]
+ Span item
Div item
+ Name Value
+ Table row item
+ ×

Icons

Add icon before element's content [data-icon].
Replace element's content with icon [data-ico] Provide [title] for accessibility.

Available icons

Display options




Code highlight

Add .language-xxx class to code element. Available language codes: html, css, js.

<!-- HTML -->
<a href="#top">Top</a>
/* CSS */
a .test {
	color: inherit;
	background: #c00;
	font: "PT Sans", sans-serif;
}
// JavaScript
let double = function(x){
	console.log('double', x);
	return 2 * x;
}

Code sample

Add .code class to div element.

HTML code sample

Theme

Customize

Style

Colors

Inline

Buttons

Link Link Link Fit

Blocks

Error Error

Warning Warning

Info Info

Yes Yes

No No

Bg

Border

Bg+Border

Status+Border

Button-like

Links and Icons

Span with generated icon: , , title, caption
Span with on-page icon: , , title, caption
Span with absent icon: , , title, caption
Simple links: Default OK
Hover links: Default OK
Buttons: Default OK
Table: Default OK

Invert

Inverted text link colors

Blocks

Media object

Some description

Link

Figure

Figure caption

Box

No items yet

Click the button to create new item

Add new item

Full height

Full

Customization with CSS vars

  • --text - base text color; default: #000
  • --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: #07f
  • --visited - visited link text color; default: #80b
  • --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
  • --shade - shadow of overlay components; default: 0 .2em .8em rgba(0,0,0,.3)
  • --topbar - height of topbar; default: 3.2rem
Customize

Reference

ItemDescriptionUsed withModifications
.rowGriddiv ul .col-0 .col-2 .col-3.flip .let .center.shift .stick .center .wrap .read .narrow
tableTable.roll.hover .fit .let .shift .flip
ul, ol, dlList.fit .row
.treeTreeul.accordion .fit
button, a.btnButtonform submit button a span.bg-x [data-target]
.flipResponsive.row .nav table
.hideVisibility by mediadiv.hide-mobile .hide-desktop .hide-print .hide-screen
.targetTogglediv.toggle .off .mem .act
.popPopup.pop>.shift
.navNavigationul.flip .hover .let .bg .center .nav.tabs.mem.act .shift
.tabsTabsul.nav
.dlgModal.close.dlg.c.let .dlg.full.center
.galGallerya .close[data-info]
.drawerDrawerdiv a.close.shift
.topbarTop bar.let
.letSpecific modifications to components.row, .nav, .dlg, .topbar, table
.iconSmall imageimg svg a button
.fixFixed block.r .l
.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* .row .nav .full
.smallSmall font*
.fitRemove formatting*.mar .pad .bord .rad .shade
.marVertical margin*
.padPadding*
.bordBorder*
.radBorder radius*
.shadeAdd shadow*
.nobrNo wrapping*

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. .fit — remove formatting: margin, border, padding, shadow
  19. .fix — fixed in corner
  20. .flip — responsive component, stacked view on small screen
  21. .full — fullscreen block
  22. .gal — fullscreen gallery
  23. .hide — hidden
  24. .hide-desktop — hidden only on large screen
  25. .hide-mobile — hidden only on small screen
  26. .hide-print — hidden on print
  27. .hide-screen — hidden on screen
  28. .hover — highlight link or table row on hover
  29. .icon — small image
  30. .invert — invert colors
  31. .l — align content to the left
  32. .let — specific modifications to components
  33. .mar — add vertical margins
  34. .narrow — narrow block width
  35. .nav — horizontal dropdown navigation
  36. .nobr — prevent automatic text wrapping
  37. .off — hidden with JavaScript
  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. .shade — add shadow
  46. .shift — shift item of .row, .nav, .pop, .drawer to the right
  47. .small — small font size
  48. .stick — stick block to the top
  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. .toggle — visibility is controlled by JavaScript, shown by default
  56. .topbar — sticky top app bar>
  57. .wrap — reasonable page width limit
  58. .yel — temporary highlight targeted block