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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

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.

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

              
                <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
<nav id="navbar">
  <header>CSS Documentation</header>
  <ul>
    <li><a href="#introduction" class="nav-link">Introduction</a></li>
    <li><a href="#css_syntax" class="nav-link">CSS Syntax</a></li>
    <li><a href="#css_selectors" class="nav-link">CSS Selectors</a></li>
    <li><a href="#css_margins" class="nav-link">CSS Margins</a></li>
    <li><a href="#css_padding" class="nav-link">CSS Padding</a></li>
  </ul>
</nav>
<main id="main-doc">
  <section id="introduction" class="main-section">
    <header>Introduction</header>
    <p>CSS is the language we use to style a Web page.</p>
    <h2>What is CSS?</h2>
    <ul>
      <li>CSS stands for Cascading Style Sheets</li>
      <li>CSS describes how HTML elements are to be displayed on screen, paper, or in other media</li>
      <li>CSS saves a lot of work. It can control the layout of multiple web pages all at once
</li>
      <li>External stylesheets are stored in CSS files
</li>
    </ul>
    <h2>Why Use CSS?</h2>
    <p>CSS is used to define styles for your web pages, including the design, layout and variations in display for different devices and screen sizes.</p>
    <h2>CSS example</h2>
    <code>
      <pre>
body {
  background-color: lightblue;
}

h1 {
  color: white;
  text-align: center;
}

p {
  font-family: verdana;
  font-size: 20px;
}
      </pre>
    </code>
    <h2>CSS Solved a Big Problem</h2>
    <p>HTML was NEVER intended to contain tags for formatting a web page!</p>
    <p>HTML was created to describe the content of a web page, like:</p>
    <p>&lt;h1&gt;This is a heading&lt;/h1&gt;</p>
    <p>&lt;p&gt;This is a paragraph.&lt;/p&gt;</p>
    <p>When tags like &lt;font&gt;, and color attributes were added to the HTML 3.2 specification, it started a nightmare for web developers. Development of large websites, where fonts and color information were added to every single page, became a long and expensive process.</p>
    <p>To solve this problem, the World Wide Web Consortium (W3C) created CSS.</p>
    <p>CSS removed the style formatting from the HTML page!</p>
    <h2>CSS Saves a Lot of Work!</h2>
    <p>The style definitions are normally saved in external .css files.</p>
    <p>With an external stylesheet file, you can change the look of an entire website by changing just one file!</p>
  </section><hr>
  <section id="css_syntax" class="main-section">
    <header>CSS Syntax</header>
    <p>A CSS rule consists of a selector and a declaration block.</p>
    <h2>CSS Syntax</h2>
    <img src="https://www.w3schools.com/css/img_selector.gif">
    <p>The selector points to the HTML element you want to style.</p>
    <p>The declaration block contains one or more declarations separated by semicolons.</p>
    <p>Each declaration includes a CSS property name and a value, separated by a colon.</p>
    <p>Multiple CSS declarations are separated with semicolons, and declaration blocks are surrounded by curly braces.</p>
    <h2>Example</h2>
    <p>In this example all &lt;p&gt; elements will be center-aligned, with a red text color:</p>
    <code>
      <pre>
p {
  color: red;
  text-align: center;
}
      </pre>
    </code>
    <h2>Example Explained</h2>
    <ul>
      <li><code>p</code> is a selector in CSS (it points to the HTML element you want to style: &lt;p&gt;).</li>
      <li><code>color</code> is a property, and <code>red</code> is the property value</li>
      <li><code>text-align</code> is a property, and <code>center</code> is the property value</li>
    </ul>
  </section><hr>
  <section id="css_selectors" class="main-section">
    <header>CSS Selectors</header>
    <p>A CSS selector selects the HTML element(s) you want to style.</p>
    <h2>CSS Selectors</h2>
    <p>CSS selectors are used to "find" (or select) the HTML elements you want to style.</p>
    <p>We can divide CSS selectors into five categories:</p>
    <ul>
      <li>Simple selectors (select elements based on name, id, class)</li>
      <li>Combinator selectors (select elements based on a specific relationship between them)</li>
      <li>Pseudo-class selectors (select elements based on a certain state)</li>
      <li>Pseudo-elements selectors (select and style a part of an element)</li>
      <li>Attribute selectors (select elements based on an attribute or attribute value)</li>
    </ul>
    <p>This page will explain the most basic CSS selectors.</p>
    <h2>The CSS element Selector</h2>
    <p>The element selector selects HTML elements based on the element name.</p>
    <h2>Example</h2>
    <p>Here, all &lt;p&gt; elements on the page will be center-aligned, with a red text color:</p>
    <code>
      <pre>
p {
  text-align: center;
  color: red;
}
      </pre>
    </code>
    <h2>The CSS id Selector</h2>
    <p>The id selector uses the id attribute of an HTML element to select a specific element.</p>
    <p>The id of an element is unique within a page, so the id selector is used to select one unique element!</p>
    <p>To select an element with a specific id, write a hash (#) character, followed by the id of the element.</p>
    <h2>Example</h2>
    <p>The CSS rule below will be applied to the HTML element with id="para1": </p>
    <code>
      <pre>
#para1 {
  text-align: center;
  color: red;
}
      </pre>
    </code>
    <p><strong>Note:</strong> An id name cannot start with a number!</p>
    <h2>The CSS class Selector</h2>
    <p>The class selector selects HTML elements with a specific class attribute.</p>
    <p>To select elements with a specific class, write a period (.) character, followed by the class name.</p>
    <h2>Example</h2>
    <p>In this example all HTML elements with class="center" will be red and center-aligned:</p>
    <code>
      <pre>
.center {
  text-align: center;
  color: red;
}
      </pre>
    </code>
    <p>You can also specify that only specific HTML elements should be affected by a class.</p>
    <h2>Example</h2>
    <p>In this example only &lt;p&gt; elements with class="center" will be red and center-aligned:</p>
    <code>
      <pre>
p.center {
  text-align: center;
  color: red;
}
      </pre>
    </code>
    <p>HTML elements can also refer to more than one class.</p>
    <h2>Example</h2>
    <p>In this example the &lt;p&gt; element will be styled according to class="center" and to class="large": </p>
    <code>
      <pre>
&lt;p class="center large"&gt;
This paragraph refers to two classes.
&lt;/p&gt;
      </pre>
    </code>
    <p><strong>Note:</strong> A class name cannot start with a number!</p>
    <h2>The CSS Universal Selector</h2>
    <p>The universal selector (*) selects all HTML elements on the page.</p>
    <h2>Example</h2>
    <p>The CSS rule below will affect every HTML element on the page:</p>
    <code>
      <pre>
* {
  text-align: center;
  color: blue;
}
      </pre>
    </code>
    <h2>The CSS Grouping Selector</h2>
    <p>The grouping selector selects all the HTML elements with the same style definitions.</p>
    <p>Look at the following CSS code (the h1, h2, and p elements have the same style definitions):</p>
    <code>
      <pre>
h1 {
  text-align: center;
  color: red;
}

h2 {
  text-align: center;
  color: red;
}

p {
  text-align: center;
  color: red;
}
      </pre>
    </code>
    <p>It will be better to group the selectors, to minimize the code.</p>
    <p>To group selectors, separate each selector with a comma.</p>
    <h2>Example</h2>
    <p>In this example we have grouped the selectors from the code above:</p>
    <code>
      <pre>
h1, h2, p {
  text-align: center;
  color: red;
}
      </pre>
    </code>
  </section><hr>
  <section id="css_margins" class="main-section">
    <header>CSS Margins</header>
    <p>Margins are used to create space around elements, outside of any defined borders.</p>
    <h2>CSS Margins</h2>
    <p>The CSS <code>margin</code> properties are used to create space around elements, outside of any defined borders.</p>
      <p>With CSS, you have full control over the margins. There are properties for setting the margin for each side of an element (top, right, bottom, and left).</p>
      <h2>Margin - Individual Sides</h2>
    <p>CSS has properties for specifying the margin for each side of an element:</p>
      <ul id="ulcode">
        <li>margin-top</li>
        <li>margin-right</li>
        <li>margin-bottom</li>
        <li>margin-left</li>
      </ul>
      <p>All the margin properties can have the following values:</p>
      <ul>
        <li>auto - the browser calculates the margin</li>
        <li><i>length</i> - specifies a margin in px, pt, cm, etc.</li>
        <li>% - specifies a margin in % of the width of the containing element</li>
        <li>inherit - specifies that the margin should be inherited from the parent element</li>
      </ul>
      <p><strong>Tip:</strong> Negative values are allowed.</p>
      <h2>Example</h2>
      <p>Set different margins for all four sides of a &lt;p&gt; element:</p>
      <code>
        <pre>
p {
  margin-top: 100px;
  margin-bottom: 100px;
  margin-right: 150px;
  margin-left: 80px;
}
        </pre>
      </code>
      <h2>Margin - Shorthand Property</h2>
      <p>To shorten the code, it is possible to specify all the margin properties in one property.</p>
      <p>The <code>margin</code> property is a shorthand property for the following individual margin properties:</p>
       <ul>
         <code id="ulcode">
           <li>margin-top</li>
           <li>margin-right</li>
           <li>margin-bottom</li>
           <li>margin-left</li>
         </code>
       </ul>
      <p>So, here is how it works:</p>
      <p>If the <code>margin</code> property has four values:</p>
      <ul>
        <li><b>margin: 25px 50px 75px 100px;</b></li>
        <ul>
          <li>top margin is 25px</li>
          <li>right margin is 50px</li>
          <li>bottom margin is 75px</li>
          <li>left margin is 100px</li>
        </ul>
      </ul>
    <h2>Example</h2>
    <p>Use the margin shorthand property with four values:</p>
    <code>
      <pre>
p {
  margin: 25px 50px 75px 100px;
}
      </pre>
    </code>
    <p>If the <code>margin</code> property has three values:</p>
    <ul>
      <li><b>margin: 25px 50px 75px;</b></li>
      <ul>
        <li>top margin is 25px</li>
        <li>right and left margins are 50px</li>
        <li>bottom margin is 75px</li>
      </ul>
    </ul>
    <h2>Example</h2>
    <p>Use the margin shorthand property with three values:</p>
    <code>
      <pre>
p {
  margin: 25px 50px 75px;
}
      </pre>
    </code>
    <p>If the <code>margin</code> property has two values:</p>
    <ul>
      <li><strong>margin: 25px 50px;</strong></li>
      <ul>
        <li>top and bottom margins are 25px</li>
        <li>right and left margins are 50px</li>
      </ul>
    </ul>
    <h2>Example</h2>
    <p>Use the margin shorthand property with two values:</p>
    <code>
      <pre>
p {
  margin: 25px 50px;
}
      </pre>
    </code>
    <p>If the <code>margin</code> property has one value:</p>
    <ul>
      <li>margin: 25px;</li>
      <ul>
        <li>all four margins are 25px</li>
      </ul>
    </ul>
    <h2>Example</h2>
    <p>Use the margin shorthand property with one value:</p>
    <code>
      <pre>
p {
  margin: 25px;
}
      </pre>
    </code>
    <h2>The auto Value</h2>
    <p>You can set the margin property to <code>auto</code> to horizontally center the element within its container.</p>
    <p>The element will then take up the specified width, and the remaining space will be split equally between the left and right margins.</p>
    <h2>Example</h2>
    <p>Use margin: auto:</p>
    <code>
      <pre>
div {
  width: 300px;
  margin: auto;
  border: 1px solid red;
}
      </pre>    
    </code>
    <h2>The inherit Value</h2>
    <p>This example lets the left margin of the &lt;p class="ex1"&gt; element be inherited from the parent element (&lt;div&gt;):</p>
    <h2>Example</h2>
    <p>Use of the inherit value:</p>
    <code>
      <pre>
div {
  border: 1px solid red;
  margin-left: 100px;
}

p.ex1 {
  margin-left: inherit;
}

      </pre>
    </code>
  </section><hr>
  <section id="css_padding" class="main-section">
    <header>CSS Padding</header>
    <p>Padding is used to create space around an element's content, inside of any defined borders.</p>
    <h2>CSS Padding</h2>
    <p>The CSS <code>padding</code> properties are used to generate space around an element's content, inside of any defined borders.</p>
    <p>With CSS, you have full control over the padding. There are properties for setting the padding for each side of an element (top, right, bottom, and left).</p>
    <h2>Padding - Individual Sides</h2>
    <p>CSS has properties for specifying the padding for each side of an element:</p>
    <ul>
      <code>
        <li>padding-top</li>
        <li>padding-right</li>
        <li>padding-bottom</li>
        <li>padding-left</li>
      </code>
    </ul>
    <p>All the padding properties can have the following values:</p>
    <ul>
      <li>length - specifies a padding in px, pt, cm, etc.</li>
      <li>% - specifies a padding in % of the width of the containing element</li>
      <li>inherit - specifies that the padding should be inherited from the parent element</li>
    </ul>
    <p><strong>Note:</strong> Negative values are not allowed.</p>
    <h2>Example</h2>
    <p>Set different padding for all four sides of a &lt;div&gt; element:</p>
    <code>
      <pre>
div {
  padding-top: 50px;
  padding-right: 30px;
  padding-bottom: 50px;
  padding-left: 80px;
}
      </pre>
    </code>
    <h2>Padding - Shorthand Property</h2>
    <p>To shorten the code, it is possible to specify all the padding properties in one property.</p>
    <p>The <code>padding</code> property is a shorthand property for the following individual padding properties:</p>
    <ul>
      <code>
        <li>padding-top</li>
        <li>padding-right</li>
        <li>padding-bottom</li>
        <li>padding-left</li>
      </code>
    </ul>
    <p>So, here is how it works:</p>
    <p>If the <code>padding</code> property has four values:</p>
    <ul>
      <li><b>padding: 25px 50px 75px 100px;</b></li>
      <ul>
        <li>top padding is 25px</li>
        <li>right padding is 50px</li>
        <li>bottom padding is 75px</li>
        <li></li>
      </ul>
    </ul>
    <h2>Example</h2>
    <p>Use the padding shorthand property with four values:</p>
    <code>
      <pre>
div {
  padding: 25px 50px 75px 100px;
}
      </pre>
    </code>
    <p>If the <code>padding</code> property has three values:</p>
    <ul>
      <li><b>padding: 25px 50px 75px;</b></li>
      <ul>
        <li>top padding is 25px</li>
        <li>right and left paddings are 50px</li>
        <li>bottom padding is 75px</li>
      </ul>
    </ul>
    <h2>Example</h2>
    <p>Use the padding shorthand property with three values:</p>
    <code>
      <pre>
div {
  padding: 25px 50px 75px;
}
      </pre>
    </code>
    <p>If the <code>padding</code> property has two values:</p>
    <ul>
      <li><b>padding: 25px 50px;</b></li>
      <ul>
        <li>top and bottom paddings are 25px</li>
        <li>right and left paddings are 50px</li>
      </ul>
    </ul>
    <h2>Example</h2>
    <p>Use the padding shorthand property with two values: </p>
    <code>
      <pre>
div {
  padding: 25px 50px;
}

      </pre>
    </code>
    <p>If the <code>padding</code> property has one value:</p>
    <ul>
      <li><b>padding: 25px;</b></li>
      <ul>
        <li>all four paddings are 25px</li>
      </ul>
    </ul>
    <h2>Example</h2>
    <p>Use the padding shorthand property with one value:</p>
    <code>
      <pre>
div {
  padding: 25px;
}
      </pre>
    </code>
    <h2>Padding and Element Width</h2>
    <p>The CSS <code>width</code> property specifies the width of the element's content area. The content area is the portion inside the padding, border, and margin of an element (the box model).</p>
    <p>So, if an element has a specified width, the padding added to that element will be added to the total width of the element. This is often an undesirable result.</p>
    <h2>Example</h2>
    <p>Here, the &lt;div&gt; element is given a width of 300px. However, the actual width of the &lt;div&gt; element will be 350px (300px + 25px of left padding + 25px of right padding):</p>
    <code>
      <pre>
div {
  width: 300px;
  padding: 25px;
}
      </pre>
    </code>
    <p>To keep the width at 300px, no matter the amount of padding, you can use the <code>box-sizing</code> property. This causes the element to maintain its actual width; if you increase the padding, the available content space will decrease.</p>
    <h2>Example</h2>
    <p>Use the box-sizing property to keep the width at 300px, no matter the amount of padding:</p>
    <code>
      <pre>
div {
  width: 300px;
  padding: 25px;
  box-sizing: border-box;
}
      </pre>
    </code>
  </section>
</main>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Barlow:wght@100&display=swap');
body {
  background-color: #eec170;
}
nav {
  position: fixed;
  left: 0;
  top: 0;
  height: 100%;
  background-color: #494947;
  width: 21%;
  color: #44ccff;
  font-size: 1.15rem;
}
nav header {
  margin: 15px;
  font-family: barlow;
  font-weight: bold;
  font-size: 25px;
}
nav ul {
  display: flex;
  flex-direction: column;
  position: relative;
  left: -15px;
  line-height: 2.5;
  font-family: barlow;
  font-size: 1.5rem;
}
nav a {
  text-decoration: none;
  color: #44ccff;
  cursor: pointer;
}

main {
  margin-left: 21%;
  width: 75%;
  padding-left: 40px;
  font-family: barlow;
}
p {
  font-size: 17px;
  font-weight: bold;
  margin-left: 15px;
}
nav li {
  list-style: none;
  border-top: 2px solid;
}
main header {
  font-size: 35px;
  font-weight: bold;
}
main li {
  font-weight: bold;
  line-height: 1.5;
}
pre {
  background-color: white;
  border-radius: 5px;
  width: 30%;
  padding: 10px;
}
section {
  margin: 0 0 50px 0;
}
#syntax img {
  border-radius: 20px;
}
strong {
  font-family: sans;
}
#css_margins p code,
#ulcode,
#css_syntax ul code,
#css_padding p code {
  color: red;
  font-size: 20px;
}
@media only screen and (max-width: 815px) {
  #navbar header {
    font-size: 20px;
  }
  nav {
    width: 25%;
    overflow-y: scroll;
    overflow-x: hidden;
  }
  li {
    font-size: 20px;
  }
}

              
            
!

JS

              
                
              
            
!
999px

Console