Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
<div id="root">
    <!-- This element's contents will be replaced with your component. -->
</div>

              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Jost:wght@400;600;800&family=Open+Sans&display=swap');

* {
	box-sizing: border-box;
  line-height: var(--s1);
}

:root {
  font-family: 'Jost', sans-serif;
  --ratio: 1.5;
  --s-5: calc(var(--s-4) / var(--ratio));
  --s-4: calc(var(--s-3) / var(--ratio));
  --s-3: calc(var(--s-2) / var(--ratio));
  --s-2: calc(var(--s-1) / var(--ratio));
  --s-1: calc(var(--s0) / var(--ratio));
  --s0: 1rem;
  --s1: calc(var(--s0) * var(--ratio));
  --s2: calc(var(--s1) * var(--ratio));
  --s3: calc(var(--s2) * var(--ratio));
  --s4: calc(var(--s3) * var(--ratio));
  --s5: calc(var(--s4) * var(--ratio));
}

:root {
  --primary: #3da9fc;
  --secondary: #90b4ce;
  --tertiary: #ef4565;
  --background: #f5f5f5;
  --text: #094067;
  --textarea-bg: #f9f9f9;
}

[data-theme="dark"] {
  --primary: #ef4565;
  --secondary: #90b4ce;
  --tertiary: #3da9fc;
  --background: #094067;
  --text: #fffffe;
  --textarea-bg: #e0e0e0;
  --textarea-text: #094067;
}

body {
  background-color: var(--background);
  color: var(--text);
}

.grid {
  display: grid;
  grid-gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.box {
  padding: var(--s-1);
  border: 5 solid;
  color: var(--text);
  background-color: var(--background);
}

textarea {
  resize: none;
}

#editor {
  width: 100%;
  height: 100vh;
  border-width: var(--s-4);
  background-color: var(--textarea-bg);
  color: var(--textarea-text);
  padding: var(--s-1);
  line-height: var(--s0);
}

#preview {
  border-width: var(--s-4);
  border-style: solid;
  border-color: rgb(169, 169, 169);
  height: 100vh;
  background-color: var(--textarea-bg);
  color: var(--textarea-text);
  padding: var(--s-1);
  overflow-y: scroll;
}

#preview * {
  line-height: var(--s0);
}

strong {
  font-weight: bold;
}

.header {
  max-width: 75ch;
  margin-left: auto;
  margin-right: auto;
  text-align: center;
}

.themeSwitch {
  padding: var(--s-1)
}

.button {
  box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
  transition: all 0.3s cubic-bezier(.25,.8,.25,1);
  background-color: var(--tertiary);
  border: none;
  color: white;
  padding: var(--s-3) var(--s-3);
  margin-right: var(--s-1);
  margin-left: var(--s-1);
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 0.8rem;
}

.button:hover {
  box-shadow: 0 6px 8px rgba(0,0,0,0.25), 0 2px 2px rgba(0,0,0,0.22);
}
              
            
!

JS

              
                marked.setOptions({
  gfm: true,
  breaks: true,
})

const App = () => {
  const [input, setInput] = React.useState(
    '# Markdown Preview \n\n' +
    '## Testing sub-heading \n\n' +
    '[This is a link to Zachary\'s homepage](https://zacharyparsons.co.uk) \n\n' +
    'new line - `this.is.code` \n\n' +
    ' ```  \n\n' +
    ' // And this is a code block \n\n' +
    ' for (let i=0; i < 10; i++) { \n\n ' +
    '   console.log(i); \n\n' +
    ' } \n\n' +
    ' ``` \n\n' +
    '* This is a list item \n\n' +
    '1. This is an ordered list item \n\n' +
    '> "This is a blockquote..." \n\n' +
    '![image of cat](https://cataas.com/cat?width=463) \n\n' +
    '**This is bold text**'
  );
  
  function handleChange(e) {
    setInput(e.target.value);
  }
  
  return (
    <div className="app">
      <Header />
      <div className="grid">
      <Editor input={input}
          onChange={handleChange} />
      <Preview output={input} />
      </div>
    </div>
  )  
}

const Editor = (props) => {  
  return (
    <div className="editor box">
      <label for="editor">Editor:</label>
      <textarea id="editor" value={props.input} onChange={props.onChange}>
      
      </textarea>
    </div>
  )
};


const Preview = (props) => {
  return (
    <div className="preview box">
    <label for="preview">Preview:</label>
    <div id="preview" dangerouslySetInnerHTML={{__html: marked(props.output)}} />
    </div>
  )
}

const Header = () => {
  return (
    <div className="header">
      <h1>Markdown Preview</h1>
      <ThemeSwitch />
    </div>
  )
}

const ThemeSwitch = () => {
  const [theme, setTheme] = React.useState('dark');
  
  function toggleTheme() {
    const currentTheme = theme === 'dark' ? 'light' : 'dark';
    setTheme(currentTheme);
    document.documentElement.setAttribute("data-theme", theme);
  }
  
  function handleClick(e) {
    e.preventDefault();
    toggleTheme();
  }
  
  return (
    <div className="themeSwitch">
      <a className="button" href="#" onClick={handleClick}>Switch Theme</a>
    </div>
      );
}


ReactDOM.render(
  <App />,
  document.getElementById('root')
);
              
            
!
999px

Console