Build a Twitter Clone From Scratch: The Design

This article represents the first in a new group effort by the Nettuts+ staff, which covers the process of designing and building a web app from scratch - in multiple languages! We'll use a fictional Twitter-clone, called Ribbit, as the basis for this series.

In this tutorial, we need to focus on the UI. We'll leverage the popular LESS Preprocessor to make our CSS as manageable as possible.


Be sure to download the assets for this tutorial, if working along.

This tutorial is divided into five major parts, which explain how to style various pages of Ribbit's layout. I will reference HTML elements using CSS selectors to make it easier to understand. But before diving into the layout, let's briefly discuss nesting.


In CSS, referencing a nested element can result in lengthy selectors. For example:

And it can grow even bigger! With LESS, you can nest one element in another, making it easier to read:

Variables and Mixins

Create a new file and name it, style.less. When using any style preprocessor, it's a good idea to store important colors and sizes within variables; you can easily adjust their values without searching the file, looking for property values that you need to change. We will use a handful of variables for the text color, border color, and content width:

Now, let's create two mixins. The first will create the illusion of anti-aliased text, and the second will allow for cross-browser gradients. The former is rather simple:

The trick is to create a shadow underneath the text with the same color and a one-pixel spread, making the browser display a nice shade around the text.

Now for the gradient; this is more complicated than the anti-aliased text because every browser implements gradients differently. Once we've compensated for the various vendor prefixes, here is the code:

Every browser has a prefix: -moz- for Firefox, -webkit- for Chrome, etc. The last line uses the W3C recommended version for gradients. If a browser supports it, it will override the previous properties because it's the last background property declaration in the rule. The linear-gradient function accepts eight parameters: four pairs of percent-color values. It creates the gradient with four color steps.

Global Styles

Let's next style some global elements, such as for buttons and links. We want all elements to use the Helvetica or Arial fonts with the text color defined earlier:


The body is pretty easy; we need a white background with an image-based pattern. There are no margins and padding:


We'll also provide a default style for all <input/> elements in the page:

We set the default size and padding, and we use the @border-color variable to remove the annoying blue outline when the element is focused. You should notice another bit of LESS sugar: we can add CSS pseudo-classes (and normal classes too) using the & character (parent reference), as shown here:

This causes the input to have a light yellow background, when focused.


Submit buttons will use both the previously defined mixin and the border-radius to create nice effect:


The links should have a different color than normal text. We'll also underline them on hover:

Basic Template

We will begin with the portion of the layout that remains the same in every page. Here is the HTML code, which I will explain below:

We start with a normal doctype definition and document head. You can use the less.js library and include the style.less in the development stage (as I did in this code). Later, you can compile the LESS file into CSS, if you don't wish to use less.js. As you've probably noticed by now, the layout is divided into three parts: header, #content, and footer. You should save this HTML to see if you are styling everything correctly.


Let's tackle the header. It contains Ribbit's logo and the two words: 'Twitter Clone'. It's wrapped in a wrapper, the width of which is controlled by the @content-width variable. There are several wrappers in the layout, and all are @content-width wide with auto margin:

The header itself is 85px tall and page wide:

After the width, add div.wrapper's style with vertical padding:

So the header should look like:

Images in the wrapper need to be 10px lower, in order to be nicely centered:

Also, the font in <span/> elements must be larger than the default size:

Here's how our design should look at this point.

Header in basic template.


There's not much we can do with #content at this time. We'll add some margin to the bottom and a minimum height; the layout will look funky if it's not tall enough:

Inside, the wrapper needs to have some vertical margin with an automatic horizontal margin:


Like the header, the footer is the same for all pages. We'll use a background image and a smaller font size. We'll also need to clear: both, because we'll use floats in the content. Without clearing, the footer will not adjust in accordance with the content:

Let's now add some padding to the wrapper, and images within it should float to the right:

Here's our footer:

The Home Page

This page displays for users not logged in to Ribbit. Therefore, it will need to present the login form in the header and a register form, with a big frog image in the content. Let's start with a basic template.

Login Boxes

Add this login form to the div.wrapper of the header, after the <span/> element:

These inputs are already styled, but we do need to add the margins and make the form display as inline. Append this after span in div.wrapper of header:

Register Form

Here is the HTML for the registration form:

Add this HTML within div.wrapper of #content. We want the image to have rounded corners and to be floated to the left (add this after margin in div.wrapper of #content):

Now, we can style the registration form. It will also be a panel that we'll use later; that's why we will style the .panel:

For now, though, we will only style the right panel. It's narrower and sticks to the right side of the panel. Naturally, insert the following into div.panel:

Also, we need to take care of the header and content of the panel. We use <h1/> elements for the header and <p/> elements for content. Notice that you can use the * wildcard inside of another element:

Here is how div.panel's style should look:

And here is a screenshot of how this page should look, thus far (click to see full size):

Home page preview

Buddies Page

The Buddies page should be displayed when a user logs in. It will display a list of the last "Ribbits," along with some statistics of your account. Once again, start with the basic template. This page, along with other pages, will display a logout button in place of the login form in the header:

The buttons have already been styled, so we only need to pin it to the right side of container and add some margins:

Because this rule's selector is an element's ID, you can place it either outside of any element or within the header's div.wrapper. It's your choice, but remember that, if you choose to place it inside of another element, the compiled CSS will have a longer selector (header div.wrapper #btnLogOut).

"Create a Ribbit" Box

First, add this panel's code to div.wrapper of #content:

The .right class was styled earlier, but we need to add some styling for the <textarea/> element. We'll give it a proper size and border:

Add this in the style definition of the right panel.

User Information

Now, let's focus on the panel, which contains the user's account information. We'll temporarily populate it with some random content to see the styling:

It may look complex, but the structure is fairly simple, when you strip out the content:

Regardless, we have another panel; so we need to style it first:

You probably know where to place this code (notice how easily you can perform arithmetical operations in LESS). This panel contains div.ribbitWrapper. So, add the following code:

There are two <span/> elements inside this element, each with a different color and font size. They have classes of .name and .time:

We should also position the avatar image near the left border. Add the following code:

Also, Ribbit's text needs to be anti-aliased, justified and moved to the right. This code will place the text next to the avatar, as opposed to beneath it:

In this paragraph, there are <span/> elements with vertical lines, visually separating them. This effect is achieved by using border, padding, and margin:

Buddies' Ribbits

This panel lists the latest ribbits from the people to whom the user follows. Insert the following after the user's information panel:

There are few example ribbits to see how it looks. We'll add some borders to visually separate them. Add this code in div.ribbitWrapper:

This styling adds the bottom border, while removing the border on the last div.ribbitWrapper; a border already exists on the panel.

Here is how this page should look now:

Buddies page preview

Public Ribbits Page

The "Public Ribbits" page will list the latest ribbits of profiles not marked as private, so that users can view the ribbits of those who they don't have in their buddy list. Surprisingly, there is nothing else to style, but we do need to add a touch of HTML. The only difference between this and the previous page is that this one doesn't have the user's information panel, but it will have other content in the final site. So feel free to copy the code of the buddies page, but remove this panel:

Also change the header of the panel to "Public Ribbits." Here is the preview of this page:

Public Profiles Page

On this page, users can see a list of profiles that are not marked as private. There is also a search box to find other profiles. We'll start with the basic template.

Profile Search

The search box will use the .right panel with an <input/> element inside:

Profiles List

Here are a handful of example profiles for the profile list, so that you can see how it looks in the browser. In a future lesson, we'll of course replace this, accordingly.

This page should look like:

Compiling The CSS

Referencing a nested element can result in lengthy selectors.

As I noted earlier, for production, you can compile your LESS to CSS (and I recommend you do so for performance reasons). There are a few available online compilers:

Along with some stand-alone compilers:

  • Crunch! (which is a full-blown LESS editor)
  • WinLess (features auto compilation when the less file changes)
  • SimpLESS (includes CSS minification)

If any of these compilers do not work for you, Google for more; there are plenty! You can also use lessc from LESS's site, but it's much easier to compile your LESS files with other compilers. Of course, there is nothing wrong with using the less.js library to dynamically compile the layout; new browsers cache the resulting CSS.


As you can see, LESS is a powerful tool that makes it much easier and faster than plain CSS to style beautiful layouts.

But this is just the beginning. Be prepared to implement Ribbit's back-end in a plethora of languages and platforms in the next set of tutorials!



Related Articles