Community Documentation

Create a new custom theme with CSS alone

Last updated May 5, 2011. Created by geerlingguy on March 7, 2009.
Edited by Carolyn, rootwork, LeeHunter, bekasu. Log in to edit this page.

In Drupal 6 and Drupal 7, there are many improvements in core that make it easy for CSS web designers to create themes without having to deal with any PHP code. The Stark theme was created to help designers see the pure xhtml code output by Drupal, and is included in Drupal 7's core. Designers can now create beautiful themes that use nothing but CSS files.

This theming how-to will show you, in a few simple steps, how to create your own CSS-only theme for Drupal 6 or 7.

Step 1: Create the theme folder and .info file

The first step in creating a theme for Drupal is creating a folder for your theme to reside in, and a .info file to tell Drupal about your theme.

To create the folder:

  1. Create your folder in the /sites/all/themes directory.
  2. Name your folder yourthemename, all lowercase.

To create the .info file:

  1. Create a document in Notepad or your favorite plain text editor, and paste in the following information (changing where necessary*):
    name = yourthemename
    description = Description of yourtheme.
    core = 6.x
    engine = phptemplate
    stylesheets[all][] = style.css
    stylesheets[all][] = layout.css
    regions[left] = Left sidebar
    regions[right] = Right sidebar
    regions[content] = Content
    regions[header] = Header
    regions[footer] = Footer
  2. Save this document in the theme folder you created above, and name it yourthemename.info (all lowercase).

*Notes on the .info file:

  • You can easily add more stylesheets to your theme.
  • You can also easily add more regions to your theme.
  • Change the core = 6.x line to core = 7.x if you're creating a theme for Drupal 7.

Step 2: Creating the Stylesheets

If you look at Stark's only stylesheet, layout.css, you'll notice there are very few CSS rules:

#sidebar-left,
#main,
#sidebar-right {
  float: left;
  display: inline;
  position: relative;
}

#sidebar-left,
#sidebar-right {
  width: 20%;
}

body.one-sidebar #main {
  width: 80%;
}

body.two-sidebars #main {
  width: 60%;
}

body.sidebar-left #main-squeeze {
  margin-left: 20px;
}

body.sidebar-right #main-squeeze {
  margin-right: 20px;
}

body.two-sidebars #main-squeeze {
  margin: 0 20px;
}

The code simply lays out the content of the default Drupal installation in a logical way. This is about as simple as a theme can get. From here, you can build out your theme in many different ways.

The first step should be to layout the regions and graphic design of your page. You should do this in your own layout.css file.

Next, you can create a style.css file for other styles.

A common practice, for ease of code-maintenance, however, is to also create other CSS files including, but not limited to, html-elements.css, print.css, and ie.css. For each additional CSS file you create, you should add a line in yourthemename.info in the following format, below the other CSS stylesheet declarations:

stylesheets[all][] = newstylesheetname.css

Step 3: Design, and have fun!

There's really nothing else to do, if you're creating a CSS-only theme...

If you want, you can view the core PHP template files you're using in your theming. The main files you might want to view include:

  • page.tpl.php (for the overall page layout)
  • node.tpl.php (for all the 'nodes' or main content sections of a page)
  • block.tpl.php (for the blocks, in whichever regions you place them)
  • comment.tpl.php (for all comments on you site)

You can copy these PHP template files to your theme folder, then modify them to your liking, if you desire to change the way the html is structured.

Note that the code on this page is for a Drupal 6 theme. A Drupal 7 theme would be somewhat different. For example, in Drupal 7 #sidebar-left and #sidebar-right would be #sidebar-first and #sidebar-second. For more information on updating a Drupal 6 theme for Drupal 7, see Converting 6.x themes to 7.x.

Comments

So, where do I find these

So, where do I find these files if I'm using CSS only?

* page.tpl.php (for the overall page layout)
* node.tpl.php (for all the 'nodes' or main content sections of a page)
* block.tpl.php (for the blocks, in whichever regions you place them)
* comment.tpl.php (for all comments on you site)

Thanks

you don't need them

- Either you don't need them and just define the layout of the ids and classes output by drupal by default in your css, this is what stark does.
- Otherwise, you copy those files from one of the base themes (found in /themes/), I'd recommend basing yourself on Bartik in Drupal 7 as it is nicely documented (/themes/bartik/templates).
- Finally you write the core PHP template files from scratch using the resources linked to above (http://drupal.org/node/190815)

strategic code monkeying

core template files

You find them in the modules folder of Drupal:

modules/system: page.tpl.php
modules/node: node.tpl.php
modules/block: block.tpl.php
modules/comment: comment.tpl.php

Other core Drupal modules also have templates and css files. Fx in modules/field/theme (Drupal 7) you will find field.css and field.tpl.php.

missing information

I feel this tutorial is missing vital information. E.g. how does the content of the .info file tie up with the .css file? In .info you have: 'regions[right] = Right sidebar'. Is this related to 'sidebar-right' in the .css? Also it mentions that you can 'easily add more regions to your theme' but doesnt explain how to do this. I.e. need more explanation on format of 'regions[right] = Right sidebar'.

The .info file doesn't

The .info file doesn't directly tie into the CSS file (besides defining one or more); but rather, you can add some template files and add your own CSS classes for regions there, or you can go into your site and use Firebug or Webkit Inspector to see what Drupal's default classes are.

This is meant to be a very simple, get your feet on the ground, introduction; therefore the other issues are left to the detailed theme documentation.

__________________
Me, to webchick, in IRC: "ice cream kittens!"
Work: Midwestern Mac, LLC | Personal: Life is a Prayer.com

Thanks for the reply. I must

Thanks for the reply. I must admit I thought this was the detailed theming documentation (its under the Theming Guide: http://drupal.org/documentation/theme). Is there more detailed documentation on theming somewhere else?

default regions in Drupal 7

From system.module:

'sidebar_first' => 'Left sidebar',
'sidebar_second' => 'Right sidebar',
'content' => 'Content',
'header' => 'Header',
'footer' => 'Footer',
'highlighted' => 'Highlighted',
'help' => 'Help',
'page_top' => 'Page top',
'page_bottom' => 'Page bottom',

Thank you all for your

Thank you all for your answers!

Notice: Undefined index in page.tpl.php

I'm getting the following errors with Drupal 7.9 after following the basic instructions above.

Notice: Undefined index: highlighted in include() (line 120 of /pathtositeremoved/modules/system/page.tpl.php).
Notice: Undefined index: sidebar_first in include() (line 132 of /pathtositeremoved/modules/system/page.tpl.php).
Notice: Undefined index: sidebar_second in include() (line 138 of /pathtositeremoved/modules/system/page.tpl.php).

To clear it up I accounted for the missing regions in the list above by adding the following lines to the .info file's regions area:

regions[highlighted] = Highlighted
regions[sidebar_first] = Sidebar first
regions[sidebar_second] = Sidebar second

And removed the two that were not listed correctly:

regions[left] = Left sidebar
regions[right] = Right sidebar

drupal Zen theme

Hello actually I m very much new to drupal...just started few days back. My query is suppose I need to configure a theme according to my requirements, but my problem is the page should look eliminate the "admin-menus" which is visible on the left side of the "wrapper-page". But if that is eliminated then how to control the administration page of drupal??? pls do reply soon thanks...

you cannot eliminate the

you cannot eliminate the admin menus. u can simply log out and view the page not more than that.

you can move the

you can move the administration menu block to any other region.

If you are using Drupal 7, by default admin toolbar is fixed at top.

------------------------------------------------
Drupal UberCart Theme | Premium Drupal Themes

CSS Web Templates

Offers a collection of quality css templates, website templates, webdesign resources, css resources.
CSS Web Templates

Ecommerce Web Designer

The scope of e-commerce has changed forever, with regional boundaries now outclassed, the evolution of internet has made e-commerce the most effective and convenient way of buying/selling products online. Ecommerce Web Designer

Magento Website Design

Creator shadow is offshore web development company. We are providing web development services in php and open source. We provide magento development services for e-commerce solutions.
Magento Website Design

Affordable Websites Design

There is a common view that a website design/development is just like a business brochure on a computer screen. We do not hold that view, we think about websites & website design/development differently.
Affordable Websites Design

Web Design Company

Creator Shadow is a professional website design team located in jaipur, india. Our web designers specialize in best-in-class custom web design services including web development, e-commerce and web promotion services.
Web Design Company

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x, Drupal 7.x
Audience
Themers

Theming Guide

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.
nobody click here