Welcome to WebmasterWorld Guest from

Forum Moderators: ergophobe

Message Too Old, No Replies

Drupal: cleanest html possible?

Stripping the unnecessary extensive html?



10:44 pm on May 10, 2014 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

Hi there, don't get me wrong I love Drupal, it's my CMS of choice and I even feel weird asking this that I should know by now.

Drupal is very clean, it shows a lot of structure and order but for some projects it's unnecessary, or perhaps I could manage things more easily without it. It doesn't fully depend on the theme, in fact I create my own themes and still I get lots of css and html out of Drupal core. How to disable this? Drupal users will surely know what I mean.

I would like to know how to do it without using modules and if possible, how to do it without compromising the upgrade routines (from version to version) but perhaps this last thing isn't that big of a deal now that Drupal goes to version 8 not compatible with previous versions.

I'm working with the last Drupal 7.xx release.

Thanks in advance. Yes I searched but nothing useful so far.


12:04 am on May 11, 2014 (gmt 0)

WebmasterWorld Administrator ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

A few things...

First, I'm not sure what the compatibility of Drupal 8 has to do with this. Remember that Drupal 7 will be the main version of Drupal in use for at least another two years. Version upgrades are such a big deal in Drupal, it isn't even expected for there to be an upgrade path for D7 -> D8 within the first year of D8. So whatever you do for a Drupal 7 site should be maintainable for at least two years. More likely you will stick with D7 until D9 comes out 4-5 years from now.

As for the question at hand...

CSS - this is the easy one. Many ways to handle this, but you can block stylesheets from loading just by including an empty file with the same name in your theme. A simple function in your template.php can also block system CSS. Friendly Machine recently published a nice list of stylesheets to block



As for the HTML, you'll need to handle this on a few levels and it will require either modules, reset themes and/or lots of work.

The classic reset theme is Mothership by MortenDK who is Drupal's crusader agains "divitis" and alleges in his standard talk that 30% of all divs on the web are caused by Drupal.

There are other minimal themes that reset lots of the system HTML.

Then you can get control over
- Content with Fences or Display Suite
- Views with Semantic Views
- Panels with Semantic Panels

After that, it starts to get real hard!


2:18 am on May 12, 2014 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

Thanks Ergo, as for compatibility I meant upgrades, security is a key and besides, it's a good rule to follow not modding core files so the system survives key upgrades. Big versions changes usually mean reinstalling and moving data.

I found this:

and this:

I love Drupal but it seems I will have to move to something more clear for now, there is too many divs involved. Empty files are a good solution but I would like to keep a very clean theme solution, it seems like a lot of work by now. I will be sharing work so, a lot of files (with data and empty ones) doesn't look good to me (as ordered work). Ohhh Drupal...


5:47 pm on May 12, 2014 (gmt 0)

WebmasterWorld Administrator ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

>>empty files

The function solution would do this, or the solutions you link to. But starting with Mothership as your base theme will get rid of most of this in one fell swoop. Achieving your goal is the entire reason the Mothership theme came into being.

But yes, getting clean markup in Drupal is a hassle. Drupal 8 will make huge changes in that regard, but anything before then is effort

ModX, I believe, takes the opposite approach - it doesn't put anything into a template that you don't ask for. Drupal has always taken the approach that it should have enough markup so that a designer can target any element and change the look even on sites that need IE6 compatibility.... which means a forest of divs, classes and ids.

If the project in question is already on Drupal, though, and you're looking at a major migration and tons of work to convert it to a new system, you really should check out the Mothership theme before you do all that work.

From the project page:
Keelhaul the div!

The Mothership is a HTML5 base theme that offers a workaround to Drupalís obscure love for wrapping everything in 2 divs and slapping on 3 CSS classes wherever possible.

Like other blank canvas base themes (eg Stark, Framework), this theme will NOT make your site look pretty. Unlike the others, it will do more to help you clean up the mess of excessive markup that Drupal provides out of the box, offering settings to optionally remove CSS classes in the markup.

Why do it change so much in Drupal
Because Drupals markup is a PITA to work with.
We like clean mean markup & css that you as a themer wants - not what Drupal thinks was good for you 5 years ago.



5:42 am on May 17, 2014 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

Thanks for the info, I agree with Drupal approach to allow detailed and specific control over any element, but this time I needed full control myself so, ended up using Symfony. But this readings are a must to improve my Drupal skills. Thanks.


6:02 pm on May 17, 2014 (gmt 0)

WebmasterWorld Administrator ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

Don't get me wrong. I do *not* agree with the Drupal approach and most people don't these days. It's just so much legacy code. But it should be a lot cleaner in D8 (there's a whole team under MortenDK, creator of Mothership who are working to fix this cruft).

I'm merely reporting... not supporting!

For my part, I feel like getting up to speed with Symfony would do me a world of good!


5:45 am on May 18, 2014 (gmt 0)

WebmasterWorld Senior Member tangor is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

Everything bloats... given time. Ultimately it is m ore difficult to trim/cut than move forward. Been there, done that. Whew!


3:02 pm on May 22, 2014 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

@ergo: I like Drupal in a lot of ways, I don't like Symfony in many but it's getting work done. It takes time to get used to it depending on personal taste but yes there is more control over the html, I would say full.

@tangor: true, it's easy to modify things if they are made/designed for it (allowing it) but it's get dirty to mod something out of the range.

Featured Threads

Hot Threads This Week

Hot Threads This Month