Introducing Native Elements
Tags: css, html, webdev
Published: 2020-06-18 15:27:08

HTML elements with CSS superpowers. 🔥

Native Elements (NE) is not a CSS framework, no bundlers required or tons of configurations to set. You can consider it as a customizable plug-n-play library for your site which helps you easily style all the available HTML elements using CSS custom properties, classes, attributes, or whatever you want in less than `6 kB`. You can also build your class-based CSS framework on top of it.

---

## Features

This library is built using modern CSS feature and best practices, the compiled version supports only the latest two Chrome, Safari, Firefox, and Edge versions and this is possible thanks to <a href="https://github.com/browserslist/browserslist" target="_blank" rel="noopener noreferrer">Browserslist</a>



### Modern

Built on top of PostCSS takes advantage of exciting new CSS features, like custom and logical properties. If you use it from source, you can define custom selectors and mixins to make styling even easier.

### Framework agnostic

In the age of Flexbox, CSS grid, and other exciting layout features, there is less and less need for a bloated CSS framework. What you do need is a simple foundation on top of which to build your styles.

If you're using the compiled version, just drop it inside your application main style. It's just CSS, so it works with <a href="https://reactjs.org" rel="noopener noreferrer" target="_blank">React</a>, <a href="https://vuejs.org/" rel="noopener noreferrer" target="_blank">Vue</a>, <a href="https://angular.io/" rel="noopener noreferrer" target="_blank">Angular</a> and <a href="https://svelte.dev/" rel="noopener noreferrer" target="_blank">Svelte.</a>

### Easy theming

With our <a href="https://app.native-elements.dev" rel="noopener" target="_blank">theme builder</a> tool you can create, tweak, and export your theme easily. In the future, we'll share new premade themes.

---

## Making a theme

Thanks to the <a href="https://app.native-elements.dev/" rel="noopener" target="_blank">Theme Builder</a> app you can create your color palette, visually change and preview all the available custom properties, and download a ready-to-use theme that you can include in your project.

<a href="https://app.native-elements.dev/" data-hide-icon rel="noopener" target="_blank"><img src="https://native-elements.dev/img/tb.png" /></a>

### Using themes

Once you have your set of custom properties, there few ways to use it. You can put the custom properties inside the global `:root` of your css, or scope it inside a custom selectors.

### Global themes

When you put your theme inside the `:root` selector it will be applied to all the elements of your page. This is useful when you have one theme active at time:

```css
:root {
  --accent-color: hsl(220, 100%, 50%);
  --ne-global-background: hsl(0, 0%, 100%);
  --ne-global-foreground: hsl(0, 0%, 0%);
  --ne-body-font-family: sans-serif;
  --ne-root-font-size: 100%;
  --ne-body-font-size: 1.125rem;
  --ne-selection-foreground: hsl(0, 0%, 100%);
  --ne-selection-background: hsl(233, 64%, 72%);
  --ne-outline-width: 2px;
  --ne-outline-color: var(--accent-color);
  --ne-basic-line-height: 1.5;
  --ne-headings-scale: 1.25;
  --ne-quote-font-size: 2rem;
  --ne-cite-foreground: var(--accent-color);
  --ne-cite-font-size: 1rem;
  --ne-cite-start-sign: '—';
  --ne-links-foreground: var(--accent-color);
  --ne-links-active-foreground: hsl(233, 64%, 52%);
  --ne-del-foreground: hsl(337, 74%, 31%);
  --ne-del-background: hsl(0, 100%, 94%);
  /* ... */
}
```

### Scoped themes

The CSS's cascade is very useful to make scoped themes, it affects custom properties like other properties.

If you want to divide your theme into multiple pieces, you can wrap the custom properties inside separate selectors. Every element inside that selector will inherit the theme, while elements outside it will use their default style.

```css
:root[data-theme="dark"] {
  --accent-color: hsl(220, 100%, 50%);
  --ne-global-background: hsl(0, 0%, 100%);
  --ne-global-foreground: hsl(0, 0%, 0%);
  --ne-body-font-family: sans-serif;
  --ne-root-font-size: 100%;
  --ne-body-font-size: 1.125rem;
  /* ... */
}
```

```css
.NeumorphicTheme {
  --accent-color: hsl(220, 100%, 50%);
  --ne-global-background: hsl(0, 0%, 100%);
  --ne-global-foreground: hsl(0, 0%, 0%);
  --ne-body-font-family: sans-serif;
  --ne-root-font-size: 100%;
  --ne-body-font-size: 1.125rem;
  /* ... */
}
```

---

## When to use it

- You're working on projects for **modern and secure web browsers**
- You're not going to mix other CSS frameworks
- You want to save time sacrificing a bit of flexibility.


## More on [native-elements.dev](https://native-elements.dev)