Hostingheaderbarlogoj
Join InMotion Hosting for $3.49/mo & get a year on Tuts+ FREE (worth $180). Start today.
Advertisement

Quick and Easy Interactive Wireframes with Bootstrap

by
Gift

Want a free year on Tuts+ (worth $180)? Start an InMotion Hosting plan for $3.49/mo.

Web design is an evolving profession. While a keen eye for color, typography, and layout will always be important, these skills are being trumped by a need to understand user motivations. It isn't enough to build a site and wait for traffic to roll in — sites must help users achieve their goals, with a minimum of cognitive friction. Bootstrap can help web professionals define these goals, and create a killer experience, too.

we're not making pages, we're making movies

I like to say we're not making pages, we're making movies. Users expect sites to load quickly, provide engaging content, and smart interactivity. Just as movies depend on quick cuts, lighting, and mood to draw users in, websites rely on transitions, interactivity, and timing. These details often get lost during the design phase—or worse, are never accounted for. While a transition that takes 0.5 seconds when it should take 0.25 seconds usually won’t sink an application, it is this level of detail separating good from great.

I will show you how Bootstrap can replace static wireframes and bring these details to the forefront earlier and with less effort.


Step 1: Setup Project

The first step is to download the latest stable Bootstrap and jQuery builds.

Though jQuery is hosted by a number of CDNs, I prefer to include all files locally so I can work with or without web access. Go ahead and set up a directory structure like the one below, and copy the unminified Bootstrap CSS, Bootstrap Responsive CSS, and Javascript files. Tweak names and locations as needed, but using this structure means you can also leverage my HTML template in the next step.

Now would be a good time to create a third stylesheet, which I will call user.css. This file will be used to override Bootstrap styles as needed.

Directory structure for Boostrap wireframes


Step 2: Create index.html and Verify Paths

This is the only other setup required to start building an interactive wireframe. Create a file in your project directory root, and name it index.html. After you have created the file, copy this code and save.

	<!DOCTYPE>
	<html lang="en">  
		<head>
			<meta http-equiv="Content-type" content="text/html; charset=utf-8">

			<title>Interactive Bootstrap Wireframes</title>

			<link rel="stylesheet" href="css/bootstrap.css" type="text/css" media="screen" title="master" charset="utf-8">
			<link rel="stylesheet" href="css/bootstrap.css" type="text/css" media="screen" title="master" charset="utf-8">
			<link rel="stylesheet" href="css/bootstrap.css" type="text/css" media="screen" title="master" charset="utf-8">
		</head>

		<body>
			<div class="container">
				Your layout will go here.
			</div>

			<script src="js/vendor/jquery-1.8.2.min.js" type="text/javascript"></script>
			<script src="js/bootstrap/bootstrap.js" type="text/javascript"></script>
		</body>
	</html>

Open a web browser and drag the saved index.html file into it. If all of the includes are properly loaded, you should see something similar to the screenshot below. If you don't see the alert box, open the Console or Web Inspector and see if a file has failed to load. After troubleshooting, remove or comment out the alert line in the $(document).ready function at the bottom of the page and get ready to build Bootstrap wireframes.

Web browser with Javascript alert box open


Step 3: Rough in Your Content Blocks

With all the necessary files in place, we can start roughing in the main content blocks. Most sites (apps) will contain a header, primary navigation, main content well, sidebar, and footer. I am deliberately keeping the layout simple, to quickly illustrate the power of Bootstrap’s grid system.

The only structural markup on the page so far is our div with class “container”.

Note: This div is a required containing block for Bootstrap; we will build our entire wireframe application inside it.

Bootstrap also requires the new HTML doctype, and generates its style rules with classes, instead of tag names. These decisions mean we can use some new HTML5 elements: header, navigation, section, article, aside, and footer. It is worth mentioning if you plan to test your layout in Internet Explorer, you will need to download and include either Modernizr, or the HTML5 Shim. Modern versions of Firefox, Chrome, and Safari natively support the HTML5 standard.

Bootstrap is built on a 12 column grid. It uses two classes, row and span to create block-level containers. By applying the row class to a container like a div or header, it automatically stretches across the entire 940px width. By adding containers with class spanN (N being a placeholder for the number of columns), you can easily create content wells, sidebars, and other layout blocks without having to manage floats or other quirks.

To get up and running quickly, I am going to build a basic header, navigation bar, main well, aside, and footer. Replace the "Your layout will go here" with the following code.

	<header class="row">
		<h1 id="banner">My Awesome App</h1>
	</header>
	
	<nav id="primary-navigation" class="row">
		<div class="span12">
			<ul>
				<li class="selected"><a href="#">Home</a></li>
				<li><a href="#">Features</a></li>
				<li><a href="#">About</a></li>
				<li><a href="#">Contact Us</a></li>
			</ul>
		</div>
	</nav>
	
	<section class="row">
		<article class="span9">
			<h2>This is the main content well</h2>
			<p>This is a short paragraph to highlight where the general content will go.</p>
		</article>
		
		<aside class="span3">
			<h3>This is the sidebar</h3>
			<p>Good content items include blogrolls, featured news, Twitter updates, etc.</p>
		</aside>
	</section>
	
	<footer class="row">
		<div class="span12">
			<h4>This is the footer</h4>
		</div>
	</footer>

I also added a few basic rules to user.css, to make the content blocks easier to identify. If all has gone well, you should see a number of gray blocks with black descriptive text inside.

	/* Basic style rule to outline and space block-level elements */
	[class*="span"] {
		background: #eee;
		margin-bottom: 10px;
	}
Multiple content blocks properly floated and ordered


Step 4: Fixed, Fluid, Responsive!

Fixed and fluid layouts have been around for a long time. Responsive layouts are relatively new, and combine the best parts of both. It gives designers tools to optimize their designs for multiple device sizes (smartphones, tablets, narrow and widescreen displays) without having to maintain a separate codebase for each. Resize your browser window to see Bootstrap’s responsive stylesheet in action, and get a feel for the awesome ability to write once and test wireframes in a number of environments.

Browsers make use of CSS break points to decide how to render a page, based on minimum and maximum width measurements. Break points in relation to browser width always begin with @media (width argument) and are very easy to read. They can also contain a second argument in another set of parenthesis, which allows a great deal of flexibility for multiple devices.

In the code sample below, I have created several rules that define background colors for four common Bootstrap responsive break points, modified slightly to show a smooth transition from one color to the next.

	/* Basic background colors for responsive break points */
	/* Max-width 480px landscape phone and down */
	@media (max-width: 480px) {
		.container {
			background: #f1ea81;
		}

		.container:after {
			content: "Max-width 480px landscape phone and down";
		}
	}

	/* Min-width 481px and max-width 767px landscape phone to portrait tablet */
	@media (min-width: 481px) and (max-width: 767px) {
		.container {
			background: #a7f7e5;
		}

		.container:after {
			content: "Min-width 481px and max-width 767px landscape phone to portrait tablet";
		}
	}

	/* Min-width 768px and max-width 979px portrait tablet to landscape */
	@media (min-width: 768px) and (max-width: 979px) {
		.container {
			background: #c4deff;
		}

		.container:after {
			content: "Min-width 768px and max-width 979px, portrait tablet to landscape";
		}
	}

	/* Min-width 980px widescreen display */
	@media (min-width: 980px) and (max-width: 1199px) {
	  .container {
			background: #fde3ff;
		}

		.container:after {
			content: "Min-width 980px, max-width 1199px, desktop format";
		}
	}

	/* Min-width 1200px widescreen display */
	@media (min-width: 1200px) {
	  .container {
			background: #ffc4c4;
		}

		.container:after {
			content: "Min-width 1200px, widescreen format";
		}
	}

We’ve built a fully responsive layout, but we're still missing the good stuff. The rest of this tutorial will show you how to add visual interest through content and interactivity.


Step 5: Sound Off!

Now that the scaffolding is in place, we can start adding content. I am deliberately keeping these views generic—gray boxes with minimal styles encourage beta users to focus squarely on the interaction, and not get too hung up on the visual style.

The Hero Unit is designed to create a front–and–center call to action. Code downloads, new applications, or breaking news items are good candidates. For our purposes, I will use it to announce a major software upgrade. Replace the existing h2 and p tags in the main content well with the code below and refresh your browser to see the hero in action.

	<div class="hero-unit">
		<hgroup>
			<h1>Version 2.0 Is Here!</h1>
			<h2>All new features, lots of improvements</h2>
		</hgroup>
		
		<h4>A more perfect package you&rsquo;re not likely to find</h4>
		<p>Our team has been busy this past year, completely revamping the inner workings of our 
			application. Faster page loads, better search, and mobile integration.</p>
		<p><a href="#" class="btn btn-primary btn-large">Download Now</a></p>
	</div>

The hero unit is a good start, but people want to see where their time and money will be going. An image gallery is a strong follow up, and is a snap to implement. Images are laid out using the same spanN grid that defines layout blocks, and can easily be extended to include headlines, tags, captions, or microdata. For now, we will use Placehold.it to generate three gray boxes underneath our hero unit.

I am a big believer in semantic markup, so we will be using the HTML5 figure and figcaption tags for increased context. Even if none of your users are browsing with a screenreader or other assistive device, descriptive markup is a best practice for UX and front–end development.

Add an unordered list and a few images inside the main content well, below your hero element like so:

	<ul class="thumbnails">
		<li class="span3">
			<figure>
				<img src="http://placehold.it/300x200" alt="3 column placeholder" />
				<figcaption>
					<h5>Image 1 title</h5>
					<p>This is a short caption.</p>
				</figcaption>
			</figure>
		</li>
		
		<li class="span3">
			<figure>
				<img src="http://placehold.it/300x200" alt="3 column placeholder" />
				<figcaption>
					<h5>Image 2 title</h5>
					<p>This is a short caption.</p>
				</figcaption>
			</figure>
		</li>
		
		<li class="span3">
			<figure>
				<img src="http://placehold.it/300x200" alt="3 column placeholder" />
				<figcaption>
					<h5>Image 3 title</h5>
					<p>This is a short caption.</p>
				</figcaption>
			</figure>
		</li>
	</ul>

Another browser refresh should yield a layout similar to this, when viewed widescreen.

Hero unit and 3 inline images


Step 6: Tabbed Navigation

The hero unit and images add a lot of visual interest, but highlight our next challenge: the bullet point links standing in for a proper navigation element.

Bootstrap has several built-in navigation styles, so experimentation is encouraged. I am going to highlight the tabbed navigation here. Our first order of business is to replace the basic navigation list:

	<nav id="primary-navigation" class="row">
		<div class="span12 tabbable">
			<ul class="nav nav-tabs">
				<li class="active"><a href="#tab1" data-toggle="tab">Home</a></li>
				<li><a href="#tab2" data-toggle="tab">Features</a></li>
				<li><a href="#tab3" data-toggle="tab">About</a></li>
				<li><a href="#tab4" data-toggle="tab">Contact Us</a></li>
			</ul>
		</div>
	</nav>

Next, let’s remove the gray background from our header and nav elements. Add the following four lines to the end of your user.css file.

	header [class*="span"],
	nav [class*="span"] {
		background: #fff;
	}

We also need to update the main content well. I have added a class of tab-content to the section element, and wrapped the hero and images in a div with class="tab-pane active" and id="tab1". I added three additional div elements below, with ID’s matching the navigation link tags. These three blocks are stubs to be filled in later, but will be useful for testing. Update the section markup and refresh the browser. If everything goes right, you should be able to toggle through the tabs and view the stubbed in content.

Tab 4 Contact Us selected to show navigation functionality


Step 7: Tooltips and Popovers

Tabs are cool, but they’re also just a start. Though the Internet is fast becoming segmented and application–like, it is still driven by links from one resource to another. Links are used to hook pages together, provide additional context, and sometimes, to house secondary functions. Tooltips and popovers are good examples of secondary function; they are easily implemented with custom data-attributes.

What are data-attributes? Per John Resig, who wrote about these devices clear back in 2008:

Simply, the specification for custom data attributes states that any attribute that starts with "data-" will be treated as a storage area for private data (private in the sense that the end user can't see it - it doesn't affect layout or presentation).

This means we can add custom data to our link tags, and Bootstrap will handle it accordingly.

Suppose our image gallery is made up of technical information. The descriptions might include terminology that is unclear to the average user. Activate tooltips by replacing the image gallery HTML, starting with the unordered list, and adding a jQuery $(document).ready function and Bootstrap’s tooltip function to the bottom of the page.

	<ul class="thumbnails">
		<li class="span3">
			<figure>
				<img src="http://placehold.it/300x200" alt="3 column placeholder" />
				<figcaption>
					<h5>Image 3 title</h5>
					<p>This is a short caption. It contains some technical language like 
						domain-specific terms like <a href="#"
							class="tooltips" 
							data-placement="top" 
							data-trigger="hover" 
							data-title="HTML: Hyper Text Markup Language"
						>HTML</a></p>
				</figcaption>
			</figure>
		</li>

		<li class="span3">
			<figure>
				<img src="http://placehold.it/300x200" alt="3 column placeholder" />
				<figcaption>
					<h5>Image 3 title</h5>
					<p>This is a short caption. It contains some technical language like 
						domain-specific terms like <a href="#"
							class="tooltips" 
							data-placement="top" 
							data-trigger="hover" 
							data-title="CSS: Cascading Style Sheets"
						>CSS</a></p>
				</figcaption>
			</figure>
		</li>

		<li class="span3">
			<figure>
				<img src="http://placehold.it/300x200" alt="3 column placeholder" />
				<figcaption>
					<h5>Image 3 title</h5>
					<p>This is a short caption. It contains some technical language like 
						domain-specific terms like <a href="#"
							class="tooltips" 
							data-placement="top" 
							data-trigger="hover" 
							data-title="JS: Javascript&mdash;The fresh language"
						>JS</a></p>
				</figcaption>
			</figure>
		</li>
	</ul>
	// Add just above the closing body tag
	// Activate the tooltips
	<script type="text/javascript" charset="utf-8">
		var tooltips = $('a.tooltips');

		$(tooltips).tooltip();
	</script>

With the HTML and Javascript in place, refresh the browser and roll over the gallery links to reveal your tooltips.

Basic search typeahead functionality

We are now going to add sharing to our image gallery (at least in a wireframe-y way) with popovers. Popovers are activated by including data-attributes in your markup, and another snippet of JavaScript.

First, let’s add a share button to each of our image captions. Add the code block just below the closing paragraph tag in each figcaption.

	<p>
		<a href="#" 
			id="test"
			class="btn btn-primary popover-link" 
			data-placement="right" 
			data-html="true"
			data-content="
				<a href='#'>Facebook</a><br/>
				<a href='#'>Twitter</a><br/>
				<a href='#'>Tumblr</a><br/>
				<a href='#'>Flickr</a><br/>
			"
			data-title="Share this image"
		>Share</a>
	</p>

It might seem strange to put each item on its own line, but I have found Bootstrap is fairly picky about well-formed markup, and it is easier to spot errors one line at a time. We need to write a few lines of JavaScript and the popovers will be ready.

	// Prevent default links actions and page jumping
	var links = $('a');
	links.on('click', function (e){
		e.preventDefault();
	});
	
	// Activate the popovers
	var popovers = $('a.popover-link');
	
	popovers.popover();

This time we have added a general links function to prevent our screen from jumping when users click on the Share button. Without delving too far into specifics, each action on a web page registers an event, which we are capturing here as the function argument 'e'. By intercepting this event, and replacing it with our custom JavaScript, the page stays where it should and our popover appears as expected.

Basic share functionality shown in a small popover


Step 8: Creating Modal Windows

Whew. After all of that, modal windows are going to be a cakewalk. Bootstrap makes modal windows available by adding a block of HTML to the top of your container, and a button or link with an href that matches the modal window ID. First, the modal HTML.

	<!-- Add this directly below div class="container"> -->
	<!-- Modal -->
	<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" 
		aria-labelledby="myModalLabel" aria-hidden="true">
	  <div class="modal-header">
	    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
	    <h3 id="myModalLabel">Catchy modal header here</h3>
	  </div>
	  <div class="modal-body">
	    <p><label for="username">Username</label><input type="text" name="username" value="" 
				placeholder="Enter username" id="username">
	    </p>
			<p><label for="password">Password</label><input type="password" name="password" 
				value="" placeholder="Enter password" id="password">
			</p>
	  </div>
	  <div class="modal-footer">
	    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
	    <button class="btn btn-primary">Save changes</button>
	  </div>
	</div>

The only other thing to do is add our trigger. Since this is an application, we would be right to assume there will be a login sequence. I have modified the header to shorten the banner area, and add our Login button next to the search box. Change the following HTML, and add the CSS to the end of your user.css file.

	<header class="row">
		<div class="span7">
			<h1 id="banner">My Awesome App</h1>
		</div>
		
		<div class="span5">
			<input type="search" placeholder="Enter search term" data-provide="typeahead" 
				id="search"/>
			<a href="#myModal" role="button" class="btn" data-toggle="modal">Login</a>
		</div>
	</header>
	/* Search box */
	header input {
		margin-top: 20px;
		width: 70%;
		float: left;
	}

	/* Login button */
	header a {
		float: right;
		margin: 20px 0 0 20px;
	}

Refresh and click the Login button. You should be rewarded with a quick animation, and the modal window presenting front and center.

Hero unit and 3 inline images


Step 9: How Will I Find Anything?

This interactive wireframe is coming along nicely. We have navigation that works, lots of blocks for adding content, interactivity, and a responsive layout. What we don’t have is a way to search for things, even in a user testing sense. Once again, Bootstrap has us covered.

Users are accustomed to the search box being prominently displayed in the top right corner of desktop displays, and just below the headline on narrower displays. We will begin by breaking the header element into two blocks, and adding a single input to the smaller:

	<header class="row">
		<div class="span9">
			<h1 id="banner">My Awesome App</h1>
		</div>
		
		<div class="span3">
			<input type="search" placeholder="Enter search term" data-provide="typeahead" 
				id="search"/>
		</div>
	</header>

We will also add a few lines of CSS to the user.css file, to push the search box off the top of the page.

	/* Search box */
	header input {
		margin-top: 20px;
		width: 90%;
	}

We will also be writing a slightly larger amount of JavaScript to make the typeahead work properly. I will keep it to a minimum, and explain what each script is doing.

I imagine some of you are thinking “I am a web designer, not a developer. Fair point, but we have to at least test the JavaScript waters to unlock Bootstrap’s full power. And besides: clients are wowed when an input box starts returning results from the first letter they type.

Add the JavaScript snippet below to your existing script tag, and hit Refresh. If it works correctly, you should see a dropdown menu with suggested results after you have typed one or more letters in the search box.

	var search = $('input#search');
	
	$(search).typeahead({
		source: [
			'Dave Mustaine',
			'Tom Morello',
			'Jim Root',
			'Kirk Hammett',
			'Joe Perry',
			'Jimi Hendrix',
			'Eric Clapton',
			'Billy Duffy',
			'Johnny Hickman',
			'Eddie Van Halen',
			'Dimebag Darrell',
			'Noel Gallagher'
		],
		items: 5
	});

Okay, here's what the code is doing. The var search = $('input#search') tells jQuery to store a reference to the search box in the named variable search. Then we call, or invoke, the jQuery function on our search variable, and also call the Bootstrap typeahead method. Inside the typeahead parenthesis, you will notice an opening and closing squiggly bracket { }. These brackets are used to create a JavaScript object, and store some information about our search box.

The first piece of information is the source array. At its simplest, an array is an ordered list of things. Here it is a list of guitar players. Every guitar player added to the array will be available as a result in our search input. The second part of the object, items: 5 tells the search box the maximum number of results to show.

These are just two of several options available. I encourage you to look at the Bootstrap typeahead documentation and experiment with different configurations. The final screen for this step should look similar to this:

Basic search typeahead functionality


Conclusion

Bootstrap has become a staple in my front–end workflow. It allows me to test when iterations are relatively painless, and try several different approaches concurrently. These discoveries help guide final design decisions, and help avoid time-consuming changes during the full development cycle. By treating wireframes as a critical part of the user experience, I am able to build tools that feel more natural and are more gratifying.

I have just scratched the surface of Bootstrap, and what is possible using its kit of parts. Wireframes are a great place to start learning the ins and outs—they are meant to be lo-fi, early test models of full applications to come. Clients and colleagues can test our assumptions, and help us refine quickly, with minimal time lost.

I hope you liked this tutorial, thanks for reading!

Advertisement