[Drupal] How to create a subtheme in Drupal

| | 2 min read

If you are a Drupal developer and not a stranger to themes and its behaviors, let us see how to create a subtheme in Drupal. A sub theme is quite similar to a theme. When we create a sub theme, it has an independent folder structure as any theme. The only difference is that it inherits everything from parent theme. There are no limits in creating subtheme for a subtheme and so on.

Creating a subtheme

Create .info file

While creating a sub-theme, it's name should contain only alphabets, numbers and underscores.

First step to let subthemes be identified is copy the .info of the parent theme to its root folder. Include these lines,


  theme name = my_subtheme
  base theme = bartik
Overriding CSS

Inheriting CSS is not a big deal. Copy style.css to styles folder. If you don't want to save the imported styles, empty the file and save.

 stylesheets[all][]   = style.css 
Overriding JS

Inheriting JS is same as that of CSS. Create a file of the same name and empty it.

 scripts[] = script.js
Overriding or adding features

Copy all the features array to the next of JS to inherit the features. In order to create a new feature, add the feature to the array.

1. Template.php function inheritance

Any thing in this is inherited such as preprocess, theme functions etc.

2. Tpl files inheritance

By copying the tpl files to the template folder, the tpl are inherited.

There are many ways to create a sub-theme. We can create sub-themes using drush, but we have to check the requirements. For more details,
click here.

Please let us know if we can be of any further help on Drupal theme Development.