Spectre.css

Spectre.css is a lightweight, responsive and modern CSS framework for faster and extensible development.

  • lightweight and clean starting point for your project and prototype
  • flexbox, responsive and mobile-friendly layout
  • built in useful components and utilities

getting started

There are 3 ways to get started with Spectre CSS framework in your projects. You can either manually install or use NPM and Bower.

Install manually

Download the compiled and minified Spectre CSS file (about 25KB):

Download Spectre.css

Install with NPM
$ npm install spectre.css
Install with Bower
$ bower install spectre.css

And include it in your website or Web app <head>

<link rel="stylesheet" href="dist/spectre.min.css" />

You could even customize Spectre CSS with your own code and removing unneeded components. It requires a LESS compiler and Autoprefixer.

typography

Typography sets default styles for headings, paragraphs, blockquote, lists and code elements.

headings

H1 Title 5rem

H2 Title 4rem

H3 Title 3rem

H4 Title 2.4rem

H5 Title 2rem
H6 Title 1.6rem
<h1>H1 Title</h1>
<h2>H2 Title <small class="label">4rem</small></h2>
paragraphs

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.

<p>Lorem ipsum dolor sit amet, <span class="highlight">consectetur</span> adipiscing elit. <a href="#">Integer</a> posuere erat a ante.</p>
<p class="lead">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.</p>
blockquote

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.

- Source
<blockquote>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante.</p>
    <small>- Source</small>
</blockquote>
lists
  • list item 1
  • list item 2
    • list item 2.1
    • list item 2.2
    • list item 2.3
  • list item 3
  1. list item 1
  2. list item 2
    1. list item 2.1
    2. list item 2.2
    3. list item 2.3
  3. list item 3
<ul class="list">
    <li>list item 1</li>
    <li>list item 2
        <ul>
            <li>list item 2.1</li>
            <li>list item 2.2</li>
            <li>list item 2.3</li>
        </ul>
    </li>
    <li>list item 3</li>
</ul>

flexbox layout

Layout includes flexbox based responsive grid system with 12 columns.

col-6
col-3
col-2
col-1
col-2
col-4
col-4
col-2

Add the class columns to a container. And add any element you want with classname column inside the container. These columns will take up the space equally. You can specific the width of each column by adding class col-[1-12].

<div class="columns">
    <div class="column col-6">col-6</div>
    <div class="column col-3">col-3</div>
    <div class="column col-2">col-2</div>
    <div class="column col-1">col-1</div>
</div>

tables

Tables include default styles for tables and data sets.

name duration genre release date
The Shawshank Redemption 2h 22min Crime, Drama 14 October 1994 USA
The Godfather 2h 55min Crime, Drama 24 March 1972 USA
Schindler's List 3h 15min Biography, Drama, History 4 February 1994 USA
Se7en 2h 7min Crime, Drama, Mystery 24 March 1972 USA

Add the class table to any <table> element. The class will add padding, border and emphasized table header. Use the class selected to make <tr> element highlighted.

<table class="table">
    <thead>
        <tr>
            <th>name</th>
            <th>duration</th>
            <th>genre</th>
            <th>release date</th>
        </tr>
    </thead>
    <tbody>
        <tr class="selected">
            <th>The Shawshank Redemption</th>
            <th>2h 22min</th>
            <th>Crime, Drama</th>
            <th>14 October 1994</th>
        </tr>
    </tbody>
</table>

buttons

Buttons include simple button styles for actions in different types and sizes.

Add the class btn to <a>, <input> or <button> elements for a default button. There are classes btn-primary and btn-link for predefined primary and link buttons. A button with the class loading can show loading indicator.

<button class="btn">default button</button>
<button class="btn btn-primary">primary button</button>
<button class="btn btn-link">link button</button>

<!-- a button with loading state -->
<button class="btn loading">button</button>
button sizes

Add the class btn-sm or btn-lg for small or large button size. Also, you can add the class btn-block for a full-width button.

<button class="btn btn-lg">large button</button>
<button class="btn btn-sm">small button</button>

<button class="btn btn-block">block button</button>

Icons with the class icon can be correctly rendered in each button size.

<button class="btn btn-primary btn-lg"><span class="icon icon-markunread"></span> large</button>
<button class="btn btn-primary"><span class="icon icon-markunread"></span> normal</button>
<button class="btn btn-primary btn-sm"><span class="icon icon-markunread"></span> small</button>
button groups

If you want to use buttons as a group, add the class btn-group to the container. You can add the class btn-group-block for a full-width button group.

<div class="btn-group btn-group-block">
    <button class="btn">first button</button>
    <button class="btn">second button</button>
    <button class="btn">third button</button>
</div>

forms

Forms provide the most common control styles used in forms, including label, input, textarea, select, checkbox, radio and switch.

<form>
    <!-- form input control -->
    <div class="form-group">
        <label class="form-label" for="input-example-1">Name</label>
        <input class="form-input" type="text" id="input-example-1" placeholder="Name" />
    </div>
    <!-- form radio control -->
    <div class="form-group">
        <label class="form-label">Gender</label>
        <label class="form-radio">
            <input type="radio" name="gender" /> Male
        </label>
        <label class="form-radio">
            <input type="radio" name="gender" checked /> Female
        </label>
    </div>
    <!-- form select control -->
    <div class="form-group">
        <select class="form-select">
            <option>Choose an option</option>
            <option>Slack</option>
            <option>Skype</option>
            <option>Hipchat</option>
        </select>
    </div>
    <!-- form switch control -->
    <div class="form-group">
        <label class="form-switch">
            <input type="checkbox" />
            Send me emails with news and tips
        </label>
    </div>
    <!-- form textarea control -->
    <div class="form-group">
        <label class="form-label" for="input-example-3">Message</label>
        <textarea class="form-input" id="input-example-3" placeholder="Textarea" rows="3"></textarea>
    </div>
    <!-- form checkbox control -->
    <div class="form-group">
        <label class="form-checkbox">
            <input type="checkbox" />
            Remember me
        </label>
    </div>
</form>

If you want to have a horizontal form, add the class form-horizontal to the <form> container. And add the class col-[1-12] to the child elements for form row layout. Please note form-horizontal only works in viewports that are at least 840px wide.

<form class="form-horizontal">
    <div class="form-group">
        <label class="form-label col-3" for="input-example-1">Name</label>
        <div class="col-9">
            <input class="form-input" type="text" id="input-example-1" placeholder="Name" />
        </div>
    </div>
    <!-- form structure -->
</form>

To use form validation styles, add is-success and is-danger to the controls or add has-success and has-danger to parent elements.

<form>
    <!-- form validation styles -->
    <div class="form-group has-success">
        <label class="form-label" for="input-example-1">Name</label>
        <input class="form-input is-success" type="text" id="input-example-1" placeholder="Name" />
    </div>
</form>
input groups
slack.com/
@slack.com
slack.com/

If you want to attach text and button along with an input, add the class input-group to the input container. And add the class input-group-addon to the text element and input-group-btn to the button element.

<div class="input-group">
    <span class="input-group-addon">slack.com/</span>
    <input type="text" class="form-input" placeholder="site name" />
</div>

<div class="input-group">
    <span class="input-group-addon">slack.com/</span>
    <input type="text" class="form-input" placeholder="site name" />
    <button class="btn btn-primary input-group-btn">Submit</button>
</div>

images

Images include responsive image class.

Add the class img-responsive to <img> elements. The images will scale with the parent sizes.

<img src="img/osx-el-capitan.jpg" class="img-responsive rounded" />

avatars

Avatars are user profile pictures.

Add the class avatar to <img> element. There are 4 additional sizes available, including avatar-xl (64px), avatar-lg (48px), avatar-sm (24px), and avatar-xs (16px). By default, the avatar size is 32px.

For users who don't have profile pictures, you may use their initials for avatars. Add the class avatar and avatar size class to <div> element. The attribute data-initial is the name appear inside the avatar.

<figure class="avatar avatar-xl">
    <img src="img/avatar-1.png" />
</figure>

<figure class="avatar avatar-xl">
    <img src="img/avatar-1.png" />
    <img src="img/avatar-5.png" class="avatar-icon" />
</figure>

<figure class="avatar avatar-xl" data-initial="YZ" style="background-color: #5764c6;"></figure>

chips

Chips are complex entities in small blocks.

Crime
Drama
Biography
Mystery
Yan Zhu
Yan Zhu
Yan Zhu

Add a container element with the class chip. And add child text elements with chip-name or icons with icon.

<div class="chip">
    <span class="chip-name">Crime</span>
    <button class="btn btn-clear"></button>
</div>

<div class="chip">
    <span class="icon icon-favorite_border"></span>
    <span class="chip-name">Drama</span>
    <button class="btn btn-clear"></button>
</div>

<div class="chip">
    <img src="img/avatar-1.png" class="avatar" />
    <span class="chip-name">Yan Zhu</span>
    <button class="btn btn-clear"></button>
</div>

file icons

File icons are written entirely in CSS. More detail is coming soon.

tooltips

Tooltips provide context information labels that appear on hover and focus.

Tooltip component is built entirely in CSS.

Add the class tooltip and the attribute data-tooltip, which contains the tooltip content, to non self closing elements. And add the class name tooltip-right, tooltip-bottom or tooltip-left to define the position of a tooltip. By default, the tooltip appears above the element.

<button class="btn tooltip" data-tooltip="Lorem ipsum dolor sit amet">top tooltip</button>
<button class="btn tooltip tooltip-right" data-tooltip="Lorem ipsum dolor sit amet">right tooltip</button>

labels

Labels are formatted text tags for highlighted, informative information.

default label primary label success label info label warning label danger label

Add the class label to <span> or <small> elements. You can add another class label-primary, label-success, label-info, label-warning, label-danger for more colored labels.

<span class="label">default label</span>
<span class="label label-primary">primary label</span>

badges

Badges are often used as unread number indicators.

Notifications
Notifications
Notifications
Notifications

Add the class badge to non self closing elements. And add the attribute data-badge to define the content of a badge. The badge will appear in the top-right direction of the element.

<span class="badge" data-badge="99">
    Notifications
</span>

toasts

Toasts are used to show alert or information to users.

Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Efficiently unleash cross-media information without cross-media value.
Efficiently unleash cross-media information without cross-media value.
Efficiently unleash cross-media information without cross-media value.
Efficiently unleash cross-media information without cross-media value.

Add a container element with the class toast. You can add any text within the container, and even icons. You may also add a close button with the class btn-clear if you need.

You can add the class toast-primary, toast-success, toast-info, toast-warning, toast-danger for additional colors.

<div class="toast">
    <button class="btn btn-clear float-right"></button>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>

<div class="toast toast-primary">
    <button class="btn btn-clear float-right"></button>
    <span class="icon icon-error_outline"></span>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</div>

modals

Modals are flexible dialog prompts.

Add a container element with the class modal. And add a real container modal-container and overlay modal-overlay inside it. You can add child elements with the class name modal-header, modal-content and modal-footer - any or all of them.

Spectre.css does not include JavaScript code, you will need to implement your JS to interact with modals. To make a modal appear, add the class active to the modal container

<div class="modal active">
    <div class="modal-overlay"></div>
    <div class="modal-container">
        <div class="modal-header">
            <button class="btn btn-clear float-right"></button>
            <div class="modal-title">Modal title</div>
        </div>
        <div class="modal-body">
            <div class="content">
                <!-- content here -->
            </div>
        </div>
        <div class="modal-footer">
            <button class="btn btn-link">Close</button>
            <button class="btn btn-primary">Share</button>
        </div>
    </div>
</div>
modal sizes

Add the class modal-sm for a smaller modal dialog.

<div class="modal modal-sm">
    <div class="modal-overlay"></div>
    <div class="modal-container">
        <!-- modal structure here -->
    </div>
</div>

cards

Cards are flexible content containers.

Microsoft

Software and hardware
Empower every person and every organization on the planet to achieve more.

Apple

Hardware and software
To make a contribution to the world by making tools for the mind that advance humankind.

Google

Software and hardware
Organize the world’s information and make it universally accessible and useful.

Add a container element with the class card. And add child elements with the class name card-image, card-header, card-content and/or card-footer. The card-image can be placed in any position.

<div class="card">
    <div class="card-image">
        <img src="img/osx-el-capitan.jpg" class="img-responsive" />
    </div>
    <div class="card-header">
        <h4 class="card-title">Microsoft</h4>
        <h6 class="card-meta">Software and hardware</h6>
    </div>
    <div class="card-body">
        To make a contribution to the world by making tools for the mind that advance humankind.
    </div>
    <div class="card-footer">
        <button class="btn btn-primary">Do</button>
    </div>
</div>

Position utilities are used for useful layout and position things, including clearfix, float, position and margin/padding utilities.

<!-- clear float -->
<div class="clearfix"></div>
<!-- float: left and right-->
<div class="float-left"></div>
<div class="float-right"></div>
<!-- position: relative, absolute and fixed-->
<div class="rel"></div>
<div class="abs"></div>
<div class="fixed"></div>
<!-- centered block -->
<div class="centered"></div>
<!-- margin: 10px and 5px in 4 directions. mt-10 = margin-top: 10px; -->
<div class="mt-10"></div>
<div class="mt-5"></div>
<!-- padding: 10px and 5px in 4 directions. pt-10 = padding-top: 10px; -->
<div class="pt-10"></div>
<div class="pt-5"></div>

Display utilities are used for display and hidden things.

<!-- display: block; -->
<div class="block"></div>
<!-- display: inline; -->
<div class="inline"></div>
<!-- display: inline-block; -->
<div class="inline-block"></div>
<!-- display: flex; -->
<div class="flex"></div>
<!-- display: inline-flex; -->
<div class="inline-flex"></div>
<!-- display: none; -->
<div class="hide"></div>
<!-- visibility: visible; -->
<div class="visible"></div>
<!-- visibility: hidden; -->
<div class="invisible"></div>
<!-- hide text contents -->
<div class="text-hide"></div>

Text utilities are used for text alignment, styles and overflow things.

<!-- left-aligned text -->
<div class="text-left"></div>
<!-- center-aligned text -->
<div class="text-center"></div>
<!-- right-aligned text -->
<div class="text-right"></div>
<!-- justified text -->
<div class="text-justify"></div>

<!-- Lowercased text -->
<div class="text-lowercase"></div>
<!-- Uppercased text -->
<div class="text-uppercase"></div>
<!-- Capitalized text -->
<div class="text-capitalize"></div>

<!-- Noral weight text -->
<div class="text-normal"></div>
<!-- Bold text -->
<div class="text-bold"></div>
<!-- Italicized text -->
<div class="text-italic"></div>

<!-- Overflow behavior: display an ellipsis to represent clipped text -->
<div class="text-ellipsis"></div>
<!-- Overflow behavior: truncate the text -->
<div class="text-clip"></div>
<!-- Text may be broken at arbitrary points -->
<div class="text-break"></div>

Shape utilities are used for change element shapes.

<!-- rounded element -->
<div class="rounded"></div>
<!-- circle element -->
<div class="circle"></div>

Loading indicator is used for loading or updating. Also, you can add the class loading to buttons for loading status.

Loading
<!-- loading element -->
<div class="">Loading</div>