Examples

Here are two introductory examples of the functionality of Swatch. These examples are meant to give you give an idea of what the library can do. Don't worry these examples are not clear, at the moment, we will explain them later in detail.

You will learn in-depth how the library is desgined and how you can leverage its powerful and code-efficient patterns in the Guides > Setters, Getters and Scope.

A basic example

This first example uses Swatch in the most simple way : html which consumes the Swatch syntax through the provided CSS classes.

Live Editor
Result

Some news article

A detailed reason for you to read the article

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis fringilla ligula vel mollis ultrices. Proin sodales faucibus sodales. Ut libero nisi, venenatis in neque interdum, ullamcorper scelerisque erat. Phasellus non lectus nisl. Quisque vel laoreet libero. Cras mi ante, efficitur a tincidunt ac, cursus at metus. Morbi porttitor magna non ipsum porttitor, vitae scelerisque arcu ullamcorper. Aenean non sapien vel leo aliquam dictum in in metus. In et elit mauris. Pellentesque ac pharetra erat.

This div has a red background and the text color is automatically contrasted.
This div has a red background and the text color is automatically contrasted.
This div has a red background and the text color is automatically contrasted.
This div has a blue background and the text color is automatically contrasted.

Dynamic theming

This second example illustrates how Swatch can be used together with javascript (here, React) to apply dynamic theming. Don't worry if how this works is not clear yet. It is covered in-depth in the Guides > Themes > Local Themes section of the guides.

Live Editor
Result

Some news article

A detailed reason for you to read the article

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis fringilla ligula vel mollis ultrices. Proin sodales faucibus sodales. Ut libero nisi, venenatis in neque interdum, ullamcorper scelerisque erat. Phasellus non lectus nisl. Quisque vel laoreet libero. Cras mi ante, efficitur a tincidunt ac, cursus at metus. Morbi porttitor magna non ipsum porttitor, vitae scelerisque arcu ullamcorper. Aenean non sapien vel leo aliquam dictum in in metus. In et elit mauris. Pellentesque ac pharetra erat.

This div has a red background. This doesnt change with the theme.