Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 619283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:38:16+00:00 2026-05-13T18:38:16+00:00

Here is a question that has been bugging me for a while, nowadays it’s

  • 0

Here is a question that has been bugging me for a while, nowadays it’s considered a good practice to indent HTML code but I’ve some reservations indenting code in a MVC pattern, here is a (silly) example:

HTML Code:

<!DOCTYPE html>
<html>
<head>
<title>Testing MVC Indentation</title>
</head>

<body>

<?php View('h1', 'I am a Level 1 Header'); ?>

    <table>
        <tr>
            <td>
                <?php View('h1', 'I am a Level 1 Header Inside a Table'); ?>
            </td>
        </tr>
    </table>

</body>
</html>

To indent correctly, the first call to the h1 view (or partial) should return:

\t<h1>I am a Level 1 Header</h1>

While the second call to the h1 view should return:

\t\t\t\t<h1>I am a Level 1 Header Inside a Table</h1>

The h1 view however, has no idea of the indentation scope it’s in, so how the hell can it return the data properly indented? Also, ignoring indentation in views can disclose part of the application logic (check the HTML source code of this page after <div id="content"> for a real-world example):

<body>

<h1>I am a Level 1 Header</h1>

    <table>
        <tr>
            <td>
<h1>I am a Level 1 Header Inside a Table</h1>
            </td>
        </tr>
    </table>

</body>

Not indenting at all solves all problems, but it also makes it harder to read and maintain:

<body>

<h1>I am a Level 1 Header</h1>

<table>
<tr>
<td>
<h1>I am a Level 1 Header Inside a Table</h1>
</td>
</tr>
</table>

</body>

The only feasible solution I see to this problem is by using Tidy and output buffering, but I wonder if it’s worth the effort since it will make processing and loading unnecessarily (?) slow. Also, this will not make it easier the maintain the HTML code since it only indents the output, not the source.

I’m sorry for the “basic” question, but I’ve been focusing on business logic for the last years and I’ve been kinda disconnected with the presentation world – in the good old days my HTML code was all unindented, but then again I also used tables to design the layout – just trying to catch up now.

Any solutions / insights on this subject?


Related Questions:

  • Do you indent your HTML code?
  • Do you generate nicely formatted HTML?
  • How to properly indent PHP/HTML mixed code?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:38:16+00:00Added an answer on May 13, 2026 at 6:38 pm

    As mentioned there is a difference between source code indentation and output indentation. The indentation of the source code can be different from the indentation of the output, because the output is constructed dynamically. When writing templates, the readability of the source code is most important. You should focus on that first! Usually the HTML indentation of the output is a non-issue.

    Having said that, two practical approaches to get rid of indentation mismatch in your output:

    Use a templating language that can properly indent the output

    One example of the first is Haml, a templating language for Ruby. It takes a template like this:

    %body
      %h1 I am a Level 1 Header
      %table
        %tr
          %td
            %h1 I am a Level 1 Header Inside a Table
    

    The output will be neatly formatted HTML similar to your example, all properly indented.

    One obvious disadvantage of this approach is that you’re not really writing HTML in your templates, you’re writing in a different language with HTML-like semantics. This can be a problem, depending on who will maintain the views.

    Strip all superfluous whitespace from the output, don’t indent at all

    Some template languages have options to remove all superfluous whitespace. Smarty for PHP has a whitespace trimming plugin that does this job nicely, for example. It completely works around the output beautification problem by purposely making all output equally non-indented. It also saves a very marginal amount of bandwidth.

    A PHP-only solution would be to use ob_start() with its $output_callback handler (which is documented here). You can write a simple callback that strips the excessive whitespace, similar to the Smarty plugin. Contrary to using Tidy in the output callback, this will still allow you to flush the buffer before the end of the page to speed up long/slow pages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 530k
  • Answers 530k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The REST dissertation covers all the constraints. Specifically, they are… May 16, 2026 at 11:44 pm
  • Editorial Team
    Editorial Team added an answer This will work: if ($(clicked).parents('#somemenu').length) { // I am a… May 16, 2026 at 11:44 pm
  • Editorial Team
    Editorial Team added an answer If I use cfhttp, do I still need to install… May 16, 2026 at 11:44 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

This is a question that has been bugging me for a while. I started
This Jquery problem has been bugging me for a while now. I developed a
This is a question that's been bugging me for some time now: In photoshop/GIMP,
Please forgive a question that has been addressed in some form or fashion previously.
I am relatively new to MYSQL and have had an issue that has been
I am expecting a HashSet that has been created with a specified EqualityComparer to
When I delete a category that has been unchecked form the list of checkboxes
We're a small software company that has been using CVS and SVN for version
I have a connection protocol that has been defined by our customer. Data are
I've been working on a custom module that has a backend for admin. Until

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.