Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <!-- React app below -->
<div id="app"></div>
<!-- React app above -->

  <br><small>Read my blog article <a href="https://dbushell.com/2018/04/05/react-redux-internationalisation/" target="_blank">React &amp; Redux - Internationalisation</a> for more information.</small>
  <br><small>Sorry for any Google translation errors!</small>
              * {
  box-sizing: border-box;

body {
  background: #f2f0e6;
  color: #494b4d;
  padding: 1rem;

button {
  background: #fff;
  border: 2px solid #1d97bf;
  border-radius: 5px;
  color: #1d97bf;
  cursor: pointer;
  flex: 0 1 auto;
  font-family: Arial;
  font-size: 18px;
  font-weight: 700;
  height: 50px;
  line-height: 30px;
  padding: 8px 20px;
  transition: background 150ms, border 150ms, color 150ms;
  width: calc(33.333% - 10px);
  &[aria-pressed="true"] {
    background-color: #39809e;
    border-color: #39809e;
    color: #fff;

  &:hover {
    background-color: #1d97bf;
    border-color: #1d97bf;
    color: #fff;

#app div {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  max-width: 600px;
  min-width: 500px;

p {
  font-size: 18px;
  flex: 1 1 auto;
  width: 100%;
  margin-bottom: 20px;

  a {
    border-bottom: 2px solid rgba(#1d97bf, 0.1);
    color: #1d97bf;
    text-decoration: none;
    transition: border 150ms, color 150ms;
    &:hover {
      border-color: #fffbcc;
      color: #39809e;

small {
  font-size: 75%;
              // using global modules for CodePen demo
// replace with import statements
const {connect, Provider} = ReactRedux;
const {createStore} = Redux;

// initial app state for demo includes i18n translations
// i18n could be loaded via JSON file, API call, or global object
const initialState = {
  lang: 'en',
  i18n: {
    en: {
      Menu: {
        desc: 'This app is translated into %1$d languages:',
        enButton: 'English',
        deButton: 'German',
        esButton: 'Spanish'
    de: {
      Menu: {
        desc: 'Diese App ist in %1$d Sprachen übersetzt:',
        enButton: 'Englisch',
        deButton: 'Deutsche',
        esButton: 'Spanisch'
    es: {
      Menu: {
        desc: 'Esta aplicación está traducida a %1$d idiomas:',
        enButton: 'Inglés',
        deButton: 'Alemán',
        esButton: 'Español'

// stateless functional component
const Menu = props => {
  // create button props from lang code
  const buttonProps = lang => ({
    onClick: () => props.onLang(lang),
    'aria-pressed': props.lang === lang
  return (
      <p>{sprintf(props.i18n.desc, props.langCount)}</p>
      <button {...buttonProps('en')}>{props.i18n.enButton}</button>
      <button {...buttonProps('de')}>{props.i18n.deButton}</button>
      <button {...buttonProps('es')}>{props.i18n.esButton}</button>

// default props probably are not necessary...
Menu.defaultProps = {
  i18n: {
    desc: 'Description',
    enButton: 'Button 1',
    deButton: 'Button 2',
    esButton: 'Button 3'

// connected container with translated component
const mapStateToProps = state => ({
  langCount: Object.keys(state.i18n).length
const mapDispatchToProps = dispatch => ({
  onLang: lang => dispatch({type: 'LANG', lang: lang})
// use higher-order component translate() instead of connect()
// to pass i18n props and connect to state
const MenuContainer = translate(

// basic Redux reducer to update state language settings
const rootReducer = (state, action = {}) => {
  if (action.type === 'LANG') {
    return {...state, lang: action.lang};
  return state;

// setup Redux store with reducer and state
const store = createStore(rootReducer, initialState);

// render app to DOM
  <Provider store={store}>
    <MenuContainer />

// higher-order component to provide translation and state
function translate(name, mapStateToProps, mapDispatchToProps) {
  return WrappedComponent => {
    // create HOC and pass through props
    const TranslatedComponent = props => {
      // find translations or use defaultProps
      props.i18n = props.i18n.hasOwnProperty(props.lang)
        ? props.i18n[props.lang][name]
        : undefined;
      return <WrappedComponent {...props} />;
    // set a name for debugging
    TranslatedComponent.displayName = `Translate(${WrappedComponent.displayName ||
      WrappedComponent.name ||
    // return HOC connected to state
    return connect(
      state => ({
        ...(mapStateToProps ? mapStateToProps(state) : {}),
        lang: state.lang,
        i18n: state.i18n
      dispatch => ({
        ...(mapDispatchToProps ? mapDispatchToProps(dispatch) : {})

🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.