author: Jeffrey D. King
published: February 3, 2009
updated: March 26, 2009
A step-by-step guide to variables for your stylesheets. Native
CSS variables have long been
requested by practitioners of web-design. The debate regarding appropriateness of native variables has spanned the 14 year history of
CSS without nearing resolution. Regardless, you can use
PHP for variable handling (and more) in your
CSS today.
Using variables in CSS simplifies website development and maintenance. Consider the case of color management. Defining your color scheme as variables used throughout your stylesheet will facilitate minor color tweaks or major color refreshes. You can even use variables to manage spacial relationships relative to font size (without the headache of managing em based inheritances).
CSS does not directly facilitate variables. To include variables in your stylesheet, you can overlay a server-side scripting language (such as PHP).
First, you will need to define your stylesheet as a PHP document. Rather than naming your stylesheet style.css, name it style.php. You can then include this stylesheet in the normal fashion:
<link rel="stylesheet" type="text/css" media="screen" href="/style.php" />
Most browsers assume file names ending in .php indicate HTML output. Consequently we must add a bit of code to the top of your stylesheet to announce CSS output. On the first line of your style.php file, enter:
<?php header("Content-type: text/css"); ?>
Now declare your variables:
<?php
// color scheme
$mainBG = "#2e0303"; //burgandy
$contentBG = "#f3e7ca"; //cream
$textColor = "#333"; //dark gray
$fontSize = 16;
$lineHeight = 1.25*$fontSize; //20px
?>
These variables are now available for use throughout your stylesheet. I prefer to use shorthand PHP for inline use to increase code readability. (Since I control the server on which the stylesheet resides, and the file is not intended for general distribution, longhand is optional). Your stylesheet may include statements like these:
body {
background-color: <?= $mainBG ?>;
font-size: <?= $fontSize ?>px;
line-height: <?= $lineHeight ?>px;
}
#content {
width: <?= 33*$fontSize ?>px;
margin: <?= 2*$lineHeight ?>px auto;
border: 1px solid <?= $textColor ?>;
padding: <?= $lineHeight-1 ?>px;
//remove border width
color: <?= $textColor ?>;
background-color: <?= $mainBG ?>;
}
Do you want to adjust the font size but maintain typographic balance? Change one variable. Your client called and wants the text to be a little darker? Now your matching border will not be forgotten in the update. Use of variables in CSS is easy and worthwhile.
author: Jeffrey D. King
published: January 13, 2009
Typophiles naturally appreciate calligraphy. Here is a great video series introducing the Chancery Cursive script.
author: Jeffrey D. King
published: January 12, 2009
With some help from JavaScript,
HTML5 can be used today. Onward!
author: Jeffrey D. King
published: January 12, 2009
As monitors grow wider, web design must accommodate browser windows in excess of 1200 pixels. Undesigned white space visable on large monitors can leave an unfinished impression on important users.
As of January 2008, 38% of all computer monitors exceeded 1024×768 resolution. When updated for January 2009, expect that number to approach 50%. The growth in monitors larger than 1024×768 resolution is almost universally wide-screen format:
Recently, a great number of wide-screen format monitors have been introduced to the market. Many manufacturers have practically abandoned the traditional 4:3 format, instead opting to manufacture 16:10 models.
With 50 – 60% of the existing monitors at 1024 pixels wide or less, we can not extend the primary content beyond that limit. But, a significant and growing percentage of our visitors are viewing expanses of undesigned white space. This is further exaggerated with designs optimized for 800 pixel-wide browser windows.
One solution is to add decorative horizontal elements that extend the entire width of the browser window. This may be an navigation bar that stretches the entire width (while keeping the actual navigation links together with the content). It could be color striations that are tied into the design of the main content area. Asymmetrical elements set wide of the content areas may add visual interest that breaks up this excess white space.
Here are some examples of websites that implement these principles and display well in very wide browser windows:
These horizontal elements should be limited to non-content elements. Here are examples of what not to do:
This may be fine in some outlier condition (like when a sub-element of a page scrolls horizontally to show expanse of product offering), but it is generally ill-conceived. Most mouse scroll wheels do not scroll horizontally, and users of the web hate horizontal scroll.
author: Jeffrey D. King
published: December 31, 2008

This week, I found unexpected insight from a pair of Chucks. Converse All Star’s have never been known for their quality of construction, but the pair I bought has surprised me with exceptional design. They are beautiful — please do not waste your entire day enraptured by the picture above. Here are some design lessons I was reminded of by these kicks.
Lesson 1: Don’t Forget Your Value
Why do people buy Converse shoes? Off the top of my head:
- They are inexpensive
- Retro Fashion
- Nostalgia
- Brand Loyalty
When looking to refresh a design, you do not want to abandon core value. These sneakers honor their value. They remain reasonably priced. They incorporate materials from the era they reflect. They maintain the same form factor of designs past. They are unquestionably Chucks. What are your core values, and how do you defend them?
Lesson 2: Free Yourself From Constraints
The design of this particular pair of shoes centers on the main material choice (design is always better when inspiration for the whole is drawn from a unified source). Gone is the canvas that is common to every other pair of Chucks. In its place is a wonderful tweed; soft to the touch with delightful texture. This is not just a new color or pattern on the old construct. Additionally, the All Star logo at the inside ankle is noticeably modified. It is now a monochromatic embossed leather badge. This was a bold choice, but necessary as the next lesson will detail.
Lesson 3: Details Matter
The main material choice embodies a subtle quality. It would have been out of place to create a strong contrast with the standard white rubber on the toe and around the sole. Instead, a light brown tint has been introduced to lessen the contrast. It has also been incorporated into the shoe laces and lining canvas. The same reasoning must have motivated the above mentioned logo modification. As you seek to build credibility with your customer base, individual details may go unnoticed. But the sum of carefully considered particulars will speak to the quality of your service or product.
Lesson 4: Evolution, Not Revolution
This design works because it built on a good foundation. It did not forget where it came from, but still found ways to significantly improve. As brand owners, as we grow weary of our logo, or website, or brand’s name — we may be tempted to start over. This may be warranted if our current brand was poorly conceived. But be careful in doing so. If possible, it advisable to evolve your brand.
Lesson 5: Know Your Audience
Who buys Converse All Stars? Generally, people who’s fashion sense leans toward simple earthiness. Although this shoes roots are in basketball, today’s principle patron are not frequent readers of
Manolo’s Shoe Blog. Every design decision was properly made to appeal to the target demographic. The resulting shoe is one that will successfully sell. Success is rarely found in absence of understanding your customer. When you understand their motivations, you can deliver value that will be desired and appreciated.
author: Jeffrey D. King
published: November 25, 2008
updated: March 26, 2009
wp-Hyphenate 1.06 beta is now available for download.
author: Jeffrey D. King
published: November 16, 2008
Version 1.05 beta of wp-Hyphenate is now available for download:
http://kingdesk.com/projects/wp-hyphenate/
author: Jeffrey D. King
published: November 15, 2008
Shouting for attention just creates noise. Website owners and web designers can fall into the trap of emphasizing too many messages on the homepage. An effective website requires clarity of purpose and a strong editorial hand.
I was asked to review a website for a real estate agent in Arizona. Upon visiting the site, I was immediately confused and overwhelmed. It is not an exaggeration to say there were 50 messages on the front page, all screaming for attention. The result was a site where every piece of content was minimized.
This is a common mistake. We have a lot to say, and most of it is important. As business owners, we offer many services; we want to sell them all. But visitors to your web site do not care. If you overwhelm them with information, they will not know where to start, they will not expend the energy to figure out where to start, and they will leave your site with malice.
As you consider your website, these three observations will help you identify what changes will increase your website’s ability to meet your business objectives:
- There is a phenomenon called banner blindness. As consumers of web content, we train ourselves to avert our eyes from anything that looks like an advertisement. Jakob Nielsen wrote a must-read article illustrating the ineffectiveness of fancy formatting.
- Suppose a website visitor’s attention could be given a point value of 10. You have these 10 points to distribute to different parts of your site. You should identify your core objectives and distribute these 10 points in proportion to their importance. The site design should give prominence in scale with the distribution of points. Your front page will be loose content, but what remains will be effective.
- Ultimately, what is described in the two points above are aspects of a philosophy called “user centered design”. You must look at the site from the users perspective. Users determine whether they think a site will provide for their need within the first 2 seconds of their visit. If they don’t see immediate hope, they quickly click the back button. What is it that your users are looking for? This is very different than what you want to tell your users. Unless you first answer your user’s questions and build credibility in doing so, they will not care what you have to say.
If you consider these points, you will realize that they are applicative to much more than your web design. They require a rethinking of your business model. Ultimately, your website is a reflection of your business. If your website is unfocused and ineffective, perhaps it is because the business it is representing needs purposeful direction.
author: Jeffrey D. King
published: November 10, 2008
wp-Hyphenate 1.04 beta is now released. This latest version of the WordPress hyphenation plugin features support for over 40 languages. Download it at
http://kingdesk.com/projects/wp-hyphenate/
author: Jeffrey D. King
published: November 4, 2008
updated: November 5, 2008
Choosing the proper text to designate as your top level heading can improve your site’s accessibility and search engine ranking. This article shows you how to properly balance individual page names and overall site identification.
HTML 4.01 defines 6 levels of headings: <h1> – <h6>. These headings are hierarchical in nature, indicating the importance of their content from most important to least. It is a matter of best practice to label the title of each page with the <h1> tag.
Semantically, it is important the <h1> tag identify the core essense of the subject page. Such practice is also beneficial to the accessibility and search ranking of your site.
Yet in practice, many web designers consistently wrap the site identification (i.e. company name or website name) in the <h1> tag, leaving the remainder of the content to share the <h2> – <h6> tags. Now, it is completely appropriate to wrap the site identification in a <h1> tag on the homepage, but this practice should be resisted on subpages. But out of laziness, this is often done.
Let’s remove excuse for the lazy, and provide code to properly use the <h1> tag.
The following HTML and PHP code provides the logic to wrap the site identification in a <h1> tag on the home page, and in a simple <div> tag on the remainder of pages:
<?php
function isHomePage() {
if( ($_SERVER["REQUEST_URI"] == "/") || (substr($_SERVER["REQUEST_URI"], 0, 7) == "/index.") {
return TRUE;
}
return FALSE;
}
?>
<?php if( isHomePage() ) { ?>
<h1 id="siteID">Company Name</h1>
<?php } else { ?>
<div id="siteID">
<a href="/">Company Name</a>
</div>
<?php } ?>
Of course, some content management systems have built in functions that do the job of isHomePage(). For example, with WordPress you can use is_page('Home').
The following is an example of CSS for styling your <h1> and site identification:
h1 {
clear: both;
margin: 36px 0 18px;
font: 54px/54px "Palatino Linotype", serif;
text-align: left;
color: #333;
text-shadow: #ccc 3px 3px 3px;
text-transform: capitalize;
}
h1#siteID, div#siteID {
clear: both;
float: left;
height: 90px;
width: 400px;
margin: 0;
padding: 0;
text-indent: -9999px;
background: url('images/logo.png') no-repeat;
}
With this handling of the site identification, you are now free to identify the title of each subordinate page as <h1>.