Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

              
                <!--
  This is a demo of how to use Font Awesome icons via CSS pseudo-elements alongside our Web Fonts with CSS framework.

  1. We're calling all styles for Font Awesome via our CDN. See the external references in the CSS configuration section of this demo.

  2.The general layout and decorative styling are being handled by the CSS included in the "demo styling" portion of this pen's CSS - anything that starts with "demo-*" is demo styling and not needed for core functionality of the demo to work.

  3. Read more about the techniques in this demo at https://fontawesome.com/how-to-use/on-the-web/advanced/css-pseudo-elements.
  -->

<html>
  <head>
    <title>Using Font Awesome Icons Via CSS Pseudo-elements (Web Fonts + CSS Framework)</title>
    
    <link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.1/css/all.css">
  </head>

  <body>
    <main class="demo-frame" style="font-size: 2rem;">
      <section class="demo-example">
        <ul class="demo-icon-list">
          <li class="demo-icon">
            <span class="icon icon-solid icon-award">Solid Award</span>
          </li>
          <li class="demo-icon">
            <span class="icon icon-regular icon-award">Regular Award</span>
          </li>
          <li class="demo-icon">
            <span class="icon icon-light icon-award">Light Award</span>
          </li>
          
          <li class="demo-icon">
            <span class="icon icon-duotone icon-award">Duotone Award</span>
          </li>
          <li class="demo-icon">
            <span class="icon icon-brand icon-adobe">Brand Icon</span>
          </li>
        </ul>
      </section>
    </main>
  </body>
</html>
              
            
!

CSS

              
                /* CSS pseudo-element styling */

/* general reset/setup styling for icons - needed on all */
.icon::before {
  -moz-osx-font-smoothing: grayscale;
  -webkit-font-smoothing: antialiased;
  display: inline-block; 
  font-style: normal;
  font-variant: normal;
  text-rendering: auto;
  line-height: 1;
}

/* defining the right font-family/font-face for each style */
.icon-solid::before,
.icon-regular::before,
.icon-light::before {
  font-family: "Font Awesome 5 Pro";
}

.icon-brand::before {
  font-family: "Font Awesome 5 Brands";
}

/* defining the right weight for each style */
.icon-solid::before {
  font-weight: 900;
}

.icon-regular::before {
  font-weight: 400;
}

.icon-light::before {
  font-weight: 300;
}

.icon-brand::before {
  font-weight: 400;
}

/* defining the right unicode values for each icon */
.icon-award::before {
  content: "\f559";
}

.icon-adobe::before {
  content: "\f778";
}


/* duotone icons follow a similar setup, but require use of the ::after pseudo-element and more styling setup */
.icon-duotone {
  position: relative;
  padding-left: 1.25em; /* make space for the width of the absolutely positioned icon */
}

.icon-duotone::before,
.icon-duotone::after {
  font-family: "Font Awesome 5 Duotone";
  font-weight: 900;
  
  /* position both layers of the icon to the left, set our fixed-width width, horizontally center layers, and then vertically align them so they flex with different line heights */
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 1.25em;
  text-align: center;
}

.icon-duotone::before {
  color: var(--fa-primary-color, inherit);
  opacity: 1;
  opacity: var(--fa-primary-opacity, 1.0);
}

.icon-duotone::after {
  color: var(--fa-secondary-color, inherit);
  opacity: var(--fa-secondary-opacity, 0.4);
}

/* we need to define the two layers of a duotone icon */
.icon-duotone.icon-award::after {
  content: "\10f559";
}

.icon-duotone.icon-award::before {
  content: "\f559";
}


/* demo styling */
* {
  /* resetting the box model for all elements */
  box-sizing: border-box;
}

.demo-frame {
  /* making a nice frame/layout for examples */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-bottom: -1rem;
  padding: 3rem;
  min-height: 100vh;
  color: rgb(52, 58, 64);
}

.demo-example {
  /* individual demo example styling */
  margin-bottom: 1rem;
}

.demo-icon-list {
  list-style: none;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
}

.demo-icon {
  margin: 0;
  padding: 1.5rem 1rem;
}

.icon::before {
  margin-right: 0.5rem;
}
              
            
!

JS

              
                
              
            
!
999px

Console