Introduction to W3.CSS


Ease of use

One thing that you will notice pretty quickly is that many of the elements are pre-made. They make excellent building blocks using ready-made margins, sizes, etc..., so that you can spend more time creating the page , rather than reinventing the multitude of elements, attributes and settings from scratch. Of course if you wish to customize any of the elements, you will have a ready-made model to work from.

Containers

HTML uses many container elements like <div>, <article>, <section>, <header>, and <footer>.

The W3.CSS container class is the perfect CSS class for these elements.

Example

<div class="w3-container">

<p>London is the capital city of England.</p>

<p>It is the most populous city in the United Kingdom,
with a metropolitan area of over 13 million inhabitants.</p>

</div>
Try It Yourself »

Result:


London is the capital city of England.

It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.



Headers

Example

<header class="w3-container teal">
  <h1>London</h1>
</header>
Try It Yourself »

Result:

London


Footers

Example

<footer class="container teal text-white-opacity">
  <h5>My Footer</h5>
  <p>Footer information goes here</p>
</footer>
Try It Yourself »

Result:


Tables

Example

<table class="w3-table-all bordered striped">
<thead>
<tr>
  <th>First Name</th>
  <th>Last Name</th>
  <th>Points</th>
</tr>
</thead>
<tbody>
<tr>
  <td>Jill</td>
  <td>Smith</td>
  <td>50</td>
</tr>
<tr>
  <td>Eve</td>
  <td>Jackson</td>
  <td>94</td>
</tr>
<tr>
  <td>Adam</td>
  <td>Johnson</td>
  <td>67</td>
</tr>
</tbody>
</table>
Try It Yourself »

Result:

First Name Last Name Points
Jill Smith 50
Eve Jackson 94
Adam Johnson 67

Cards

Car

card-2

Car

card-4

Car

card-8


Example

<div class="w3-card-4">
... card content ...
</div>
Try It Yourself »

Self-Validating Input Forms

Input Form


Example

<form class="w3-container w3-card-4">

<h2>Input Form</h2>

<form class="w3-container w3-card-4">

<h2>Input Form</h2>

<p>
<input class="w3-input" type="text" required>
<label class="w3-label w3-validate">Name</label></p>

<p>
<input class="w3-input" type="email" required>
<label class="w3-label w3-validate">Email</label></p>

<p>
<textarea class="w3-input"></textarea>
<label class="w3-label">Subject</label></p>

<p>
<input id="milk" class="w3-check" type="checkbox" checked="checked">
<label class="w3-validate">Milk</label></p>

<p>
<input id="sugar" class="w3-check" type="checkbox">
<label class="w3-validate">Sugar</label></p>

<p>
<input id="lemon" class="w3-check" type="checkbox" disabled>
<label class="w3-validate">Lemon (Disabled)</label></p>

</form>
Try It Yourself »

Buttons

There are two button types in W3.CSS.

The standard button signifies actions and has depth on a flat page.

The floating button is circular and meant for important functions.

+ +

Example

<a class="w3-btn">Button</a>
<a class="w3-btn w3-teal">Button</a>
<a class="w3-btn w3-disabled">Button</a>

<a class="w3-btn-floating w3-teal">+</a>
<a class="w3-btn-floating w3-disabled">+</a>
Try It Yourself »

Modals

Example

<button onclick="document.getElementById('id01').style.display='block'" class="w3-btn">
Open Modal</button>

<div id="id01" class="w3-modal">
  <div class="w3-modal-content w3-card-4">
    <header class="w3-container w3-teal">
      <span onclick="document.getElementById('id01') .style.display='none'" class="w3-closebtn">&times;</span>
      <h2>Header</h2>
    </header>
    <div class="w3-container">
      <p>Some text. Some text. Some text. </p>
      <p>Some text. Some text.Some text. </p>
    </div>
    <footer class="w3-container w3-teal">
      <p>Footer</p>
    </footer>
  </div>
</div>
Try It Yourself »

Tooltips

Example

<p>Hover over the text!</p>

<p class="w3-tooltip">Hover over me!
<span class="w3-text">Tooltip content</span></p>
Try It Yourself »

Example

<p>Hover over the picture!</p>

<div class="w3-tooltip">

<div class="w3-text w3-container w3-teal">
A car is a wheeled, self-powered motor vehicle used for transportation.
Most definitions of the term specify that cars are designed to run primarily on roads,
to have seating for one to eight people,
to typically have four wheels. (Wikipedia)
</div>

<img src="images/img_car.png" alt="Car" style="width:100%">

</div>
Try It Yourself »

 







W3.CSS Typography


Easy to Read

W3.CSS pages are easy to read, even for people with slight reading disabilities.


HTML Headings <h1> - <h6>

By default w3.css styles HTML headings this way:

Example

<h1>Heading 1 (36px)</h1>

<h2>Heading 2 (30px)</h2>

<h3>Heading 3 (24px)</h3>

<h4>Heading 4 (20px)</h4>

<h5>Heading 5 (18px)</h5>
<h6>Heading 6 (16px)</h6>
Try It Yourself »

Font-Size Classes

Headings should be used for what they are: Headings.

With W3.CSS, font sizes can be set by classes:

Example

tiny
small
medium (Default)
large
xlarge
xxlarge
xxxlarge
jumbo
Try It Yourself »

Blockquotes

Blockquotes can be displayed in any size or color:

Make it as simple as possible, but not simpler.
Albert Einstein

Make it as simple as possible, but not simpler.
Albert Einstein

Make it as simple as possible, but not simpler.
Albert Einstein

Make it as simple as possible, but not simpler.
Albert Einstein

Example

<div class="blockquote">
  <p>Make it as simple as possible, but not simpler.<br>Albert Einstein</p>
</div>
Try It Yourself »

 







W3.CSS Containers


Container Classes

Container classes are important for:


HTML Containers

Typical HTML container elements are:

The W3.CSS w3-container class is the perfect CSS class for these HTML elements.

Example

<div class="w3-container">

<p>
A car is a wheeled, self-powered motor vehicle used for transportation.
</p>

</div>
Try It Yourself »

To add a border, add a border class:

Example

<div class="w3-container w3-border">

<p>
A car is a wheeled, self-powered motor vehicle used for transportation.
</p>

</div>
Try It Yourself »

To add a color, add a color class:

Example

<div class="w3-container w3-red">

<p>
A car is a wheeled, self-powered motor vehicle used for transportation.
</p>

</div>
Try It Yourself »

Headers

To style a header, use the w3-container class:

Heading 1

Example

<header class="w3-container teal">
  <h1>Heading 1</h1>
</header>
Try It Yourself »

Articles

To style an article, use the w3-container class:

Example

<article class="w3-container">

<p>
A car is a wheeled, self-powered motor vehicle used for transportation.
</p>

</article>
Try It Yourself »

Sections

To style a section, use the w3-container class:

Example

<section class="w3-container">

<p>
A car is a wheeled, self-powered motor vehicle used for transportation.
</p>

</section>
Try It Yourself »

Footers

To style a footer, use the w3-container class:

Example

<footer class="w3-container teal">
  <h5>Footer</h5>
  <p>Footer information goes here</p>
</footer>
Try It Yourself »

Padding

The container class has padding of 1px (top and bottom), and 16px (left and right).

If you want to change the padding for a container, you can use a padding class: 

Example

<div class="w3-container w3-padding-32 red">

<h2>London</h2>

<p>London is the capital city of England.
It is the most populous city in the United Kingdom,
with a metropolitan area of over 13 million inhabitants.</p>

</div>
Try It Yourself »

Code Containers

HTML Example

<div class="w3-code htmlHigh">

.. HTML code goes here

</div>
Try It Yourself »

CSS Example

<div class="code cssHigh">

.. CSS code here

</div>
Try It Yourself »

JavaScript Example

<div class="code jsHigh">

.. JavaScript code here

</div>
Try It Yourself »

Hiding (Closing) Containers

Hiding or closing a container is easy:

Example

<div class="w3-container red">

<span class="w3-closebtn" onclick="this.parentElement.style.display= 'none'">X</span>

<p>To close this container, click on the X in the upper right corner. </p>

</div>
Try It Yourself »

Combinations

Header

Car
Beautiful Car

A car is a wheeled, self-powered motor vehicle used for transportation. Most definitions of the term specify that cars are designed to run primarily on roads, to have seating for one to eight people, to typically have for one to eight people, to typically have four wheels. (Wikipedia)

Example using HTML <div> elements

<div class="w3-container red">
  <h1>Header</h1>
</div>

<div class="w3-image">
  <img src="images/bmw5.jpg" alt="Car" style="width:100%">
  <div class="w3-title w3-text-black">Beautiful Car</div>
</div>

<div class="w3-container">
<p>
A car is a wheeled, self-powered motor vehicle used for transportation.
Most definitions of the term specify that cars are designed to run primarily on roads,
to have seating for one to eight people, to typically have for one to eight people,
to typically have four wheels. (Wikipedia)
</p>
</div>

<div class="w3-container w3-red">
  <h5>Footer</h5>
</div>
Try It Yourself »

Example using HTML semantic elements

<header class="w3-container w3-red">
  <h1>Header</h1>
</header>

<div class="w3-image">
  <img src="images/img_car.png" alt="Car" style="width:100%">
  <div class="w3-title w3-text-black">Nice Car</div>
</div>

<article class="w3-container">
<p>
A car is a wheeled, self-powered motor vehicle used for transportation.
Most definitions of the term specify that cars are designed to run primarily on roads,
to have seating for one to eight people, to typically have for one to eight people,
to typically have four wheels. (Wikipedia)
</p>
</article>

<footer class="w3-container w3-red">
  <h5>Footer</h5>
</footer>
Try It Yourself »

 







W3.CSS Cards


Card Classes for Paper-like Cards

w3-card-2

w3-card-8


w3-card-16
Class Defines
w3-card Container for any HTML content (With border)
w3-card-2 Container for any HTML content (2px bordered shadow)
w3-card-4 Container for any HTML content (4px bordered shadow)
w3-card-8 Container for any HTML content (8px bordered shadow)
w3-card-12 Container for any HTML content (12px bordered shadow)
w3-card-16 Container for any HTML content (16px bordered shadow)
w3-card-24 Container for any HTML content (24px bordered shadow)

Example (Yellow Cards)

<div class="w3-card w3-yellow">
 <p>w3-card</p>
</div>
Try It Yourself »

Example (White Cards)

<div class="w3-card">
  <p>card</p>
</div>
Try It Yourself »

More Examples

Header

A car is a wheeled, self-powered motor vehicle used for transportation. Most definitions of the term specify that cars are designed to run primarily on roads, to have seating for one to eight people, to typically have for one to eight people, to typically have four wheels. (Wikipedia)


Header

A car is a wheeled, self-powered motor vehicle used for transportation. Most definitions of the term specify that cars are designed to run primarily on roads, to have seating for one to eight people, to typically have for one to eight people, to typically have four wheels. (Wikipedia)

Example

<div class="w3-card-4" style="width:50%">
 
<header class="w3-container w3-blue">
  <h1>Header</h1>
</header>

<div class="w3-container">
<p>A car is a wheeled, self-powered motor vehicle used for transportation.
Most definitions of the term specify that cars are designed to run primarily on roads,
to have seating for one to eight people, to typically have for one to eight people,
to typically have four wheels. (Wikipedia)</p>
</div>

</div>
Try It Yourself »

Photo Card

Car

w3-card-12 example


Example

<div class="w3-card-12" style="width:50%">
  <img src="images/img_car.png" alt="Car" style="width:100%">
  <div class="container">
    <p>w3-card-12 example</p>
  </div>
</div>
Try It Yourself »

 







W3.CSS Built-In Responsiveness


Responsive Classes

These are the responsive classes:

Class Description
w3-half Occupies 1/2 of the window (on medium or large screens)
w3-third Occupies 1/3 of the window (on medium or large screens)
w3-quarter Occupies 1/4 of the window (on medium or large screens)
w3-col Defines a column in a 12 column grid (see next chapter)

Responsive Rows

Responsive classes must reside inside a row to be fully responsive.

Class Description
w3-row Defines a padding-less container for responsive classes.

The w3-half Class

The width of the w3-half class is 1/2 of the parent element (style="width:50%").

On screens smaller than 601 pixels it resizes to 100%.

w3-half

w3-half

Example

<div class="w3-row">
  <div class="w3-container w3-half">
    <h2>w3-half</h2>
    <p>This is a paragraph</p>
  </div>
  <div class="w3-container w3-half">
    <h2>half</h2>
    <p>This is a paragraph</p>
  </div>
</div>
Try It Yourself »

The w3-third Class

The width of the third class is 1/3 of the parent element (style="width:33.33%").

On screens smaller than 601 pixels it resizes to 100%.

w3-third

w3-third

w3-third

Example using third

<div class="w3-row">
  <div class="w3-container w3-third">
    <h2>w3-third</h2>
    <p>This is a paragraph</p>
  </div>
  <div class="w3-container w3-third">
    <h2>w3-third</h2>
    <p>This is a paragraph</p>
  </div>
  <div class="w3-container w3-third">
    <h2>w3-third</h2>
    <p>This is a paragraph</p>
  </div>
</div>
Try It Yourself »

The w3-quarter Class

The width of the quarter class is 1/4 of the parent element (style="width:25%").

On screens smaller than 601 pixels it resizes to 100%.

w3-quarter

Example using w3-quarter

<div class="w3-row">
  <div class="w3-container w3-quarter">
    <h2>w3-quarter</h2>
    <p>This is a paragraph</p>
  </div>
  <div class="w3-container w3-quarter">
    <h2>w3-quarter</h2>
    <p>This is a paragraph</p>
  </div>
  <div class="w3-container w3-quarter">
    <h2>w3-quarter</h2>
    <p>This is a paragraph</p>
  </div>
</div>
Try It Yourself »

Combinations

w3-quarter

w3-quarter

w3-quarter

w3-quarter


w3-quarter

w3-half

w3-quarter


w3-quarter

w3-quarter

w3-half


Example: half Inside half

<div class="w3-row">
  <div class="w3-half w3-container">
    <h2>w3-half</h2>
    <div class="w3-row">
      <div class="w3-half w3-container w3-red">
        <h2>w3-half</h2>
        <p>This is a paragraph. </p>
      </div>
      <div class="w3-half container">
        <h2>w3-half</h2>
        <p>This is a paragraph. </p>
      </div>
    </div>
  </div>
  <div class="w3-half container">
    <h2>w3-half</h2>
    <div class="w3-row">
      <div class="w3-half w3-container w3-red">
        <h2>w3-half</h2>
        <p>This is a paragraph. </p>
      </div>
      <div class="w3-half container">
        <h2>w3-half</h2>
        <p>This is a paragraph. </p>
      </div>
    </div>
  </div>
</div>
Try It Yourself »

The w3-content Class

Example

<body class="w3-content" style="max-width:600px">

<div class="w3-container w3-card-2 w3-indigo">
  <h1>Movies 2014</h1>
</div>

<ul class="w3-ul">
  <li>
    <h3>Frozen</h3>
    <p>The social media response
    to the animations was ridiculous.</p>
  </li>
  <li>
    <h3>The Fault in Our Stars</h3>
    <p>Touching, gripping and genuinely well made. </p>
  </li>
  <li>
    <h3>The Avengers</h3>
    <p>The Avengers is a hugely bankable franchise for Marvel and Disney.</p>
   </li>
</ul>

<div class="w3-container w3-indigo w3-xlarge">
  <h5>Movies 2014</h5>
</div>

</body>
Try It Yourself »

12 Column responsive fluid grid

W3.CSS also supports an advanced 12 column responsive fluid grid.

Resize the page to see the effect!

1
2
3
4
5
6
7
8
9
10
11
12

This part will occupy 12 columns on a small screen, 4 on a medium screen, and 3 on a large screen.

This part will occupy 12 columns on a small screen, 8 on a medium screen, and 9 on a large screen.

1
2
3
4
5
6
7
8
9
10
11
12

You will learn more about the fluid grid in a later chapter.


 







W3.CSS Utilities (Helpers)


Color Utilities (Helpers)

London is the capital city of England. It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.


London is the capital city of England. It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.

Example

<div class="w3-container orange">
<p>
London is the capital city of England. It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.
</p>
</div>

<div class="w3-container w3-red">
<p>London is the capital city of England. It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.
</p>
</div> 
Try It Yourself »

Utilities are often called Helpers


Padding Utilities (Helpers)

London is the capital city of England. It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.

Example

<div class="w3-padding-jumbo orange">
<p>
London is the capital city of England. It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.
</p>
</div> 
Try It Yourself »

Example

<div class="w3-padding-16 orange">
<p>
London is the capital city of England. It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.
</p>
</div> 
Try It Yourself »

Border Utilities

London is the capital city of England. It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.


London is the capital city of England. It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.

Example

<div class="w3-border-left border-right">
<p>
London is the capital city of England. It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.
</p>
</div>
Try It Yourself »

Example

<div class="w3-border-left border-right">
<p>
London is the capital city of England. It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.
</p>
</div>
Try It Yourself »

Size Utilities

I'm tiny (using w3-tiny)

I'm small (using w3-small)

I'm medium. The default.

I'm large (using w3-large)

I'm xlarge (using w3-xlarge)

Example

<p class="w3-small">I'm small (using w3-small)</p>
<p>I'm medium. The default.</p>
<p class="w3-large">I'm large (using w3-large)</p>
<p class="w3-xlarge">I'm xlarge (using w3-xlarge)</p>
Try It Yourself »

Margin Utilities

London is the capital city of England. It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.

London is the capital city of England. It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.

Example

<div class="w3-border-left border-right">
<p>
London is the capital city of England. It is the most populous city in the United Kingdom, with a metropolitan area of over 13 million inhabitants.
</p>
</div>
Try It Yourself »

Circle

Example

<img class="w3-circle" src="images/img_car.png" alt="Car">
Try It Yourself »

Center

Example

<div class="w3-container w3-center w3-black w3-card-2">
  <img class="w3-circle" src="images/img_car.png" alt="Car">
</div> 
Try It Yourself »

 







W3.CSS Buttons


Button Elements

With W3.CSS, all HTML elements can be buttons.

But the most common elements are <input>, <button>, and <a>:

Buttons have the ability to add eye candy to a normally drab page and encourage more user interaction with the page. As you will see, there are many options available to make buttons that stand out and beg for interaction.

Link Button

Div Button

Example

<input class="w3-btn" value="Input Button">

<button class="w3-btn">Button Button</button>

<a class="w3-btn" href="http://www.w3schools.com">Link Button </a>

<div class="w3-btn" style="height:100px;width:200px">
  <p>Div Button</p>
</div>
Try It Yourself »

Button Colors

Buttons come in all the colors you need:

Example

<button class="w3-btn w3-khaki">Khaki</button>
<button class="w3-btn w3-yellow">Yellow</button>
<button class="w3-btn w3-orange">Orange</button>
<button class="w3-btn w3-red">Red</button>
<button class="w3-btn w3-purple">Purple</button>
Try It Yourself »

Button Shapes

Buttons come in all the shapes you need:

Example

<button class="w3-btn">Normal</button>
<button class="w3-btn w3-round">Round</button>
<button class="w3-btn w3-round-large">Rounder</button>
<button class="w3-btn w3-round-xlarge">and Rounder</button>
<button class="w3-btn w3-round-xxlarge">and Rounder</button>
Try It Yourself »

Button Sizes

Buttons come in all the sizes you need:

Example

<button class="w3-btn w3-tiny">Tiny</button>
<button class="w3-btn w3-small">Small</button>
<button class="w3-btn w3-medium">Medium</button>
<button class="w3-btn w3-large">Large</button>
<button class="w3-btn w3-xlarge">xLarge</button>
Try It Yourself »

Button Borders

Buttons can have borders.

Example

<button class="w3-btn w3-white border">Button</button>
<button class="w3-btn w3-khaki border">Button</button>
<button class="w3-btn w3-yellow border">Button</button>
Try It Yourself »

Buttons with Text Effects

Buttons can have italic and bold text effects.

Example

<button class="w3-btn">Normal</button>
<button class="w3-btn"><i>Italic</i></button>
<button class="w3-btn"><b>Bold</b></button>
Try It Yourself »

Buttons can have shadow text effects.

Example

<button class="w3-btn w3-red text-shadow">Shadow</button>
<button class="w3-btn w3-red text-shadow"><i>Shadow</i> </button>
<button class="w3-btn w3-red text-shadow"><b>Shadow</b> </button>
Try It Yourself »

Buttons can have slim and wide text effects.

Example

<button class="w3-btn">Normal</button>
<button class="w3-btn w3-slim">Slim</button>
<button class="w3-btn w3-wide">Wide</button>
Try It Yourself »

Hover Effects / Disabled Buttons

Buttons stands out when you mouse over them.

Normal buttons display a finger pointer.

Disabled buttons are opaque and display a no parking sign.

Example

<button class="w3-btn w3-teal">Button</button>
<button class="w3-btn w3-disabled">Button</button>

<input type="button" class="w3-btn" value="Button">
<input type="button" class="w3-btn" value="Button" disabled>
Try It Yourself »

Buttons with Ripple Effects

Buttons can have ripple effects when clicked.

Try to click on these buttons:

Example

<button class="w3-btn w3-ripple">Button</button>
<button class="w3-btn w3-ripple red">Button</button>
<button class="w3-btn w3-ripple yellow">Button</button>
Try It Yourself »

Button Groups

Buttons can be grouped together (without space in between) using "btn-group":


Example

<div class="w3-btn-group">
 <button class="w3-btn w3-ripple">Button</button>
 <button class="w3-btn w3-ripple w3-red">Button</button>
 <button class="w3-btn w3-ripple w3-yellow">Button</button>
</div>
Try It Yourself »

Button Elements

With W3.CSS, all elements can be a button.

A picture can be a button

Any div, header, footer or other container can be a button.