diff --git a/Text/Hamlet/Parse.hs b/Text/Hamlet/Parse.hs
--- a/Text/Hamlet/Parse.hs
+++ b/Text/Hamlet/Parse.hs
@@ -75,9 +75,9 @@
          backslash <|>
          try controlIf <|>
          try controlElseIf <|>
-         try (string "$else" >> eol >> return LineElse) <|>
+         try (string "$else" >> many (oneOf " \t") >> eol >> return LineElse) <|>
          try controlMaybe <|>
-         try (string "$nothing" >> eol >> return LineNothing) <|>
+         try (string "$nothing" >> many (oneOf " \t") >> eol >> return LineNothing) <|>
          try controlForall <|>
          tag <|>
          (do
@@ -106,12 +106,14 @@
         _ <- string "$if"
         spaces
         x <- deref False
+        _ <- many $ oneOf " \t"
         eol
         return $ LineIf x
     controlElseIf = do
         _ <- string "$elseif"
         spaces
         x <- deref False
+        _ <- many $ oneOf " \t"
         eol
         return $ LineElseIf x
     controlMaybe = do
@@ -120,6 +122,7 @@
         x <- deref False
         spaces
         y <- ident
+        _ <- many $ oneOf " \t"
         eol
         return $ LineMaybe x y
     controlForall = do
@@ -128,6 +131,7 @@
         x <- deref False
         spaces
         y <- ident
+        _ <- many $ oneOf " \t"
         eol
         return $ LineForall x y
     tag = do
diff --git a/hamlet.cabal b/hamlet.cabal
--- a/hamlet.cabal
+++ b/hamlet.cabal
@@ -1,5 +1,5 @@
 name:            hamlet
-version:         0.5.0.1
+version:         0.5.0.2
 license:         BSD3
 license-file:    LICENSE
 author:          Michael Snoyman <michael@snoyman.com>
diff --git a/runtests.hs b/runtests.hs
--- a/runtests.hs
+++ b/runtests.hs
@@ -78,6 +78,7 @@
     , testCase "cassius pseudo-class" casePseudo
     , testCase "different binding names" caseDiffBindNames
     , testCase "blank line" caseBlankLine
+    , testCase "leading spaces" caseLeadingSpaces
     ]
 
 data Url = Home | Sub SubUrl
@@ -709,3 +710,22 @@
 
     bar: baz
 |]
+
+caseLeadingSpaces :: Assertion
+caseLeadingSpaces =
+    celper "foo{bar:baz}" [$cassius|
+  foo
+    bar: baz
+|]
+
+caseTrailingSpaces :: Assertion
+caseTrailingSpaces = helper "" [$hamlet|
+$if   True   
+$elseif   False   
+$else   
+$maybe Nothing   x 
+$nothing  
+$forall   empty    x   
+|]
+  where
+    empty = []
