Notes on modern CSS and HTML

...for want of a better place to put and organize them.

Once you've analyzed the structure of your pages, it's time to take a look under the proverbial hood and analyze your existing markup for presentational HTML that can be replaced with structural markup.

At the begining, give each div a border. For example, div {border: 1px dotted gray; padding: .5em} This will help you see where they begin and end, and also whether or not you have any nesting going on.

Write your CSS for element selectors first (<html>, <body>, <p>, <h1>, <h2>, <ul>, <li>, etc.)

Use contextual or descendant selectors as much as possible. This will keep your markup much cleaner. For example, #subnav li {border: 1px solid black; padding: .5em; display: inline} will only affect list items that occur within your subnav div.

Mason's tutorial on CSS styles

CSS styles

#ids are generally for unique, one-shot cases whereas,
.classes are rules expected to apply here and there when needed (like object classes).

 <div id="test">
	Text here...

 #test { font-style: italic; }

will make the paragraph text above always italic.

 <p id="test">
 Text here...

will also be in italics no matter where, but here the example cries for a class (<p class="...">) because it's not within the <div> and it's likely going to be useful elsewhere.

In the example above, <td> text will also be italic. If that's not the intent, then maybe do <td class="not-italic"> (or that effect) to prevent. You can also use !important (but don't do it).

For margins, padding, etc.

Remember that margins are on the outside, padding is on the inside of the <div> or other element. The CSS box model is:


      +-- border -------------------------
      |     padding
      |     +-----------------------------
      |     |
      |     |    content
      |     |

Links to great sites with CSS suggestions

Useful and ready-to-use HTML 5 snippets

I ripped this collection off from a post on DZone; the author ripped them off from elsewhere.

HTML5 Starter Template

When starting a new project, you need a starter template. Here is a concise and clean template to serve as a basis for your HTML5 projects.

<!DOCTYPE html>
<meta charset="utf-8">
<!--[if lt IE 9]>
<script src=""></script>


Get Directions Form (Google Maps)

Here is a simple yet powerful code to create a form where the user can enter his location to get directions to a specific place. Very useful for contact pages.

<form action="" method="get" target="_blank">
   <label for="saddr">Enter your location</label>
   <input type="text" name="saddr" />
   <input type="hidden" name="daddr" value="350 5th Ave New York, NY 10018 (Empire State Building)" />
   <input type="submit" value="Get directions" />

Source: Source:

Base64 Encode of a 1*1px “spacer” GIF

I don’t recommend using transparent “spacer” gifs, but I know that even in 2013, many people are still using them from time to time. If you’re one of them, you’ll probably enjoy this Base64 encode of a 1*1px “spacer” gif. Way better than using an image.


Source: Source:

Regexp Pattern for Email Validation

HTML5 allows, among other things, validating emails using a regular expression pattern. Here is a ready to use input field with the regexp pattern to validate an email address.

<input type="text" title="email" required pattern="[^@]+@[^@]+\.[a-zA-Z]{2,6}" />

Source: Source:

Valid Flash Embed

Are you often embedding Flash files into your html pages? If yes, you’d better save the valid embedded code below for future use.

<object type="application/x-shockwave-flash" 
  width="0" height="0">
  <param name="movie" value="your-flash-file.swf" />
  <param name="quality" value="high"/>

Source: Source:

HTML5 Video with Flash Fallback

Another great feature of the new HTML5 specification is definitely the video tag which allows you to easily embed video files. But unfortunately, some browsers can’t deal with embedded HTML5 video. So, here is a complete code snippet with a flash fallback for older browsers.

<video width="640" height="360" controls>
	<source src="__VIDEO__.MP4"  type="video/mp4" />
	<source src="__VIDEO__.OGV"  type="video/ogg" />
	<object width="640" height="360" type="application/x-shockwave-flash" data="__FLASH__.SWF">
		<param name="movie" value="__FLASH__.SWF" />
		<param name="flashvars" value="controlbar=over&image=__POSTER__.JPG&file=__VIDEO__.MP4" />
		<img src="__VIDEO__.JPG" width="640" height="360" alt="__TITLE__"
		     title="No video playback capabilities, please download the video below" />

Source: Source:

iPhone Call & SMS Links

With the release of the iPhone, Apple introduced a quick way to create call and SMS links. Here is a code snippet to keep in your library.

<a href="tel:1-408-555-5555">1-408-555-5555</a>
<a href="sms:1-408-555-1212">New SMS Message</a>

Source: Source:…

Autocompletion with HTML5 Datalists

Using the datalist element, HTML5 allows you to create a list of data to autocomplete an input field. Super useful! Here is a code snippet to re-use in your own projects.

<input name="frameworks" list="frameworks" />

<datalist id="frameworks">
	<option value="MooTools">
	<option value="Moobile">
	<option value="Dojo Toolkit">
	<option value="jQuery">
	<option value="YUI">

Source: Source:

Country Drop-down List for Web Forms

Here’s another time saver: A ready-to-use dropdown list with all countries. Due to the size of the code, please see the source directly.

Source: Source:

Downloadable Files

HTML5 allows you to force download of files using the download attribute. Here is a standard link to a downloadable file.

<!-- will download as "expenses.pdf" -->
<a href="/files/adlafjlxjewfasd89asd8f.pdf" download="expenses.pdf">Download Your Expense Report</a>

Useful line-drawing characters

The initial use of this table was for converting Linux tree representations to display in HTML.

horizontal bar &#9472;
vertical bar &#9474;
last indent &#9492;
indent &#9500;