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 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

              
                <div class="container">
  <h1>Flex buttons</h1>
  <p>Use inline-flex to improve buttons with icons</p>
  <h2>Witout inline-flex</h2>
  <button class="btn btn-primary" type="button">Button</button>
  <button class="btn btn-primary" type="button"> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="">
      <circle cx="11" cy="11" r="8"></circle>
      <line x1="21" y1="21" x2="16.65" y2="16.65"></line>
    </svg>Button</button>
  <div class="d-grid gap-2 col-6 mt-2">
    <button class="btn btn-primary" type="button">Button</button>
    <button class="btn btn-primary" type="button"> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="">
        <circle cx="11" cy="11" r="8"></circle>
        <line x1="21" y1="21" x2="16.65" y2="16.65"></line>
      </svg> Button</button>
    <button class="btn btn-primary" type="button">Button <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="">
        <circle cx="11" cy="11" r="8"></circle>
        <line x1="21" y1="21" x2="16.65" y2="16.65"></line>
      </svg></button>
  </div>
  <!-- inline flex -->

  <h2>With inline flex</h2>
  <button class="btn btn-flex btn-primary" type="button"> Button</button>
  <button class="btn btn-flex btn-flex-fix btn-primary" type="button"> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="">
      <circle cx="11" cy="11" r="8"></circle>
      <line x1="21" y1="21" x2="16.65" y2="16.65"></line>
    </svg> Button + fix</button>
  
  <button class="btn btn-flex btn-primary" type="button">Button without span <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="">
      <circle cx="11" cy="11" r="8"></circle>
      <line x1="21" y1="21" x2="16.65" y2="16.65"></line>
    </svg></button>
    <button class="btn btn-flex btn-flex-fix btn-primary" type="button">
      <span>Button with span (and the fix)</span><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="">
      <circle cx="11" cy="11" r="8"></circle>
      <line x1="21" y1="21" x2="16.65" y2="16.65"></line>
    </svg></button>
  
  <button class="btn btn-flex btn-primary" type="button">
      <span>Button with parent span (no fix!) <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="">
      <circle cx="11" cy="11" r="8"></circle>
      <line x1="21" y1="21" x2="16.65" y2="16.65"></line>
    </svg></span></button>

  <div class="d-grid gap-2 col-6 mt-2">
    <button class="btn btn-flex btn-primary" type="button"> Button</button>
    <button class="btn btn-flex btn-primary" type="button"> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="">
        <circle cx="11" cy="11" r="8"></circle>
        <line x1="21" y1="21" x2="16.65" y2="16.65"></line>
      </svg> Button</button>
  </div>
  <p class="mt-2">Display <code>inline-flex</code> will collapse space between elements by default except if you use the fix or a parent span</p>
  <h2>Button in paragraph</h2>
  <p>Vertical align middle is being used</p>
  <p>
    This is a text with an <a href="#" class="btn btn-primary">inline button</a>.
  </p>

  <p>
    This is a text with an <a href="#" class="btn btn-primary btn-flex">flex inline button</a>.
  </p>
  
  <h2>Button with strong</h2>
  <div style="background:#eee">
  <p>
    <a href="#" class="btn btn-primary"><strong>very very very very very very very very very</strong> long text in a button (spacing is preserved)</a>
  </p>

  <p>
    <a href="#" class="btn btn-primary btn-flex"><strong>very very very very very very very very very</strong> long text in a button (space not preserved by default or it could split the button)</a>
  </p>
  </div>
  <div class="d-grid gap-2 col-4 mt-2" style="background:#eee">
    <p>
    <a href="#" class="btn btn-primary"><strong>very very very very very very very very very</strong> long text in a button (spacing is preserved)</a>
  </p>
    
    <p>Below needs <code>flex-flow: wrap</code> (or <code>flex-wrap : wrap</code>) due to small container</p>
    <p>By default, flex element get a "nowrap" value and therefore we get two columns</p>

  <p>
    <a href="#" class="btn btn-primary btn-flex"><strong>very very very very very very very very very</strong> long flex text in a button (space not preserved by default or it could split the button)</a>
  </p>
    
      <p>
    <a href="#" class="btn btn-primary btn-flex"><strong>very very very very very very very very very</strong><span>long flex text in a button with span (space not preserved by default or it could split the button)</span></a>
  </p>
    
       <p>
    <a href="#" class="btn btn-primary btn-flex" style="flex-wrap: wrap;"><strong>very very very very very very very very very</strong><span>long flex text in a button with span (space not preserved by default or <em>it could split the button</em>)</span></a>
  </p>
    
    <p>Our with one parent span</p>
     <p>
    <a href="#" class="btn btn-primary btn-flex" style="flex-wrap: wrap;"><span><strong>not so long</strong> <span>long flex text in a button with span (space not preserved by default or <em>it could split the button</em>)</span></a>
  </p>
</div>
  </div>
              
            
!

CSS

              
                .btn-flex {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
}
.better-btn-flex {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  flex-wrap: wrap;
}
/* This fixes almost the spacing issues from nested elements 
like span or strong tags. It needs a span to work better */
.btn-flex-fix > * {
  margin-right: 0.5ch;
}
              
            
!

JS

              
                
              
            
!
999px

Console