React HTML elements with CSS-in-JS Sample in 2020

React HTML elements with CSS-in-JS Sample in 2020

tutorials -


React HTML elements with CSS-in-JS.

npm i horror styled-components

Quick Start

To create a Horror starter project, run:

npm init horror my-horror-project


import React from 'react'
import { Div, H1 } from 'horror'

export default props =>
  <Div css={{
    padding: '32px'
    <H1 css={`color: red;`}>
  • Includes all HTML elements
  • Use object literal or CSS syntax
  • Style any component
  • Support for [styled-components][sc] or [emotion][emotion]


Changing the underlying HTML tag can be done in any of the following ways:

  • Importing the tag directly: import { Header } from 'horror'
  • Using a key on the default import: <Horror.header />
  • Using the is prop: <Horror is='header' />
  • Using the styled-components API: const H1 = Horror.withComponent('h1')

Using Custom Components

To use a custom component, pass it to the is prop:

import React from 'react'
import { Link } from 'react-router-dom'
import H from 'horror'

const RedLink = props =>
      color: 'red'

Creating Style Components

Horror can be used to create component primitive abstractions, similar to using [styled-components][sc] or [react-emotion][emotion],
but with a more React-like syntax.

import React from 'react'
import H from 'horror'

const Button = ({
}) =>
      fontFamily: 'inherit',
      fontSize: '14px',
      fontWeight: 'bold',
      textAlign: 'center',
      textDecoration: 'none',
      display: 'inline-block',
      margin: 0,
      paddingLeft: '16px',
      paddingRight: '16px',
      paddingTop: '8px',
      paddingBottom: '8px',
      verticalAlign: 'middle',
      appearance: 'none',
      border: 0,
      borderRadius: '4px',
      color: 'white',
      backgroundColor: primary ? '#07c' : '#444',
      '&:hover': {
        boxShadow: 'inset 0 0 0 64px rgba(0, 0, 0, .125)'

Button.displayName = 'Button'

export default Button


Horror also works with [emotion][emotion]:

npm i emotion react-emotion
import H from 'horror/emotion'


Trending On Tutorial Stuff

Our Sponsors

Top Applications in Tutorial Stuff

Top Experts In Tutorial Stuff