HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URL's added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js" defer></script>
<nav class="nav" id="navbar">
<header class="heading-primary nav__title">
<h1 class="heading-primary">React Documentation</h1>
</header>
<ul class="nav__list">
<li class="nav__item">
<a href="#Introduction" class="nav__link nav-link">Introduction</a>
</li>
<li class="nav__item">
<a href="#Hello_World" class="nav__link nav-link">Hello World</a>
</li>
<li class="nav__item">
<a href="#Introducing_JSX" class="nav__link nav-link">
Introducing JSX</a>
</li>
<li class="nav__item">
<a href="#Rendering_Elements" class="nav__link nav-link">
Rendering Elements</a>
</li>
<li class="nav__item">
<a href="#Components_and_Props" class="nav__link nav-link">
Components and Props</a>
</li>
<li class="nav__item">
<a href="#State_and_Lifecycle" class="nav__link nav-link">
State and Lifecycle</a>
</li>
<li class="nav__item">
<a href="#Handling_Events" class="nav__link nav-link">
Handling Events</a>
</li>
<li class="nav__item">
<a href="#Conditional_Rendering" class="nav__link nav-link">
Conditional Rendering</a>
</li>
<li class="nav__item">
<a href="#Lists_and_Keys" class="nav__link nav-link">
Lists and Keys</a>
</li>
<li class="nav__item">
<a href="#Forms" class="nav__link nav-link"> Forms</a>
</li>
<li class="nav__item">
<a href="#Lifting_State_Up" class="nav__link nav-link">
Lifting State Up</a>
</li>
<li class="nav__item">
<a href="#Composition_vs_Inheritance" class="nav__link nav-link">
Composition vs Inheritance</a>
</li>
<li class="nav__item">
<a href="#Thinking_in_React" class="nav__link nav-link">
Thinking In React</a>
</li>
</ul>
</nav>
<main class="main" id="main-doc">
<section class="main__section main-section" id="Introduction">
<header>
<h2 class="heading-secondary">Introduction</h2>
</header>
<p class="main__section__para">
React makes it painless to create interactive UIs. Design simple views
for each state in your application, and React will efficiently update
and render just the right components when your data changes.
Declarative views make your code more predictable and easier to debug.
</p>
<ul class="main__section__list">
<li>Easy to learn and use</li>
<li>Reusable components</li>
<li>Great tool set for developers</li>
<li>Fast rendering with virtual DOM</li>
<li>Testability</li>
</ul>
</section>
<section class="main__section main-section" id="Hello_World">
<header>
<h2 class="heading-secondary">Hello World</h2>
</header>
<p class="main__section__para">
The smallest React example looks like this:
</p>
<code class="main__section__code">ReactDOM.render( <h1> Hello, world! </h1> ,
document.getElementById ('root') );</code>
<p class="main__section__para">
It displays a heading saying “Hello, world!” on the page.
</p>
</section>
<section class="main__section main-section" id="Introducing_JSX">
<header>
<h2 class="heading-secondary">Introducing JSX</h2>
</header>
<p class="main__section__para">Consider this variable declaration:</p>
<code class="main__section__code">const element = <h1>Hello, world!</h1> ;</code>
<p class="main__section__para">
This funny tag syntax is neither a string nor HTML.
</p>
<p class="main__section__para">
It is called JSX, and it is a syntax extension to JavaScript. We
recommend using it with React to describe what the UI should look
like. JSX may remind you of a template language, but it comes with the
full power of JavaScript.
</p>
</section>
<section class="main__section main-section" id="Rendering_Elements">
<header>
<h2 class="heading-secondary">Rendering Elements</h2>
</header>
<p class="main__section__para">
Elements are the smallest building blocks of React apps.
</p>
<p class="main__section__para">
An element describes what you want to see on the screen:.
</p>
<code class="main__section__code">const element = <h1>Hello, world</h1> ;</code>
<p class="main__section__para">
It displays a heading saying “Hello, world!” on the page.
</p>
</section>
<section class="main__section main-section" id="Components_and_Props">
<header>
<h2 class="heading-secondary">Components and Props</h2>
</header>
<p class="main__section__para">
The smallest React example looks like this:
</p>
<code class="main__section__code">ReactDOM.render( <h1> Hello, world! </h1> ,
document.getElementById ('root') );</code>
<p class="main__section__para">
It displays a heading saying “Hello, world!” on the page.
</p>
</section>
<section class="main__section main-section" id="State_and_Lifecycle">
<header>
<h2 class="heading-secondary">State and Lifecycle</h2>
</header>
<p class="main__section__para">
The smallest React example looks like this:
</p>
<code class="main__section__code">ReactDOM.render( <h1> Hello, world! </h1> ,
document.getElementById ('root') );</code>
<p class="main__section__para">
It displays a heading saying “Hello, world!” on the page.
</p>
</section>
<section class="main__section main-section" id="Handling_Events">
<header>
<h2 class="heading-secondary">Handling Events</h2>
</header>
<p class="main__section__para">
The smallest React example looks like this:
</p>
<code class="main__section__code">ReactDOM.render( <h1> Hello, world! </h1> ,
document.getElementById ('root') );</code>
<p class="main__section__para">
It displays a heading saying “Hello, world!” on the page.
</p>
</section>
<section class="main__section main-section" id="Conditional_Rendering">
<header>
<h2 class="heading-secondary">Conditional Rendering</h2>
</header>
<p class="main__section__para">
The smallest React example looks like this:
</p>
<code class="main__section__code">ReactDOM.render( <h1> Hello, world! </h1> ,
document.getElementById ('root') );</code>
<p class="main__section__para">
It displays a heading saying “Hello, world!” on the page.
</p>
</section>
<section class="main__section main-section" id="Lists_and_Keys">
<header>
<h2 class="heading-secondary">Lists and Keys</h2>
</header>
<p class="main__section__para">
The smallest React example looks like this:
</p>
<code class="main__section__code">ReactDOM.render( <h1> Hello, world! </h1> ,
document.getElementById ('root') );</code>
<p class="main__section__para">
It displays a heading saying “Hello, world!” on the page.
</p>
</section>
<section class="main__section main-section" id="Forms">
<header>
<h2 class="heading-secondary">Forms</h2>
</header>
<p class="main__section__para">
The smallest React example looks like this:
</p>
<code class="main__section__code">ReactDOM.render( <h1> Hello, world! </h1> ,
document.getElementById ('root') );</code>
<p class="main__section__para">
It displays a heading saying “Hello, world!” on the page.
</p>
</section>
<section class="main__section main-section" id="Lifting_State_Up">
<header>
<h2 class="heading-secondary">Lifting State Up</h2>
</header>
<p class="main__section__para">
The smallest React example looks like this:
</p>
<code class="main__section__code">ReactDOM.render( <h1> Hello, world! </h1> ,
document.getElementById ('root') );</code>
<p class="main__section__para">
It displays a heading saying “Hello, world!” on the page.
</p>
</section>
<section class="main__section main-section" id="Composition_vs_Inheritance">
<header>
<h2 class="heading-secondary">Composition vs Inheritance</h2>
</header>
<p class="main__section__para">
The smallest React example looks like this:
</p>
<code class="main__section__code">ReactDOM.render( <h1> Hello, world! </h1> ,
document.getElementById ('root') );</code>
<p class="main__section__para">
It displays a heading saying “Hello, world!” on the page.
</p>
</section>
<section class="main__section main-section" id="Thinking_in_React">
<header>
<h2 class="heading-secondary">Thinking in React</h2>
</header>
<p class="main__section__para">
The smallest React example looks like this:
</p>
<code class="main__section__code">ReactDOM.render( <h1> Hello, world! </h1> ,
document.getElementById ('root') );</code>
<p class="main__section__para">
It displays a heading saying “Hello, world!” on the page.
</p>
</section>
</main>
// BASE
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap");
$bp-medium: 43.75em; // 800px
$bp-big: 60em; // 1000px
html {
font-size: 62.5%;
box-sizing: border-box;
scroll-behavior: smooth;
@media only screen and(max-width: $bp-big) {
font-size: 50%;
}
}
*,
*::before,
*::after {
box-sizing: inherit;
margin: 0;
padding: 0;
}
:root {
--heading-primary: rgb(14, 47, 73);
--heading-secondary: #1c5b80;
}
body {
font-size: 2rem;
font-family: "Poppins", sans-serif;
@media only screen and(max-width: $bp-medium) {
display: flex;
flex-direction: column;
}
}
// TYPOGRAPHY
.heading-primary {
color: var(--heading-primary);
font-size: 2.5rem;
font-weight: 700;
}
.heading-secondary {
color: var(--heading-secondary);
font-weight: 700;
font-size: 2.5rem;
}
.nav {
height: 100vh;
padding: 3rem;
border-radius: 5px;
margin: 3px;
position: fixed;
width: 40rem;
overflow: auto;
@media only screen and(max-width: $bp-medium) {
width: 100%;
height: 20rem;
z-index: 2;
margin: 0;
background-color: white;
border-radius: 0;
border-bottom: 1px solid black;
position: static;
}
&__list {
list-style: none;
}
&__title {
margin-bottom: 2rem;
}
&__link {
text-decoration: none;
color: var(--heading-secondary);
display: inline-block;
padding: 1.5rem;
margin: 2px;
font-weight: 500;
width: 100%;
box-shadow: 0px 1px 3px 0px rgba(0, 0, 0, 0.158);
}
}
.main {
background-color: rgb(247, 246, 245);
margin-left: 40rem;
padding: 3vw;
@media only screen and(max-width: $bp-medium) {
width: 100%;
margin: 0;
}
&__section {
margin: 1rem;
padding: 1rem;
box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.1);
&__list {
margin: 1rem;
background-color: rgb(238, 238, 238);
padding: 1rem;
list-style-position: inside;
}
&__code {
display: inline-block;
padding: 1rem;
background-color: rgb(71, 71, 71);
border-radius: 3px;
color: rgb(231, 231, 231);
max-width: 100%;
}
&__para {
margin: 1rem;
}
}
}
Also see: Tab Triggers