Holy grail (web design)

Last updated
Holy grail Layout with Dropping Footer HolyGrail.svg
Holy grail Layout with Dropping Footer

The holy grail is a web page layout which has multiple equal-height columns that are defined with style sheets. It is commonly desired and implemented, but for many years, the various ways in which it could be implemented with available technologies all had drawbacks. [1] Because of this, finding an optimal implementation was likened to searching for the elusive Holy Grail.

Contents

The limitations of CSS and HTML, the desirability of semantically meaningful pages that rank well in search engines, and the deficiencies of various browsers combined historically to create a situation in which there was no way to create this type of layout that would be considered totally correct. As the underlying technologies did not provide a proper solution, web designers found various ways to work around the limitations. Common workarounds included changes in page structure, the addition of graphics, scripting, and the creative use of CSS. These methods were imperfect, inconvenient, and considered by some to be abuse of the web standards and their intent.

More recent web standards have provided much more complete and robust solutions for implementing this layout. In particular, the CSS Flexible Box Layout and CSS Grid Layout modules have both provided full solutions. [2] [3]

The problem

Many web pages require a layout with multiple (often three) columns, with the main page content in one column (often the center), and supplementary content such as menus and advertisements in the other columns (sidebars). These columns commonly require separate backgrounds, with borders between them, and should appear to be the same height no matter which column has the tallest content. A common requirement is that the sidebars have a fixed width, with the center column adjusting in size to fill the window (fluid or liquid layout). Another common requirement is that, when a page does not contain enough content to fill the screen, the footer should drop to the bottom of the browser window instead of leaving blank space underneath.

CSS Layout with floated columns and cleared footer, without holy grail features UnholyGrail.svg
CSS Layout with floated columns and cleared footer, without holy grail features

There were many obstacles to accomplishing this:

Known workarounds

Tables

Before the widespread implementation of CSS, designers commonly used tables to lay out pages. Sometimes they achieved their desired layout by nesting several tables inside each other. Although placing the columns inside table cells easily achieves the desired visual appearance, using a table is semantically incorrect, although the "role" WAI-ARIA HTML attribute can be set to "presentation" to regain semantic context. There is also no way to control the order of the columns in the page source.

Divisions with display:table

It is possible to make columns equal height using the CSS display property. [5] This requires nested container divisions that are set to display: table and display: table-row, and columns that are set to display: table-cell. This is semantically correct, as only the display is affected. However, this method lacks the ability to control the order of the source code. It will also not work with some older, unsupported browsers, such as Internet Explorer 7.

Faux columns

This method uses a background image which provides the background colors and vertical borders of all three columns. [6] The content of each column is enclosed in a division, and positioned over its background using techniques such as floats, negative margins, and relative positioning. The background is normally only a few pixels high, and is made to cover the page using the "repeat-y" attribute. This works fine for fixed-width layouts, and can be adapted for percentage-based variable-width pages, but cannot be used for fluid center pages.

JavaScript

In this method, after the page is loaded, a script measures the height of each of the columns, and sets the height of each column to the greater value. This will not work in browsers that do not support JavaScript, or have JavaScript disabled.

Fixed or absolute positioning

In this method, the corners of the column divisions are locked in a specific place on the page. [7] This may be acceptable or even desired, but does not solve the holy grail problem as it is a significantly different layout. The consequences of this method may include having content appearing below the columns (such as a footer) fixed at the screen bottom, blank space under the column content, and requiring scrollbars for each column to view all the content.

Nested divisions

A division with its background will grow in height to contain its content. This behavior is used to solve the problem by creating three divisions nested inside each other which provide the three backgrounds. These divisions are placed in their proper location using positioning techniques, and the three content divisions are placed inside the innermost background division, positioned over their respective backgrounds. The background divisions then become as tall as the tallest content division. The drawbacks of this method include the three non-semantic divisions, and the difficulty of positioning the elements of this complex layout. [8]

Border color

A simpler version of the nested division method entails using a single container division. The background properties of this division provide the background of the center column, and the left and right borders, which are given widths equal to the side column widths, provide the background colors of the sidebars. The content of each column is positioned over its background. This method still uses one non-semantic division, and makes it difficult to apply background images and borders to the sidebars. [9]

Bottom padding

By placing a large amount of padding at the bottom of the column container, the background will extend far below the column content. A corresponding negative margin will bring content below the columns back into its proper position. Positioning is simple in this method, as the container of a column's content also contains its background. A padding value of 32767px is the largest that will be recognized by all modern browsers. If the difference in column heights is greater than this, the background of the shorter column will not fully fill the column. [10]

Current solutions

The CSS3 standards contain modules which can properly lay out page elements. Two of these fully solve the holy grail problem. [1] [11] Support for these modules is lacking or otherwise deficient in older browsers. Many designers will implement these modules while providing compatible styling for older browsers, which will be overridden in modern browsers by the new syntax. Support for older browsers became less important in 2020, when extended support for Windows 7 ended, and use of Internet Explorer became less common.

CSS Flexible Box Layout (Flexbox)

The World Wide Web Consortium (W3C) has approached the layout issue through various proposals. The most mature proposal is the Flexible Box Layout Module (A.K.A. Flexbox), which is in Candidate Recommendation status as of November 2018. [12] Setting an element's display property to display: flex or display: inline-flex causes the element to become a new type of container (similar to a block or inline block, respectively), with new methods of positioning child objects. The W3C proposal contains an example which achieves the holy grail column layout using four simple CSS rules, and makes the layout responsive with a simple media query rule. The module can also be used to address many other layout issues.

The Flexible Box Layout Module is supported in all of the modern browsers, although Internet Explorer's implementation has issues. [13]

CSS Grid Layout

The Grid Layout Module similarly allows a designer to create a container for layout, which contains rows and columns of fixed or variable size into which elements can be placed. It is in Candidate Recommendation status as of December 2020. [14] It is supported in all modern browsers, however Internet Explorer's implementation has issues. [15] This module is a continuation of previous work done as the Grid Positioning Module, Template Layout Module, and Advanced Layout Module. [16]

One aspect of this module is the ability to create grid slots in a container semi-graphically, in a manner that has been described as "ASCII art", as in the superseded Template Layout module.

Although the Flexible Box module is capable of performing 2-dimensional page layout, its intended purpose is to position elements primarily along a single axis. Grid Layout is preferred for laying out complex pages, and pages whose layout varies greatly in a responsive design. [17]

History

The first three-column flanking design that used pure CSS was developed by Rob Chandanais of BlueRobot [18] for the site wrongwaygoback.com in 2001. At that point Neale Talbot was using JavaScript to determine the positioning of the right-hand column. Chandanais came up with an elegant solution for the positioning using pure CSS instead and soon after dubbed The Holy Grail by Eric Costello of Glish.com. [19]

See also

Related Research Articles

<span class="mw-page-title-main">HTML</span> HyperText Markup Language

HyperText Markup Language (HTML) is the standard markup language for documents designed to be displayed in a web browser. It defines the content and structure of web content. It is often assisted by technologies such as Cascading Style Sheets (CSS) and scripting languages such as JavaScript.

Web design encompasses many different skills and disciplines in the production and maintenance of websites. The different areas of web design include web graphic design; user interface design ; authoring, including standardised code and proprietary software; user experience design ; and search engine optimization. Often many individuals will work in teams covering different aspects of the design process, although some designers will cover them all. The term "web design" is normally used to describe the design process relating to the front-end design of a website including writing markup. Web design partially overlaps web engineering in the broader scope of web development. Web designers are expected to have an awareness of usability and be up to date with web accessibility guidelines.

An HTML element is a type of HTML document component, one of several types of HTML nodes. The first used version of HTML was written by Tim Berners-Lee in 1993 and there have since been many versions of HTML. The current de facto standard is governed by the industry group WHATWG and is known as the HTML Living Standard.

XSL-FO is a markup language for XML document formatting that is most often used to generate PDF files. XSL-FO is part of XSL, a set of W3C technologies designed for the transformation and formatting of XML data. The other parts of XSL are XSLT and XPath. Version 1.1 of XSL-FO was published in 2006.

A web style sheet is a form of separation of content and presentation for web design in which the markup of a webpage contains the page's semantic content and structure, but does not define its visual layout (style). Instead, the style is defined in an external style sheet file using a style sheet language such as CSS or XSLT. This design approach is identified as a "separation" because it largely supersedes the antecedent methodology in which a page's markup defined both style and structure.

In the context of a web browser, a frame is a part of a web page or browser window which displays content independent of its container, with the ability to load content independently. The HTML or media elements in a frame may come from a web site distinct from the site providing the enclosing content. This practice, known as framing, is today often regarded as a violation of same-origin policy.

A spacer GIF is a small, transparent GIF image that is used in web design and HTML coding. They were used to control the visual layout of HTML elements on a web page, at a time when the HTML standard alone did not allow this. They became mostly obsolete after the browser wars-fueled addition of layout attributes to HTML 2.0 table tags, and were mostly unused by the time Cascading Style Sheets became widely adopted.

In computing, quirks mode is an approach used by web browsers to maintain backward compatibility with web pages designed for old web browsers, instead of strictly complying with web standards in standards mode. This behavior has since been codified, so what was previously standards mode is now referred to as simply no quirks mode.

Tableless web design is a web design method that avoids the use of HTML tables for page layout control purposes. Instead of HTML tables, style sheet languages such as Cascading Style Sheets (CSS) are used to arrange elements and text on a web page.

In HTML, <div> and <span> tags are elements used to define parts of a document, so that they are identifiable when a unique classification is necessary. Where other HTML elements such as <p> (paragraph), <em> (emphasis), and so on, accurately represent the semantics of the content, the additional use of <span> and <div> tags leads to better accessibility for readers and easier maintainability for authors. Where no existing HTML element is applicable, <span> and <div> can valuably represent parts of a document so that HTML attributes such as class, id, lang, or dir can be applied.

<span class="mw-page-title-main">YUI Library</span>

The Yahoo! User Interface Library (YUI) is a discontinued open-source JavaScript library for building richly interactive web applications using techniques such as Ajax, DHTML, and DOM scripting. YUI includes several cores CSS resources. It is available under a BSD License. Development on YUI began in 2005 and Yahoo! properties such as My Yahoo! and the Yahoo! front page began using YUI in the summer of that year. YUI was released for public use in February 2006. It was actively developed by a core team of Yahoo! engineers.

<span class="mw-page-title-main">Column (typography)</span>

In typography, a column is one or more vertical blocks of content positioned on a page, separated by gutters or rules. Columns are most commonly used to break up large bodies of text that cannot fit in a single block of text on a page. Additionally, columns are used to improve page composition and readability. Newspapers very frequently use complex multi-column layouts to break up different stories and longer bodies of texts within a story. Column can also more generally refer to the vertical delineations created by a typographic grid system which type and image may be positioned. In page layout, the whitespace on the outside of the page are known as margins; the gap between two facing pages is also considered a gutter, since there are columns on both sides.

Extensible HyperText Markup Language (XHTML) is part of the family of XML markup languages which mirrors or extends versions of the widely used HyperText Markup Language (HTML), the language in which Web pages are formulated.

<span class="mw-page-title-main">CSS</span> Style sheet language

Cascading Style Sheets (CSS) is a style sheet language used for specifying the presentation and styling of a document written in a markup language such as HTML or XML. CSS is a cornerstone technology of the World Wide Web, alongside HTML and JavaScript.

XFrames is an XML format for combining and organizing web based documents together on a single webpage through the use of frames. Similarly to HTML Frames, XFrames can be made useful through its power to create a content frame that is scrollable while other frames - such as sidebar menus, the header and footer remain in place on the page. XFrames will be particularly useful to web developers who will be able to modify a single document and have that modification appear on all pages that contain the document within a frame.

<span class="mw-page-title-main">CSS box model</span> Model used for styling websites

In web development, the CSS box model refers to how HTML elements are modeled in browser engines and how the dimensions of those HTML elements are derived from CSS properties. It is a fundamental concept for the composition of HTML webpages. The guidelines of the box model are described by web standards World Wide Web Consortium (W3C) specifically the CSS Working Group. For much of the late-1990s and early 2000s there had been non-standard compliant implementations of the box model in mainstream browsers. With the advent of CSS2 in 1998, which introduced the box-sizing property, the problem had mostly been resolved.

<span class="mw-page-title-main">Responsive web design</span> Approach to web design for making web pages render well on a variety of devices

Responsive web design (RWD) or responsive design is an approach to web design that aims to make web pages render well on a variety of devices and window or screen sizes from minimum to maximum display size to ensure usability and satisfaction.

<span class="mw-page-title-main">Bootstrap (front-end framework)</span> Web design front-end

Bootstrap is a free and open-source CSS framework directed at responsive, mobile-first front-end web development. It contains HTML, CSS and (optionally) JavaScript-based design templates for typography, forms, buttons, navigation, and other interface components.

CSS Flexible Box Layout, commonly known as Flexbox, is a CSS web layout model. It is in the W3C's candidate recommendation (CR) stage. The flex layout allows responsive elements within a container to be automatically arranged depending on viewport size.

<span class="mw-page-title-main">CSS grid layout</span> CSS properties for complex responsive webpages

In Cascading Style Sheets, CSS grid layout or CSS grid creates complex responsive web design grid layouts more easily and consistently across browsers. Historically, there have been other methods for controlling web page layout methods, such as tables, floats, and more recently, CSS Flexible Box Layout (flexbox). CSS grid is currently not an official standard although it has been adopted by the recent versions of all current major browsers.

References

  1. 1 2 .appendTo: Solving the Holy Grail Layout
  2. "Holy Grail Layout — Solved by Flexbox — Cleaner, hack-free CSS". philipwalton.github.io. Retrieved 2019-03-26.
  3. "The Holy Grail Layout with 5 Lines of CSS". CSS-Tricks. Retrieved 2019-03-26.
  4. "HTML Standard". html.spec.whatwg.org.
  5. Build Internet: Four Methods to Create Equal Height Columns
  6. Cederholm, Dan (January 9, 2004). "Faux Columns". A List Apart.
  7. "Tableless layout HOWTO". www.w3.org.
  8. "Equal-Height Columns (CSS Grid, Flexbox, & Table Methods)". Matthew James Taylor.
  9. Pearce, Alan (August 6, 2008). "Multi-Column Layouts Climb Out of the Box". A List Apart.
  10. "CSS Equal Height Columns: Practical Guide With Code Examples". www.positioniseverything.net. December 15, 2021.
  11. "Holy Grail Layout — Solved by Flexbox — Cleaner, hack-free CSS". philipwalton.github.io.
  12. "CSS Flexible Box Layout Module Level 1". www.w3.org.
  13. "Can I use... Support tables for HTML5, CSS3, etc". CanIUse.com. Retrieved 2016-02-27.
  14. "CSS Grid Layout Module Level 1". www.w3.org.
  15. "CSS Grid Layout (level 1) | Can I use... Support tables for HTML5, CSS3, etc". caniuse.com.
  16. Bos, Bert; Acebal, César (March 26, 2015). "CSS Template Layout Module". www.w3.org.
  17. "Why Flexboxes Aren't Good for Page Layout — Tab Completion". www.xanthir.com.
  18. "Blue Robot | Messaging, Chat Bots & Social Experiences". www.bluerobot.com. Archived from the original on April 25, 2013.
  19. "Glish.com Layout Techniques – 3 columns, The Holy Grail". Archived from the original on 2008-12-01. Retrieved 2013-05-15.