A drop-in collection of CSS styles to make simple websites just a little nicer

  • By Kognise
  • Last update: Dec 1, 2022
  • Comments: 12

NPM page On Product Hunt Contributors MIT license


Water.css

๐ŸŒŠ A drop-in collection of CSS styles to make simple websites just a little nicer

Water.css


Goals

  • Responsive
  • Themeable
  • Good browser support (works on my old kindle's browser :P)
  • Tiny size
  • Beautiful
  • No classes

Why?

I commonly make quick demo pages or websites with simple content. For these, I don't want to spend time styling them but don't like the ugliness of the default styles.

Water.css is a CSS framework that doesn't require any classes. You just include it in your <head> and forget about it, while it silently makes everything nicer.

Who?

You might want to use Water.css if you're making a simple static page or demo website that you don't want to spend time styling.

Although it originally wasn't built for more complex websites, many developers have used Water.css as a base stylesheet and creatively applied custom styles to build out an entire app. Nothing is stopping you from doing the same!

How?

Just stick this in your <head>:

๐ŸŒ™ / โ˜€ Automatic Theme:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/out/water.min.css">

๐ŸŒ™ Dark Theme:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/out/dark.min.css">

โ˜€ Light Theme:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/out/light.min.css">


A preview of the different themes is available on the demo page! โšก

How the "Automatic Theme" works

The main water.css file automatically switches between light and dark mode depending on the system preferences of a user's device. This detection is made possible through a CSS media query called prefers-color-scheme. In browsers where the preference can't be detected, water.css will stick to the light theme.

If you want to avoid this behavior, use either dark.css or light.css.

Supporting Internet Explorer

All three distributions of Water.css support Internet Explorer 11, but the main water.css file doesn't respect the user's color scheme and will be locked to light mode due to lack of prefers-color-scheme support.

Be aware that IE also doesn't support runtime theming, and fixed fallback values will be used. If you want to override the Water.css theme in a way that's compatible with IE, we recommend that you compile your own theme.

Unminified builds

All versions are also available as unminified stylesheets, which can be handy during development.
Simply remove the .min from the file name.

Theming

Do you want to make some adjustments or build your own theme completely different from the official dark or light themes? Since Water.css is built with CSS variables this is super easy to do! Here's a list list of all the variables you can change to your liking:

  • --background-body
  • --background
  • --background-alt
  • --selection
  • --text-main
  • --text-bright
  • --text-muted
  • --links
  • --focus
  • --border
  • --code
  • --animation-duration
  • --button-hover
  • --scrollbar-thumb
  • --scrollbar-thumb-hover
  • --form-placeholder
  • --form-text
  • --variable
  • --highlight
  • --select-arrow

Runtime theming

โš  If you use a version with support for legacy browsers like Internet Explorer, skip to Compiling your own theme!

Water.css uses Custom Properties ("CSS variables") to define its base styles such as colors. These can be changed and overwritten right in the browser.

Because of this, you can simply add your own stylesheet to the page and set your own CSS variables there. As long as your stylesheet comes after Water.css in the HTML, your values will override the default ones and your theme is applied!

This short example will use Water.css, but color all links red:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/[email protected]/out/water.min.css" />
<style>
  :root {
    --links: red;
  }
</style>

If you want to change a value for dark or light mode only, use a media query like this:

<style>
  :root {
    --links: blue; /* Always applied */
  }

  @media (prefers-color-scheme: dark) {
    :root {
      --links: yellow; /* Only applied in dark mode (overrides blue) */
    }
  }
</style>

Compiling your own theme

If you are targeting browsers without support for CSS Custom Properties such as Internet Explorer, runtime theming is not an option. To apply your own theming, you'll need to make your changes in the source files themselves, then re-compile the CSS files. This works like the following:

  • Clone the repository to your machine
  • Run yarn to install dependencies
  • Make the theming changes you want in src/variables-*.css
  • Run yarn build to compile the CSS files
  • Use the compiled files in the out/ directory on your site

You also might want to check out the Contributing Guide as it contains further information about the build setup.

Contributing

Water.css becomes better for everyone when people like you help make it better!

Check out our Contributing Guide to learn how to get started.
And thanks for taking the time to contribute! :)

Github

https://github.com/kognise/water.css

Comments(12)

  • 1

    Water.css 2.0

    ๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰ This PR proposes merging Water.css 2.0.0 into master!

    @kylejrp you said there were some comments you wanted to make, what are they?

    Also, this introduces a lot of changes - how can we best summarize them for the changeset?

    This closes #187.

  • 2

    Next Steps

    EDIT: Here's the current checklist:

    • [x] Update the old jsdelivr url to the new one everywhere
    • [x] Remake the file structure and docs #191
    • [x] Add redirects from the github pages site #158
    • [x] Update the demo site url to watercss.kognise.dev everywhere
    • [x] Add the bookmarklet #20
    • [x] Create a changeset and merge into master
    • [ ] Publish 2.0

    As far as I can see, here's the current state of Water.css 2.0:

    • There are several conflicting pull requests relating to the documentation site, and it's likely that merging the wrong ones will completely break the site.
    • The css file that the site references is out of sync with the one that's currently in the readme, and the readme references some features that aren't yet in the site.
    • We're currently included the built css files in the repository and managing versions with git tags, but this makes contributing more complex and pull requests significantly harder to merge.
    • The plan is to use npm for version management in the future, but then existing sites won't receive updates unless we also continue pushing git tags.
    • The development workflow, currently based on gulp, isn't ideal and has a few issues.
    • We're currently using netlify to deploy the documentation site but there have been some concerns raised about their new policies.

    I'd love feedback on what we should do about these things but here's what I've been thinking:

    I think we should stop including the dist folder within the repository and instead rely on a continuous integration platform, potentially github actions, to build the code and deploy it to both a git tag and npm. This will make contributing easier and ensure that existing sites get updates.

    I'm not entirely sure about this, but we might want to consider completely remaking the documentation site and build pipeline with something slightly less janky. We could also consider deploying the site to a different service, maybe vercel? This will give the added benefit of being able to gracefully switch over to the new documentation.

    Furthermore, a lot of the issues are simply caused by multiple pull requests that have overlap and merge conflicts - I propose instead we create one monster pr that when merged will update everything.

    Sorry for the huge block of text, please tell me if I was unclear in any way!

    cc @kylejrp @kimulaco @jonaskuske @JackFly26

  • 3

    ::selection

    By darkening the background color by 40% we can get a nice background color for selections.

    I propose adding something like this:

    ::selection {
      background-color: darken($background-color, 40%);
    }
    
  • 4

    [WIP] New File Structure + Version Picker

    This PR changes the file structure to water.css, dark.css, and light.css. It also introduces a full rewrite of the version picker on the documentation site.

    Todo:

    • [x] Add fancy animations, @jonaskuske :)
    • [x] Wire up the copy to clipboard button
    • [x] Update the readme with the new files

    Are there any other changes in scope of this pull request?

  • 5

    prefers-color-scheme

    https://developer.apple.com/documentation/safari_release_notes/safari_12_1_release_notes

    Be good if you can support Safari media queries so that if a user wants a dark scheme, they would get one. And if a user doesn't, they would get a light theme instead?

  • 6

    ::selection makes --text-muted barely visible

    Both the ::selection color and --text-muted are a sort-of similar shade of gray, so selecting text that's muted, e.g. a <footer> / <cite> means the text becomes very hard to read.

  • 7

    Accessibility Compliance

    We should pick a specific level of accessibility and make sure all of our components meet that level of accessibility.

    Steps:

    • Choose between AA and AAA accessibility
    • Add an accessibility checker to our gulp build tools and/or pull requests
    • Make sure each CSS component complies with our accessibility checks
    • Make sure the demo page complies with our accessibility checks before merging
    • Add accessibility to the project goals

    I can take care of the build tools, but I think I'm looking for @kognise and the community's opinion on what level of accessibility we should be complying with.

  • 8

    heading semantics

    Styling for <h1> headings is currently broken, as all <h1> headings are forced to have the same font size.

    HTML allows you to have multiple <h1> elements on a pageยน, with one being the main site title and the others being nested e.g. inside <article> elements and acting as the main title for the respective article.

    Browsers respect this and display nested <h1> elements smaller than the main one, but water.css breaks this because it forces all <h1> elements to have the same font-size.

    <html>
      <body>
        <h1>Main title</h1>
        <article>
          <h1>Sub title</h1> <!-- Should have same size as <h2> -->
        </article>
      </body>
    </html>
    

    ยน The Document Outline as intended by HTML5 โ€“ but while browsers visually adhere to it by scaling down <h1> elements, they don't implement the Outline algorithm on a semantic level, unfortunately.

  • 9

    Gulp build tools

    I replaced the previous development server with a souped-up gulp build pipeline. Now you're playing with power! ๐Ÿ˜Ž

    Gulp

    Gulp replaces the previous compiling of the sass files and also handles the development tools. Gulp has lots of other extensions for things like html templating and minification that the demo page could take advantage of in the future.

    Sourcemaps

    Devtools will now show you the original sass file the rule came from instead of just the full .css file: image

    It will even show you the original Sass file in devtools: image

    Note: this makes the dark.css/light.css look really big in devtools, but that's because it's also downloading the sourcemap file. The actual .css file is still small when using in production.

    Autoprefixing

    You can forget about browser prefixes now - autoprefixer will handle them! I've put a recommended set of supported browsers in the package.json. You can see the coverage here. Feel free to modify! https://browserl.ist/?q=last+1+version%2C+not+dead%2C+%3E+0.2%25

    CSS Minification

    postcss/cssnano are handling css minification. I'm using their "safe" defaults, but they could be tuned even further to provide some even better minification.

    Browser Sync

    This does the live reloading / development environment that you had previously set up with dev.js. However, there's no more server code for you to maintain! This should automatically stream changes to your browser when you have it open. It automatically launches and watches index.html and the sass files when running yarn dev.

  • 10

    Publish to npm

    It might be nice to have water.css published to npm with every release. Then, users can install it using npm install water.css and include it in their projects without referencing a CDN.

    This would mean we would have to update the package.json version semantically with every release as well.

  • 11

    [Blockquotes] Added background and new file for blockquote

    Objetives:

    • Making the blockquotes element similar to the other UI elements using border radius 6px and background.
    • Making the _variables file for using elements like spacing, radius and borders to make a consistant UI when using those elements.
  • 12

    feat(radio): change focus ring to match round input

    Description

    This uses a drop-shadow filter and clip path to create a round focus indicator on radio inputs. Issue #278

    Method

    • A box-shadow can only apply square shadows to an element, resulting in a mismatched focus indicator. Screenshot of the original focus state:
    Screen Shot 2022-10-24 at 8 25 59 AM
    • Instead of box-shadow, I used a drop-shadow filter. Drop-shadow filter does not yet support the spread variable that box-shadow has, so we cannot create the unblurred solid 2px shadow that box-shadow allows. Instead, I used 4 layered shadow filters which cover a wide enough area to build the focus indicator. Screenshot of the four layered shadow filters:
    Screen Shot 2022-10-24 at 8 32 05 AM
    • The shadow is then limited to closely match the original 2 pixel solid box shadow spread by creating a circular clip path which slightly overshoots the edge of the component to allow approximately 2 pixels of shadow to show through:
    Screen Shot 2022-10-24 at 8 25 20 AM

    How and where has this been tested?

    • Chrome 106 for macOS
    • Firefox 106 for macOS
    • Safari 16 for macOS

    Screenshots

    Screen Shot 2022-10-23 at 3 09 34 PM

    Browser Compatibility

    Although this is compatible with Safari, it is worth noting that an existing issue with the display of radio inputs in Safari results in cropping of the input. This was a pre-existing issue due to the width, height, and font size on the input. I recommend that this be resolved in a separate issue.

    Safari screenshot: water-safari-radio-issue

    Please let me know if any changes are needed and I would be glad to take care of it.